[pygtk] questions about "configura-event" signal

cbx bnucbx at gmail.com
Wed Aug 12 17:43:12 WST 2009


Hi.
I am writing a program that user can drag a layout up and down.
But there are two questions in the way:
1.When you are dragging upwards,the portion that was invisible at the
beginning, that is,those below the window's border, will never show up.
  I tried to add some line(see the code below) in the self.moveCB().But it
seems not to work.
2.If you move or resize the window manually,the layout would simply discard
all the scrolling made before.
  Adding some code to scroll back wouldn't work.

Best regards


Code:

import gtk

class Example:
    def __init__(self):
        window = gtk.Window()
        self.window = window
        window.connect("destroy", lambda w: gtk.main_quit())
        window.set_default_size(400, 400)
        window.connect("configure-event", self.configureCB)

        vbox = gtk.VBox()
        self.vbox = vbox
        vbox.set_homogeneous(True)
        vbox.set_spacing(5)

        for i in range(1,20):
            label = gtk.Label("Hello,there" + '1'*i)
            vbox.pack_start(label)

        layout = gtk.Layout()
        self.layout = layout
        layout.put(vbox, 0, 0)

        layout.add_events(gtk.gdk.BUTTON_RELEASE_MASK |
gtk.gdk.BUTTON1_MOTION_MASK | gtk.gdk.POINTER_MOTION_HINT_MASK)
        layout.connect("button-press-event", self.pressCB)
        layout.connect("motion-notify-event", self.moveCB)
        layout.connect("button-release-event", self.releaseCB)

        self.dragging = False            #is dragging
        self.dragBeginPos = [0, 0]
        self.yPos = 0                #remember vertical scrolling position

        window.add(layout)
        window.show_all()

        layout.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.HAND1))

    def pressCB(self, widget, event):
        self.dragBeginPos = [event.x, event.y]
        self.dragging = True
        return True

    def moveCB(self, widget, event):
        if(self.dragging == True):
            dy = event.y - self.dragBeginPos[1]
            self.layout.get_parent_window().scroll(0, int(dy))
#line added but seems not to work
            self.layout.queue_draw()
                                     #line added but seems not to work
            self.layout.window.process_updates(True)
            self.yPos = self.yPos + dy            #update self.yPos
        return True

    def releaseCB(self, widget, event):
        dragging = False

    def configureCB(self, widget, event):
        size = self.window.get_size()
        size = size[0]
        size = (size - self.vbox.allocation.width)/2
        self.layout.move(self.vbox, size, 0)

        self.layout.get_parent_window().scroll(0, int(self.yPos))

if  __name__ == "__main__":
    Example()
    gtk.main()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.daa.com.au/pipermail/pygtk/attachments/20090812/4f57794e/attachment.htm 


More information about the pygtk mailing list