Posts about Computing

Creating Linux Applications Using PyGTK

September 30th, 2008

I’ve looked at using python to create GUIs in Linux a few times but coming from a background of using Visual Basic it seemed very different and the learning curve a bit steep. This time I decided to really give it a new try and I have to say that it’s way easier than I expected.

My first recommendation is to use glade-3. Last time I used glade-2 but I have a real problem with the multiple windows concept as windows keep disappearing behind other application windows. If you use gtk.Builder then the glade file created by glade-3 needs to be converted to a compatible xml file before it can be loaded, but this is easy to achieve with the following command.

$ gtk-builder-convert gui.glade gui.xml

From there I was amazed how easy it was to attach events and quickly write code, a very basic example to load an xml file an attach events is shown here.

This is the xml file created by using glade and running gtk-builder-convert. It’s just a window containing a button.

<?xml version="1.0"?>
<!--Generated with glade3 3.4.4 on Tue Sep 30 11:46:18 2008 -->
<interface>
  <object class="GtkWindow" id="window1">
    <signal handler="on_window1_destroy" name="destroy"/>
    <child>
      <object class="GtkButton" id="button1">
        <property name="visible">True</property>
        <property name="can_focus">True</property>
        <property name="receives_default">True</property>
        <property name="label" translatable="yes">gtk-close</property>
        <property name="use_stock">True</property>
        <signal handler="on_button1_clicked" name="clicked"/>
      </object>
    </child>
  </object>
</interface>

This is the python code to run the gui, very simple indeed.

#!/usr/bin/env python 

import pygtk
import gtk
pygtk.require("2.0") 

class GUI(object):
  def __init__(self):
      builder = gtk.Builder()
      builder.add_from_file("GUI.xml")
      builder.connect_signals(self)
      self.window1 = builder.get_object("window1")
      self.window1.show()

  def on_window1_destroy(self,widget,data=None):
      gtk.main_quit()

  def on_button1_clicked(self,widget,data=None):
      gtk.main_quit()  

if __name__ == "__main__":
  app = GUI()
  gtk.main()

To run just save the python file as gui.py, chmod +x the python file and then run using ./gui.py. Just make sure the xml file is in the same directory as the python file.

I’ll post more pygtk as I learn but so far I’m amazed how easy it is to create very professional looking applications in a very short time. There are thousands of tutorials on pygtk on the net but I found this one very useful.

http://www.micahcarrick.com/12-24-2007/gtk-glade-tutorial-part-1.html

Host Moved My Site Without Warning (Again)

September 29th, 2008

For the second time in only a few months my site was down for god-knows-how-long. I first noticed when my main site and blog redirected to a moving page for the server that, rather ironically, returns a 404, page not found error.

It didn’t take me long to ftp to my site and look at the htaccess file to see that someone had added a line at the bottom to redirect all traffic to the page mentioned above. I removed the line and sure enough my site was still there, however after contacting support (who initially told me that they had not added the offending line!) it turns out that my server was moved to a new IP address.

This just required me to change my a records at my nameserver (I use Zoneedit and highly recommend them) and in a few minutes I could access the new server. More annoying was that I has not received any notification of the move, plus I had posted a new blog post but to the old server so I had to manually rewrite the entry since I could no no longer access the old server (Googles cache helps a lot in these situations).

I pay very little for my hosting so I cannot complain too much, however it is making me wonder if I should pay more to move hosts to a more reliable outfit (maybe Dreamhost).

Gnome 2.24 Released

September 25th, 2008

I read today that Gnome 2.24 has been released. There’s a few nice features but tabs in Nautilus seems like the one I’ll find the most useful (assuming you can drag files between tabs). Actually the biggest deal for many users will be that this 7 year old bug in GTK has been fixed.

Many people have probably encountered this bug when the mouse is hovering over the location of a button on a form that opens under the mouse. In this situation the button cannot be clicked until you move the mouse away and back over the button. It’s a really annoying bug and I’m glad it’s fixed.

Gnome 2.24 will be in Fedora 10 due to be released on 25th of November so I’ll have to wait until then for a test drive.

Safely Shutdown a Frozen Linux System

September 17th, 2008

For when everything freezes totally it’s useful to know the commands on this Free Software Magazine page.

I notice that on Fedora these keys are not captured by default but this is easily fixed using the following command as root.

# echo 1 > /proc/sys/kernel/sysrq

On my system this also opens gnome-screenshot but don’t worry as the kernel still gets the keys as well. My only problem is that the /proc/sys/kernel/sysrq file gets overwritten on boot so I need to make the change permanent, if I find a solution I’ll update the post.

Update - on Fedora it’s very easy to set the sysrq parameter to 1 permanently. Just open the file /etc/sysctl.conf as root and look for the following line, changing it from 0 to 1.

# Controls the System Request debugging functionality of the kernel
kernel.sysrq = 0

Remove DOS newlines from Python files

September 17th, 2008

I’ve been working on a few python files in WIndows and then moving them to Linux but whenever I try to run them I get an error about ‘directory not found’.

I soon discovered that the Windows carriage return messes up the files for Linux so we need to remove them all. If you open the offending file using vi you’ll see lots of ^M characters spread through the file. Fortunately these are pretty easy to remove using vi. Open the file in vi, press escape so we can enter a command, type this command press enter and save the file.

%s/^M/ /g

