Feeds:
Posts
Comments

Archive for the ‘linux’ Category

I’ve been working on enhancing the user interface of my LeMMA app, which is written in Python/Tkinter. This discusses some of my thoughts while researching the current state of the art with regards to using Tkinter.

Why did I choose Tkinter when there are other widget libraries that looks better and works natively? My decision was mainly based on the ease of installation by users, i.e. no installation required. Because Tkinter comes standard with Python on almost all platforms (except on Ubuntu where you must explicitly install the python-tk package). I don’t want my users to have to install any third-party widget libraries. Users should be able to simply unzip and run the app immediately.

(For the record, I’ve used PyGtk and like it, but I still haven’t found an easy way to install GTK on Windows, other than installing other GTK apps like GIMP or pidgin…)

However, Tkinter suffers from the following issues:

  • Dated look and feel: Surprisingly, despite Python’s widespread use in the major Linux distros, Tkinter looks ugliest on Linux. For Gnome-based distros, it appears that the PyGtk bridge is a more popular choice for GUI Python apps.
  • Lack of good documentation: Yes, there is the Tk documentation, but what is mentioned there is not necessarily available in Python. And some options don’t work for some widgets/platforms. For certain platforms, e.g. Mac you have to resort to direct Tk calls to get certain behavior, and even then not everything described works. You can find some good resources at NMT and effbot.org, but they are not complete. It’s no wonder that we often refer to it as Tk ‘folklore’.

And some platform-specific problems I discovered are:

  • On Linux, the menu in the OptionMenu widget won’t display if it is taller than screen height. The menubutton+menu approach works, but it doesn’t scroll so it is still not useable. Mac and Windows implementations use native menus that can scroll.
  • Mac doesn’t support flat relief buttons (well, I use them in LeMMA, so they looked really bad).
  • Tix is currently broken at least on Ubuntu due to version mismatch in packaging (Ubuntu python is compiled with Tk 8.5, i.e. ttk support). Ok, this is not really a valid problem, but no Tix-love until Ubuntu fixes its repositories. What? You mean there isn’t any Python Tix apps that people are complaining are broken in Ubuntu…?

The next-generation Tkinter is ttk (Tiled Tk), which is able to use native widgets in Mac and Windows, however:

  • It is NOT a drop-in replacement for Tk. Current apps won’t be automagically beautified. You will need to explicitly import the ttk module.
  • It’s not just a simple import statement. Only a subset of widget options are supported in ttk, and the style options were removed. Styling in ttk has a different approach. Perhaps this is a better way, but it means that old Tkinter programs wanting a fresh coat of paint need to be re-coded.
  • Even if a simple import works, all subclassed Tk widgets will NOT get the benefit of ttk, so no third-party widget extensions, or you will get a weird ‘mashup’ of different widget look-and-feel.
  • On the plus side, assuming the documentation at the TkDocs website is accurate, the standard extended widgets will be styled eventually in future Python releases (version 2.7?). That’s not the case yet for the current Tkinter/Tk8.5 implementations as far as I know.
  • Widgets on Linux will look somewhat better, but it’s still ugly, partly because there is no one standard native widget engine, unlike Mac and Windows. Hopefully, at least GTK and Qt can be supported in future, as they are what’s used in most modern Linux distros today. I don’t think the built-in theming support in ttk is the correct way ahead (I’m still looking for instructions on how to design and install new themes for use in Tkinter).

We are finally seeing the beginning of real cross-platform GUI development with Tkinter, using native widgets, but there are still quite a few raw edges. For now I’ll use the following approach:

  • Current: Use the Tk 8.4 widgets set, and write my own pure Tk widgets extensions, avoiding the use of all third-party Tk extensions.
  • Near-future: Re-code my app to auto-detect the availability of ttk and continue to work with and without it. A command-line option to force either selection is also recommended, in case ttk doesn’t work for some users.
  • (Far?) future: When ttk is finally mature, stable and widespread, to Use only ttk widgets.

Another consideration is the eventual migration of your app to Python 3. That might be good time to make a clean break between 2.x + Tk8.4 apps and 3.x + Tk8.5/Ttk apps.

Of course, if you just want to write new Python apps for the future and don’t care about the current installed base, by all means go ahead and write in Python 3 (which is already supported in Python 2.6) and ttk. We need good apps to encourage people to switch anyway. 🙂

Advertisements

Read Full Post »

