Creating the Application Object
The simplest way to create an
application object for Scribble is to subclass one of the standard
application objects. The PythonWin application object is implemented
in
pywin.framework.intpyapp
,
and it derives from the
CApp
class in
pywin.framework.app
. This base class provides much
of the functionality for an application, so we too will derive our
application from CApp
.
This makes the application object small and simple. You obviously may
need to enhance certain aspects; in this case, you should use the
pywin.framework
modules as a guide. The minimal
application object looks like:
# scribbleApp.py # # The application object for Python. from pywin.framework.app import CApp class ScribbleApplication(CApp): def InitInstance(self): # All we need do is call the base class, # then import our document template. CApp.InitInstance(self) import scribble2 # And create our application object. ScribbleApplication()
To run this, use the following command line:
C:\Scripts> start pythonwin /app scribbleApp.py
An instance of Pythonwin.exe now starts, but uses the application object you defined. Therefore, there’a no Interactive Window, the application doesn’t offer to open .py files, etc. The Scribble application should look like Figure 20.5.
There is also a technique to avoid this command line, but you need a copy of a resource ...
Get Python Programming On Win32 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.