Hi.<br>I am writing a program that user can drag a layout up and down.<br>But there are two questions in the way:<br>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.<br>
I tried to add some line(see the code below) in the self.moveCB().But it seems not to work.<br>2.If you move or resize the window manually,the layout would simply discard all the scrolling made before.<br> Adding some code to scroll back wouldn't work.<br>
<br>Best regards<br><br><br>Code:<br><br>import gtk<br><br>class Example:<br> def __init__(self):<br> window = gtk.Window()<br> self.window = window<br> window.connect("destroy", lambda w: gtk.main_quit())<br>
window.set_default_size(400, 400)<br> window.connect("configure-event", self.configureCB)<br> <br> vbox = gtk.VBox()<br> self.vbox = vbox<br> vbox.set_homogeneous(True)<br>
vbox.set_spacing(5)<br> <br> for i in range(1,20):<br> label = gtk.Label("Hello,there" + '1'*i)<br> vbox.pack_start(label)<br><br> layout = gtk.Layout()<br>
self.layout = layout<br> layout.put(vbox, 0, 0)<br><br> layout.add_events(gtk.gdk.BUTTON_RELEASE_MASK | gtk.gdk.BUTTON1_MOTION_MASK | gtk.gdk.POINTER_MOTION_HINT_MASK)<br> layout.connect("button-press-event", self.pressCB)<br>
layout.connect("motion-notify-event", self.moveCB)<br> layout.connect("button-release-event", self.releaseCB)<br> <br> self.dragging = False #is dragging<br> self.dragBeginPos = [0, 0]<br>
self.yPos = 0 #remember vertical scrolling position<br><br> window.add(layout)<br> window.show_all()<br> <br> layout.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.HAND1))<br><br>
def pressCB(self, widget, event):<br> self.dragBeginPos = [event.x, event.y]<br> self.dragging = True<br> return True<br><br> def moveCB(self, widget, event):<br> if(self.dragging == True):<br>
dy = event.y - self.dragBeginPos[1]<br> self.layout.get_parent_window().scroll(0, int(dy)) #line added but seems not to work<br> self.layout.queue_draw() #line added but seems not to work<br>
self.layout.window.process_updates(True)<br> self.yPos = self.yPos + dy #update self.yPos<br> return True<br><br> def releaseCB(self, widget, event):<br> dragging = False<br>
<br> def configureCB(self, widget, event):<br> size = self.window.get_size() <br> size = size[0]<br> size = (size - self.vbox.allocation.width)/2<br> self.layout.move(self.vbox, size, 0) <br>
<br> self.layout.get_parent_window().scroll(0, int(self.yPos))<br> <br>if __name__ == "__main__":<br> Example()<br> gtk.main()<br><br>