Re: [gDesklets] events in controls



Johan van der Slikke wrote:
> Hi,
> 
> thanks for you reply.
> 
>>> I'm developing a desklets to monitor my laptop battery. So I started
>>> with writing an control to provide the information to the desklet. I'm
>>> asking the info from HAL via dbus. To let HAL notify me of changes
>>> (i.e. an connected power cable) I would normally start a loop with:
>>> 
>>> self.__ac_obj.connect_to_signal ("PropertyModified", 
>>> self.__property_modified) self.__batt_obj.connect_to_signal 
>>> ("PropertyModified", self.__property_modified)
>>> 
>>> self.__loop = gobject.MainLoop() self.__loop.run()
>>> 
>>> But this seems to mess up gdesklets: I can only get it working again
>>> with killing python and start gdesklets again.
>> I think the main problem is that you don't need to run a main loop (so 
>> you can get rid of both references to self.__loop).  You could either 
>> call connect_to_signal() in __init__() or in the function that gets 
>> called whenever a property gets set.  It looks like you might want to do
>> this in __init__() if you're going to go with the method you have laid
>> out above.
> 
> From what I understand from loops is that they are required to let a
> application receive events. Otherwise a function gets finished and is not
> able to listen to events anymore. I don't know exactly how a Control works.
> I understand from the developer's book that the way to let a Control
> providing information is a timer. But it would be much cleaner if it can
> run as a kind of deamon to react to Hal events and update the desklet. I
> don't know how to archieve this. And maybe I've not enough knowledge about
> Python to archieve this :)

Looking at the D-Bus-Python documentation [1], it looks like you're right.
They only claim to support one "main loop", which is Glib.  I haven't looked
at the gD source in a while, so I'm not sure if it runs the Glib main loop.
If it does, you might be in luck...otherwise, I think the fix has to be in D-Bus.

If there's something in Glib that needs to be shutdown, you could define the
function "_shutdown()" in your Control's class and do whatever needs to be
done there to terminate the Glib loop.  That may also be a solution.

[snip]
>> Feel free to email the list if you have more Control or Python questions.
>> I used to have an IRC community to bother with mine ;)
> 
> Maybe I should also ask my questions programming questions there?

Unfortunately it kind of withered out a few years ago.  It used to be
#gdesklets on irc.gnome.org, but I don't think you'll find anybody there now.

--
Joe

[1]
http://dbus.freedesktop.org/doc/dbus-python/doc/tutorial.html#setting-up-an-event-loop


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]