It’s very important that you create the ^M character by typing alt+v then press m while still holding down alt+v, do not paste straight from this page.

Try Downloading Linpus Linux Lite

September 11th, 2008

After posting that the Acer Aspire One netbook uses a modified version of Linpus Linux Lite I thought I’d download it and run it within Virtualbox just to take a look around.

For a website with iso files available to download it’s the slowest site I’ve come across in ages, even the regular site takes an age to load so you can forget trying to download it for yourself.

It would have taken about 25 hours to fully download the 673.61 MB iso file and I couldn’t find any mirrors with better bandwidth, so unless you’re very patient it’s out of the question.

Tempted to buy a Netbook

September 8th, 2008

With companies seemingly releasing a new netbook every week I must admit that I’m tempted to buy one. There’s few things that are very appealing:

  • Price, they’re very cheap so can be used as a second computer.
  • Very light and portable. My 15″ laptop is miles more powerful but you can’t just throw it in a bag and not notice, the new netbooks all weight around 1kg.
  • Great to play around with using Linux. The default systems run by may of these is somewhat limited but there’s a whole slew of sites started up showing you how to install your favourite Linux distro on these machines. Hours of fun for people like me!
  • Later machines have better keyboards and improved battery life so are comfortable to use on long trips and will last all day.

I’m looking at the Acer Aspire One right now but I’d rather wait until it’s available with the 6 cell battery as the 3 cells only gives 2.5 to 3 hours of battery life. It runs a Linux disro called Linpus Linux Lite which is a modified version of Fedora 8 but running XFCE as the desktop manager.

I tried one out in a shop over the weekend, it was the 512MB version with the 8GB SSD disk and running Linux. I thought it felt pretty snappy in use with very little lag when opening applications, of course opening a 100+ page pdf file took about 30 seconds but for everyday use it seemed good.

The Thunar file manager was very easy to use and files appeared instantly when browsing the drive. Even though by default it’s pretty locked down there’s plenty of sites explaining how to unlock the interface. Failing that I might just install a new distro, the only problem being that it will have to be from a usb drive since I don’t have an external DVD drive (and don’t intend to buy one).

Edit: there’s a really good review of the Aspire One here.

Windows Scheduled Tasks Problem

September 5th, 2008

On my work PC I have some batch jobs set up that run from a network resource. Because of this I have to set up the job with my domain user name and password.

This worked fine until I changed my network password yesterday, suddenly I was getting ‘Access Denied’ messages when I tried to save the jobs.

After a long talk with IT it turns out that my new password was the problem, I was trying to use ‘iosteam::in’ as my password but it seems that the double colon is not accepted or recognised by Windows Scheduled tasks so if you get the same problem just change your password and all should be OK.

Google Chrome

September 3rd, 2008

Well I guess like every other technology blogger I should give my impression of Google Chrome so as not to disappoint here goes.

Overall I’m very impressed, especially for a first beta release.

  1. It’s fast, start up speed is blazingly fast and rendering time on regular pages is good. Javascript heavy sites are very responsive with little or no delay.
  2. It’s simple, uncluttered interface is very appealing. It gets the job done with a minimum of options and fuss.
  3. If you save pages as applications shortcuts it really does blur the line between local applications on your PC and those running from the internet. A bit like the shortcuts using in some netbooks where email points directly to gmail but even more so.
  4. As far as another browser in the marketplace I think more competition can only be a good thing.
  5. Very pleased they made it open source, no doubt the new V8 Javascript virtual machine and other elements will make it into other browsers. This will raise the bar for all browser vendors.
  6. Looking at the speed improvements it leaves the other browsers way behind and makes IE7/8 seem even more bloated. If Google really push this then it I think it’s a major threat to IE, plus it really takes the wind out of the sails of the unreleased IE8 (not like there was much excitement to begin with).
  7. If people are going to use this as their main browser it will need extensions. I just can’t handle seeing adverts again!

Of course I’ve only tested this on Windows (not my OS of choice) but I’m really looking forward to running it on Linux when available.

Holiday Computer Woes

September 2nd, 2008

I’ve been away for 3 weeks on holiday, first in Denmark but I also had 12 days on Naxos in Greece. I still managed some computer time while in Denmark but the time in Greece was well away from all things on-line, it was a nice break even though it’s good to be back on-line.

My girlfriends mother has a donated PC from a company that runs Windows XP Professional, it broke completely while I was there visiting. The thing would get as far as the Windows boot screen but then crash with a blue screen of death that flashed past so quick it was impossible to read the error.

Even booting into safe mode wouldn’t work with some error about ‘file could not be read’. I suspected that the file system was somehow corrupted but trying to fix it without the original Windows disks was near impossible. All the downloads I could find to get hold of CHKDSK would require a floppy drive which the broken PC had but not my laptop that I was using to try to get the recovery software. My usual method would be to boot a live Linux CD but unfortunately there are no Linux tools to fix an NTFS partition.

Running out of time I decided to install Ubunbtu 8.04 in a dual boot set-up so at least she could get internet access. This worked fine until I had to abort a software update using synaptic that was taking too long. On next restart everything seemed fine but underneath were strangely broken, for example clicking on any menu or desktop icon did nothing at all. I’m sure this was easy to fix but I didn’t have time so unfortunately her computer is still not working. If only there was a way to remotely fix a broken PC there would be no problem.