]> git.saurik.com Git - wxWidgets.git/blob - wxPython/docs/wxPythonExamples.txt
Script updates
[wxWidgets.git] / wxPython / docs / wxPythonExamples.txt
1 =================================
2 Example Programs Using wxPython
3 =================================
4
5 --------------------------------------------------
6 A survival guide for the post-wx-prefixed world.
7 --------------------------------------------------
8
9 :Author: Patrick K. O'Brien
10 :Contact: pobrien@orbtech.com
11 :Organization: Orbtech_
12 :Date: $Date$
13 :Revision: $Revision$
14
15 .. _Orbtech: http://www.orbtech.com/
16
17 .. contents::
18
19
20 Introduction
21 ============
22
23 This document illustrates example programs using wxPython. All the
24 examples make use of the new wx package syntax introduced in wxPython
25 2.4.1, which is a bit different than older examples you might come
26 across.
27
28
29 Background (with tongue firmly in cheek)
30 ========================================
31
32 If something hits you on the head, don't run around screaming that the
33 sky is falling. Instead, take a close look and see if it wasn't a
34 "wx" prefix that hit you. Apparently, they're dropping off wxPython
35 class names like flies dropping dead in the scorching heat of a
36 summer's day.
37
38 Yes, the world is changing, and even our little wxPython world must
39 change with it. Then again, I'm not fond of pesky summertime flies,
40 and I'm not too upset that the "wx" prefixes are going to bite the
41 dust. I think it's for the best. But, being the kind, considerate
42 person that I am, I decided to write this guide to make the wx
43 namespace transition easier for everyone, even Chicken Little.
44
45 .. note:: Say what?
46
47 If you have no idea what I mean by the "wx namespace transition,"
48 consider yourself lucky. You can simply use these examples to
49 learn wxPython in its current state (beginning with wxPython
50 version 2.4.1). All you need to know is that previous wxPython
51 code used a slightly different syntax that some folks (including
52 me) considered ugly. So we changed it. And that's when the sky
53 starting falling...
54
55 If you want more of the technical details, read the `wx package
56 documentation`_.
57
58 .. _wx package documentation: wxPackage.html
59
60
61 Rather than simply **tell** you that everything will be okay, I
62 decided to **show** you that everything will be okay. To do that,
63 I've created a bunch of example programs using the new wx package. I
64 hope you like them.
65
66
67 Basic Program Example
68 =====================
69
70 It doesn't get much simpler than this. Every wxPython program needs
71 an application and a frame. To encourage good coding habits, I've
72 split them into separate modules. They don't do much, but they're a
73 good starting point.
74
75 I include a simple App class in the frame module because the PyWrap
76 "wrapper" utility (``pywrap``) only works with modules that contain an
77 application class. So including a simple one in each of your frame
78 modules allows you to use the PyWrap runtime wrapper and debug your
79 frames independent of your full application.
80
81 Here is the module (``frame.py``) that defines the frame class:
82
83 .. include:: ../samples/wx_examples/basic/frame.py
84 :literal:
85
86 And here is the module (``app.py``) that defines the application class
87 and imports the frame from ``frame.py``:
88
89 .. include:: ../samples/wx_examples/basic/app.py
90 :literal:
91
92
93 Hello wxPython Example
94 ======================
95
96 This program displays an image file (``wxPython.jpg``) inside a frame
97 sized to match the graphic.
98
99 .. figure:: screenshots/hello-win98.png
100 :scale: 100
101
102 Running ``hello.py`` on Windows.
103
104 .. figure:: screenshots/hello-linux.png
105 :scale: 100
106
107 Running ``hello.py`` on Linux.
108
109 .. figure:: screenshots/hello-mac.png
110 :scale: 100
111
112 Running ``hello.py`` on Mac OS X.
113
114 Here is the source code for ``hello.py``:
115
116 .. include:: ../samples/wx_examples/hello/hello.py
117 :literal:
118