File: MegaWidget_test.py

package info (click to toggle)
python-pmw 0.8.5-6
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,820 kB
  • ctags: 3,468
  • sloc: python: 14,898; makefile: 37; sh: 17
file content (129 lines) | stat: -rw-r--r-- 4,117 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# Based on itk2.2/tests/widget.test code.

import Tkinter
import Test
import Pmw

Test.initialise()

class TestWidget(Pmw.MegaWidget):

    def __init__(self, parent = None, **kw):

	# Define the megawidget options.
	optiondefs = (
	    ('status',         '',          self._status),
	    ('background',     'linen',     None),
	    ('borderwidth',    2,           None),
	    ('foreground',     'navy',      None),
	)
	self.defineoptions(kw, optiondefs)

	# Initialise the base class (after defining the options).
	Pmw.MegaWidget.__init__(self, parent)

	# Create the components.
	interior = self.interior()
	self._label = self.createcomponent('label',
		(), None,
		Tkinter.Label, (interior,))
	self._label.pack(side='left', padx=2)

	self._button = self.createcomponent('button',
		(), 'Mygroup',
		Tkinter.Button, (interior,), text = 'Push Me',
		activebackground = 'white', background = 'ivory')
	self._button.pack(side='right', fill='x', padx=2)

	# Initialise instance variables.
	self._statusList = []

	# Check keywords and initialise options.
	self.initialiseoptions(TestWidget)

    def statusList(self, val=None):
        if val is None:
	    return self._statusList
	else:
	    self._statusList = val

    def action(self, info):
        self._statusList.append(info)

    def _status(self):
        self._statusList.append(self['status'])

def _componentOption(component, option):
    w = Test.currentWidget()
    return w.component(component).cget(option)

def _componentInvoke(component):
    w = Test.currentWidget()
    w.component(component).invoke()

def _addComponent():
    w = Test.currentWidget()
    label2 = w.createcomponent('label2',
	    (), 'Mygroup',
	    Tkinter.Label, (w.interior(),),
	    text = 'Temporary', background = 'yellow')
    label2.pack(fill = 'x')
    return label2.cget('text')

expectedOptions = {
    'background': ('background', 'background', 'Background', 'linen', 'linen'),
    'borderwidth': ('borderwidth', 'borderwidth', 'Borderwidth', 2, 2),
    'foreground': ('foreground', 'foreground', 'Foreground', 'navy', 'navy'),
    'status': ('status', 'status', 'Status', '', ''),
}

c = TestWidget
tests = (
  # Set status list to a known state, since configure(status) may have
  # been called during contruction.
  (c.statusList, ([''])),
  (c.pack, ()),
  (c.configure, (), {}, expectedOptions),
  (c.configure, ('background'), expectedOptions['background']),
  (c.configure, ('borderwidth'), expectedOptions['borderwidth']),
  (c.configure, ('foreground'), expectedOptions['foreground']),
  (c.configure, ('status'), expectedOptions['status']),
  ('hull_background', 'red'),
  ('label_background', 'red'),
  ('borderwidth', 1),
  ('button_command', Test.callback),
  ('hull_cursor', 'trek'),
  ('label_cursor', 'trek'),
  ('Mygroup_foreground', 'IndianRed'),
  ('button_activebackground', 'MistyRose'),
  ('button_background', 'MistyRose2'),
  ('status', 'test message'),
  ('label_text', 'Label:'),
  (c.components, (), ['button', 'hull', 'label']),
  (c.component, ('hull'), Tkinter.Frame),
  (c.component, ('label'), Tkinter.Label),
  (c.component, ('button'), Tkinter.Button),
  (_componentOption, ('hull', 'cursor'), 'trek'),
  (_componentOption, ('label', 'cursor'), 'trek'),
  (_componentOption, ('hull', 'background'), 'red'),
  (_componentOption, ('label', 'background'), 'red'),
  (_componentOption, ('button', 'background'), 'MistyRose2'),
  (_componentOption, ('label', 'text'), 'Label:'),
  (_componentOption, ('button', 'text'), 'Push Me'),
  (c.statusList, (), ['', 'test message']),
  ('button_command', Test.actioncallback),
  (c.statusList, ([])),
  (_componentInvoke, 'button'),
  ('status', 'in between'),
  (_componentInvoke, 'button'),
  (c.statusList, (), ['button press', 'in between', 'button press']),
  (_addComponent, (), 'Temporary'),
  (c.components, (), ['button', 'hull', 'label', 'label2']),
  (_componentOption, ('label2', 'background'), 'yellow'),
  (c.destroycomponent, ('label2')),
  (c.components, (), ['button', 'hull', 'label']),
)
testData = ((c, ((tests, {}),)),)

if __name__ == '__main__':
    Test.runTests(testData)