Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v9 / lib / python2.4 / site-packages / Pmw / Pmw_1_2 / demos / Resources.py
CommitLineData
920dae64
AT
1title = 'Using Tk option database to configure Tk widgets'
2
3# Import Pmw from this directory tree.
4import sys
5sys.path[:0] = ['../../..']
6
7import string
8import Tkinter
9import Pmw
10
11info = """
12 The Tk widgets contained in this
13 simple megawidget have been
14 configured using the Tk option
15 database.
16 *DemoClass*Listbox.cursor is 'heart'
17 *DemoClass*Entry.cursor is 'hand1'
18 *DemoClass*background is 'pink'
19 *DemoClass*highlightBackground is 'green'
20 *DemoClass*foreground is 'blue'
21"""
22
23class DemoClass(Pmw.MegaWidget):
24
25 # Demo Pmw megawidget.
26
27 def __init__(self, parent = None, **kw):
28
29 # Define the megawidget options.
30 optiondefs = ()
31 self.defineoptions(kw, optiondefs)
32
33 # Initialise the base class (after defining the options).
34 Pmw.MegaWidget.__init__(self, parent)
35
36 interior = self.interior()
37 listbox = Tkinter.Listbox(interior, height = 12, width = 40)
38 listbox.pack(fill='both', expand='yes')
39 for line in string.split(info, '\n'):
40 listbox.insert('end', line)
41
42 entry = Tkinter.Entry(interior)
43 entry.pack(fill='y')
44 entry.insert(0, 'Hello, World!')
45
46 # Check keywords and initialise options.
47 self.initialiseoptions()
48
49class Demo:
50 def __init__(self, parent):
51
52 # Test Tk option database settings.
53 parent.option_add('*DemoClass*Listbox.cursor', 'heart')
54 parent.option_add('*DemoClass*Entry.cursor', 'hand1')
55 parent.option_add('*DemoClass*background', 'pink')
56 parent.option_add('*DemoClass*highlightBackground', 'green')
57 parent.option_add('*DemoClass*foreground', 'blue')
58
59 # Create and pack the megawidget.
60 demo = DemoClass(parent)
61 demo.pack(fill = 'both', expand = 1)
62
63######################################################################
64
65# Create demo in root window for testing.
66if __name__ == '__main__':
67 root = Tkinter.Tk()
68 Pmw.initialise(root)
69 root.title(title)
70
71 exitButton = Tkinter.Button(root, text = 'Exit', command = root.destroy)
72 exitButton.pack(side = 'bottom')
73 widget = Demo(root)
74 root.mainloop()