]> git.saurik.com Git - wxWidgets.git/blame - wxPython/docs/MigrationGuide.html
added --enable-tga (on by default)
[wxWidgets.git] / wxPython / docs / MigrationGuide.html
CommitLineData
6158f936 1<?xml version="1.0" encoding="iso-8859-1" ?>
d14a1e28
RD
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>
6158f936 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/" />
05d6c206 7<title>wxPython 2.6 Migration Guide</title>
974a50f1
RD
8<style type="text/css">
9
10/*
11:Author: David Goodger
12:Contact: goodger@users.sourceforge.net
13:Date: $Date$
14:Revision: $Revision$
15:Copyright: This stylesheet has been placed in the public domain.
16
17Default cascading style sheet for the HTML output of Docutils.
18
19See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
20customize this style sheet.
21*/
22
23/* used to remove borders from tables and images */
24.borderless, table.borderless td, table.borderless th {
25 border: 0 }
26
27table.borderless td, table.borderless th {
28 /* Override padding for "table.docutils td" with "! important".
29 The right padding separates the table cells. */
30 padding: 0 0.5em 0 0 ! important }
31
32.first {
33 /* Override more specific margin styles with "! important". */
34 margin-top: 0 ! important }
35
36.last, .with-subtitle {
37 margin-bottom: 0 ! important }
38
39.hidden {
40 display: none }
41
42a.toc-backref {
43 text-decoration: none ;
44 color: black }
45
46blockquote.epigraph {
47 margin: 2em 5em ; }
48
49dl.docutils dd {
50 margin-bottom: 0.5em }
51
52/* Uncomment (and remove this text!) to get bold-faced definition list terms
53dl.docutils dt {
54 font-weight: bold }
55*/
56
57div.abstract {
58 margin: 2em 5em }
59
60div.abstract p.topic-title {
61 font-weight: bold ;
62 text-align: center }
63
64div.admonition, div.attention, div.caution, div.danger, div.error,
65div.hint, div.important, div.note, div.tip, div.warning {
66 margin: 2em ;
67 border: medium outset ;
68 padding: 1em }
69
70div.admonition p.admonition-title, div.hint p.admonition-title,
71div.important p.admonition-title, div.note p.admonition-title,
72div.tip p.admonition-title {
73 font-weight: bold ;
74 font-family: sans-serif }
75
76div.attention p.admonition-title, div.caution p.admonition-title,
77div.danger p.admonition-title, div.error p.admonition-title,
78div.warning p.admonition-title {
79 color: red ;
80 font-weight: bold ;
81 font-family: sans-serif }
82
83/* Uncomment (and remove this text!) to get reduced vertical space in
84 compound paragraphs.
85div.compound .compound-first, div.compound .compound-middle {
86 margin-bottom: 0.5em }
87
88div.compound .compound-last, div.compound .compound-middle {
89 margin-top: 0.5em }
90*/
91
92div.dedication {
93 margin: 2em 5em ;
94 text-align: center ;
95 font-style: italic }
96
97div.dedication p.topic-title {
98 font-weight: bold ;
99 font-style: normal }
100
101div.figure {
102 margin-left: 2em ;
103 margin-right: 2em }
104
105div.footer, div.header {
106 clear: both;
107 font-size: smaller }
108
109div.line-block {
110 display: block ;
111 margin-top: 1em ;
112 margin-bottom: 1em }
113
114div.line-block div.line-block {
115 margin-top: 0 ;
116 margin-bottom: 0 ;
117 margin-left: 1.5em }
118
119div.sidebar {
120 margin-left: 1em ;
121 border: medium outset ;
122 padding: 1em ;
123 background-color: #ffffee ;
124 width: 40% ;
125 float: right ;
126 clear: right }
127
128div.sidebar p.rubric {
129 font-family: sans-serif ;
130 font-size: medium }
131
132div.system-messages {
133 margin: 5em }
134
135div.system-messages h1 {
136 color: red }
137
138div.system-message {
139 border: medium outset ;
140 padding: 1em }
141
142div.system-message p.system-message-title {
143 color: red ;
144 font-weight: bold }
145
146div.topic {
147 margin: 2em }
148
149h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
150h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
151 margin-top: 0.4em }
152
153h1.title {
154 text-align: center }
155
156h2.subtitle {
157 text-align: center }
158
159hr.docutils {
160 width: 75% }
161
162img.align-left {
163 clear: left }
164
165img.align-right {
166 clear: right }
167
168ol.simple, ul.simple {
169 margin-bottom: 1em }
170
171ol.arabic {
172 list-style: decimal }
173
174ol.loweralpha {
175 list-style: lower-alpha }
176
177ol.upperalpha {
178 list-style: upper-alpha }
179
180ol.lowerroman {
181 list-style: lower-roman }
182
183ol.upperroman {
184 list-style: upper-roman }
185
186p.attribution {
187 text-align: right ;
188 margin-left: 50% }
189
190p.caption {
191 font-style: italic }
192
193p.credits {
194 font-style: italic ;
195 font-size: smaller }
196
197p.label {
198 white-space: nowrap }
199
200p.rubric {
201 font-weight: bold ;
202 font-size: larger ;
203 color: maroon ;
204 text-align: center }
205
206p.sidebar-title {
207 font-family: sans-serif ;
208 font-weight: bold ;
209 font-size: larger }
210
211p.sidebar-subtitle {
212 font-family: sans-serif ;
213 font-weight: bold }
214
215p.topic-title {
216 font-weight: bold }
217
218pre.address {
219 margin-bottom: 0 ;
220 margin-top: 0 ;
221 font-family: serif ;
222 font-size: 100% }
223
224pre.literal-block, pre.doctest-block {
225 margin-left: 2em ;
226 margin-right: 2em ;
227 background-color: #eeeeee }
228
229span.classifier {
230 font-family: sans-serif ;
231 font-style: oblique }
232
233span.classifier-delimiter {
234 font-family: sans-serif ;
235 font-weight: bold }
236
237span.interpreted {
238 font-family: sans-serif }
239
240span.option {
241 white-space: nowrap }
242
243span.pre {
244 white-space: pre }
245
246span.problematic {
247 color: red }
248
249span.section-subtitle {
250 /* font-size relative to parent (h1..h6 element) */
251 font-size: 80% }
252
253table.citation {
254 border-left: solid 1px gray;
255 margin-left: 1px }
256
257table.docinfo {
258 margin: 2em 4em }
259
260table.docutils {
261 margin-top: 0.5em ;
262 margin-bottom: 0.5em }
263
264table.footnote {
265 border-left: solid 1px black;
266 margin-left: 1px }
267
268table.docutils td, table.docutils th,
269table.docinfo td, table.docinfo th {
270 padding-left: 0.5em ;
271 padding-right: 0.5em ;
272 vertical-align: top }
273
274table.docutils th.field-name, table.docinfo th.docinfo-name {
275 font-weight: bold ;
276 text-align: left ;
277 white-space: nowrap ;
278 padding-left: 0 }
279
280h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
281h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
282 font-size: 100% }
283
284tt.docutils {
285 background-color: #eeeeee }
286
287ul.auto-toc {
288 list-style-type: none }
289
290</style>
d14a1e28
RD
291</head>
292<body>
05d6c206
RD
293<div class="document" id="wxpython-2-6-migration-guide">
294<h1 class="title">wxPython 2.6 Migration Guide</h1>
d14a1e28 295<p>This document will help explain some of the major changes in wxPython
05d6c206 2962.6 since the 2.4 series and let you know what you need to do to adapt
40efbdda
RD
297your programs to those changes. Be sure to also check in the <a class="reference" href="CHANGES.html">CHANGES</a>
298file like usual to see info about the not so major changes and other
299things that have been added to wxPython.</p>
974a50f1
RD
300<div class="section">
301<h1><a id="wxname-change" name="wxname-change">wxName Change</a></h1>
e8a71fa0 302<p>The <strong>wxWindows</strong> project and library is now known as
29bfe46b 303<strong>wxWidgets</strong>. Please see <a class="reference" href="http://www.wxwidgets.org/name.htm">here</a> for more details.</p>
e8a71fa0 304<p>This won't really affect wxPython all that much, other than the fact
40efbdda
RD
305that the wxwindows.org domain name has changed to wxwidgets.org,
306so mail list, CVS, and etc. addresses have also changed. We're going
e8a71fa0
RD
307to try and smooth the transition as much as possible, but I wanted you
308all to be aware of this change if you run into any issues.</p>
309</div>
974a50f1
RD
310<div class="section">
311<h1><a id="module-initialization" name="module-initialization">Module Initialization</a></h1>
d14a1e28 312<p>The import-startup-bootstrap process employed by wxPython was changed
fc33e5e1 313such that wxWidgets and the underlying gui toolkit are <strong>not</strong>
d14a1e28
RD
314initialized until the wx.App object is created (but before wx.App.OnInit
315is called.) This was required because of some changes that were made
316to the C++ wxApp class.</p>
317<p>There are both benefits and potential problems with this change. The
318benefits are that you can import wxPython without requiring access to
319a GUI (for checking version numbers, etc.) and that in a
320multi-threaded environment the thread that creates the app object will
321now be the GUI thread instead of the one that imports wxPython. Some
322potential problems are that the C++ side of the &quot;stock-objects&quot;
323(wx.BLUE_PEN, wx.TheColourDatabase, etc.) are not initialized until
324the wx.App object is created, so you should not use them until after
6158f936 325you have created your wx.App object. If you do then an exception will
e8a71fa0 326be raised telling you that the C++ object has not been initialized
6158f936 327yet.</p>
d14a1e28
RD
328<p>Also, you will probably not be able to do any kind of GUI or bitmap
329operation unless you first have created an app object, (even on
330Windows where most anything was possible before.)</p>
64316568 331<p><strong>[Changed in 2.5.2.x]</strong> All the Window and GDI (pen, bitmap, etc.)
40efbdda
RD
332class constructors and also many toplevel functions and static methods
333will now check that a wx.App object has already been created and will
334raise a wx.PyNoAppError exception if not.</p>
d14a1e28 335</div>
974a50f1
RD
336<div class="section">
337<h1><a id="swig-1-3" name="swig-1-3">SWIG 1.3</a></h1>
d14a1e28
RD
338<p>wxPython is now using SWIG 1.3.x from CVS (with several of my own
339customizations added that I hope to get folded back into the main SWIG
340distribution.) This has some far reaching ramifications:</p>
341<blockquote>
342<p>All classes derive from object and so all are now &quot;new-style
40efbdda
RD
343classes.&quot; This also allows you to use mixin classes that are
344new-style and to use properties, staticmethod, etc.</p>
d14a1e28 345<p>Public data members of the C++ classes are wrapped as Python
40efbdda
RD
346properties using property() instead of using
347__getattr__/__setattr__ hacks like before. Normally you shouldn't
348notice any difference, but if you were previously doing something
349with __getattr__/__setattr__ in derived classes then you may have
350to adjust things.</p>
351<p>Static C++ methods are wrapped using the staticmethod() feature of
352Python and so are accessible as ClassName.MethodName as expected.
353They are still also available as top level functions named like
d14a1e28
RD
354ClassName_MethodName as before.</p>
355<p>The relationship between the wxFoo and wxFooPtr classes have
356changed for the better. Specifically, all instances that you see
40efbdda
RD
357will be wx.Foo even if they are created internally using wx.FooPtr,
358because wx.FooPtr.__init__ will change the instance's __class__ as
d14a1e28 359part of the initialization. If you have any code that checks
40efbdda
RD
360class type using something like isinstance(obj, wx.FooPtr) you will
361need to change it to isinstance(obj, wx.Foo).</p>
d14a1e28
RD
362</blockquote>
363</div>
974a50f1
RD
364<div class="section">
365<h1><a id="binding-events" name="binding-events">Binding Events</a></h1>
d14a1e28
RD
366<p>All of the EVT_* functions are now instances of the wx.PyEventBinder
367class. They have a __call__ method so they can still be used as
368functions like before, but making them instances adds some
29bfe46b 369flexibility that I expect to take advantave of in the future.</p>
d14a1e28
RD
370<p>wx.EvtHandler (the base class for wx.Window) now has a Bind method that
371makes binding events to windows a little easier. Here is its
372definition and docstring:</p>
373<pre class="literal-block">
374def Bind(self, event, handler, source=None, id=wxID_ANY, id2=wxID_ANY):
375 &quot;&quot;&quot;
376 Bind an event to an event handler.
377
378 event One of the EVT_* objects that specifies the
379 type of event to bind.
380
381 handler A callable object to be invoked when the event
382 is delivered to self. Pass None to disconnect an
383 event handler.
384
385 source Sometimes the event originates from a different window
386 than self, but you still want to catch it in self. (For
387 example, a button event delivered to a frame.) By
388 passing the source of the event, the event handling
389 system is able to differentiate between the same event
390 type from different controls.
391
392 id,id2 Used for menu IDs or for event types that require a
393 range of IDs
394
395 &quot;&quot;&quot;
396</pre>
397<p>Some examples of its use:</p>
398<pre class="literal-block">
399self.Bind(wx.EVT_SIZE, self.OnSize)
400self.Bind(wx.EVT_BUTTON, self.OnButtonClick, theButton)
8eda5e35
RD
401self.Bind(wx.EVT_MENU, self.OnExit, id=wx.ID_EXIT)
402</pre>
403<p>The wx.Menu methods that add items to a wx.Menu have been modified
404such that they return a reference to the wx.MenuItem that was created.
405Additionally menu items and toolbar items have been modified to
406automatically generate a new ID if -1 is given, similar to using -1
407with window classess. This means that you can create menu or toolbar
408items and event bindings without having to predefine a unique menu ID,
409although you still can use IDs just like before if you want. For
e8a71fa0
RD
410example, these are all equivallent other than their specific ID
411values:</p>
8eda5e35
RD
412<pre class="literal-block">
4131.
414 item = menu.Append(-1, &quot;E&amp;xit&quot;, &quot;Terminate the App&quot;)
415 self.Bind(wx.EVT_MENU, self.OnExit, item)
416
974a50f1 4172.
8eda5e35
RD
418 item = menu.Append(wx.ID_EXIT, &quot;E&amp;xit&quot;, &quot;Terminate the App&quot;)
419 self.Bind(wx.EVT_MENU, self.OnExit, item)
420
974a50f1 4213.
8eda5e35
RD
422 menu.Append(wx.ID_EXIT, &quot;E&amp;xit&quot;, &quot;Terminate the App&quot;)
423 self.Bind(wx.EVT_MENU, self.OnExit, id=wx.ID_EXIT)
d14a1e28 424</pre>
d14a1e28
RD
425<p>If you create your own custom event types and EVT_* functions, and you
426want to be able to use them with the Bind method above then you should
40efbdda 427change your EVT_* to be an instance of wx.PyEventBinder instead of a
29bfe46b 428function. For example, if you used to have something like this:</p>
d14a1e28
RD
429<pre class="literal-block">
430myCustomEventType = wxNewEventType()
431def EVT_MY_CUSTOM_EVENT(win, id, func):
432 win.Connect(id, -1, myCustomEventType, func)
433</pre>
434<p>Change it like so:</p>
435<pre class="literal-block">
6158f936
RD
436myCustomEventType = wx.NewEventType()
437EVT_MY_CUSTOM_EVENT = wx.PyEventBinder(myCustomEventType, 1)
d14a1e28
RD
438</pre>
439<p>The second parameter is an integer in [0, 1, 2] that specifies the
440number of IDs that are needed to be passed to Connect.</p>
64316568 441<p><strong>[Changed in 2.5.2.x]</strong> There is also an Unbind method added to
40efbdda
RD
442wx.EvtHandler that can be used to disconenct event handlers. It looks
443like this:</p>
444<pre class="literal-block">
445def Unbind(self, event, source=None, id=wx.ID_ANY, id2=wx.ID_ANY):
446 &quot;&quot;&quot;
447 Disconencts the event handler binding for event from self.
448 Returns True if successful.
449 &quot;&quot;&quot;
450</pre>
d14a1e28 451</div>
974a50f1
RD
452<div class="section">
453<h1><a id="the-wx-namespace" name="the-wx-namespace">The wx Namespace</a></h1>
d14a1e28
RD
454<p>The second phase of the wx Namespace Transition has begun. That means
455that the real names of the classes and other symbols do not have the
456'wx' prefix and the modules are located in a Python package named
457wx. There is still a Python package named wxPython with modules
458that have the names with the wx prefix for backwards compatibility.
459Instead of dynamically changing the names at module load time like in
4602.4, the compatibility modules are generated at build time and contain
461assignment statements like this:</p>
462<pre class="literal-block">
40efbdda 463wxWindow = wx._core.Window
d14a1e28 464</pre>
40efbdda 465<p>Don't let the &quot;_core&quot; in the name bother you. That and some other
d14a1e28 466modules are implementation details, and everything that was in the
6158f936 467wxPython.wx module before will still be in the wx package namespace
40efbdda
RD
468after this change. So from your code you would use it as wx.Window or
469wxWindow if you import from the wxPython.wx module.</p>
d14a1e28
RD
470<p>A few notes about how all of this was accomplished might be
471interesting... SWIG is now run twice for each module that it is
472generating code for. The first time it outputs an XML representaion
473of the parse tree, which can be up to 20MB and 300K lines in size!
474That XML is then run through a little Python script that creates a
475file full of SWIG %rename directives that take the wx off of the
476names, and also generates the Python compatibility file described
477above that puts the wx back on the names. SWIG is then run a second
478time to generate the C++ code to implement the extension module, and
479uses the %rename directives that were generated in the first step.</p>
480<p>Not every name is handled correctly (but the bulk of them are) and so
481some work has to be done by hand, especially for the reverse-renamers.
482So expect a few flaws here and there until everything gets sorted out.</p>
6158f936
RD
483<p>In summary, the wx package and names without the &quot;wx&quot; prefix are now
484the official form of the wxPython classes. For example:</p>
485<pre class="literal-block">
486import wx
487
488class MyFrame(wx.Frame):
489 def __init__(self, parent, title):
490 wx.Frame.__init__(self, parent, -1, title)
491 p = wx.Panel(self, -1)
492 b = wx.Button(p, -1, &quot;Do It&quot;, (10,10))
493 self.Bind(wx.EVT_BUTTON, self.JustDoIt, b)
494
495 def JustDoIt(self, evt):
496 print &quot;It's done!&quot;
497
498app = wx.PySimpleApp()
499f = MyFrame(None, &quot;What's up?&quot;)
500f.Show()
501app.MainLoop()
502</pre>
503<p>You shouldn't need to migrate all your modules over to use the new
504package and names right away as there are modules in place that try to
505provide as much backwards compatibility of the names as possible. If
82a074ce 506you rewrote the above sample using &quot;from wxPython.wx import * &quot;, the
6158f936
RD
507old wxNames, and the old style of event binding it will still work
508just fine.</p>
d14a1e28 509</div>
974a50f1
RD
510<div class="section">
511<h1><a id="new-wx-dc-methods" name="new-wx-dc-methods">New wx.DC Methods</a></h1>
64316568 512<p><strong>[Changed in 2.5.2.x]</strong> In wxPython 2.5.1.5 there was a new
40efbdda
RD
513implementation of the wx.DC Draw and other methods that broke
514backwards compatibility in the name of consistency. That change has
515been reverted and the wx.DC Draw methods with 2.4 compatible
516signatures have been restored. In addition a new set of methods have
517been added that take wx.Point and/or wx.Size parameters instead of
518separate integer parameters. The Draw and etc. methods now available
519in the wx.DC class are:</p>
d14a1e28 520<pre class="literal-block">
40efbdda
RD
521FloodFill(self, x, y, colour, style = wx.FLOOD_SURFACE)
522FoodFillPoint(self, pt, colour, style = wx.FLOOD_SURFACE)
d14a1e28 523
40efbdda 524GetPixel(self, x,y)
974a50f1 525GetPixelPoint(self, pt)
d14a1e28 526
40efbdda
RD
527DrawLine(self, x1, y1, x2, y2)
528DrawLinePoint(self, pt1, pt2)
d14a1e28 529
40efbdda
RD
530CrossHair(self, x, y)
531CrossHairPoint(self, pt)
d14a1e28 532
40efbdda
RD
533DrawArc(self, x1, y1, x2, y2, xc, yc)
534DrawArcPoint(self, pt1, pt2, centre)
d14a1e28 535
40efbdda
RD
536DrawCheckMark(self, x, y, width, height)
537DrawCheckMarkRect(self, rect)
d14a1e28 538
40efbdda
RD
539DrawEllipticArc(self, x, y, w, h, sa, ea)
540DrawEllipticArcPointSize(self, pt, sz, sa, ea)
d14a1e28 541
40efbdda
RD
542DrawPoint(self, x, y)
543DrawPointPoint(self, pt)
d14a1e28 544
40efbdda
RD
545DrawRectangle(self, x, y, width, height)
546DrawRectangleRect(self, rect)
547DrawRectanglePointSize(self, pt, sz)
d14a1e28 548
40efbdda
RD
549DrawRoundedRectangle(self, x, y, width, height, radius)
550DrawRoundedRectangleRect(self, r, radius)
551DrawRoundedRectanglePointSize(self, pt, sz, radius)
d14a1e28 552
40efbdda
RD
553DrawCircle(self, x, y, radius)
554DrawCirclePoint(self, pt, radius)
d14a1e28 555
40efbdda
RD
556DrawEllipse(self, x, y, width, height)
557DrawEllipseRect(self, rect)
558DrawEllipsePointSize(self, pt, sz)
d14a1e28 559
40efbdda
RD
560DrawIcon(self, icon, x, y)
561DrawIconPoint(self, icon, pt)
d14a1e28 562
40efbdda
RD
563DrawBitmap(self, bmp, x, y, useMask = False)
564DrawBitmapPoint(self, bmp, pt, useMask = False)
d14a1e28 565
40efbdda
RD
566DrawText(self, text, x, y)
567DrawTextPoint(self, text, pt)
d14a1e28 568
40efbdda
RD
569DrawRotatedText(self, text, x, y, angle)
570DrawRotatedTextPoint(self, text, pt, angle)
d14a1e28 571
40efbdda
RD
572bool Blit(self, xdest, ydest, width, height, sourceDC, xsrc, ysrc,
573 rop = wx.COPY, useMask = False, xsrcMask = -1, ysrcMask = -1)
974a50f1 574BlitPointSize(self, destPt, sz, sourceDC, srcPt, rop = wx.COPY,
40efbdda 575 useMask = False, srcPtMask = wxDefaultPosition)
d14a1e28 576
6158f936 577
40efbdda
RD
578SetClippingRegion(self, x, y, width, height)
579SetClippingRegionPointSize(self, pt, sz)
580SetClippingRegionAsRegion(self, region)
581SetClippingRect(self, rect)
d14a1e28 582</pre>
d14a1e28 583</div>
974a50f1
RD
584<div class="section">
585<h1><a id="building-extending-and-embedding-wxpython" name="building-extending-and-embedding-wxpython">Building, Extending and Embedding wxPython</a></h1>
d14a1e28
RD
586<p>wxPython's setup.py script now expects to use existing libraries for
587the contribs (gizmos, stc, xrc, etc.) rather than building local
588copies of them. If you build your own copies of wxPython please be
05d6c206 589aware that you now need to also build the stc, xrc, animate and gizmos
29bfe46b 590libraries in addition to the main wx lib.</p>
d14a1e28 591<p>The wxPython.h and other header files are now in
9ec83f8d
RD
592.../wxPython/include/wx/wxPython instead of in wxPython/src. You
593should include it via the &quot;wx/wxPython/wxPython.h&quot; path and add
29bfe46b
RD
594.../wxPython/include to your list of include paths. On OSX and
595unix-like systems the wxPython headers are installed to the same place
9ec83f8d
RD
596that the wxWidgets headers are installed, so if you are building
597wxPython compatible extensions on those platforms then your include
598path should already be set properly.</p>
29bfe46b
RD
599<p>If you are also using SWIG for your extension then you'll need to
600adapt how the wxPython .i files are imported into your .i files. See
601the wxPython sources for examples. Your modules will need to at least
c66cd08a 602<tt class="docutils literal"><span class="pre">%import</span> <span class="pre">core.i</span></tt>, and possibly others if you need the definition of
9ec83f8d
RD
603other classes. Since you will need them to build your modules using
604SWIG, the main wxPython .i files are also installed with the wxPython
605headers in an i_files sibdirectory. It should be enough to pass a
606-I/pathname on the command line for SWIG to find the files.</p>
29bfe46b
RD
607<p>The bulk of wxPython's setup.py has been moved to another module,
608wx/build/config.py. This module will be installed as part of wxPython
609so 3rd party modules that wish to use the same setup/configuration
610code can do so simply by importing this module from their own setup.py
c66cd08a 611scripts using <tt class="docutils literal"><span class="pre">import</span> <span class="pre">wx.build.config</span></tt>.</p>
d14a1e28
RD
612<p>You no longer need to call wxClassInfo::CleanUpClasses() and
613wxClassInfo::InitializeClasses() in your extensions or when embedding
614wxPython.</p>
29bfe46b
RD
615<p>The usage of wxPyBeginAllowThreads and wxPyEndAllowThreads has changed
616slightly. wxPyBeginAllowThreads now returns a boolean value that must
617be passed to the coresponding wxPyEndAllowThreads function call. This
618is to help do the RightThing when calls to these two functions are
619nested, or if calls to external code in other extension modules that
620are wrapped in the standard Py_(BEGIN|END)_ALLOW_THERADS may result in
621wx event handlers being called (such as during the call to
622os.startfile.)</p>
d14a1e28 623</div>
974a50f1
RD
624<div class="section">
625<h1><a id="two-or-three-phase-create" name="two-or-three-phase-create">Two (or Three!) Phase Create</a></h1>
6158f936
RD
626<p>If you use the Precreate/Create method of instantiating a window, (for
627example, to set an extended style flag, or for XRC handlers) then
628there is now a new method named PostCreate to help with transplanting
629the brain of the prewindow instance into the derived window instance.
630For example:</p>
631<pre class="literal-block">
632class MyDialog(wx.Dialog):
633 def __init__(self, parent, ID, title, pos, size, style):
634 pre = wx.PreDialog()
635 pre.SetExtraStyle(wx.DIALOG_EX_CONTEXTHELP)
636 pre.Create(parent, ID, title, pos, size, style)
637 self.PostCreate(pre)
638</pre>
639</div>
974a50f1
RD
640<div class="section">
641<h1><a id="sizers" name="sizers">Sizers</a></h1>
8eda5e35 642<p>The hack allowing the old &quot;option&quot; keyword parameter has been removed.
ff0ac6b0 643If you use keyword args with wx.Sizer Add, Insert, or Prepend methods
c66cd08a
RD
644then you will need to use the <tt class="docutils literal"><span class="pre">proportion</span></tt> name instead of
645<tt class="docutils literal"><span class="pre">option</span></tt>. (The <tt class="docutils literal"><span class="pre">proportion</span></tt> keyword was also allowed in 2.4.2.4.)</p>
29bfe46b 646<p>When adding a spacer to a sizer you now need to use a wx.Size or a
40efbdda
RD
6472-integer sequence instead of separate width and height parameters.
648This was optionally allowed in 2.4, but now it is required. This
649allows for more consistency in how you add the various types of items
650to a sizer. The first parameter defines the item (instead of the
651possibily first two, depending on if you are doing a spacer or not,)
652and that item can either be a window, a sizer or a spacer (which can
653be a sequence or a wx.Size.) Removing the option for separate width
654and height parameters greatly simplified the wrapper code.</p>
29bfe46b 655<p>The wx.GridBagSizer class (very similar to the RowColSizer in the
6158f936
RD
656library) has been added to C++ and wrapped for wxPython. It can also
657be used from XRC.</p>
658<p>You should not use AddWindow, AddSizer, AddSpacer (and similar for
659Insert, Prepend, and etc.) methods any longer. Just use Add and the
64316568 660wrappers will figure out what to do. <strong>[Changed in 2.5.2.x]</strong>
60b517c1 661AddWindow, AddSizer, AddSpacer and etc. will now issue a
287cb697
RD
662DeprecationWarning. <strong>[Changed in 2.5.4.x]</strong> These methods have now
663been undeprecated at the request of Riaan Booysen, the Boa Constructor
664team lead. They are now just simple compatibility aliases for Add,
665and etc.</p>
da2c7672
RD
666<p><strong>[Changed in 2.5.2.x]</strong> The Sizers have had some fundamental internal
667changes in the 2.5.2.x release intended to make them do more of the
668&quot;Right Thing&quot; but also be as backwards compatible as possible.
669First a bit about how things used to work:</p>
670<blockquote>
671<ul class="simple">
672<li>The size that a window had when Add()ed to the sizer was assumed
673to be its minimal size, and that size would always be used by
674default when calculating layout size and positions, and the
675sizer itself would keep track of that minimal size.</li>
c66cd08a
RD
676<li>If the window item was added with the <tt class="docutils literal"><span class="pre">wx.ADJUST_MINSIZE</span></tt>
677flag then when layout was calculated the item's <tt class="docutils literal"><span class="pre">GetBestSize</span></tt>
da2c7672
RD
678would be used to reset the minimal size that the sizer used.</li>
679</ul>
680</blockquote>
ff0ac6b0 681<p>The main thrust of the new Sizer changes was to make behavior like
c66cd08a 682<tt class="docutils literal"><span class="pre">wx.ADJUST_MINSIZE</span></tt> be the default, and also to push the tracking of
da2c7672
RD
683the minimal size to the window itself (since it knows its own needs)
684instead of having the sizer take care of it. Consequently these
685changes were made:</p>
686<blockquote>
687<ul class="simple">
c66cd08a 688<li>The <tt class="docutils literal"><span class="pre">wx.FIXED_MINSIZE</span></tt> flag was added to allow for the old
ff0ac6b0 689behavior. When this flag is used the size a window has when
da2c7672
RD
690added to the sizer will be treated as its minimal size and it
691will not be readjusted on each layout.</li>
c66cd08a
RD
692<li>The min size stored in <tt class="docutils literal"><span class="pre">wx.Window</span></tt> and settable with
693<tt class="docutils literal"><span class="pre">SetSizeHints</span></tt> or <tt class="docutils literal"><span class="pre">SetMinSize</span></tt> will by default be used by
da2c7672
RD
694the sizer (if it was set) as the minimal size of the sizer item.
695If the min size was not set (or was only partially set) then the
696window's best size is fetched and it is used instead of (or
c66cd08a 697blended with) the min size. <tt class="docutils literal"><span class="pre">wx.Window.GetBestFittingSize</span></tt>
da2c7672
RD
698was added to facilitate getting the size to be used by the
699sizers.</li>
700<li>The best size of a window is cached so it doesn't need to
c66cd08a 701recaculated on every layout. <tt class="docutils literal"><span class="pre">wx.Window.InvalidateBestSize</span></tt>
da2c7672
RD
702was added and should be called (usually just internally in
703control methods) whenever something is done that would make the
704best size change.</li>
705<li>All wxControls were changed to set the minsize to what is passed
706to the constructor or Create method, and also to set the real
707size of the control to the blending of the min size and best
c66cd08a 708size. <tt class="docutils literal"><span class="pre">wx.Window.SetBestFittingSize</span></tt> was added to help with
da2c7672 709this, although most controls don't need to call it directly
c66cd08a 710because it is called indirectly via the <tt class="docutils literal"><span class="pre">SetInitialSize</span></tt>
da2c7672
RD
711called in the base classes.</li>
712</ul>
713</blockquote>
714<p>At this time, the only situation known not to work the same as before
715is the following:</p>
716<pre class="literal-block">
717win = SomeWidget(parent)
718win.SetSize(SomeNonDefaultSize)
719sizer.Add(win)
720</pre>
721<p>In this case the old code would have used the new size as the minimum,
722but now the sizer will use the default size as the minimum rather than
723the size set later. It is an easy fix though, just move the
724specification of the size to the constructor (assuming that SomeWidget
725will set its minsize there like the rest of the controls do) or call
c66cd08a 726<tt class="docutils literal"><span class="pre">SetMinSize</span></tt> instead of <tt class="docutils literal"><span class="pre">SetSize</span></tt>.</p>
da2c7672
RD
727<p>In order to fit well with this new scheme of things, all wxControls or
728custom controls should do the following things. (Depending on how
729they are used you may also want to do the same thing for non-control
730custom windows.)</p>
731<blockquote>
732<ul>
c66cd08a 733<li><p class="first">Either override or inherit a meaningful <tt class="docutils literal"><span class="pre">DoGetBestSize</span></tt> method
da2c7672
RD
734that calculates whatever size is &quot;best&quot; for the control. Once
735that size is calculated then there should normally be a call to
c66cd08a 736<tt class="docutils literal"><span class="pre">CacheBestSize</span></tt> to save it for later use, unless for some
da2c7672
RD
737reason you want the best size to be recalculated on every
738layout.</p>
c66cd08a
RD
739<p>Note: In order to successfully override <tt class="docutils literal"><span class="pre">DoGetBestSize</span></tt> in
740Python the class needs to be derived from <tt class="docutils literal"><span class="pre">wx.PyWindow</span></tt>,
741<tt class="docutils literal"><span class="pre">wx.PyControl</span></tt>, or etc. If your class instead derives from
da2c7672
RD
742one of the standard wx classes then just be sure that the min
743size gets explicitly set to what would have been the best size
744and things should work properly in almost all situations.</p>
745</li>
746<li><p class="first">Any method that changes the attributes of the control such that
c66cd08a 747the best size will change should call <tt class="docutils literal"><span class="pre">InvalidateBestSize</span></tt> so
da2c7672
RD
748it will be recalculated the next time it is needed.</p>
749</li>
750<li><p class="first">The control's constructor and/or Create method should ensure
751that the minsize is set to the size passed in, and that the
752control is sized to a blending of the min size and best size.
c66cd08a 753This can be done by calling <tt class="docutils literal"><span class="pre">SetBestFittingSize</span></tt>.</p>
da2c7672
RD
754</li>
755</ul>
756</blockquote>
6158f936 757</div>
974a50f1
RD
758<div class="section">
759<h1><a id="platforminfo" name="platforminfo">PlatformInfo</a></h1>
fc33e5e1
RD
760<p>Added wx.PlatformInfo which is a tuple containing strings that
761describe the platform and build options of wxPython. This lets you
762know more about the build than just the __WXPORT__ value that
763wx.Platform contains, such as if it is a GTK2 build. For example,
764instead of:</p>
765<pre class="literal-block">
766if wx.Platform == &quot;__WXGTK__&quot;:
767 ...
768</pre>
769<p>you should do this:</p>
770<pre class="literal-block">
771if &quot;__WXGTK__&quot; in wx.PlatformInfo:
772 ...
773</pre>
774<p>and you can specifically check for a wxGTK2 build by looking for
775&quot;gtk2&quot; in wx.PlatformInfo. Unicode builds are also detectable this
776way. If there are any other platform/toolkit/build flags that make
777sense to add to this tuple please let me know.</p>
778<p>BTW, wx.Platform will probably be deprecated in the future.</p>
779</div>
974a50f1
RD
780<div class="section">
781<h1><a id="activex" name="activex">ActiveX</a></h1>
90805926
RD
782<p>Lindsay Mathieson's newest <a class="reference" href="http://members.optusnet.com.au/~blackpaw1/wxactivex.html">wxActiveX</a> class has been wrapped into a new
783extension module called wx.activex. It is very generic and dynamic
784and should allow hosting of arbitray ActiveX controls within your
785wxPython apps. So far I've tested it with IE, PDF, and Flash
786controls, (and there are new samples in the demo and also library
787modules supporting these.)</p>
788<p>The new wx.activex module contains a bunch of code, but the most
789important things to look at are ActiveXWindow and ActiveXEvent.
790ActiveXWindow derives from wxWindow and the constructor accepts a
791CLSID for the ActiveX Control that should be created. (There is also
792a CLSID class that can convert from a progID or a CLSID String.) The
793ActiveXWindow class simply adds methods that allow you to query some
794of the TypeInfo exposed by the ActiveX object, and also to get/set
795properties or call methods by name. The Python implementation
796automatically handles converting parameters and return values to/from
797the types expected by the ActiveX code as specified by the TypeInfo,
798(just bool, integers, floating point, strings and None/Empty so far,
799but more can be handled later.)</p>
800<p>That's pretty much all there is to the class, as I mentioned before it
801is very generic and dynamic. Very little is hard-coded and everything
802that is done with the actual ActiveX control is done at runtime and
803referenced by property or method name. Since Python is such a dynamic
804language this is a very good match. I thought for a while about doing
805some Python black-magic and making the specific methods/properties of
806the actual ActiveX control &quot;appear&quot; at runtime, but then decided that
807it would be better and more understandable to do it via subclassing.
808So there is a utility class in wx.activex that given an existing
809ActiveXWindow instance can generate a .py module containing a derived
810class with real methods and properties that do the Right Thing to
811reflect those calls to the real ActiveX control. There is also a
812script/tool module named genaxmodule that given a CLSID or progID and
813a class name, will generate the module for you. There are a few
814examples of the output of this tool in the wx.lib package, see
815iewin.py, pdfwin.py and flashwin.py.</p>
816<p>Currently the genaxmodule tool will tweak some of the names it
817generates, but this can be controled if you would like to do it
818differently by deriving your own class from GernerateAXModule,
819overriding some methods and then using this class from a tool like
820genaxmodule. [TODO: make specifying a new class on genaxmodule's
821command-line possible.] The current default behavior is that any
822event names that start with &quot;On&quot; will have the &quot;On&quot; dropped, property
823names are converted to all lower case, and if any name is a Python
824keyword it will have an underscore appended to it. GernerateAXModule
825does it's best when generating the code in the new module, but it can
826only be as good as the TypeInfo data available from the ActiveX
827control so sometimes some tweaking will be needed. For example, the
828IE web browser control defines the Flags parameter of the Navigate2
829method as required, but MSDN says it is optional.</p>
830<p>It is intended that this new wx.activex module will replace both the
831older version of Lindsay's code available in iewin.IEHtmlWindow, and
832also the wx.lib.activexwraper module. Probably the biggest
833differences you'll ecounter in migrating activexwrapper-based code
834(besides events working better without causing deadlocks) is that
835events are no longer caught by overriding methods in your derived
836class. Instead ActiveXWindow uses the wx event system and you bind
837handlers for the ActiveX events exactly the same way you do for any wx
838event. There is just one extra step needed and that is creating an
839event ID from the ActiveX event name, and if you use the genaxmodule
840tool then this extra step will be handled for you there. For example,
841for the StatusTextChange event in the IE web browser control, this
842code is generated for you:</p>
843<pre class="literal-block">
844wxEVT_StatusTextChange = wx.activex.RegisterActiveXEvent('StatusTextChange')
845EVT_StatusTextChange = wx.PyEventBinder(wxEVT_StatusTextChange, 1)
846</pre>
847<p>and you would use it in your code like this:</p>
848<pre class="literal-block">
849self.Bind(iewin.EVT_StatusTextChange, self.UpdateStatusText, self.ie)
850</pre>
851<p>When the event happens and your event handler function is called the
852event properties from the ActiveX control (if any) are converted to
853attributes of the event object passed to the handler. (Can you say
854'event' any more times in a single sentence? ;-) ) For example the
855StatusTextChange event will also send the text that should be put into
856the status line as an event parameter named &quot;Text&quot; and you can access
857it your handlers as an attribute of the event object like this:</p>
858<pre class="literal-block">
859def UpdateStatusText(self, evt):
860 self.SetStatusText(evt.Text)
861</pre>
862<p>Usually these event object attributes should be considered read-only,
863but some will be defined by the TypeInfo as output parameters. In
864those cases if you modify the event object's attribute then that value
865will be returned to the ActiveX control. For example, to prevent a
866new window from being opened by the IE web browser control you can do
867this in the handler for the iewin.EVT_NewWindow2 event:</p>
868<pre class="literal-block">
869def OnNewWindow2(self, evt):
974a50f1 870 evt.Cancel = True
90805926 871</pre>
29bfe46b 872<p>So how do you know what methods, events and properties that an ActiveX
90805926
RD
873control supports? There is a funciton in wx.activex named GetAXInfo
874that returns a printable summary of the TypeInfo from the ActiveX
875instance passed in. You can use this as an example of how to browse
876the TypeInfo provided, and there is also a copy of this function's
877output appended as a comment to the modules produced by the
878genaxmodule tool. Beyond that you'll need to consult the docs
879provided by the makers of the ActiveX control that you are using.</p>
880</div>
974a50f1
RD
881<div class="section">
882<h1><a id="png-images" name="png-images">PNG Images</a></h1>
40efbdda
RD
883<p>Prior to 2.5 the PNG image handler would convert all alpha channel
884information to a mask when the image was loaded. Pixels that were
885more than halfway transparent would be made fully transparent by the
886mask and the rest would be made fully opaque.</p>
887<p>In 2.5 the image handler has been updated to preserve the alpha
888channel and will now only create a mask when all the pixels in the
889image are either fully transparent or fully opaque. In addition, the
890wx.DC.DrawBitmap and wx.DC.Blit methods are able to correctly blend
ff0ac6b0 891the pixels in the image with partially transparent alpha values.</p>
40efbdda
RD
892<p>If you are using a PNG with an alpha channel but you need to have a
893wx.Mask like you automatically got in 2.4 then you can do one of the
894following:</p>
895<blockquote>
896<ul class="simple">
897<li>Edit the image and make all the partially transparent pixels be
898fully transparent.</li>
899<li>Use a different image type.</li>
900<li>Set a mask based on colour after you load the image.</li>
901</ul>
902</blockquote>
903</div>
974a50f1
RD
904<div class="section">
905<h1><a id="ogl-is-dead-long-live-ogl" name="ogl-is-dead-long-live-ogl">OGL is dead! LONG LIVE OGL!</a></h1>
64316568 906<p><strong>[Changed in 2.5.2.x]</strong></p>
05d6c206
RD
907<p>The wx.ogl module was deprecated in version 2.5.2 in favor of the new
908Python port of the OGL library located at wx.lib.ogl contributed by
909