[Python编程(第4版)].(Programming.Python.4th.Edition).Mark.Lutz.文字版

(yzsuai) #1
arguments by using Python’s func(**kargs) call syntax. As is, labels are assumed
to be text, but images could be supported too (see the note under “BigGui: A Client
Demo Program” on page 609).

For variety, the mouse cursor changes based upon its location: a hand in the toolbar,
crosshairs in the default middle part, and something else over Help buttons of frame-
based menus (customize as desired).


Subclass Protocols


In addition to menu and toolbar layouts, clients of this class can also tap into and
customize the method and geometry protocols the class implements:


Template attributes
Clients of this class are expected to set menuBar and toolBar attributes somewhere
in the inheritance chain by the time the start method has finished.


Initialization
The start method can be overridden to construct menu and toolbar templates
dynamically, since self is available when it is called; start is also where general
initializations should be performed—GuiMixin’s init constructor must be run,
not overridden.


Adding widgets
The makeWidgets method can be redefined to construct the middle part of the win-
dow—the application portion between the menu bar and the toolbar. By default,
makeWidgets adds a label in the middle with the name of the most specific class,
but this method is expected to be specialized.


Packing protocol
In a specialized makeWidgets method, clients may attach their middle portion’s
widgets to any side of self (a Frame) since the menu and toolbars have already
claimed the container’s top and bottom by the time makeWidgets is run. The middle
part does not need to be a nested frame if its parts are packed. The menu and
toolbars are also automatically packed first so that they are clipped last if the win-
dow shrinks.


Gridding protocol
The middle part can contain a grid layout, as long as it is gridded in a nested
Frame that is itself packed within the self parent. (Remember that each container
level may use grid or pack, not both, and that self is a Frame with already packed
bars by the time makeWidgets is called.) Because the GuiMaker Frame packs itself
within its parent, it is not directly embeddable in a container with widgets arranged
in a grid, for similar reasons; add an intermediate gridded Frame to use it in this
context.


GuiMaker: Automating Menus and Toolbars | 607
Free download pdf