]> SALOME platform Git repositories - tools/eficas.git/blob - Pmw/Pmw_1_2/demos/PanedWidget_2.py
Salome HOME
Modif V6_4_°
[tools/eficas.git] / Pmw / Pmw_1_2 / demos / PanedWidget_2.py
1 title = 'Pmw.PanedWidget demonstration (pane factory)'
2
3 # Import Pmw from this directory tree.
4 import sys
5 sys.path[:0] = ['../../..']
6
7 import Tkinter
8 import Pmw
9
10 class Demo:
11     def __init__(self, parent):
12         self.paneCount = 0
13
14         # Create a "pane factory".
15         label = Tkinter.Label(parent,
16                 pady = 10,
17                 text = 'Below is a simple "pane factory".\n' +
18                         'Drag the handle on the left\nto create new panes.')
19         label.pack()
20         self.factory = Pmw.PanedWidget(parent,
21                 orient='horizontal',
22                 command = self.resize,
23                 hull_borderwidth = 1,
24                 hull_relief = 'raised',
25                 hull_width=300, hull_height=200
26                 )
27         self.factory.add('starter', size = 0.0)
28         self.factory.add('main')
29         button = Tkinter.Button(self.factory.pane('main'),
30                 text = 'Pane\n0')
31         button.pack(expand = 1)
32         self.factory.pack(expand = 1, fill = 'both')
33
34     def resize(self, list):
35         # Remove any panes less than 2 pixel wide.
36         for i in range(len(list) - 1, 0, -1):
37             if list[i] < 2:
38                 self.factory.delete(i)
39
40         # If the user has dragged the left hand handle, create a new pane.
41         if list[0] > 1:
42             self.paneCount = self.paneCount + 1
43
44             # Add a button to the new pane.
45             name = self.factory.panes()[0]
46             text = 'Pane\n' + str(self.paneCount)
47             button = Tkinter.Button(self.factory.pane(name), text = text)
48             button.pack(expand = 1)
49
50             # Create a new starter pane.
51             name = 'Pane ' + str(self.paneCount)
52             self.factory.insert(name, size=0.0)
53
54 ######################################################################
55
56 # Create demo in root window for testing.
57 if __name__ == '__main__':
58     root = Tkinter.Tk()
59     Pmw.initialise(root)
60     root.title(title)
61
62     exitButton = Tkinter.Button(root, text = 'Exit', command = root.destroy)
63     exitButton.pack(side = 'bottom')
64     widget = Demo(root)
65     root.mainloop()