2010-05-27
Reflecting on the past
Working on heybuddy, I have learned a few things.
  • I probably should have used Vala
  • using threads in python isn't hard
  • using threads in a python GTK app isn't hard
  • Documentation for pygtk is not the greatest

Why Vala Had I written the program using Vala, Heybuddy would have been a compiled native application and would use less system resources. However, using Python certainly has its advantages; the most notable being that it is quite easy to move Heybuddy to a different architecture ( as long as the operating system on the new architecture has Python and GTK).
Heybuddy on x86, x86-64, ARM, PPC? No problem. Just copy the code and run it.

Threads For a few days, I was tearing out my hair trying to figure out how to properly use threads to fix a major bug in heybuddy.
The problem was this: When heybuddy would request data from the identi.ca server, the user interface would freeze until heybuddy was finished reading the data from the server.
The solution: use seperate threads to show the UI and read data from the server

Unfortunately using threads didn't work. Then I learned some stuff.
When using python threading with a GTK application, threads will not work without first calling the function gobject.threads_init() or gtk.gdk.threads_init().
One more time:
When using python threading with a GTK application, threads will not work without first calling the function gobject.threads_init() or gtk.gdk.threads_init().

This however, turned up a new problem. The server data reading thread was emitting signals for the main thread to process and this would sometimes happen when the main thread was updating the GUI and there would be a resulting crash of the application. The work around for this was to use gobject.idle_add( handle_the_signal_stuff ) which will allow the main thread to do the handling of the signal stuff when the main thread isn't busy and thus segfaults are averted. YEA!

links in labels Although it isn't in the pygtk pango reference it is possible to put links in a labels markup. For example:
label=gtk.Label() markup="Visit <a href='http://www.jezra.net'>Jezra's Website</a>" label.set_markup(markup)

This will put a clickable link in the text of a GTK label. Sweet!

OK, that's enough for me. I have some bugs to fix.

Now quit reading, and go write something.
Comments
2010-05-28 senshikaze:
theards aren't hard per se, just a pain in the ass, and you are right. no where, and I mean NO WHERE in documentation(that i could find) was the whole threads.init() mentioned, and only a few stackoverflow posts mentioned it.
question: why do they have two? is one going to be deprecated in later versions? I know I got a depreciated warning, not on the init.threads, but when trying to force the UI into a separate thread (not the way to go).
Name:
not required
Email:
not required (will not be displayed)
Website:
not required (will link your name to your site)
Comment:
required
Please do not post HTML code or bbcode unless you want it to show up as code in your post. (or if you are a blog spammer, in which case, you probably aren't reading this anyway).
Prove you are human by solving a math problem! I'm sorry, but due to an increase of blog spam, I've had to implement a CAPTCHA.
Problem:
6 plus 7
Answer:
required
  • Tags:
  • Python
  • Heybuddy
subscribe
 
2019
2016
2015
2014
2013
2012
2011
2010
December
November
October
September
August
July
June
May
April
March
February
January
2009
December
November
October
September
August
July
June
May
April
March
February
January
2008