This class is designed to be a GUI application framework.
This class creates a simple application dialog including a
menubar, status message area, progress meter, help and about
dialogs. The class methods also provide simple access to features
of Pmw and Tkinter such as
changing the cursor during a busy processing time
displaying message and error dialogs
providing menu bar items.
registering documentation as part of the built-in online help
system
status messages,
The class acts as the base class for simple GUI applications,
making the job of creating a small application to perform a simple
task easy. The constructor manages all of the startup and
initialization required for Tk, Tkinter, and Pmw. A subclass
defines a method to create the interface for the application, and
(optionally) a method to perform application initialization. An
instance is created, and the run method is then used to run the
application.
Since this class is a base class, the user expected to subclass it
and override several attributes as well as the createinterior()
method in order to create an application.
The documentation for each method indicates whether it should be
overridden by the subclass or not. There are three types of
methods:
- Override
This method should be overridden.
- Override ok
This method can be overridden, but maybe
shouldn't be and should not need to be.
- No override
Do not override this method.
Class Attributes to Override
-
appversion string
What version of your application is this?
-
appname string
What is the name of your application?
-
contactname string
Name of the person to contact when the user has questions.
-
copyrightname string
Name of the person holding copyright to the app.
-
copyright string
Copyright notice for the app.
-
contactphone string
Recommended for use only with apps used by other members of
your organization. This information will be included in the
About dialog.
-
contactemail string
Email address to use to request help about the app.
-
resizeWidth integer
If true, the user is allowed to resize the main dialog width.
-
resizeHeight integer
If true, the user is allowed to resize the main dialog height.
-
padx integer
X padding for spacing between widgets.
-
pady integer
Y padding for spacing between widgets.
-
usebuttonbox integer
If true, build a button box area of the GUI app to provide
quick buttons for some actions. This area is not created if
false. Defaults to false.
Options
-
balloon_state="both" The type of help provided by the
balloon manager. Valid options are described in the
documentation for the Pmw.Balloon class.
-
padx Internal X spacing for child widgets.
-
pady Internal Y spacing for child widgets.
-
resizeheight=1 Boolean controlling whether the application
frame will allow resizing in the Y direction. The default,
true, means resizing will be allowed.
-
resizewidth=1 Boolean controlling whether the application
frame will allow resizing in the X direction. The default,
true, means resizing will be allowed.
-
usebuttonbox=0 Boolean controlling whether the
Pmw.ButtonBox portion of the interface is packed (it is always
created).
Components
-
balloon This component is a Pmw.Balloon, and is
automatically tied to the message area of the application
window.
-
bottomtray This component is a Tkinter.Frame which contains
the message bar and progress meter at the very bottom of the
application window.
-
buttonbox This component is a Pmw.ButtonBox used for the set
of buttons arranged along the bottom of the main application
window. The class attribute usebuttonbox controls whether or not
the button box is displayed.
-
dialogchildsite This component is a Tkinter.Frame and is
used for the container of application interface components. This
is the widget returned by the interior() method of the
GuiAppD.
-
hull This acts as the body for the entire megawidget. Other
components are created as children of the hull to further
specialise the widget. By default, this component is a
Tkinter.Frame.
-
menubar This acts as the main menu for the entire
application. Submenus which are automatically created are File
and Help. Other submenus and menu items can be created by the
subclass.
-
messagebar This component is a Pmw.MessageBar displayed at
the bottom left of the application window, inside the
bottomtray . The message bar is automatically tied to the
balloon component to display status messages. This is also
where messages passed to the statusMessage() method are
displayed.
-
progressmeter This component is a PmwContribD.ProgressMeter
displayed at the bottom right of the application window, inside
the bottomtray. See the updateProgress() method.
Screenshots
Take a look at GuiAppD running on a
Macintosh.
Methods
|
|
|
|
__init__
|
__init__ ( self, **kw )
|
|
addHelpItem
|
addHelpItem (
self,
key,
text,
)
Add a help item to the help text tree.
Arguments
-
key String placing the help node into the tree of
online help. Sections of the path are colon separated.
For example:
w.addHelpItem(Menu:File:Save as..., Save file with new name.)
will insert a help node under the (Menu, File) section of
the help tree. The name of the node will be "Save as..."
and the body of the node will be "Save file with new
name."
-
text Help text associated with the key.
|
|
addMenuItem
|
addMenuItem (
self,
menuName,
itemType,
helpText,
label,
command,
accelerator='',
acceleratorKey='',
binding=None,
**kw,
)
Add a new item to the menu structure for the app.
Add a new menu item with name label in the menu menuName .
When the menu item is invoked, command will be called.
If acceleratorKey is specified, a binding for a platform-dependant
accelerator_prefix with that one character key will be created
on the application toplevel window. If accelerator and
binding are specified, and acceleratorKey is not, the
binding and accelerator are taken as specified.
Arguments
-
menuName Name of the menu into which item should be added.
-
itemType Type of the item to insert (usually command ).
-
helpText Balloon help for the menu item.
-
label Text to appear on the item button.
-
command Function to call when item is selected.
-
accelerator Used in combination with binding if
acceleratorKey not specified.
-
acceleratorKey String with one key which should be set
as the keyboard accelerator to access the menu item
directly.
-
binding Keybinding which should invoke the menu item.
Override ok.
|
|
appInit
|
appInit ( self )
Called before interface is created.
Override.
|
|
balloon
|
balloon ( self )
Return the balloon help manager.
No override.
|
|
bell
|
bell ( self )
Ring the bell as an alert.
Override ok.
|
|
bind
|
bind (
self,
child,
balloonHelpMsg,
statusHelpMsg=None,
)
Bind a help message and/or status message to a widget.
Arguments
-
child Widget with which the help message is associated.
-
balloonHelpMsg Text to show in balloon help popup.
-
statusHelpMsg Text to show in message bar.
Override ok.
|
|
buildHelpTable
|
buildHelpTable ( self )
Install help text not associated with specific widgets.
Override
|
|
busyEnd
|
busyEnd ( self )
Take the UI out of busy mode.
Override ok.
|
|
busyStart
|
busyStart ( self, newcursor=None )
Use this to put the UI into busy mode.
Arguments
- newcursor
Optional cursor name to be used while in busy mode.
Override ok.
|
|
buttonAdd
|
buttonAdd (
self,
buttonName,
helpMessage=None,
statusMessage=None,
**kw,
)
Add a button to the button box. Returns the new button.
Arguments
-
buttonName Text to appear on the button.
-
helpMessage Help text to be registered.
-
statusMessage Help text to be registered.
-
**kw Other keyword arguments.
Override ok.
|
|
buttonBox
|
buttonBox ( self )
Retrieve the button box.
Override ok.
|
|
centerMessageDialog
|
centerMessageDialog ( self, msgDialog )
Centers a message dialog on the screen.
Obsolete
|
|
checkScreenBoundary
|
checkScreenBoundary (
self,
xCoord,
yCoord,
wCoord,
hCoord,
)
Makes sure message windows do not appear off screen
No override.
|
|
createHelpButton
|
createHelpButton ( self )
Add a help button to the button box.
Override ok.
|
|
createInterface
|
createInterface ( self )
Create the interface for the app.
Override.
|
|
createMenuBar
|
createMenuBar ( self )
Create the menu bar for this application class.
Override ok.
|
|
getFilenameToOpen
|
getFilenameToOpen (
self,
title='Open File',
filetypes=[( 'Text Files', '*.txt' ), ],
initialdir=None,
)
Present a dialog and ask the user for the name of a file to open.
Arguments
- title
Title for the dialog.
- filetypes
Sequence of (label, pattern) tuples. The same
pattern may occur with several titles. Use "*" as pattern
to indicate all files.
- initialdir
Initial directory.
|
|
initializeTk
|
initializeTk ( self, root )
Initialize platform specific options
Override ok.
|
|
interior
|
interior ( self )
Retrieve the interior site where children should go.
Override ok.
|
|
main
|
main ( self )
Main application processing.
No override.
|
|
quit
|
quit ( self, *args )
Exit the app.
Override ok.
|
|
run
|
run ( self )
Run the application.
No override.
|
|
savePrefsCB
|
savePrefsCB ( self, prefs )
Callback to be invoked when preferences are saved.
Override.
|
|
showAbout
|
showAbout ( self )
Shows the About dialog.
Input is blocked by the dialog until the user presses ok.
Override ok.
|
|
showError
|
showError ( self, errorMessage )
Beep and display errorMessage in a dialog.
Override ok.
|
|
showHelpDialog
|
showHelpDialog ( self, event=None )
Display the help dialog.
Override ok.
|
|
showMessage
|
showMessage (
self,
type,
msgTxt=None,
)
Show a message in the message bar.
Override ok.
|
|
showMessageDialog
|
showMessageDialog (
self,
messageText,
justify='center',
buttons=( 'OK', ),
title=None,
)
Display messageText in a dialog.
Override ok.
|
|
showPrefsDialog
|
showPrefsDialog ( self )
Display the preferences dialog for the application.
No override.
|
|
toggleBalloon
|
toggleBalloon ( self )
Control whether or not the balloon help is displayed.
Looks into the w.toggleBalloonVar value to determine if the
balloon help should be turned on or off.
Override ok.
|
|
updateProgress
|
updateProgress (
self,
newValue=0,
newLimit=0,
)
Show progress.
Arguments
-
newValue The new progress state.
-
newLimit The new maximum limit value for the progress
meter. (See ProgressMeter for more details.)
Override ok.
|
|