Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / src / nas,5.n2.os.2 / lib / python / lib / python2.4 / site-packages / Pmw / Pmw_1_2 / demos / ScrolledCanvas.py
CommitLineData
86530b38
AT
1title = 'Pmw.ScrolledCanvas demonstration'
2
3# Import Pmw from this directory tree.
4import sys
5sys.path[:0] = ['../../..']
6
7import Tkinter
8import Pmw
9
10class Demo:
11 def __init__(self, parent):
12 # Create the ScrolledCanvas.
13 self.sc = Pmw.ScrolledCanvas(parent,
14 borderframe = 1,
15 labelpos = 'n',
16 label_text = 'ScrolledCanvas',
17 usehullsize = 1,
18 hull_width = 400,
19 hull_height = 300,
20 )
21
22 # Create a group widget to contain the scrollmode options.
23 w = Pmw.Group(parent, tag_text='Scroll mode')
24 w.pack(side = 'bottom', padx = 5, pady = 5)
25
26 hmode = Pmw.OptionMenu(w.interior(),
27 labelpos = 'w',
28 label_text = 'Horizontal:',
29 items = ['none', 'static', 'dynamic'],
30 command = self.sethscrollmode,
31 menubutton_width = 8,
32 )
33 hmode.pack(side = 'left', padx = 5, pady = 5)
34 hmode.invoke('dynamic')
35
36 vmode = Pmw.OptionMenu(w.interior(),
37 labelpos = 'w',
38 label_text = 'Vertical:',
39 items = ['none', 'static', 'dynamic'],
40 command = self.setvscrollmode,
41 menubutton_width = 8,
42 )
43 vmode.pack(side = 'left', padx = 5, pady = 5)
44 vmode.invoke('dynamic')
45
46 buttonBox = Pmw.ButtonBox(parent)
47 buttonBox.pack(side = 'bottom')
48 buttonBox.add('yview', text = 'Show\nyview', command = self.showYView)
49 buttonBox.add('scroll', text = 'Page\ndown', command = self.pageDown)
50 buttonBox.add('center', text = 'Center', command = self.centerPage)
51
52 # Pack this last so that the buttons do not get shrunk when
53 # the window is resized.
54 self.sc.pack(padx = 5, pady = 5, fill = 'both', expand = 1)
55
56 self.sc.component('canvas').bind('<1>', self.addcircle)
57
58 testEntry = Tkinter.Entry(parent)
59 self.sc.create_line(20, 20, 100, 100)
60 self.sc.create_oval(100, 100, 200, 200, fill = 'green')
61 self.sc.create_text(100, 20, anchor = 'nw',
62 text = 'Click in the canvas\nto draw ovals',
63 font = testEntry.cget('font'))
64 button = Tkinter.Button(self.sc.interior(),
65 text = 'Hello,\nWorld!\nThis\nis\na\nbutton.')
66 self.sc.create_window(200, 200,
67 anchor='nw',
68 window = button)
69
70 # Set the scroll region of the canvas to include all the items
71 # just created.
72 self.sc.resizescrollregion()
73
74 self.colours = ('red', 'green', 'blue', 'yellow', 'cyan', 'magenta',
75 'black', 'white')
76 self.oval_count = 0
77 self.rand = 12345
78
79 def sethscrollmode(self, tag):
80 self.sc.configure(hscrollmode = tag)
81
82 def setvscrollmode(self, tag):
83 self.sc.configure(vscrollmode = tag)
84
85 def addcircle(self, event):
86 x = self.sc.canvasx(event.x)
87 y = self.sc.canvasy(event.y)
88 width = 10 + self.random() % 100
89 height = 10 + self.random() % 100
90 self.sc.create_oval(
91 x - width, y - height, x + width, y + height,
92 fill = self.colours[self.oval_count])
93 self.oval_count = (self.oval_count + 1) % len(self.colours)
94 self.sc.resizescrollregion()
95
96 # Simple random number generator.
97 def random(self):
98 self.rand = (self.rand * 125) % 2796203
99 return self.rand
100
101 def showYView(self):
102 print self.sc.yview()
103
104 def pageDown(self):
105 self.sc.yview('scroll', 1, 'page')
106
107 def centerPage(self):
108 top, bottom = self.sc.yview()
109 size = bottom - top
110 middle = 0.5 - size / 2
111 self.sc.yview('moveto', middle)
112
113######################################################################
114
115# Create demo in root window for testing.
116if __name__ == '__main__':
117 root = Tkinter.Tk()
118 Pmw.initialise(root)
119 root.title(title)
120
121 exitButton = Tkinter.Button(root, text = 'Exit', command = root.destroy)
122 exitButton.pack(side = 'bottom')
123 widget = Demo(root)
124 root.mainloop()