PmwBase_test.py :  » GUI » Pmw » Pmw.1.3.2 » src » Pmw » Pmw_1_3 » tests » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » GUI » Pmw 
Pmw » Pmw.1.3.2 » src » Pmw » Pmw_1_3 » tests » PmwBase_test.py
# Tests for Pmw megawidgets

import Tkinter
import Test
import Pmw

Test.initialise()

class TestWidget(Pmw.MegaWidget):

    def __init__(self, parent = None, **kw):
        # Define the megawidget options.
        optiondefs = ()
        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,), text = 'test')
  self._label.pack(side='left', padx=2)

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

    def addComponent(self, nickname):
  self.createcomponent(nickname,
    (), None,
    TestComponent, (self.interior(),), status = 'create')

    def addTestWidget(self, widget, option, value):
  w = self.createcomponent('test',
    (), None,
    widget, (self.interior(),))
  apply(self.configure, (), {'test_' + option : value})
  if w.__class__.__name__ not in ('Menu', 'Toplevel'):
      w.pack()
  if hasattr(widget, 'geometry'):
      w.geometry('+100+100')
  return str(w.cget(option))

    def deleteTestWidget(self):
  w = self.component('test')
  if hasattr(widget, 'pack'):
      w.pack_forget()
  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.
  optiondefs = (
      ('status', '', self._status),
  )
  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,), text = 'test')
  self._label.pack(side='left', padx=2)

  self._statusList = []

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

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

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

c = TestWidget
tests = (
  (c.pack, ()),
  (c.components, (), ['hull', 'label']),

  (c.addComponent, 'k0'),
  (c.getStatusList, 'k0', ['create']),
  (c.packComponent, 'k0'),
  ('k0_status', 'foo'),
  (c.getStatusList, 'k0', ['create', 'foo']),

  (c.addComponent, 'k1'),
  (c.packComponent, 'k1'),
  ('k1_status', 'bar'),
  (c.getStatusList, 'k1', ['create', 'bar']),

  (c.addComponent, 'k2'),
  (c.packComponent, 'k2'),
  ('k2_label_foreground', 'green'),
  ('hull_cursor', 'gumby'),
  ('k2_label_cursor', 'gumby'),
  (c.componentOption, ('k2', 'label_foreground'), 'green'),
  (c.componentOption, ('k2', 'label_cursor'), 'gumby'),

  (c.addComponent, 'k3'),
  (c.packComponent, 'k3'),
  ('k3_label_foreground', 'red'),
  ('hull_background', 'white'),
  ('k3_label_background', 'white'),
  ('hull_cursor', 'dot'),
  ('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]:
    tests = tests + (
      (c.addTestWidget, (widget, 'foreground', 'blue'), 'blue'),
      (c.deleteTestWidget, ())
    )

for widget in [Tkinter.Canvas, Tkinter.Frame, Tkinter.Scrollbar, Tkinter.Toplevel]:
    tests = tests + (
      (c.addTestWidget, (widget, 'background', 'grey80'), 'grey80'),
      (c.deleteTestWidget, ())
    )

# Test the logical fonts.
for fontName in Pmw.logicalfontnames():
    for sizeIncr in (-2, 0, 1, 2, 4, 8):
  font = Pmw.logicalfont(fontName, sizeIncr)
        tests = tests + (
          ('label_text', 'Testing font\n' + fontName + ' ' + str(sizeIncr)),
          ('label_font', font),
        )
fontList = (
  (('Helvetica', 0), {}),
  (('Times', 0), {}),
  (('Typewriter', 0), {}),
  (('Typewriter', 0), {'width' : 'condensed'}),
  (('Typewriter', -1), {'width' : 'condensed'}),
  (('Fixed', 0), {}),
  (('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)
    tests = tests + (
        ('label_text', 'Testing font\n' + str(args) + '\n' + str(dict)),
        ('label_font', font),
    )

testData = ((c, ((tests, {'label_text' : 'Testing Pmw base classes'}),)),)

if __name__ == '__main__':
    Test.runTests(testData)
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.