Tuesday, October 20, 2009

Add a Nautilus launcher

Many times you may have to execute your programs as root user in Ubuntu and we most often use 'sudo' when working in a terminal. However, the files and directories created under sudo will be not be accessible by the default user from the File Explorer. It can be circumvented by launching a nautilus window from the terminal.
$gksudo nautilus

You can also add a launcher on your desktop and set the command of that launcher to "gksudo nautilus". Double-clicking on that launcher would launch a File Explorer with root permission. You can do pretty much everything you do as a sudo in command line.

Friday, October 16, 2009

Select the wx version while importing

My ubuntu 9.04 had wx python version 2.6 by default and I installed version 2.8 for one of my lab work. But I wasn't aware of the fact before that 9.04 runs wx 2.6 by default. Initially, my project did not work due to unknown methods associated with the wx python objects I used. I had to then google to find out which version has these methods and which one lacks. I finally figured out by few trial and errors that python (2.5) on my system chose wxpython 2.6 by default. Fortunately, wx now offers a new package called wxversion which you can use to select the version of wxpython you wish to run if you have multiple versions of wxpython installed.

import wxversion
wxversion.select("2.8")
import wx #imports wxpython 2.8

If the requested version is not found, it selects the default version (2.6 in this case). You can find more information regarding this in wxversion.py file included in your python distribution. ( e.g. /usr/lib/python2.5/site-packages/wxversion.py or /usr/lib/python2.6/dist-packages/wxversion.py).

You can also dynamically check the version of wxpython you have imported using wx constants.

>>> print wx.VERSION_STRING #returns version as a string
2.8.10.1
>>> print wx.VERSION #returns version values in a tuple
(2, 8, 10, 1, '')