oogui
index
oogui.py

Object-oriented version of the filegui tutorial that displays the
files in the specified directory, and displays the contents of the
file in the lower portion of the window.
 
OVERVIEW
========
<.> This is a simple GUI base class, intended to provide the
    'interface' (abstract class) for various GUI implementations
    to 'show off' some of their basic GUI constructs.
<.> Template and hook methods raise a NotImplementedError to ensure
    the derived GUIs provide the minimum functionality required.
<.> A toolkit's demos, example programs are a great help resource.
 
'SEQUENCE' OF OPERATIONS
========================
<< libGui == the class from the GUI toolkit being used as application window >>
 
oogui
  (module level)
  + parse command line args
  + instantiate requested GUI type
                                          DerivedGui(OOGui, libGui)
                                          + initialize instance variables
                                          + call libGui's constructor
                                          + call OOGui's constructor
  OOGui
  + OOGui.__init__
  + set self._topLevel
  + call template method                   _buildGui()
  + _setCWD(startdir)
  + call template method:                  _startGui()
                                            + show self._topLevel
                                            + start the main event loop
 
EVENT HANDLING HOOKS
====================
Derived GUI's should connect the following events (signals) to the
base class's implementation. The base class will use the implemented
hook methods to do the work.
 
<.> User double-clicks on a name in the Directories list
    + OOGui._directorySelected()
                                          + _getSelectedDirectory()
                                          + _setCWD(cwd)
                                          
<.> User double-clicks on a name in the Files list
    + OOGui._fileSelected(*unused)
                                          + _getSelectedFile()
                                          + _setFilename(filename)
      ++determines file 'type'
                                          + _display<FileType>(filename)

 
Modules
            
os
sys

 
Classes
            
DisplayFrame
OOGui

 
class DisplayFrame
      Abstract class intended to be derived by the different GUI
toolkits in the tutorial, used to display the selected file in
the toolkit's OOGui implementation.
 
LEFT AS AN EXERCISE FOR THE STUDENT to refactor the current OOGui
implementations' display frames to use this abstract base class.
 
  
__init__(self)
binary(self, filename)
Abstract method to display the binary file named by filename
html(self, filename)
Abstract method to display the HTML file named by filename
image(self, filename)
Abstract method to display the image file named by filename
show(self, filename)
Figure out what type of file is specified by its extension,
and then display appropriately using the derived class's
implementation of the abstract methods.
text(self, filename)
Abstract method to display the text file named by filename

 
class OOGui
      Wrapper class for the object-oriented version of the filegui example,
with the feature of being able to display the selected file.
 
  
__init__(self, topLevel=None, geometry=None, resourceFile=None, startdir=r'http://www.metaslash.com/brochure/tutorial/docs')
Creates the object-oriented filegui object
_buildGui(self, title)
Abstract method to build the GUI.
_directorySelected(self, *unused)
The base class does the parsing of the selected directory, and
then calls the derived object's _setCWD() method to set the
new working directory. Derived GUI classes should NOT implement
this method; they should call it as the action event handler
when a directory entry is 'double-clicked'.
_displayBinary(self, filename)
Abstract method to display binary files with appropriate binary
viewer.
_displayHTML(self, filename)
Abstract method to display HTML files.
_displayImage(self, filename)
Abstract method to display image files.
_displayText(self, filename)
Abstract method to display text files.
_fileSelected(self, *unused)
The base class does the parsing of the selected file, and
then calls the appropriate display handler for the type of file,
based on its file extension.  Derived GUI classes should NOT implement
this method; they should call it as the action event handler when a
file entry is 'double-clicked'.
_getCurrentDirectory(self)
Abstract method that returns the full pathname of the
current working directory.
_getEntries(self, cwd)
Given the current working directory, returns the names of the
directory and file entries. (Note: NOT meant to be overridden.)
_getSelectedDirectory(self)
Abstract method that returns the basename of the selected entry
in the directories list.
_getSelectedFile(self)
Abstract method that returns the basename of the selected entry
in the files list.
_getTopLevel(self)
Abstract method used to get the top level (root) window for
the application.  If the top level window cannot be created
before constructing the OOGui base, this method is called
by the OOGui constructor to ensure a valid top level window is
available upon which to build the GUI.
_loadResources(self, resourceFile=None)
Loads GUI resources to customize the look and feel of widgets;
return true if all is well. If resource file is used, implementation
should override method and return value indicating status of load.
_setCWD(self, pathname)
Abstract method to set the current working directory to
'pathname' and update the GUI.
_setFilename(self, filename)
Abstract to set the filename entry text field of the GUI.
_startGui(self, geometry=None)
Abstract method to start the GUI, including the main event loop.

 
Data
             APP_HEIGHT = 500
BORDER = 10
DIRS_LABEL = 'Directories'
DISPLAY_HEIGHT = 160
DISPLAY_LABEL = 'Display file: '
DISPLAY_UNAVAIL = 'Viewer Not Available for File'
DISPLAY_WIDTH = 360
FILENAME_LABEL = 'Selected File'
FILES_LABEL = 'Files'
SASH_MIN = 100
SASH_POSITION = 200
_BINARY = ('pyc', 'exe', 'o', 'obj', 'com', 'ppt', 'doc')
_FXPY = 'F'
_GEOMETRY = 'g'
_GUITYPES = ['T', 'W', 'Q', 'G', 'F']
_HELP = 'h'
_HTML = ('htm', 'html')
_IMAGES = ('gif', 'jpg', 'jpeg', 'ppm', 'bmp', 'png', 'tif', 'tiff', 'wmf', 'pbm', 'pil')
_OTHEROPT = {'g': 'geometry, e.g., <width>x<height>+<x>+<y>', 'r': 'resourceFile', 's': 'startupDirectory'}
_PYGTK = 'G'
_PYQT = 'Q'
_RESFILE = 'r'
_STARTDIR = 's'
_TITLE = 'Object-Oriented GUI Example'
_TKINTER = 'T'
_WXWIN = 'W'
__file__ = r'http://www.metaslash.com/brochure/tutorial/oogui.pyc'
__name__ = 'oogui'