MegaWidget_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 » MegaWidget_test.py
# 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()

    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)
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.