On Sun, Apr 11, 1999 at 01:40:16PM -0500, Tim Peoples wrote:

> Is there any way for me to define my own signal names for pygtk [compound]

I don't remember the technical reason this could not be implemented.  I
found a way to emulate this behavior using a dictionary and delegation.
Here's a silly example:

----------------------------------------8<---------------------------
from gtk import *

class TwoButtons(GtkHBox):

    def __init__(self, label1, label2):
        GtkHBox.__init__(self)
        button = GtkButton(label1)
        toggle = GtkToggleButton(label2)
        self.pack_start(button)
        self.pack_start(toggle)
        self._signalmap = {"hello" : (button, "clicked"),
                        "howdy" : (toggle, "toggled") }

    def show(self):
        for obj, signal in self._signalmap.values():
            obj.show()
        GtkHBox.show(self)

    def connect(self, new_signal, callback, *extra):
        if self._signalmap.has_key(new_signal):
            object, signal = self._signalmap[new_signal]
            apply(object.connect, (signal, callback) + extra)
        else:
            apply(GtkHBox.connect, (self, new_signal, callback) + extra)
            

def howdy(*args):
    print args
    print "Howdy!"

def hello(*args):
    print args
    print "Hello!"

def welcome(*args):
    print args
    print "Welcome!"

win = GtkWindow()
win.connect("delete-event", mainquit)
buttons = TwoButtons("Howdy", "Hello")
buttons.connect("howdy", howdy)
buttons.connect("hello", hello)
buttons.connect("show", welcome)
win.add(buttons)
buttons.show()
win.show()
mainloop()
------------------------------8<----------------------------------

Dave Cook
To unsubscribe: echo "unsubscribe" | mail [EMAIL PROTECTED]

Reply via email to