Search code examples
labelpygtkcropfixed

pygtk Child Label resizes Fixed container while moving


I'm writing a "flying text" with pygtk. A small test code looks like this:

class MainWindow(gobject.GObject):
    def __init__(self,sender):
        self.__gobject_init__()
        sender.connect('move_label', self.move_label)
        self.box = HBox()
        self.w = gtk.Window()
        self._mainbox = gtk.VBox()
        self._flybox = gtk.Fixed()
        self._label = gtk.Label("testing")
        self._x = 10
        self._flybox.put(self._label,self._x,0);
        self._mainbox.pack_start(self.box)
        self._mainbox.pack_start(self._flybox)
        self.w.add(self._mainbox)

    def move_label(self,sender):
        self._x += 10
        self._flybox.move(self._label,self._x,0)

    def main(self, fname):
        self.w.show_all()
        self.w.connect("destroy", gtk.main_quit)
        gtk.main()


class Sender(gobject.GObject):
    def __init__(self):
        self.__gobject_init__()

    def trigger_move_label(self):
        gobject.timeout_add(2*1000, self.trigger_move_label)
        self.emit('move_label');

gobject.signal_new('move_label',Sender,gobject.SIGNAL_RUN_FIRST,gobject.TYPE_NONE,())

sender = Sender()
gobject.timeout_add(2*1000, sender.trigger_move_label)
player = VideoPlayer(sender)
player.main(sys.argv[1])

This example creates a window with a Fixed box at the bottom containing a label "testing". Also it creates a timer that triggers every 2 seconds a method that moves (self._flybox.move(........)) label to the end of the container. The problem is that after label is moved to the end of the window. It keeps moving and resizes the Fixed container and whole window. But I want this label to be croped while it moves out of the Fixed container


Solution

  • I've figred it out. I need to use gtk.Layout() instead of gtk.Fixed() to make label crop after moving out of the container