1#!/usr/bin/env python
2"""Paned Widgets
3
4The GtkHPaned and GtkVPaned Widgets divide their content area into two panes
5with a divider in between that the user can adjust. A separate child is placed
6into each pane.
7There are a number of options that can be set for each pane. This test contains
8both a horizontal(HPaned) and a vertical(VPaned) widget, and allows you to
9adjust the options for each side of each widget."""
10
11import pygtk
12pygtk.require('2.0')
13import gtk
14
15class PanedWidgetsDemo(gtk.Window):
16    def __init__(self, parent=None):
17        # Create the toplevel window
18        gtk.Window.__init__(self)
19        try:
20            self.set_screen(parent.get_screen())
21        except AttributeError:
22            self.connect('destroy', lambda *w: gtk.main_quit())
23
24        self.set_title(self.__class__.__name__)
25        self.set_border_width(0)
26
27        vbox = gtk.VBox(False, 0)
28        self.add(vbox)
29
30        vpaned = gtk.VPaned()
31        vbox.pack_start(vpaned, True, True)
32        vpaned.set_border_width(5)
33
34        hpaned = gtk.HPaned()
35        vpaned.add1(hpaned)
36
37        frame = gtk.Frame()
38        frame.set_shadow_type(gtk.SHADOW_IN)
39        frame.set_size_request(60, 60)
40        hpaned.add1(frame)
41
42        button = gtk.Button("_Hi there")
43        frame.add(button)
44
45        frame = gtk.Frame()
46        frame.set_shadow_type(gtk.SHADOW_IN)
47        frame.set_size_request(80, 60)
48        hpaned.add2(frame)
49
50        frame = gtk.Frame()
51        frame.set_shadow_type(gtk.SHADOW_IN)
52        frame.set_size_request(60, 80)
53        vpaned.add2(frame)
54
55        # Now create toggle buttons to control sizing
56
57        vbox.pack_start(
58            self.__create_pane_options(hpaned, "Horizontal", "Left", "Right"),
59            False, False, 0)
60
61        vbox.pack_start(
62            self.__create_pane_options(vpaned, "Vertical", "Top", "Bottom"),
63            False, False, 0)
64
65        self.show_all()
66
67    def on_resize_toggled(self, tbutton, child):
68        paned = child.parent
69
70        if child == paned.get_children()[0]:
71            paned.remove(child)
72            paned.pack1(child, tbutton.get_active(), 0)
73        else:
74            paned.remove(child)
75            paned.pack2(child, tbutton.get_active(), 0)
76
77    def on_shrink_toggled(self, tbutton, child):
78        paned = child.parent
79
80        if child == paned.get_children()[0]:
81            paned.remove(child)
82            paned.pack1(child, 0, tbutton.get_active())
83        else:
84            paned.remove(child)
85            paned.pack2(child, 0, tbutton.get_active())
86
87    def __create_pane_options(self, paned, frame_label, label1, label2):
88        frame = gtk.Frame(frame_label)
89        frame.set_border_width(4)
90
91        table = gtk.Table(3, 2, True)
92        frame.add(table)
93
94        label = gtk.Label(label1)
95        table.attach(label, 0, 1, 0, 1)
96
97        check_button = gtk.CheckButton("_Resize")
98        check_button.connect('toggled', self.on_resize_toggled, paned.get_children()[0])
99        table.attach(check_button, 0, 1, 1, 2)
100
101        check_button = gtk.CheckButton("_Shrink")
102        check_button.set_active(True)
103        check_button.connect('toggled', self.on_shrink_toggled, paned.get_children()[0])
104        table.attach(check_button, 0, 1, 2, 3)
105
106        label = gtk.Label(label2)
107        table.attach(label, 1, 2, 0, 1)
108
109        check_button = gtk.CheckButton("_Resize")
110        check_button.set_active(True)
111        check_button.connect('toggled', self.on_resize_toggled, paned.get_children()[1])
112        table.attach(check_button, 1, 2, 1, 2)
113
114        check_button = gtk.CheckButton("_Shrink")
115        check_button.set_active(True)
116        check_button.connect('toggled', self.on_shrink_toggled, paned.get_children()[1])
117        table.attach(check_button, 1, 2, 2, 3)
118
119        return frame
120
121def main():
122    PanedWidgetsDemo()
123    gtk.main()
124
125if __name__ == '__main__':
126    main()
127