显示标签为“ubuntu”的博文。显示所有博文
显示标签为“ubuntu”的博文。显示所有博文

2011年12月12日星期一

Ubuntu 环境变量的设置


持久性的环境变量



到目前为止,我们只讨论临时设置一个环境变量的方式,当设置它时所在的shell会话被关闭时这个环境变量也就失效了。有人可能会问,是否有一种方法来永久设置一个环境变量为特定的值。

Note: 下面提到的Shell配置文件只为特定Shells和桌面环境所读取,不应该被以其他方式使用。

会话范围环境变量


只影响特定用户的环境变量 (而不是整个系统)应该在下面文件中设置:

  • ~/.pam_environment - 这个文件是特别为设置用户的环境变量.它并不是一个脚本文件,而是由每行一句声明表达式组成


Note:使用 .pam_environment 需要重新登录以便初始化环境变量. 仅仅重新打开 terminal 并不能够立即使用这些变量.

如果你正在使用 KDE, 请查看 the KDE User-base page on this topic.

不推荐在下面文件中设置:

  • ~/.profile - This is probably the best file for placing environment variable assignments, since it gets executed automatically by the Display Manager during the start-up process desktop session as well as by the login shell when one logs-in from the textual console.

  • ~/.bash_profile or ~./bash_login - If one of these file exist, bash executes it rather then "~/.profile" when it is started as a login shell. (Bash will prefer "~/.bash_profile" to "~/.bash_login"). However, these files won't influence a graphical session by default.

  • ~/.bashrc - Because of the way Ubuntu currently sets up the various script files by default, this may be the easiest place to set variables in. The default configuration nearly guarantees that this file will be executed in each and every invocation of bash as well as while logging in to the graphical environment. However, performance-wise this may not be the best thing to do since it will cause values to be unnecessarily set many times.



系统范围环境变量


影响整个系统的环境变量设置 (而不是仅仅一个用户) 不应该放在任何系统或桌面会话加载时被执行的系统级别的脚本中,而应该在下面文件中设置:

  • /etc/environment - 这个文件是特别为设置系统范围的环境变量. 它并不是一个脚本文件,而是由每行一句声明表达式组成. 特别地,这个文件存储了系统范围的 locale 和 path 设置.


不推荐在以下文件中设置:

  • /etc/profile - This file gets executed whenever a bash login shell is entered (e.g. when logging in from the console or over ssh), as well as by the Display Manager when the desktop session loads. This is probably the file you will get referred to when asking veteran UNIX system administrators about environment variables. In Ubuntu, however, this file does little more then invoke the /etc/bash.bashrc file.

  • /etc/bash.bashrc - This is the system-wide version of the ~/.bashrc file. Ubuntu is configured by default to execute this file whenever a user enters a shell or the desktop environment.


Note: 当处理多用户桌面系统时,把设置放在上面提到的用户的~/.pam_environment 文件中是比较合适的,而不是系统范围的文件,因为这些文件不需要root权限来编辑,并且很容易在多个系统中移动。

原文链接:https://help.ubuntu.com/community/EnvironmentVariables

2010年10月13日星期三

使用wxWidgets时发现的一些bug及解决方案

Ubuntu中

wxDC类

bug 1.  使用SetLogicalOrigin时必须确保坐标轴为默认方向(SetAxisOrientation(true,false)),使用后可更改为需要的方向(SetAxisOrientation(true,true));

解决方案:查看wxGTK源代码文件dc.cpp可看到如下代码:

void wxDC::SetLogicalOrigin( wxCoord x, wxCoord y )
{
m_logicalOriginX = x * m_signX; // is this still correct ?
m_logicalOriginY = y * m_signY;
ComputeScaleAndOrigin();
}

作者也察觉到了这里可能有问题,标注了// is this still correct ?


将上面代码修改如下即可:



void wxDC::SetLogicalOrigin( wxCoord x, wxCoord y )
{
m_logicalOriginX = x ;
m_logicalOriginY = y ;
ComputeScaleAndOrigin();
}

bug 2. 使用SetUserScale函数设置放大倍数时画笔(wxPen)的宽度随之放大,但在xp系统下画笔宽度不变。也就是说如果设置SetUserScale(1,1000),则画笔宽度可能变为1000像素,导致无法成功绘制图像。

解决方案:从源代码文件dc.cpp中我们可以看到SetUserScale函数的定义:

