File: app.txt

package info (click to toggle)
python-wpy 0.53-0.1
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 832 kB
  • ctags: 1,991
  • sloc: python: 8,624; makefile: 57; sh: 24
file content (175 lines) | stat: -rw-r--r-- 8,193 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
General

Wpy is a document/view model of a GUI.  The most important classes are:

CWinApp, the application.  You must write an application class derived from
this class and provide your own InitInstance method.  See below.  There can
be only one instance of the application class.  Generally, a wpy program
consists of class definitions plus a single line at the end "app=MyApp()"
to instantiate the application class instance.

CScrollView, a scroll view class.  You need to write a view class derived from
one of the CView classes.  CScrollView is a CView with built in scrolling
capabilities.  If the view does not require scrolling, the scroll bars disappear,
so this class is generally useful.

CDocument, a document class.  If your program reads and writes documents to
disk, you will need to derive a document class from this class.

There are many other useful classes such as CDialog, but the above three are
central to the document/view model.  Although a frame class is required, it
is not as important, and does not play a central role.

SDI and MDI Models

Wpy can create Single Document and Multi Document Interface GUI models.  The SDI
model means that the application has only one window with a menu on the screen.
In the MDI model, there are multiple child windows clipped to fit within
a single main window.  Each child window can have a menu, but that menu is displayed on
the main window when the child window is active.  The client area of the main window
is not used except as a background for the child windows.  Either model may also have
an unlimited number of dialog windows.

The choice between SDI and MDI is made in the InitInstance method of your application
class.  The code is mostly boiler plate.  To create a SDI application do the following:

1)  class MyApp(CWinApp):
2)    def InitInstance(self):
3)      templ = CSingleDocTemplate(CDocument, CFrameWnd, MyView, MyMenu)
4)      templ.wpyText = "Usual Hello World Demo"
5)      self.AddDocTemplate(templ)
6)      self.FileNew()

Line 1 derives a class from CWinApp, and line 2 overrides the InitInstance method.
This is required by every wpy app.  Line 3 instantiates a "template" instance from
an SDI template.  The template specifies how to create documents, frames, views and
menus for the application.  You specify the classes from which these objects will be
created.  The document and frame classes are wpy classes, and the view class is
a user-specified class derived (in this example) from CScrollView.  The frame class
for the SDI model must be CFrameWnd, or a user class derived from it.  Line 4 just
specifies a document title.  Note that this is an attribute of the
template.  Line 5 records the template in the application.  Line 6 creates a new
empty document plus its frame and view.  This is the same operation which would
occur if the user selected File/New from a main menu.  Line 6 is required, otherwise
there would be no window to display after InitInstance returns.  When "FileNew()"
is called, the template will be used to make an instance of the four classes
specified, namely CDocumnet, CFrameWnd, MyView and MyMenu.  These classes will be
linked together, and the window will appear on the screen.

Wpy has the concept of a "Main Window".  In SDI the main window is the only window.
In a MDI model things are a little more complicated.  You need different frame classes,
and you use a different template.  To create a MDI application do the following:

1)  class MyApp(CWinApp):
2)    def InitInstance(self):
3)      templ = CMultiDocTemplate(CDocument, CMDIChildWnd, MyView, ScribFrameMenu)
4)      templ.wpyText = "Scribble"
5)      self.AddDocTemplate(templ)
6)      main_frame = CMDIFrameWnd()
7)      main_frame.wpyMenu = ScribMainFrameMenu()
8)      main_frame.wpyText = "Main frame title"
9)      main_frame.Create()
10)     self.FileNew()

Lines 1 and 2 drive an application class and override InitInstance as
before.  Line 3 creates a template but this time it is an MDI template
with a different frame type CMDIChildWnd.  This template is responsible
for creating child windows.  Line 5 records the doc template as before.
Line 6 makes a main frame window which will act as a container for all
the child windows.  Many wpy objects require two-step creation, so line 9
actually creates the main window and makes it visible.  Line 10 is optional
in this case, since there is already a main window.  It just creates a
single empty child window.  The menu in Line 3 is an attribute of the
template, and is created for every child window.  The menu in line 7 is
an attribute of the main window and will only be visible if there are no
child windows.  Otherwise, the menu shown on the main window will be that
of the active child.

After InitInstance returns, all further interaction with the system will
be in response to events.  So you need to be sure you have set up a main
window in InitInstance, and that all your derived classes have proper
message handlers.  If you return zero from InitInstance() the application
will exit.

When a document is opened, it is possible to specify a file filter as
part of the document template.  This controls what files will initially
be visible in the open file dialog box.  The filter is a tuple of two
strings.  The first is the name of the file type, the second is the extension
for files of that type including the ".".  For example,
          templ.wpyFilter = ("Point data files", ".pdf")

There is only one CWinApp object in any WPY application, so it is a
convenient place to put data attributes and methods which refer to
the whole application.  The single app instance is available from
any instance derived from CObject (almost all WPY instances are derived from
CObject) as self.wpyApp.  For example, to create a beep sound from a
button b1, use "b1.wpyApp.MessageBeep()".

Class CWinApp Attributes

wpyText, string
	The name of the application.  This is used as a title for
	AfxMessageBox(), and defaults to "Python".  Change in
	InitInstance() to get a different name.

wpyMainTitle, string
	The base name to use as a frame title for SDI applications.
	Change it in InitInstance.

Class CWinApp Methods

AddDocTemplate(self, template)
	Add a document template to the application.  There can be multiple
	templates representing multiple types of documents.

GetActiveFrame(self)
	Return the active frame (like GetActiveFrameDV()).

GetActiveFrameDV(self)
	Return the active frame, document, view as a tuple.  For a MDI app,
	the returned frame is one of the CMDIChildWnd's if there are any,
	otherwise the main frame theApp.wpyMainFrame.  For an SDI app,
	it returns theApp.wpyMainFrame.

FileOpen(self)
	Open a document and create its frame and view.  This is the default
	handler for File/Open.  If multiple templates are specified, then
	the first template is used.

FileNew(self, templ = None)
	Create a new empty document and create its frame and view.  This
	is the default handler for File/New.  If templ is specified, then
	that template will be used, and "templ" must be a valid template
	added to the application with AddDocTemplate().  Otherwise,
	the system will present a choice list of all the document types which
	have names "template.wpyFileNewName" specified.  If no such names are
	specified, the first template is used.  If there is only one such
	template, it is used and the dialog box does not appear.

WindowNew(self, templ = None)
	For a MDI application, create another view of the active document.  This
	is the default handler for Window/New.  If templ is specified, then that
	template is used, and "templ" must be a valid template added to the
	application with AddDocTemplate().  Otherwise, the template of the current
	document is used.

Exit(self, event = None)
	Exit the application.

PumpMessages(self):
	Process any waiting window system messages.  This is used to
	update the screen during lengthy calculations.

MessageBeep(self):
	Make a beep sound.



Methods of templates

To open a document without asking the user for a file name, use the template
method OpenDocumentFile().

OpenDocumentFile(self, filename)
filename	The file name to open.
Returns the document which was opened.