Note that there are some explanatory texts on larger screens.

plurals
  1. POIs there a generic update notification/pub sub system for GTK?
    primarykey
    data
    text
    <p>I'm building a PyGTK application with several widgets that when changed, need to <strong>notify other widgets about the change</strong>. I would like to avoid code like this:</p> <pre><code>def on_entry_color_updated(self, widget): self.paint_tools_panel.current_color_pane.update_color() self.main_window.status_bar.update_color() self.current_tool.get_brush().update_color() </code></pre> <p>And do something like this instead:</p> <pre><code>def on_entry_color_updated(self, widget): self.update_notify('color-changed') </code></pre> <p>The status bar, current color pane and current tool would subscribe to that notification event and act accordingly. From what I can tell, the GObject signaling mechanism only allows me to register a callback on a particular widget, so each object that wants to receive a notification has to be aware of that widget.</p> <p><strong>Does GTK provide such a system or should I build it myself?</strong> Developers of Shotwell, a photo organization application for GNOME, had to build their own signaling mechanism, if I understand their <a href="http://redmine.yorba.org/projects/shotwell/wiki/ShotwellArchDataStructures" rel="nofollow">design doc</a> correctly. Searching here on SO didn't turn out any definitive answers.</p> <h2>Edit:</h2> <p>Clarification why I think GObject signaling is not what I need (or just a part of what I need). With GObject, I need to explicitly connect an object to another object, like so:</p> <pre><code>emitter.connect('custom-event', receiver.event_handler) </code></pre> <p>So in my application, I would have to do this:</p> <pre><code>class ColorPane(gtk.Something): def __init__(self, application): # init stuff goes here... application.color_pallette.connect('color-changed', self.update_color) def update_color(self, widget): """Show the new color.""" pass class StatusBar(gtk.Something): def __init__(self, application): # init stuff goes here... application.color_pallette.connect('color-changed', self.update_color) def update_color(self, widget): """Show the new color name.""" pass class Brush(gtk.Something): def __init__(self, application): # init stuff goes here... application.color_pallette.connect('color-changed', self.update_color) def update_color(self, widget): """Draw with new color.""" pass </code></pre> <p>In other words, I have to pass the application object or some other object that knows about the color_pallete to other objects in my application so that they connect to color_pallette signals. This is the kind of coupling that I want to avoid.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload