# Tests for Pmw megawidgets
class TestWidget(Pmw
.MegaWidget
):
def __init__(self
, parent
= None, **kw
):
# Define the megawidget options.
self
.defineoptions(kw
, optiondefs
)
# Initialise the base class (after defining the options).
Pmw
.MegaWidget
.__init
__(self
, parent
)
interior
= self
.interior()
self
._label
= self
.createcomponent('label',
Tkinter
.Label
, (interior
,), text
= 'test')
self
._label
.pack(side
='left', padx
=2)
# Check keywords and initialise options.
self
.initialiseoptions(TestWidget
)
def addComponent(self
, nickname
):
self
.createcomponent(nickname
,
TestComponent
, (self
.interior(),), status
= 'create')
def addTestWidget(self
, widget
, option
, value
):
w
= self
.createcomponent('test',
widget
, (self
.interior(),))
apply(self
.configure
, (), {'test_' + option
: value
})
if w
.__class
__.__name
__ not in ('Menu', 'Toplevel'):
if hasattr(widget
, 'geometry'):
return str(w
.cget(option
))
def deleteTestWidget(self
):
w
= self
.component('test')
if hasattr(widget
, 'pack'):
self
.destroycomponent('test')
def packComponent(self
, nickname
):
self
.component(nickname
).pack()
def getStatusList(self
, nickname
):
return self
.component(nickname
)._statusList
def componentOption(self
, nickname
, option
):
return self
.component(nickname
).cget(option
)
class TestComponent(Pmw
.MegaWidget
):
def __init__(self
, parent
= None, **kw
):
# Define the megawidget options.
('status', '', self
._status
),
self
.defineoptions(kw
, optiondefs
)
# Initialise the base class (after defining the options).
Pmw
.MegaWidget
.__init
__(self
, parent
)
interior
= self
.interior()
self
._label
= self
.createcomponent('label',
Tkinter
.Label
, (interior
,), text
= 'test')
self
._label
.pack(side
='left', padx
=2)
# Check keywords and initialise options.
self
._statusList
.append(info
)
self
._statusList
.append(self
['status'])
(c
.components
, (), ['hull', 'label']),
(c
.getStatusList
, 'k0', ['create']),
(c
.getStatusList
, 'k0', ['create', 'foo']),
(c
.getStatusList
, 'k1', ['create', 'bar']),
('k2_label_foreground', 'green'),
('hull_cursor', 'gumby'),
('k2_label_cursor', 'gumby'),
(c
.componentOption
, ('k2', 'label_foreground'), 'green'),
(c
.componentOption
, ('k2', 'label_cursor'), 'gumby'),
('k3_label_foreground', 'red'),
('hull_background', 'white'),
('k3_label_background', 'white'),
('k3_label_cursor', 'dot'),
(c
.componentOption
, ('k3', 'label_foreground'), 'red'),
(c
.componentOption
, ('k3', 'label_background'), 'white'),
(c
.componentOption
, ('k3', 'label_cursor'), 'dot'),
('label_background', 'white'),
(c
.destroycomponent
, 'k0'),
(c
.destroycomponent
, 'k1'),
(c
.destroycomponent
, 'k2'),
(c
.destroycomponent
, 'k3'),
# Test each of the standard widgets as components.
for widget
in [Tkinter
.Button
, Tkinter
.Checkbutton
, Tkinter
.Entry
, Tkinter
.Label
, Tkinter
.Listbox
, \
Tkinter
.Menu
, Tkinter
.Menubutton
, Tkinter
.Message
, Tkinter
.Radiobutton
, Tkinter
.Scale
, Tkinter
.Text
]:
(c
.addTestWidget
, (widget
, 'foreground', 'blue'), 'blue'),
for widget
in [Tkinter
.Canvas
, Tkinter
.Frame
, Tkinter
.Scrollbar
, Tkinter
.Toplevel
]:
(c
.addTestWidget
, (widget
, 'background', 'grey80'), 'grey80'),
# Test the logical fonts.
for fontName
in Pmw
.logicalfontnames():
for sizeIncr
in (-2, 0, 1, 2, 4, 8):
font
= Pmw
.logicalfont(fontName
, sizeIncr
)
('label_text', 'Testing font\n' + fontName
+ ' ' + str(sizeIncr
)),
(('Typewriter', 0), {'width' : 'condensed'}),
(('Typewriter', -1), {'width' : 'condensed'}),
(('Fixed', 0), {'width' : 'condensed'}),
(('Fixed', -1), {'width' : 'condensed'}),
(('Helvetica', 2), {'slant' : 'italic'}),
(('Helvetica', 0), {'size' : 18}),
(('Helvetica', 0), {'weight' : 'bold'}),
(('Helvetica', 12), {'weight' : 'bold', 'slant' : 'italic'}),
(('Typewriter', 0), {'size' : 8, 'weight' : 'bold'}),
(('Fixed', 0), {'size' : 8, 'weight' : 'bold'}),
(('Times', 0), {'size' : 24, 'weight' : 'bold', 'slant' : 'italic'}),
for args
, dict in fontList
:
font
= apply(Pmw
.logicalfont
, args
, dict)
('label_text', 'Testing font\n' + str(args
) + '\n' + str(dict)),
testData
= ((c
, ((tests
, {'label_text' : 'Testing Pmw base classes'}),)),)
if __name__
== '__main__':