]> git.saurik.com Git - wxWidgets.git/blame - wxPython/docs/wxPythonExamples.txt
wxTextCtrl::HitTest
[wxWidgets.git] / wxPython / docs / wxPythonExamples.txt
CommitLineData
1fded56b
RD
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
20Introduction
21============
22
23This document illustrates example programs using wxPython. All the
24examples make use of the new wx package syntax introduced in wxPython
252.4.1, which is a bit different than older examples you might come
26across.
27
28
29Background (with tongue firmly in cheek)
30========================================
31
32If something hits you on the head, don't run around screaming that the
33sky 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
35class names like flies dropping dead in the scorching heat of a
36summer's day.
37
38Yes, the world is changing, and even our little wxPython world must
39change with it. Then again, I'm not fond of pesky summertime flies,
40and I'm not too upset that the "wx" prefixes are going to bite the
41dust. I think it's for the best. But, being the kind, considerate
42person that I am, I decided to write this guide to make the wx
43namespace 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
61Rather than simply **tell** you that everything will be okay, I
62decided to **show** you that everything will be okay. To do that,
63I've created a bunch of example programs using the new wx package. I
64hope you like them.
65
66
67Basic Program Example
68=====================
69
70It doesn't get much simpler than this. Every wxPython program needs
71an application and a frame. To encourage good coding habits, I've
72split them into separate modules. They don't do much, but they're a
73good starting point.
74
75I include a simple App class in the frame module because the PyWrap
76"wrapper" utility (``pywrap``) only works with modules that contain an
77application class. So including a simple one in each of your frame
78modules allows you to use the PyWrap runtime wrapper and debug your
79frames independent of your full application.
80
81Here is the module (``frame.py``) that defines the frame class:
82
83.. include:: ../samples/wx_examples/basic/frame.py
84 :literal:
85
86And here is the module (``app.py``) that defines the application class
87and imports the frame from ``frame.py``:
88
89.. include:: ../samples/wx_examples/basic/app.py
90 :literal:
91
92
93Hello wxPython Example
94======================
95
96This program displays an image file (``wxPython.jpg``) inside a frame
97sized 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
114Here is the source code for ``hello.py``:
115
116.. include:: ../samples/wx_examples/hello/hello.py
117 :literal:
118