Having been using git for some time now, I decided it was time I get comfortable with branching. I was trying to configure a color bash prompt that can tell me which git branch I’m currently in (using “__git_ps1”), with a color indicator to tell me whether the working directory is dirty or not. There are a lot of examples online, but I soon hit a problem – long lines get wrapped on the same line instead of moving to the next line. And trying to backspace reveals an ‘invisible wall’.

The problem is because in order to get the ‘dirty’ color indicator, I called an external command from within the pompt. Now the way to return a string from a bash function is to use echo. This is the catch: color ANSI codes in the output are also counted by bash as part of the prompt when determining when to wrap, and this screws it up.

The Bash Prompt How-To says that non-printing characters (that includes the ANSI color codes) must be delimited with \[ and \]. However,I found that this does not work if echoed from a function. They must be defined in $PS1 directly otherwise bash cannot interpret it.

I could workaround this problem by defining another function to return a color only, in addition to the one for the git branch, but since deciding on the color also means deciding whether we are in a git repository in the first place, this is essentially doing the same thing twice and is not elegant anymore. I decided to settle for printing an asterisk as a dirty flag instead.

I’m not familiar with the history of terminal programs, but I think perhaps it shouldn’t be too hard to get bash to autodetect the ANSI color codes as non-printing characters and not count them into the prompt length? It will still be compatible with the use of \[ and \], and it will save a lot new users a lot of frustration.

Read Full Post »

Ubuntu 9.04 is out!

I just upgraded to Ubuntu 9.04 on my laptop and netbook. The upgrade experience was quite smooth, but I’m expecting the bugs to start appearing. So far, I’ve found that gnome system monitor is crashing for some reason. I don’t feel very ‘jaunty’ yet.

I also tried installing the real-time kernel on the netbook but it failed to boot. Disappointing, as the real-time kernel has not been working for me since 8.10.

Update 1 May 09: Looks like the major issue with Jaunty is the graphics. EXA is supposed to be a new and better way to do graphics than XAA, but for me the performance is much worse (especially in Flash, which is already bad enough under Linux). On my old Dell D600 (ATI Radeon Mobility 9000) I had to set AccelMethod back to XAA. On my Asus 1000HE (Intel 945GME) setting XAA doesn’t work – I’m still studying the options. The new audio mixer also has some quirks. The only plus side for me is that on the Asus 1000HE touchpad edge scrolling is now enabled, but all in all I think Jaunty is pretty much a flop. No point getting faster boot if the system lags after booting.

Read Full Post »

After installing Ubuntu on my Asus 1000HE, I decided to repartition the hard disk, so I backed up everything using fsarchiver and restore everything after I was done.

I found that the UUID for the swap partition has changed from the repartitioning so I edited /etc/fstab to mount the new swap partition. Then I discovered that my Ubuntu boot splash refused to stay in graphical mode. It will always drop to text at the “resume image” step. What to do? Google for the solution!

Turns out that this step in the boot process is looking for the swap partition at the old UUID.

There are two ways to fix this:

METHOD 1: Recreate the swap partition with the old UUID. Revert the /etc/fstab entry as well.

METHOD 2: Update /etc/initramfs-tools/conf.d/resume to reflect the new swap UUID, then run ‘sudo update-initramfs -u’ to update the initramfs image.

And voila, graphical boot all the way to the login screen!

Read Full Post »

Set up a minimal Ubuntu server in VirtualBox

These are my notes on setting up a minimal Ubuntu server in VirtualBox. The host is Windows Vista. I work in a mostly Java shop, so the focus here is on setting up a typical Apache/Tomcat/MySQL web stack with as small a footprint as I can, for development/testing purposes.

Initial setup:

  • If you need to use port forwarding feature, get VirtualBox 2.1.2 (latest version as of time of writing). This feature is broken in 2.1.0.
  • Download the minimal Ubuntu iso, install as normal. Make sure you have a working Internet connection, as this downloads the packages from the Internet. The minimal install will take up about 1Gb. Perl and Python are already included as part of the minimal install.
  • Try pinging out from the server to test VirtualBox NAT is working.
  • If network has problems, check /etc/udev/rules.d/70-persistent-net.rules to see which MAC address got mapped to eth0. you need to do this if you regenerate a new MAC address in VirtualBox.
  • Set the correct timezone: dpkg-reconfigure tzdata

Install the following packages (note that you can combine them all into a single apt-get line):

  • Sun JDK:  sudo apt-get install sun-java6-jdk
  • Apache 2: sudo apache2
  • MySQL: sudo apt-get mysql
  • Postfix (for sending emails): sudo apt-get postfix
  • Subversion: sudo apt-get svn
  • SSH: sudo apt-get ssh