void wxDC::SetUserScale( double x, double y )
{
// allow negative ? -> no
m_userScaleX = x;
m_userScaleY = y;
ComputeScaleAndOrigin();
}

在源代码文件dcclient.cpp中我们可以看到wxWindowDC::ComputeScaleAndOrigin()函数的定义:



void wxWindowDC::ComputeScaleAndOrigin()
{
const wxRealPoint origScale(m_scaleX, m_scaleY);

wxDC::ComputeScaleAndOrigin();

// if scale has changed call SetPen to recalulate the line width
if ( wxRealPoint(m_scaleX, m_scaleY) != origScale && m_pen.Ok() )
{
// this is a bit artificial, but we need to force wxDC to think the pen
// has changed
wxPen pen = m_pen;
m_pen = wxNullPen;
SetPen( pen );
}
}

进一步我们可以找到函数 wxWindowDC::SetPen 的定义



void wxWindowDC::SetPen( const wxPen &pen )

{

wxCHECK_RET( Ok(), wxT(“invalid window dc”) );
if (m_pen == pen) return;
m_pen = pen;
if (!m_pen.Ok()) return;
if (!m_window) return;

gint width = m_pen.GetWidth();
if (width <= 0)
{
// CMB: if width is non-zero scale it with the dc
width = 1;
}
else
{
// X doesn’t allow different width in x and y and so we take
// the average
double w = 0.5 +
( fabs((double) XLOG2DEVREL(width)) +
fabs((double) YLOG2DEVREL(width)) ) / 2.0;
width = (int)w; //注意,这个宽度是最终绘制的宽度
if ( !width )
{
// width can’t be 0 or an internal GTK error occurs inside
// gdk_gc_set_dashes() below
width = 1;
}
}

//…… 中间的代码省略

gdk_gc_set_line_attributes( m_penGC, width, lineStyle, capStyle, joinStyle );

m_pen.GetColour().CalcPixel( m_cmap );

gdk_gc_set_foreground( m_penGC, m_pen.GetColour().GetColor() );

}

综合以上代码分析我们可以看到:当我们调用函数SetUserScale 放大绘制的图形时,wxGTK同时放大了绘制线条的宽度。


解决办法是删除 width = (int)w;  这行代码。



修改源代码后,重新编译wxGTK即可。



XP中

wxDateTime

bug 1. wxDateTime::Format 函数不支持中文字符的格式化。

解决方案:暂时可以使用wxString::Format函数替代。

2010年8月27日星期五

ubuntu 安装小记

从来没有想到ubuntu的安装会这么简单。


像大多数人一样我之前用的是xp系统,在安装ubuntu之前不想离开xp,何况电脑上还有大量数据,迁移起来会是不小的工程,于是就想着先把E盘分为两个盘,然后在F盘上安装ubuntu。下面是今天安装的过程。



  • 1. 在google上搜索并下载了两个磁盘分区软件,准备把E盘的空闲空间分为F盘,结果折腾了有一个多小时都没有成功,分区软件运行一会就没反应了,试了几次都是这样,E盘系统也有些损坏,害我用xp自带的文件系统修复命令修复了一遍,幸亏E盘数据没有丢失。看来这个方法行不通。

  • 2. 在网上搜索了大量xp系统上安装ubuntu的文章,说的都比较简单,于是就想着不管那么多了,直接在E盘上安装算了,如果数据丢失了也不要紧,反正都是电影音乐图片之类的文件。

  • 3.从网上下载了ubuntu-10 iso镜像文件 和 一个免费刻盘软件BurnAware Free 并刻盘。

  • 4.电脑光盘启动,接下来就是ubuntu非常人性化的图形安装界面,每一步都非常简单,选择语言、选择时区、选择键盘方式。

  • 5. 最关键一步的是选择分区那一步,选择自定义分区,然后选择E盘,增加一个不做任何操作的分区,ubuntu会自动将E盘以前的数据迁移. 接下来增加一个2G的邏辑分区给交换空间,然后增加一个20G的主分区并选择EXT4日志文件系统.

  • 6. 就是这些了,接下来按照ubuntu默认安装就行了.

  • 7.安装完成后进入ubuntu, 你会惊讶地发现,在ubuntu里面竟然可以查看并修改之前xp上面的文件.


所以,所以这么简单,快迁移到ubuntu上面来吧,一样有图形用戶界面,最关健的是速度飞快.