Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / amd64 / lib / python2.4 / site-packages / Pmw / Pmw_1_2 / demos / PanedWidget_2.py
CommitLineData
920dae64
AT
1title = 'Pmw.PanedWidget demonstration (pane factory)'
2
3# Import Pmw from this directory tree.
4import sys
5sys.path[:0] = ['../../..']
6
7import Tkinter
8import Pmw
9
10class 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.
57if __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()