I just finished writing my money managing applicat…

I just finished writing my money managing application which I will post on my blog soon. This application has five separate views that can be switched in the main window like the “workspaces” in Jokosher. However I didn’t want to restrict myself to only looking at one of these views at a time, so I put in the option to create a new window that does not have any toolbars or menus, just the view switcher. This means that there could be any number of GUI instances looking at my program’s model at the same time. There could be two copies of the same view and when one is updated and other one has to reflect the changes.

I have implemented my listener code using Python’s GObject bindings so that all the views can know when a signal is emitted on the model. However if there are many views all running at the same time, sending a GObject signal takes a long time. If a signal is sent in response to a button being clicked, the button will stay pushed down for a few seconds while it waits for the signal emission to return. This makes the application look slow and unpolished. I decided that it doesn’t matter if not all the views are updated immediately; I’d rather have the button come back up and then have everything update. So I made this little class to do exactly that:

import gobjectclass AsyncGObject(gobject.GObject):       def __init__(self):               gobject.GObject.__init__(self)

       def emit(self, *args):               gobject.idle_add(gobject.GObject.emit, self, *args)

Just subclass this class instead of gobject.GObject and all your signals will be asynchronous.

Comments are closed.