]> git.saurik.com Git - wxWidgets.git/blame - wxPython/docs/wxPackage.html
overwrite old wx DLLs even if the version numbers match
[wxWidgets.git] / wxPython / docs / wxPackage.html
CommitLineData
8eda5e35
RD
1<?xml version="1.0" encoding="iso-8859-1" ?>
2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4<head>
5<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
974a50f1 6<meta name="generator" content="Docutils 0.4: http://docutils.sourceforge.net/" />
8eda5e35
RD
7<title>The wxPython wx Package</title>
8<meta name="author" content="Patrick K. O'Brien" />
9<meta name="author" content="Robin Dunn" />
10<meta name="organization" content="Orbtech" />
7fa23c09 11<meta name="date" content="2004-03-26" />
974a50f1
RD
12<style type="text/css">
13
14/*
15:Author: David Goodger
16:Contact: goodger@users.sourceforge.net
17:Date: $Date$
18:Revision: $Revision$
19:Copyright: This stylesheet has been placed in the public domain.
20
21Default cascading style sheet for the HTML output of Docutils.
22
23See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
24customize this style sheet.
25*/
26
27/* used to remove borders from tables and images */
28.borderless, table.borderless td, table.borderless th {
29 border: 0 }
30
31table.borderless td, table.borderless th {
32 /* Override padding for "table.docutils td" with "! important".
33 The right padding separates the table cells. */
34 padding: 0 0.5em 0 0 ! important }
35
36.first {
37 /* Override more specific margin styles with "! important". */
38 margin-top: 0 ! important }
39
40.last, .with-subtitle {
41 margin-bottom: 0 ! important }
42
43.hidden {
44 display: none }
45
46a.toc-backref {
47 text-decoration: none ;
48 color: black }
49
50blockquote.epigraph {
51 margin: 2em 5em ; }
52
53dl.docutils dd {
54 margin-bottom: 0.5em }
55
56/* Uncomment (and remove this text!) to get bold-faced definition list terms
57dl.docutils dt {
58 font-weight: bold }
59*/
60
61div.abstract {
62 margin: 2em 5em }
63
64div.abstract p.topic-title {
65 font-weight: bold ;
66 text-align: center }
67
68div.admonition, div.attention, div.caution, div.danger, div.error,
69div.hint, div.important, div.note, div.tip, div.warning {
70 margin: 2em ;
71 border: medium outset ;
72 padding: 1em }
73
74div.admonition p.admonition-title, div.hint p.admonition-title,
75div.important p.admonition-title, div.note p.admonition-title,
76div.tip p.admonition-title {
77 font-weight: bold ;
78 font-family: sans-serif }
79
80div.attention p.admonition-title, div.caution p.admonition-title,
81div.danger p.admonition-title, div.error p.admonition-title,
82div.warning p.admonition-title {
83 color: red ;
84 font-weight: bold ;
85 font-family: sans-serif }
86
87/* Uncomment (and remove this text!) to get reduced vertical space in
88 compound paragraphs.
89div.compound .compound-first, div.compound .compound-middle {
90 margin-bottom: 0.5em }
91
92div.compound .compound-last, div.compound .compound-middle {
93 margin-top: 0.5em }
94*/
95
96div.dedication {
97 margin: 2em 5em ;
98 text-align: center ;
99 font-style: italic }
100
101div.dedication p.topic-title {
102 font-weight: bold ;
103 font-style: normal }
104
105div.figure {
106 margin-left: 2em ;
107 margin-right: 2em }
108
109div.footer, div.header {
110 clear: both;
111 font-size: smaller }
112
113div.line-block {
114 display: block ;
115 margin-top: 1em ;
116 margin-bottom: 1em }
117
118div.line-block div.line-block {
119 margin-top: 0 ;
120 margin-bottom: 0 ;
121 margin-left: 1.5em }
122
123div.sidebar {
124 margin-left: 1em ;
125 border: medium outset ;
126 padding: 1em ;
127 background-color: #ffffee ;
128 width: 40% ;
129 float: right ;
130 clear: right }
131
132div.sidebar p.rubric {
133 font-family: sans-serif ;
134 font-size: medium }
135
136div.system-messages {
137 margin: 5em }
138
139div.system-messages h1 {
140 color: red }
141
142div.system-message {
143 border: medium outset ;
144 padding: 1em }
145
146div.system-message p.system-message-title {
147 color: red ;
148 font-weight: bold }
149
150div.topic {
151 margin: 2em }
152
153h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
154h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
155 margin-top: 0.4em }
156
157h1.title {
158 text-align: center }
159
160h2.subtitle {
161 text-align: center }
162
163hr.docutils {
164 width: 75% }
165
166img.align-left {
167 clear: left }
168
169img.align-right {
170 clear: right }
171
172ol.simple, ul.simple {
173 margin-bottom: 1em }
174
175ol.arabic {
176 list-style: decimal }
177
178ol.loweralpha {
179 list-style: lower-alpha }
180
181ol.upperalpha {
182 list-style: upper-alpha }
183
184ol.lowerroman {
185 list-style: lower-roman }
186
187ol.upperroman {
188 list-style: upper-roman }
189
190p.attribution {
191 text-align: right ;
192 margin-left: 50% }
193
194p.caption {
195 font-style: italic }
196
197p.credits {
198 font-style: italic ;
199 font-size: smaller }
200
201p.label {
202 white-space: nowrap }
203
204p.rubric {
205 font-weight: bold ;
206 font-size: larger ;
207 color: maroon ;
208 text-align: center }
209
210p.sidebar-title {
211 font-family: sans-serif ;
212 font-weight: bold ;
213 font-size: larger }
214
215p.sidebar-subtitle {
216 font-family: sans-serif ;
217 font-weight: bold }
218
219p.topic-title {
220 font-weight: bold }
221
222pre.address {
223 margin-bottom: 0 ;
224 margin-top: 0 ;
225 font-family: serif ;
226 font-size: 100% }
227
228pre.literal-block, pre.doctest-block {
229 margin-left: 2em ;
230 margin-right: 2em ;
231 background-color: #eeeeee }
232
233span.classifier {
234 font-family: sans-serif ;
235 font-style: oblique }
236
237span.classifier-delimiter {
238 font-family: sans-serif ;
239 font-weight: bold }
240
241span.interpreted {
242 font-family: sans-serif }
243
244span.option {
245 white-space: nowrap }
246
247span.pre {
248 white-space: pre }
249
250span.problematic {
251 color: red }
252
253span.section-subtitle {
254 /* font-size relative to parent (h1..h6 element) */
255 font-size: 80% }
256
257table.citation {
258 border-left: solid 1px gray;
259 margin-left: 1px }
260
261table.docinfo {
262 margin: 2em 4em }
263
264table.docutils {
265 margin-top: 0.5em ;
266 margin-bottom: 0.5em }
267
268table.footnote {
269 border-left: solid 1px black;
270 margin-left: 1px }
271
272table.docutils td, table.docutils th,
273table.docinfo td, table.docinfo th {
274 padding-left: 0.5em ;
275 padding-right: 0.5em ;
276 vertical-align: top }
277
278table.docutils th.field-name, table.docinfo th.docinfo-name {
279 font-weight: bold ;
280 text-align: left ;
281 white-space: nowrap ;
282 padding-left: 0 }
283
284h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
285h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
286 font-size: 100% }
287
288tt.docutils {
289 background-color: #eeeeee }
290
291ul.auto-toc {
292 list-style-type: none }
293
294</style>
8eda5e35
RD
295</head>
296<body>
297<div class="document" id="the-wxpython-wx-package">
298<h1 class="title">The wxPython wx Package</h1>
299<h2 class="subtitle" id="or-how-to-survive-the-new-wx-namespace-changes">Or, how to survive the new wx namespace changes.</h2>
300<table class="docinfo" frame="void" rules="none">
301<col class="docinfo-name" />
302<col class="docinfo-content" />
303<tbody valign="top">
304<tr><th class="docinfo-name">Author:</th>
305<td>Patrick K. O'Brien</td></tr>
306<tr><th class="docinfo-name">Author:</th>
307<td>Robin Dunn</td></tr>
308<tr><th class="docinfo-name">Contact:</th>
309<td><a class="first last reference" href="mailto:pobrien&#64;orbtech.com">pobrien&#64;orbtech.com</a></td></tr>
310<tr><th class="docinfo-name">Organization:</th>
311<td><a class="first last reference" href="http://www.orbtech.com/">Orbtech</a></td></tr>
312<tr><th class="docinfo-name">Date:</th>
7fa23c09 313<td>2004-03-26</td></tr>
8eda5e35 314<tr><th class="docinfo-name">Revision:</th>
7fa23c09 315<td>1.4</td></tr>
8eda5e35
RD
316</tbody>
317</table>
974a50f1
RD
318<div class="contents topic">
319<p class="topic-title first"><a id="contents" name="contents">Contents</a></p>
8eda5e35
RD
320<ul class="simple">
321<li><a class="reference" href="#introduction" id="id2" name="id2">Introduction</a></li>
322<li><a class="reference" href="#why-change-anything" id="id3" name="id3">Why change anything?</a></li>
323<li><a class="reference" href="#what-does-the-new-wx-package-do" id="id4" name="id4">What does the new wx package do?</a></li>
324<li><a class="reference" href="#will-any-of-this-effect-my-existing-code" id="id5" name="id5">Will any of this effect my existing code?</a></li>
325<li><a class="reference" href="#what-about-all-the-other-modules-like-grid-html-and-stc" id="id6" name="id6">What about all the other modules, like grid, html, and stc?</a></li>
326<li><a class="reference" href="#how-do-i-use-this-new-wx-package" id="id7" name="id7">How do I use this new wx package?</a></li>
327<li><a class="reference" href="#what-are-the-issues-with-converting-old-code-to-use-the-new-wx-package" id="id8" name="id8">What are the issues with converting old code to use the new wx package?</a></li>
328<li><a class="reference" href="#where-can-i-find-example-programs-using-the-new-wx-syntax" id="id9" name="id9">Where can I find example programs using the new wx syntax?</a></li>
329</ul>
330</div>
974a50f1
RD
331<div class="section">
332<h1><a class="toc-backref" href="#id2" id="introduction" name="introduction">Introduction</a></h1>
8eda5e35
RD
333<p>In the begining there was Python, and Python had modules, and Python
334was good. But after a time Guido looked on Python and saw that Python
335needed organizational assistance, and so Guido took code from Python's
336side and created Packages and then Python was very good. About this
337time wxPython was reborn, and wxPython used Packages, but being young
338and trying to use a new technology wxPython did not know how to use
339Packages effectivly. wxPython was good, but dreamed of being much
340better...</p>
341<p>Now many years later, after tons of code reorganization and build
342hacking wxPython has reached that goal. In version 2.4.1 a prototype
343of this new structure was introduced that dynamically built at import
344time a new toplevel package named simply &quot;wx&quot; that contained all the
345items from wxPython.wx but with the names edited to remove the wx
346prefix. Now in 2.5 the final phase of that switcheroo has been
347completed and the <em>real</em> classes, functions and constants are now
348located in the wx package, leaving some compatibility modules in
349wxPython.wx. This document should answer all the questions you might
350have concerning the new wx package. Please also take a look at the
351<a class="reference" href="MigrationGuide.html">2.5 Migration Guide</a> to see notes about other big differences in
352this release.</p>
353</div>
974a50f1
RD
354<div class="section">
355<h1><a class="toc-backref" href="#id3" id="why-change-anything" name="why-change-anything">Why change anything?</a></h1>
8eda5e35 356<p>This change is being made for a couple of reasons. The first reason
c66cd08a 357is to discourage the use of <tt class="docutils literal"><span class="pre">import</span> <span class="pre">*</span></tt>, which is a dangerous
8eda5e35
RD
358technique that can create name conflicts and bloated namespaces.</p>
359<p>The second reason is to remove what some perceive to be a &quot;wart.&quot; For
360example, the following code is rather ugly in that the &quot;wx&quot; prefix on
361the wxFrame class name is no longer useful when you're using the wx
362module prefix:</p>
363<pre class="literal-block">
364from wxPython import wx
365
366class Frame(wx.wxFrame)
367</pre>
368<p>The new wx package allows you to write code like this, instead:</p>
369<pre class="literal-block">
370import wx
371
372class Frame(wx.Frame)
373</pre>
374<p>The third reason is that the wxWindows project has considered doing
375the same thing (implement a new wx namespace and drop the &quot;wx&quot; prefix)
376and we want wxPython to lead the way.</p>
377</div>
974a50f1
RD
378<div class="section">
379<h1><a class="toc-backref" href="#id4" id="what-does-the-new-wx-package-do" name="what-does-the-new-wx-package-do">What does the new wx package do?</a></h1>
8eda5e35
RD
380<p>As mentioned in the Introduction, wxPython 2.4.1 introduced a way of
381getting to this new syntax as quickly as possible. It would import
382the old names (like &quot;wxFrame&quot;) from the old package and then create new
383names in the wx package without the wx prefix, (like &quot;Frame&quot;.)
384Starting with wxPython 2.5 the renaming is moved up to the wxPython
385build step, so the real classes and etc. are actually named with the
386new name (like &quot;Frame&quot;) and are located in the new wx package.</p>
387<p>For compatibility the old wxPython package still exists, but now it is
388populated with modules that simply import the new names and then
389&quot;reverse-renames&quot; them to the old names. It probably sounds a bit
390complicated, but it is mostly automated and so it doesn't cause
391problems in most cases.</p>
392</div>
974a50f1
RD
393<div class="section">
394<h1><a class="toc-backref" href="#id5" id="will-any-of-this-effect-my-existing-code" name="will-any-of-this-effect-my-existing-code">Will any of this effect my existing code?</a></h1>
8eda5e35
RD
395<p>No. Your existing code will continue to work and be supported for
396some time. It will be up to you to decide when to switch to the new
397syntax. But all new documentation and code examples will use the new
398syntax. So don't wait too long. You wouldn't want anyone calling you
399old-fashioned, would you?</p>
400<p>When you import from wxPython.wx and use a class with the old name,
401such as wxButton, you are actually using the wx.Button class. I
402expect that the vast majority of the existing code should work fine
403using this scheme. The only things that may cause problems is if your
404old code is depending on some of the implemtation details, or if you
405are using other things that have changed in the API. See the
406<a class="reference" href="MigrationGuide.html">Migration Guide</a> for more details.</p>
407</div>
974a50f1
RD
408<div class="section">
409<h1><a class="toc-backref" href="#id6" id="what-about-all-the-other-modules-like-grid-html-and-stc" name="what-about-all-the-other-modules-like-grid-html-and-stc">What about all the other modules, like grid, html, and stc?</a></h1>
8eda5e35
RD
410<p>There's more to the old wxPython than just the wxPython.wx module.
411And we've got those extra modules covered as well. Each of those
412modules (as well as the lib subpackage) has been moved to the new wx
413package and reverse-renamers have been placed in the wxPython package
414as needed.</p>
415</div>
974a50f1
RD
416<div class="section">
417<h1><a class="toc-backref" href="#id7" id="how-do-i-use-this-new-wx-package" name="how-do-i-use-this-new-wx-package">How do I use this new wx package?</a></h1>
8eda5e35
RD
418<p>The wx package is automatically created when you install wxPython
419version 2.4.1 or higher. So all you have to do is:</p>
420<pre class="literal-block">
421import wx
422</pre>
423</div>
974a50f1
RD
424<div class="section">
425<h1><a class="toc-backref" href="#id8" id="what-are-the-issues-with-converting-old-code-to-use-the-new-wx-package" name="what-are-the-issues-with-converting-old-code-to-use-the-new-wx-package">What are the issues with converting old code to use the new wx package?</a></h1>
8eda5e35
RD
426<p>Obviously, you need to change your import statements from:</p>
427<pre class="literal-block">
428from wxPython import wx
429</pre>
430<p>or:</p>
431<pre class="literal-block">
432from wxPython.wx import *
433</pre>
434<p>to:</p>
435<pre class="literal-block">
436import wx
437</pre>
438<p>Then you need to refer to wx attributes without a &quot;wx&quot; prefix, such
439as:</p>
440<pre class="literal-block">
441class MyFrame(wx.Frame):
442</pre>
443<p>In most cases, existing code can be modified with a simple search and
444replace.</p>
445</div>
974a50f1
RD
446<div class="section">
447<h1><a class="toc-backref" href="#id9" id="where-can-i-find-example-programs-using-the-new-wx-syntax" name="where-can-i-find-example-programs-using-the-new-wx-syntax">Where can I find example programs using the new wx syntax?</a></h1>
90805926 448<p>The wxPython demo application and most of the sample apps have been
c66cd08a 449converted to use the new <tt class="docutils literal"><span class="pre">import</span> <span class="pre">wx</span></tt> style of programming with
90805926 450wxPython, so there are lots of examples to look at and to play with.
c66cd08a 451Here is one of them, it is the <tt class="docutils literal"><span class="pre">simple</span></tt> sample.</p>
90805926
RD
452<pre class="literal-block">
453#----------------------------------------------------------------------
60b517c1
RD
454# A very simple wxPython example. Just a wx.Frame, wx.Panel,
455# wx.StaticText, wx.Button, and a wx.BoxSizer, but it shows the basic
90805926
RD
456# structure of any wxPython application.
457#----------------------------------------------------------------------
458
459import wx
460
461
462class MyFrame(wx.Frame):
463 &quot;&quot;&quot;
464 This is MyFrame. It just shows a few controls on a wxPanel,
465 and has a simple menu.
466 &quot;&quot;&quot;
467 def __init__(self, parent, title):
468 wx.Frame.__init__(self, parent, -1, title,
469 pos=(150, 150), size=(350, 200))
470
471 # Create the menubar
472 menuBar = wx.MenuBar()
473
474 # and a menu
475 menu = wx.Menu()
476
477 # add an item to the menu, using \tKeyName automatically
478 # creates an accelerator, the third param is some help text
479 # that will show up in the statusbar
480 menu.Append(wx.ID_EXIT, &quot;E&amp;xit\tAlt-X&quot;, &quot;Exit this simple sample&quot;)
481
482 # bind the menu event to an event handler
483 self.Bind(wx.EVT_MENU, self.OnTimeToClose, id=wx.ID_EXIT)
484
485 # and put the menu on the menubar
486 menuBar.Append(menu, &quot;&amp;File&quot;)
487 self.SetMenuBar(menuBar)
488
489 self.CreateStatusBar()
490
491
492 # Now create the Panel to put the other controls on.
493 panel = wx.Panel(self)
494
495 # and a few controls
496 text = wx.StaticText(panel, -1, &quot;Hello World!&quot;)
497 text.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL, wx.BOLD))
498 text.SetSize(text.GetBestSize())
499 btn = wx.Button(panel, -1, &quot;Close&quot;)
500 funbtn = wx.Button(panel, -1, &quot;Just for fun...&quot;)
501
502 # bind the button events to handlers
503 self.Bind(wx.EVT_BUTTON, self.OnTimeToClose, btn)
504 self.Bind(wx.EVT_BUTTON, self.OnFunButton, funbtn)
505
506 # Use a sizer to layout the controls, stacked vertically and with
507 # a 10 pixel border around each
508 sizer = wx.BoxSizer(wx.VERTICAL)
509 sizer.Add(text, 0, wx.ALL, 10)
510 sizer.Add(btn, 0, wx.ALL, 10)
511 sizer.Add(funbtn, 0, wx.ALL, 10)
512 panel.SetSizer(sizer)
513 panel.Layout()
514
515
516 def OnTimeToClose(self, evt):
517 &quot;&quot;&quot;Event handler for the button click.&quot;&quot;&quot;
518 print &quot;See ya later!&quot;
519 self.Close()
520
521 def OnFunButton(self, evt):
522 &quot;&quot;&quot;Event handler for the button click.&quot;&quot;&quot;
523 print &quot;Having fun yet?&quot;
524
525
526class MyApp(wx.App):
527 def OnInit(self):
528 frame = MyFrame(None, &quot;Simple wxPython App&quot;)
90805926 529 self.SetTopWindow(frame)
60b517c1
RD
530
531 print &quot;Print statements go to this stdout window by default.&quot;
532
533 frame.Show(True)
90805926
RD
534 return True
535
60b517c1 536app = MyApp(redirect=True)
90805926
RD
537app.MainLoop()
538
539
540</pre>
8eda5e35
RD
541</div>
542</div>
8eda5e35
RD
543</body>
544</html>