Hi,
Attached is the patch which allows subscribing to events in common/events.py (using publisher/subscriber pattern). As a side-effect, this patch decouples systray.py and common/events.py (common/events.py no longer even imports common.gajim).
The patch allows additional modules to be written, which do the different things when events arrive (e.g. blinking LED, executing external program). Existing things, such as emiting DBus messages on new events also may be restructured to use this mechanism.
Mikhail Gusarov a écrit :
Hi,
Attached is the patch which allows subscribing to events in common/events.py (using publisher/subscriber pattern). As a side-effect, this patch decouples systray.py and common/events.py (common/events.py no longer even imports common.gajim).
The patch allows additional modules to be written, which do the different things when events arrive (e.g. blinking LED, executing external program). Existing things, such as emiting DBus messages on new events also may be restructured to use this mechanism.
Thanks for the patch. It's a good solution to handle events better in our code. I've modified your code a bit (integrate SystrayEventsListener class in Systray one) and commited it in rev 8008
Twas brillig at 12:29:16 10.03.2007 UTC+01 when yann did gyre and gimble:
y> Thanks for the patch. It's a good solution to handle events better y> in our code. I've modified your code a bit (integrate y> SystrayEventsListener class in Systray one) and commited it in rev y> 8008
Oops, I forgot to mail updated patch, last one had two bugs:
- 'fire_event_deleted' instead of 'fire_event_removed' once.
- 'fire_event_removed' may be called both with 'event' argument and without one, depending on the context, so let it accept and pass further optional 'event' argument.
See the fix in attach.
ps: I'm subscribed to gajim-devel, no need to copy answer to my address.
pps: Probably it worth to factor out publisher/subsriber snippet to the separate class and use it in everywhere. I'd do it if you agree that's a good idea.
Mikhail Gusarov wrote:
Oops, I forgot to mail updated patch, last one had two bugs:
'fire_event_deleted' instead of 'fire_event_removed' once.
'fire_event_removed' may be called both with 'event' argument and without one, depending on the context, so let it accept and pass further optional 'event' argument.
See the fix in attach.
ps: I'm subscribed to gajim-devel, no need to copy answer to my address.
pps: Probably it worth to factor out publisher/subsriber snippet to the separate class and use it in everywhere. I'd do it if you agree that's a good idea.
to be more general, fire_event_removed get and transmit a list of removed events.
about your pps: you want systray (and other classes that would use this event system) to be a child of a new class that will contain some general code to register / unregister listener ? that sounds a good idea
Twas brillig at 10:05:06 11.03.2007 UTC+01 when Yann Le Boulanger did gyre and gimble:
YLB> about your pps: you want systray (and other classes that would use this YLB> event system) to be a child of a new class that will contain some general YLB> code to register / unregister listener ? that sounds a good idea
Yes. Probably it's more "pythonic" to create just generic Event class, instances of which act like this:
a = Event(...) a.subscribe(handler) a.fire() ...
Mikhail Gusarov wrote:
Twas brillig at 10:05:06 11.03.2007 UTC+01 when Yann Le Boulanger did gyre and gimble:
YLB> about your pps: you want systray (and other classes that would use this YLB> event system) to be a child of a new class that will contain some general YLB> code to register / unregister listener ? that sounds a good idea
Yes. Probably it's more "pythonic" to create just generic Event class, instances of which act like this:
a = Event(...) a.subscribe(handler) a.fire() ...
that sounds a good idea. I wait your patch :)
thanks,