Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / amd64 / lib / python2.4 / site-packages / Pmw / Pmw_1_2 / doc / ScrolledCanvas.html
CommitLineData
920dae64
AT
1
2 <html>
3 <head>
4 <meta name="description" content="Pmw - a toolkit for building high-level compound widgets in Python">
5 <meta name="content" content="python, megawidget, mega widget, compound widget, gui, tkinter">
6 <title>Pmw.ScrolledCanvas reference manual</title>
7 </head>
8
9 <body bgcolor="#ffffff" text="#000000" link="#0000ee"
10 vlink="551a8b" alink="ff0000">
11
12 <h1 ALIGN="CENTER">Pmw.ScrolledCanvas</h1>
13
14<center><IMG SRC=ScrolledCanvas.gif ALT="" WIDTH=382 HEIGHT=240></center>
15<dl>
16<dt> <h3>Name</h3></dt><dd>
17<p>Pmw.ScrolledCanvas() -
18 canvas with optional scrollbars
19</p>
20
21
22</dd>
23<dt> <h3>Inherits</h3></dt><dd>
24<a href="MegaWidget.html">Pmw.MegaWidget</a><br>
25</dd>
26<dt> <h3>Description</h3></dt><dd>
27<p>
28 A scrolled canvas consists of a standard canvas widget with optional
29 scrollbars which can be used to scroll the canvas. The scrollbars
30 can be <em>dynamic</em>, which means that a scrollbar will only be
31 displayed if it is necessary, that is, if the scrollregion of the
32 canvas is larger than the canvas.</p>
33
34<p></p>
35
36
37</dd>
38<dt> <h3>Options</h3></dt><dd>
39Options for this megawidget and its base
40classes are described below.<p></p>
41<a name=option.borderframe></a>
42<dl><dt> <strong>borderframe
43</strong></dt><dd>
44Initialisation option. If true, the <strong>borderframe</strong> component will be created. The default is <strong>0</strong>.</p>
45
46
47</dd></dl>
48<a name=option.canvasmargin></a>
49<dl><dt> <strong>canvasmargin
50</strong></dt><dd>
51Initialisation option. The margin around the items in the canvas. Used by the
52 <strong>resizescrollregion()</strong> method. The default is <strong>0</strong>.</p>
53
54
55</dd></dl>
56<a name=option.hscrollmode></a>
57<dl><dt> <strong>hscrollmode
58</strong></dt><dd>
59The horizontal scroll mode. If <strong>'none'</strong>, the horizontal scrollbar
60 will never be displayed. If <strong>'static'</strong>, the scrollbar will always
61 be displayed. If <strong>'dynamic'</strong>, the scrollbar will be displayed
62 only if necessary. The default is <strong>'dynamic'</strong>.</p>
63
64
65</dd></dl>
66<a name=option.labelmargin></a>
67<dl><dt> <strong>labelmargin
68</strong></dt><dd>
69Initialisation option. If the <strong>labelpos</strong> option is not <strong>None</strong>, this specifies the
70 distance between the <strong>label</strong> component and the rest of the
71 megawidget. The default is <strong>0</strong>.</p>
72
73
74</dd></dl>
75<a name=option.labelpos></a>
76<dl><dt> <strong>labelpos
77</strong></dt><dd>
78Initialisation option. Specifies where to place the <strong>label</strong> component. If not
79 <strong>None</strong>, it should be a concatenation of one or two of the
80 letters <strong>'n'</strong>, <strong>'s'</strong>, <strong>'e'</strong> and <strong>'w'</strong>. The first letter
81 specifies on which side of the megawidget to place the label.
82 If a second letter is specified, it indicates where on that
83 side to place the label. For example, if <strong>labelpos</strong> is <strong>'w'</strong>,
84 the label is placed in the center of the left hand side; if
85 it is <strong>'wn'</strong>, the label is placed at the top of the left
86 hand side; if it is <strong>'ws'</strong>, the label is placed at the
87 bottom of the left hand side.</p>
88<p> If <strong>None</strong>, a label component is not created. The default is <strong>None</strong>.</p>
89
90
91
92</dd></dl>
93<a name=option.scrollmargin></a>
94<dl><dt> <strong>scrollmargin
95</strong></dt><dd>
96Initialisation option. The distance between the scrollbars and the enclosing canvas
97 widget. The default is <strong>2</strong>.</p>
98
99
100</dd></dl>
101<a name=option.usehullsize></a>
102<dl><dt> <strong>usehullsize
103</strong></dt><dd>
104Initialisation option. If true, the size of the megawidget is determined solely by the
105 width and height options of the <strong>hull</strong> component.</p>
106<p> Otherwise, the size of the megawidget is determined by the width
107 and height of the <strong>canvas</strong> component, along with the size and/or
108 existence of the other components, such as the label, the
109 scrollbars and the scrollmargin option. All these affect the
110 overall size of the megawidget. The default is <strong>0</strong>.</p>
111
112
113
114</dd></dl>
115<a name=option.vscrollmode></a>
116<dl><dt> <strong>vscrollmode
117</strong></dt><dd>
118The vertical scroll mode. If <strong>'none'</strong>, the vertical scrollbar
119 will never be displayed. If <strong>'static'</strong>, the scrollbar will always
120 be displayed. If <strong>'dynamic'</strong>, the scrollbar will be displayed
121 only if necessary. The default is <strong>'dynamic'</strong>.</p>
122
123
124</dd></dl>
125</dd>
126<dt> <h3>Components</h3></dt><dd>
127Components created by this megawidget and its base
128classes are described below.<p></p>
129<a name=component.borderframe></a>
130<dl><dt> <strong>borderframe
131</strong></dt><dd>
132A frame widget which snuggly fits around the canvas, to give the
133 appearance of a canvas border. It is created with a border so
134 that the canvas, which is created without a border, looks like it
135 has a border. By default, this component is a Tkinter.Frame.</p>
136
137
138</dd></dl>
139<a name=component.canvas></a>
140<dl><dt> <strong>canvas
141</strong></dt><dd>
142The canvas widget which is scrolled by the scrollbars. If the
143 <strong>borderframe</strong> option is true, this is created with a borderwidth
144 of <strong>0</strong> to overcome a known problem with canvas widgets: if a
145 widget inside a canvas extends across one of the edges of the
146 canvas, then the widget obscures the border of the canvas.
147 Therefore, if the canvas has no border, then this overlapping does
148 not occur. By default, this component is a Tkinter.Canvas.</p>
149
150
151</dd></dl>
152<a name=component.horizscrollbar></a>
153<dl><dt> <strong>horizscrollbar
154</strong></dt><dd>
155The horizontal scrollbar. By default, this component is a Tkinter.Scrollbar. Its component group is <strong>Scrollbar</strong>.</p>
156
157
158</dd></dl>
159<a name=component.hull></a>
160<dl><dt> <strong>hull
161</strong></dt><dd>
162This acts as the body for the entire megawidget. Other components
163 are created as children of the hull to further specialise this
164 class. By default, this component is a Tkinter.Frame.</p>
165
166
167</dd></dl>
168<a name=component.label></a>
169<dl><dt> <strong>label
170</strong></dt><dd>
171If the <strong>labelpos</strong> option is not <strong>None</strong>, this component is
172 created as a text label for the megawidget. See the
173 <strong>labelpos</strong> option for details. Note that to set, for example,
174 the <strong>text</strong> option of the label, you need to use the <strong>label_text</strong>
175 component option. By default, this component is a Tkinter.Label.</p>
176
177
178</dd></dl>
179<a name=component.vertscrollbar></a>
180<dl><dt> <strong>vertscrollbar
181</strong></dt><dd>
182The vertical scrollbar. By default, this component is a Tkinter.Scrollbar. Its component group is <strong>Scrollbar</strong>.</p>
183
184
185</dd></dl>
186</dd>
187<a name=methods></a>
188<dt> <h3>Methods</h3></dt><dd>
189Only methods specific to this megawidget are described below.
190For a description of its inherited methods, see the
191manual for its base class
192<strong><a href="MegaWidget.html#methods">Pmw.MegaWidget</a></strong>.
193In addition, methods from the
194<strong>Tkinter.Canvas</strong> class
195are forwarded by this megawidget to the
196<strong>canvas</strong> component.
197<p></p>
198<a name=method.bbox></a>
199<dl><dt> <strong>bbox</strong>(*<em>args</em>)</dt><dd>
200This method is explicitly forwarded to the <strong>canvas</strong> component's
201 <code>bbox()</code> method. Without this explicit forwarding, the <code>bbox()</code>
202 method (aliased to <code>grid_bbox()</code>) of the <strong>hull</strong> would be invoked,
203 which is probably not what the programmer intended.</p>
204
205
206</dd></dl>
207<a name=method.interior></a>
208<dl><dt> <strong>interior</strong>()</dt><dd>
209Return the canvas widget within which the programmer should create
210 graphical items and child widgets. This is the same as
211 <code>component('canvas')</code>.</p>
212
213
214</dd></dl>
215<a name=method.resizescrollregion></a>
216<dl><dt> <strong>resizescrollregion</strong>()</dt><dd>
217Resize the scrollregion of the <strong>canvas</strong> component to be the
218 bounding box covering all the items in the canvas plus a margin on
219 all sides, as specified by the <strong>canvasmargin</strong> option.</p>
220
221
222</dd></dl>
223</dd>
224<dt> <h3>Example</h3></dt><dd>
225The image at the top of this manual is a snapshot
226of the window (or part of the window) produced
227by the following code.<p></p>
228<pre>
229class Demo:
230 def __init__(self, parent):
231 # Create the ScrolledCanvas.
232 self.sc = Pmw.ScrolledCanvas(parent,
233 borderframe = 1,
234 labelpos = 'n',
235 label_text = 'ScrolledCanvas',
236 usehullsize = 1,
237 hull_width = 400,
238 hull_height = 300,
239 )
240
241 # Create a group widget to contain the scrollmode options.
242 w = Pmw.Group(parent, tag_text='Scroll mode')
243 w.pack(side = 'bottom', padx = 5, pady = 5)
244
245 hmode = Pmw.OptionMenu(w.interior(),
246 labelpos = 'w',
247 label_text = 'Horizontal:',
248 items = ['none', 'static', 'dynamic'],
249 command = self.sethscrollmode,
250 menubutton_width = 8,
251 )
252 hmode.pack(side = 'left', padx = 5, pady = 5)
253 hmode.invoke('dynamic')
254
255 vmode = Pmw.OptionMenu(w.interior(),
256 labelpos = 'w',
257 label_text = 'Vertical:',
258 items = ['none', 'static', 'dynamic'],
259 command = self.setvscrollmode,
260 menubutton_width = 8,
261 )
262 vmode.pack(side = 'left', padx = 5, pady = 5)
263 vmode.invoke('dynamic')
264
265 buttonBox = Pmw.ButtonBox(parent)
266 buttonBox.pack(side = 'bottom')
267 buttonBox.add('yview', text = 'Show\nyview', command = self.showYView)
268 buttonBox.add('scroll', text = 'Page\ndown', command = self.pageDown)
269 buttonBox.add('center', text = 'Center', command = self.centerPage)
270
271 # Pack this last so that the buttons do not get shrunk when
272 # the window is resized.
273 self.sc.pack(padx = 5, pady = 5, fill = 'both', expand = 1)
274
275 self.sc.component('canvas').bind('&lt;1&gt;', self.addcircle)
276
277 testEntry = Tkinter.Entry(parent)
278 self.sc.create_line(20, 20, 100, 100)
279 self.sc.create_oval(100, 100, 200, 200, fill = 'green')
280 self.sc.create_text(100, 20, anchor = 'nw',
281 text = 'Click in the canvas\nto draw ovals',
282 font = testEntry.cget('font'))
283 button = Tkinter.Button(self.sc.interior(),
284 text = 'Hello,\nWorld!\nThis\nis\na\nbutton.')
285 self.sc.create_window(200, 200,
286 anchor='nw',
287 window = button)
288
289 # Set the scroll region of the canvas to include all the items
290 # just created.
291 self.sc.resizescrollregion()
292
293 self.colours = ('red', 'green', 'blue', 'yellow', 'cyan', 'magenta',
294 'black', 'white')
295 self.oval_count = 0
296 self.rand = 12345
297
298 def sethscrollmode(self, tag):
299 self.sc.configure(hscrollmode = tag)
300
301 def setvscrollmode(self, tag):
302 self.sc.configure(vscrollmode = tag)
303
304 def addcircle(self, event):
305 x = self.sc.canvasx(event.x)
306 y = self.sc.canvasy(event.y)
307 width = 10 + self.random() % 100
308 height = 10 + self.random() % 100
309 self.sc.create_oval(
310 x - width, y - height, x + width, y + height,
311 fill = self.colours[self.oval_count])
312 self.oval_count = (self.oval_count + 1) % len(self.colours)
313 self.sc.resizescrollregion()
314
315 # Simple random number generator.
316 def random(self):
317 self.rand = (self.rand * 125) % 2796203
318 return self.rand
319
320 def showYView(self):
321 print self.sc.yview()
322
323 def pageDown(self):
324 self.sc.yview('scroll', 1, 'page')
325
326 def centerPage(self):
327 top, bottom = self.sc.yview()
328 size = bottom - top
329 middle = 0.5 - size / 2
330 self.sc.yview('moveto', middle)
331
332</pre>
333</dd>
334</dl>
335
336 <center><P ALIGN="CENTER">
337 <IMG SRC = blue_line.gif ALT = "" WIDTH=320 HEIGHT=5>
338 </p></center>
339
340
341 <font size=-1>
342 <center><P ALIGN="CENTER">
343 Pmw 1.2 -
344 5 Aug 2003
345 - <a href="index.html">Home</a>
346 <br>Manual page last reviewed: 20 September 1998
347 </p></center>
348 </font>
349
350 </body>
351 </html>
352