I'm trying to create a modified TreeView which would have a bit
different style of moving around. (Like pressing up and down would
only move to the next sibling and wouldn't move if there are no
siblings in that direction, pressing left would move to the parent
node and close that subtree, etc.)

I thought the best way of doing this is to subclass TreeView, add new
signals (like 'move-to-signal', 'ascend-and-close' etc.) and create
default keybindings.

Just to try out this idea, I wrote the following test:
-----------8<-----------------

class HnbTreeView(gtk.TreeView):
    """ TreeView with modified keybindings """

    __gsignals__={
         'move-to-sibling' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,
                               (gobject.TYPE_INT,))
    }
    def __init__(self, model, *a, **kw):
        self.__gobject_init__()
        gtk.TreeView.__init__(self, model, *a, **kw)

    def do_move_to_sibling(*a, **kw):
        print 'called'
        print a
        print kw

gobject.type_register(HnbTreeView)
gtk.binding_entry_add_signal(HnbTreeView, gtk.gdk.keyval_from_name('Up'),
                             gtk.gdk.CONTROL_MASK, 'move-to-sibling',
                             gobject.TYPE_INT, 1)

--------------8<---------------

The gobject tutorial at
http://www.sicem.biz/personal/lgs/docs/gobject-tutorial/gobject-tutorial.html
mentions that:
"""
If you define custom properties or signals in your new class you can't
call the superclass __init__ method in your __init__ method or it will
overwrite your property definitions. You should call the
__gobject_init__ method instead.
"""

Apparently this is my problem. If I call gtk.TreeView.__init__,
nothing happens, and the new signal is not usable (Control-Up does the
same as Up in itself, and if I try to emit the signal with
treeview.emit(...) I get a "TypeError: unknown signal name".) If I
leave out the call to gtk.TreeView.__init__(), I get a completly blank
widget. (Which does have the new signal as I can with treeview.emit())

Is creating new signals in subclasses of existing widgets impossible?

-- 
Abel Daniel
_______________________________________________
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to