Salome HOME
Modif V6_4_°
[tools/eficas.git] / Pmw / Pmw_1_2 / demos / BltTabset.py
1 title = 'Blt Tabset demonstration'
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         if not Pmw.Blt.haveblt(parent):
13             message = 'Sorry\nThe BLT package has not been\n' + \
14                     'installed on this system.\n' + \
15                     'Please install it and try again.'
16             w = Tkinter.Label(parent, text = message)
17             w.pack(padx = 8, pady = 8)
18             return
19
20         self.tabset = Pmw.Blt.Tabset(parent,
21             borderwidth = 0,
22             highlightthickness = 0,
23             selectpad = 0,
24             tiers = 2,
25         )
26         background = self.tabset.cget('background')
27         self.tabset.configure(selectbackground = background,
28                 tabbackground = background, activebackground = background)
29
30         configurePanel = Tkinter.Frame(self.tabset)
31         sideMenu = Pmw.OptionMenu (configurePanel,
32                 labelpos = 'w',
33                 label_text = 'Side:',
34                 items = ('top', 'bottom', 'left', 'right'),
35                 menubutton_width = 10,
36                 command = self.changeSide,
37         )
38         sideMenu.pack(anchor = 'w', padx = 10, pady = 10)
39
40         rotateMenu = Pmw.ComboBox(configurePanel,
41                 labelpos = 'w',
42                 label_text = 'Text rotation:',
43                 entryfield_validate = 'integer',
44                 entry_width = 8,
45                 selectioncommand = self.rotateText,
46                 scrolledlist_items = (0, 45, 90, 135, 180, 225, 270, 315),
47         )
48         rotateMenu.pack(side = 'left', padx = 10, pady = 10)
49
50         rotateMenu.selectitem(0)
51         self.rotateText('0')
52
53         self.appearancePanel = Tkinter.Label(self.tabset)
54         helpersPanel = Tkinter.Button(self.tabset,
55                 text = 'This is a lot\nof help!')
56
57         self.tabset.insert('end',
58                 'Appearance', 'Configure', 'Helpers', 'Images')
59
60         self.tabset.tab_configure('Appearance',
61                 command = self.appearance_cb, fill = 'both')
62         self.tabset.tab_configure('Configure', window = configurePanel)
63         self.tabset.tab_configure('Images',
64                 command = self.images_cb, fill = 'both')
65         self.tabset.tab_configure('Helpers',
66                 window = helpersPanel, padx = 100, pady = 150)
67
68         self.tabset.invoke(1)
69         self.tabset.pack(fill = 'both', expand = 1, padx = 5, pady = 5)
70         self.tabset.focus()
71
72     def appearance_cb(self):
73         self.appearancePanel.configure(
74                 text = 'Don\'t judge a book\nby it\'s cover.')
75         self.tabset.tab_configure('Appearance', window = self.appearancePanel)
76
77     def images_cb(self):
78         self.appearancePanel.configure(text = 'Beauty is only\nskin deep.')
79         self.tabset.tab_configure('Images', window = self.appearancePanel)
80
81     def changeSide(self, side):
82         self.tabset.configure(side = side)
83
84     def rotateText(self, angle):
85         if Pmw.integervalidator(angle) == Pmw.OK:
86             self.tabset.configure(rotate = angle)
87         else:
88             self.tabset.bell()
89
90 ######################################################################
91
92 # Create demo in root window for testing.
93 if __name__ == '__main__':
94     root = Tkinter.Tk()
95     Pmw.initialise(root)
96     root.title(title)
97
98     exitButton = Tkinter.Button(root, text = 'Exit', command = root.destroy)
99     exitButton.pack(side = 'bottom')
100     widget = Demo(root)
101     root.mainloop()