]> SALOME platform Git repositories - tools/eficas.git/blob - Pmw/Pmw_1_2/tests/MegaWidget_test.py
Salome HOME
Modif V6_4_°
[tools/eficas.git] / Pmw / Pmw_1_2 / tests / MegaWidget_test.py
1 # Based on itk2.2/tests/widget.test code.
2
3 import Tkinter
4 import Test
5 import Pmw
6
7 Test.initialise()
8
9 class TestWidget(Pmw.MegaWidget):
10
11     def __init__(self, parent = None, **kw):
12
13         # Define the megawidget options.
14         optiondefs = (
15             ('status',         '',          self._status),
16             ('background',     'linen',     None),
17             ('borderwidth',    2,           None),
18             ('foreground',     'navy',      None),
19         )
20         self.defineoptions(kw, optiondefs)
21
22         # Initialise the base class (after defining the options).
23         Pmw.MegaWidget.__init__(self, parent)
24
25         # Create the components.
26         interior = self.interior()
27         self._label = self.createcomponent('label',
28                 (), None,
29                 Tkinter.Label, (interior,))
30         self._label.pack(side='left', padx=2)
31
32         self._button = self.createcomponent('button',
33                 (), 'Mygroup',
34                 Tkinter.Button, (interior,), text = 'Push Me',
35                 activebackground = 'white', background = 'ivory')
36         self._button.pack(side='right', fill='x', padx=2)
37
38         # Initialise instance variables.
39         self._statusList = []
40
41         # Check keywords and initialise options.
42         self.initialiseoptions()
43
44     def statusList(self, val=None):
45         if val is None:
46             return self._statusList
47         else:
48             self._statusList = val
49
50     def action(self, info):
51         self._statusList.append(info)
52
53     def _status(self):
54         self._statusList.append(self['status'])
55
56 def _componentOption(component, option):
57     w = Test.currentWidget()
58     return w.component(component).cget(option)
59
60 def _componentInvoke(component):
61     w = Test.currentWidget()
62     w.component(component).invoke()
63
64 def _addComponent():
65     w = Test.currentWidget()
66     label2 = w.createcomponent('label2',
67             (), 'Mygroup',
68             Tkinter.Label, (w.interior(),),
69             text = 'Temporary', background = 'yellow')
70     label2.pack(fill = 'x')
71     return label2.cget('text')
72
73 expectedOptions = {
74     'background': ('background', 'background', 'Background', 'linen', 'linen'),
75     'borderwidth': ('borderwidth', 'borderwidth', 'Borderwidth', 2, 2),
76     'foreground': ('foreground', 'foreground', 'Foreground', 'navy', 'navy'),
77     'status': ('status', 'status', 'Status', '', ''),
78 }
79
80 c = TestWidget
81 tests = (
82   # Set status list to a known state, since configure(status) may have
83   # been called during contruction.
84   (c.statusList, ([''])),
85   (c.pack, ()),
86   (c.configure, (), {}, expectedOptions),
87   (c.configure, ('background'), expectedOptions['background']),
88   (c.configure, ('borderwidth'), expectedOptions['borderwidth']),
89   (c.configure, ('foreground'), expectedOptions['foreground']),
90   (c.configure, ('status'), expectedOptions['status']),
91   ('hull_background', 'red'),
92   ('label_background', 'red'),
93   ('borderwidth', 1),
94   ('button_command', Test.callback),
95   ('hull_cursor', 'trek'),
96   ('label_cursor', 'trek'),
97   ('Mygroup_foreground', 'IndianRed'),
98   ('button_activebackground', 'MistyRose'),
99   ('button_background', 'MistyRose2'),
100   ('status', 'test message'),
101   ('label_text', 'Label:'),
102   (c.components, (), ['button', 'hull', 'label']),
103   (c.component, ('hull'), Tkinter.Frame),
104   (c.component, ('label'), Tkinter.Label),
105   (c.component, ('button'), Tkinter.Button),
106   (_componentOption, ('hull', 'cursor'), 'trek'),
107   (_componentOption, ('label', 'cursor'), 'trek'),
108   (_componentOption, ('hull', 'background'), 'red'),
109   (_componentOption, ('label', 'background'), 'red'),
110   (_componentOption, ('button', 'background'), 'MistyRose2'),
111   (_componentOption, ('label', 'text'), 'Label:'),
112   (_componentOption, ('button', 'text'), 'Push Me'),
113   (c.statusList, (), ['', 'test message']),
114   ('button_command', Test.actioncallback),
115   (c.statusList, ([])),
116   (_componentInvoke, 'button'),
117   ('status', 'in between'),
118   (_componentInvoke, 'button'),
119   (c.statusList, (), ['button press', 'in between', 'button press']),
120   (_addComponent, (), 'Temporary'),
121   (c.components, (), ['button', 'hull', 'label', 'label2']),
122   (_componentOption, ('label2', 'background'), 'yellow'),
123   (c.destroycomponent, ('label2')),
124   (c.components, (), ['button', 'hull', 'label']),
125 )
126 testData = ((c, ((tests, {}),)),)
127
128 if __name__ == '__main__':
129     Test.runTests(testData)