summaryrefslogtreecommitdiff
path: root/examples/gtk/bin.py
blob: 273c3ab01ffc4437ee42565280ad32d37d952600 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# A simple gtk.Conatiner subclassing example reimplementing gtk.Bin in python
import gobject
import gtk

class Bin(gtk.Container):
    __gtype_name__ = 'PyGtkBin'
    def __init__(self):
        gtk.Container.__init__(self)
        self.child = None

    def do_add(self, child):
        child.set_parent(self)
        self.child = child

    def do_remove(self, child):
        widget_was_visible = child.flags() & gtk.VISIBLE
        child.unparent()
        self.child = None

        if widget_was_visible:
            self.queue_resize()

    def do_forall(self, internal, callback, data):
        if self.child:
            callback(self.child, data)

label = gtk.Label()
c = Bin()
c.add(label)
print c.get_children()
c.remove(label)