The following are installed manually, because Ubuntu’s packages include gcj dependencies (which takes up about 20 Mb), but we don’t need/want that because we are using Sun’s Java.

Install optional packages, for convenience:

  • Zip: sudo apt-get zip
  • Vim: sudo apt-get vim (vim-tiny is installed by minimal but has no syntax highlighting)

Let’s set up the port forwarding for the VM first before continuing. This will allow you to access apache and SSH. Do this when the VM is shut down, replace “UbuDev” with the name of your VM.

cd "\Program Files\Sun\xVM VirtualBox"
VBoxManage setextradata UbuDev "VBoxInternal/Devices/pcnet/0/LUN#0/Config/apache/HostPort" 8888
VBoxManage setextradata UbuDev "VBoxInternal/Devices/pcnet/0/LUN#0/Config/apache/GuestPort" 80
VBoxManage setextradata UbuDev "VBoxInternal/Devices/pcnet/0/LUN#0/Config/apache/Protocol" TCP
VBoxManage setextradata UbuDev "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/HostPort" 2222
VBoxManage setextradata UbuDev "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/GuestPort" 22
VBoxManage setextradata UbuDev "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/Protocol" TCP
VBoxManage setextradata UbuDev "VBoxInternal/Devices/pcnet/0/LUN#0/Config/tomcat/HostPort" 8880
VBoxManage setextradata UbuDev "VBoxInternal/Devices/pcnet/0/LUN#0/Config/tomcat/GuestPort" 8080
VBoxManage setextradata UbuDev "VBoxInternal/Devices/pcnet/0/LUN#0/Config/tomcat/Protocol" TCP
VBoxManage setextradata UbuDev "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssl/HostPort" 8443
VBoxManage setextradata UbuDev "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssl/GuestPort" 443
VBoxManage setextradata UbuDev "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssl/Protocol" TCP
  • Use PuTTY to check that you can connect to the guest SSH server through port 2222 on the host.
  • For Apache, check that you can access the default “It works!” page at port 8888.
  • Check Tomcat at port 8880 (Tomcat by default will be at guest port 8080).

Set up your site on Apache:

  • Decide where to put your own document root, logs, ssl certs directories. I won’t go into details. Please read the Apache docs and examples.
  • Set up a site and enable it:
    • Use “sudo a2ensite” and “a2dissite” to manage sites
  • Enable mod_ssl (use “sudo a2enmod” and “a2dismod”). I won’t go into details of how to set up an SSL-enabled site. Please read the Apache docs and examples.
  • Generate and configure new self-signed cert:
    • sudo /usr/sbin/make-ssl-cert /usr/share/ssl-cert/ssleay.cnf /etc/apache2/ssl/apache.pem
  • Note: If you try to use HTTPS on port 80 (host port 8888), VB proxy appears to return a “record too long” error. Check which port you are trying to access first before wasting time trying to Google for a solution!

Set up Tomcat:

  • Set up logrotate for Tomcat (because we installed this manually). This is quite standard, you can get many examples from the Web.
  • logrotate is run daily by default, see /etc/cron.daily

We’ll use mod_proxy_ajp (comes with Apache 2 out of the box) to connect Apache to Tomcat:

  • Enable mod_proxy_ajp
  • Secure the proxy first (from Apache docs):
      <Proxy *>
        Order Deny,Allow
        Deny from all
        Allow from [your allowed IP addresses]      
      </Proxy>
  • Use ProxyPass and ProxyPassReverse to setup the connections to port 8009 (default ajp port)
  • For the configured URLs, try to access them via port 8888 on the host.
  • If ok, you can disable 8080 and 8443 HTTP handlers in tomcat config, so everything will pass through Apache.

Read Full Post »

Playing midi with audacious & AMidi plugin

I use the audacious player with AMidi plugin for playing midi files (and most audio files). There are two choices of backends – Timidity and Fluidsynth. I used to use the Timidity backend but found that lately the playback keeps skipping with my soundfonts, so I switched to the Fluidsynth backend and it’s much better now.

Read Full Post »

Mounting samba shares in Ubuntu on ps3

Somehow I could only get my samba share (running from an NSLU2) mounted on ps3 Ubuntu 8.10 by adding the ‘nounix’ option. Before that I kept getting error 20 or error 6. The ‘nounix’ option isn’t in the man pages, I didn’t need to use this on my laptop (also running 8.10), and both smbfs versions are the same on both the laptop and ps3, so go figure…

Read Full Post »

Older Posts »