annotate Mac/Demo/example2.html @ 5817:48b94de85bf3 legacy-trunk

Extensive changes by AMK.
author Guido van Rossum <guido@python.org>
date Thu, 17 Jul 1997 16:29:42 +0000
parents 3b3870b9acf2
children 9a3e6f0d6b5a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3457
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1 <HTML><HEAD><TITLE>Using python to create Macintosh applications, part two</TITLE></HEAD>
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
2 <BODY>
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
3 <H1>Using python to create Macintosh applications, part two</H1>
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
4 <HR>
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
5
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
6 In this document we rewrite the application of the <A
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
7 HREF="example1.html">previous example</A> to use modeless dialogs. We
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
8 will use an application framework, and we will have a look at creating
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
9 applets, standalone applications written in Python. <A
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
10 HREF="example2/InterslipControl-2.py">Source</A> and resource file (in
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
11 binary and <A HREF="example2/InterslipControl-2.rsrc.hqx">BinHex</A>
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
12 form for downloading) are available in the folder <A
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
13 HREF="example2">example2</A>. If you want to run the program on your
3531
38e1480e7f89 Added documentation on FrameWork, TextEdit and Waste
Jack Jansen <jack.jansen@cwi.nl>
parents: 3457
diff changeset
14 machine and you have Python 1.3 or earlier you will also need a new copy of <A
3457
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
15 HREF="update-to-1.3/FrameWork.py">FrameWork.py</A>, which has been
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
16 updated since the 1.3 release. <p>
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
17
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
18 Again, we start with ResEdit to create our dialogs. Not only do we
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
19 want a main dialog this time but also an "About" dialog, and we
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
20 provide the <A NAME="bundle">BNDL resource</A> and related stuff that
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
21 an application cannot be without. (Actually, a python applet can be
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
22 without, <A HREF="#no-bundle">see below</A>). "Inside Mac" or various
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
23 books on macintosh programming will help here. Also, you can refer to
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
24 the resource files provided in the Python source distribution for some
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
25 of the python-specific points of BNDL programming: the
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
26 "appletbundle.rsrc" file is what is used for creating applets if you
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
27 don't provide your own resource file. <p>
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
28
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
29 Let's have a look at InterslipControl-2.rsrc, our resource file. First
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
30 off, there's the standard BNDL combo. I've picked 'PYTi' as signature
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
31 for the application. I tend to pick PYT plus one lower-case letter for
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
32 my signatures. The finder gets confused if you have two applications
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
33 with the same signature. This may be due to some incorrectness on the
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
34 side of "mkapplet", I am not sure. There is one case when you
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
35 definitely need a unique signature: when you create an applet that has
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
36 its own data files and you want the user to be able to start your
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
37 applet by double-clicking one of the datafiles. <p>
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
38
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
39 There's little to tell about the BNDL stuff: I basically copied the
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
40 generic Python applet icons and pasted in the symbol for
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
41 InterSLIP. The two dialogs are equally unexciting: dialog 512 is our
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
42 main window which has four static text fields (two of which we will be
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
43 modifying during runtime, to show the status of the connection) and
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
44 two buttons "connect" and "disconnect". The "quit" and "update status"
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
45 buttons have disappeared, because they are handled by a menu choice
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
46 and automatically, respectively. <p>
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
47
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
48 <H2>A modeless dialog application using FrameWork</H2>
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
49
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
50 On to the source code in <A
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
51 HREF="example2/InterslipControl-2.py">InterslipControl-2.py</A>. The
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
52 start is similar to our previous example program <A
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
53 HREF="example1/InterslipControl-1.py">InterSlipControl-1.py</A>, with
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
54 one extra module being imported. To make life more simple we will use
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
55 the <CODE>FrameWork</CODE> module, a nifty piece of code that handles
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
56 all the gory mac details of event loop programming, menubar
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
57 installation and all the other code that is the same for every mac
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
58 program in the world. Like most standard modules, FrameWork will run
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
59 some sample test code when you invoke it as a main program, so try it
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
60 now. It will create a menu bar with an Apple menu with the about box
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
61 and a "File" menu with some pythonesque choices (which do nothing
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
62 interesting, by the way) and a "Quit" command that works. <p>
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
63
3531
38e1480e7f89 Added documentation on FrameWork, TextEdit and Waste
Jack Jansen <jack.jansen@cwi.nl>
parents: 3457
diff changeset
64 <BLOCKQUOTE>
38e1480e7f89 Added documentation on FrameWork, TextEdit and Waste
Jack Jansen <jack.jansen@cwi.nl>
parents: 3457
diff changeset
65 If you have not used <code>FrameWork</code> before you may want to
38e1480e7f89 Added documentation on FrameWork, TextEdit and Waste
Jack Jansen <jack.jansen@cwi.nl>
parents: 3457
diff changeset
66 first take a look at the <A HREF="textedit.html">Pathetic EDitor</A>
38e1480e7f89 Added documentation on FrameWork, TextEdit and Waste
Jack Jansen <jack.jansen@cwi.nl>
parents: 3457
diff changeset
67 example, which builds a minimal text editor using FrameWork and TextEdit.
38e1480e7f89 Added documentation on FrameWork, TextEdit and Waste
Jack Jansen <jack.jansen@cwi.nl>
parents: 3457
diff changeset
68 On the other hand: we don't use many features of FrameWork, so you could
38e1480e7f89 Added documentation on FrameWork, TextEdit and Waste
Jack Jansen <jack.jansen@cwi.nl>
parents: 3457
diff changeset
69 also continue with this document.
38e1480e7f89 Added documentation on FrameWork, TextEdit and Waste
Jack Jansen <jack.jansen@cwi.nl>
parents: 3457
diff changeset
70 </BLOCKQUOTE>
3457
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
71
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
72 After the imports we get the definitions of resource-IDs in our
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
73 resource file, slightly changed from the previous version of our
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
74 program, and the state to string mapping. The main program is also
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
75 similar to our previous version, with one important exception: we
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
76 first check to see whether our resource is available before opening
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
77 the resource file. Why is this? Because later, when we will have
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
78 converted the script to an applet, our resources will be available in
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
79 the applet file and we don't need the separate resource file
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
80 anymore. <p>
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
81
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
82 Next comes the definition of our main class,
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
83 <CODE>InterslipControl</CODE>, which inherits
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
84 <CODE>FrameWork.Application</CODE>. The Application class handles the
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
85 menu bar and the main event loop and event dispatching. In the
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
86 <CODE>__init__</CODE> routine we first let the base class initialize
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
87 itself, then we create our modeless dialog and finally we jump into
4314
3b3870b9acf2 Calling Application._quit() is now preferred over raising self.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3531
diff changeset
88 the main loop. The main loop continues until we call <CODE>self._quit</CODE>,
3b3870b9acf2 Calling Application._quit() is now preferred over raising self.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3531
diff changeset
89 which we will do when the user selects "quit". When we create
3457
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
90 the instance of <CODE>MyDialog</CODE> (which inherits
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
91 <CODE>DialogWindow</CODE>, which inherits <CODE>Window</CODE>) we pass
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
92 a reference to the application object, this reference is used to tell
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
93 Application about our new window. This enables the event loop to keep
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
94 track of all windows and dispatch things like update events and mouse
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
95 clicks. <p>
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
96
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
97 The <CODE>makeusermenus()</CODE> method (which is called sometime
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
98 during the Application <CODE>__init__</CODE> routine) creates a File
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
99 menu with a Quit command (shortcut command-Q), which will callback to
4314
3b3870b9acf2 Calling Application._quit() is now preferred over raising self.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3531
diff changeset
100 our quit() method. <CODE>Quit()</CODE>, in turn, calls <CODE>_quit</CODE> which
3b3870b9acf2 Calling Application._quit() is now preferred over raising self.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3531
diff changeset
101 causes the mainloop to terminate at a convenient time. <p>
3457
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
102
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
103 Application provides a standard about box, but we override this by
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
104 providing our own <CODE>do_about()</CODE> method which shows an about
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
105 box from a resource as a modal dialog. This piece of code should look
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
106 familiar to you from the previous example program. That do_about is
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
107 called when the user selects About from the Apple menu is, again,
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
108 taken care of by the __init__ routine of Application. <p>
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
109
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
110 Our main object finally overrides <CODE>idle()</CODE>, the method
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
111 called when no event is available. It passes the call on to our dialog
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
112 object to give it a chance to update the status fields, if needed. <p>
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
113
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
114 The <CODE>MyDialog</CODE> class is the container for our main
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
115 window. Initialization is again done by first calling the base class
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
116 <CODE>__init__</CODE> function and finally setting two local variables
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
117 that are used by <CODE>updatestatus()</CODE> later. <p>
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
118
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
119 <CODE>Do_itemhit()</CODE> is called when an item is selected in this
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
120 dialog by the user. We are passed the item number (and the original
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
121 event structure, which we normally ignore). The code is similar to the
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
122 main loop of our previous example program: a switch depending on the
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
123 item selected. <CODE>Connect()</CODE> and <CODE>disconnect()</CODE>
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
124 are again quite similar to our previous example. <p>
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
125
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
126 <CODE>Updatestatus()</CODE> is different, however. It is now
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
127 potentially called many times per second instead of only when the
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
128 user presses a button we don't want to update the display every time
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
129 since that would cause some quite horrible flashing. Luckily,
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
130 <CODE>interslip.status()</CODE> not only provides us with a state and
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
131 a message but also with a message sequence number. If neither state
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
132 nor message sequence number has changed since the last call there is
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
133 no need to update the display, so we just return. For the rest,
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
134 nothing has changed. <p>
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
135
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
136 <H2><IMG SRC="html.icons/mkapplet.gif"><A NAME="applets">Creating applets</A></H2>
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
137
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
138 Now, if you have a PowerPC Macintosh, let us try to turn the python
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
139 script into an applet, a standalone application. Actually,
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
140 "standalone" is probably not the correct term here, since an applet
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
141 does still depend on a lot of the python environment: the PythonCore
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
142 shared library, the Python Preferences file, the python Lib folder and
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
143 any other modules that the main module depends on. It is possible to
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
144 get rid of all these dependencies except for the dependency on
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
145 PythonCore, but at the moment that is still quite difficult so we will
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
146 ignore that possibility for now. By standalone we mean here that the
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
147 script has the look-and-feel of an application, including the ability
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
148 to have its own document types, be droppable, etc. <p>
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
149
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
150 The easiest way to create an applet is to take your source file and
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
151 drop it onto "mkapplet" (normally located in the Python home
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
152 folder). This will create an applet with the same name as your python
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
153 source with the ".py" stripped. Also, if a resource file with the same
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
154 name as your source but with ".rsrc" extension is available the
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
155 resources from that file will be copied to your applet too. If there
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
156 is no resource file for your script a set of default resources will be
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
157 used, and the applet will have the default creator 'PYTa'. The latter
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
158 also happens if you do have a resource file but without the BNDL
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
159 combo. <A NAME="no-bundle">Actually</A>, for our example that would
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
160 have been the most logical solution, since our applet does not have
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
161 its own data files. It would have saved us hunting for an unused
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
162 creator code. The only reason for using the BNDL in this case is
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
163 having the custom icon, but that could have been done by pasting an
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
164 icon on the finder Info window, or by providing an custon icon in your
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
165 resource file and setting the "custom icon" finder bit. <p>
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
166
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
167 If you need slightly more control over the mkapplet process you can
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
168 double-click mkapplet, and you will get dialogs for source and
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
169 destination of the applet. The rest of the process, including locating
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
170 the resource file, remains the same. <p>
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
171
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
172 Note that though our example application completely bypasses the
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
173 normal python user interface this is by no means necessary. Any python
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
174 script can be turned into an applet, and all the usual features of the
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
175 interpreter still work. <p>
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
176
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
177 That's all for this example, you may now return to the <A HREF="index.html">
a71d2fd90fa8 Explanations of the examples here
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
178 table of contents</A> to pick another topic. <p>