GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing docs.wxpython.org — Phoenix Migration Guide — wxPython 4.3.2 Docs Phoenix Migration Guide¶wxPython’s Project Phoenix is a new incarnation of the wxPython toolkit in which everything that existed before will be cast into the flames in the hopes that that which emerges from the ashes will be better, brighter, stronger and faster than before. For more details about why and how, please see the ProjectPhoenix pages in the wiki. This document will describe some of the incompatibilities that programmers will run into when migrating code from Classic wxPython to the Phoenix. For some types of changes there won’t be any attempt to document the nitty gritty details of the differences, but rather the general patterns of the changes will be documented. Most programmers should then be able to work out the details for themselves. Please note that throughout this document and elsewhere in the project, as well as community discussions and such, you may see the term “Classic” used by itself. This refers to the original implementation of wxPython. Likewise, a standalone “Phoenix” or “Project Phoenix” will generally refer to this new implementation of wxPython. Version Numbers¶The version numbers for wxPython are no longer kept in sync with the wxWidgets version number. In the past the common version number was used to indicate exactly which version of wxWidgets should be used for the wxPython build. Now wxWidgets is a git submodule, and the linked version is included in the wxPython source tarball, so there is no longer any need to use the matching version numbers to implicitly specify the version of the wxWidgets source to use. This means that wxPython can go back to a 3-component version number and follow the common conventions used by 99% of the other software projects out there. The 3 components are commonly called MAJOR, MINOR and RELEASE. Since wxPython Phoenix is a major upgrade over wxPython Classic then we will start out with a new MAJOR version number to help communicate that this isn’t just a little update from previous releases. Additional flags will be appended to the version number in a manner that is
compliant with Python’s PEP-440. This includes syntax for alpha, beta,
release candidate releases, post-release builds, development snapshots, etc.
See Overloaded Functions¶In order to support more than one of the versions of an overloaded C++
function or class method in Classic wxPython, we had to rename all but one of
them. For example, for the C++ This also includes the default constructor for all widget classes, used for
the 2-phase create. Previously they were renamed to be the class name with
“Pre” prepended to it. For example, For those renamed items that are more commonly used in the old Classic
wxPython I’ll add some aliases that will issue a FindWindow Methods¶One instance of undoing the renames for overloading done in Classic that may
be not make as much sense as the others is the So we now have the following FindWindow-related methods and static methods
available in the These are non-static and do a recursive search in wx.Window.FindWindow(self, id) wx.Window.FindWindow(self, name) These are wx.Window.FindWindowById(id, parent=None) wx.Window.FindWindowByLabel(label, parent=None) wx.Window.FindWindowByName(name, parent=None) And these extra module-level helper functions added in Classic are still available in Phoenix: wx.FindWindowById(id, parent=None) wx.FindWindowByLabel(label, parent=None) wx.FindWindowByName(name, parent=None) Static Methods¶In the distant past when SWIG was generating wrapper code for C++ static
methods it would create a standalone function named c = wx.SystemSettings_GetColour(wx.SYS_COLOUR_MENUTEXT) to this: c = wx.SystemSettings.GetColour(wx.SYS_COLOUR_MENUTEXT) You can also make this change in your existing code that is using pre-Phoenix versions of wxPython, in order to help you prepare for the transition. Unicode and Auto-Converting Strings¶Starting with the wxPython 2.9 release series, there are no longer separate ansi/Unicode builds of wxPython. All wxPython builds are now essentially the same as the old Unicode builds. This means that all string objects (in Python 2.7) or bytes objects (Python 3+) passed to wx API functions or methods are converted to Unicode before calling the C++ function or method. By default Classic wxPython would use the encoding specified by the locale that was current at the time of the import of the wx module. However using the default locale could sometimes cause issues because it meant that slightly different encodings could be used on different platforms, even in the same locale, or the program could end up using an encoding in a different locale that the developer has not tested their code with. Project Phoenix takes this Unicode simplification one step further by stipulating that only the utf-8 encoding will be used for auto-converting string/bytes objects to the Unicode objects that will be passed on to the wx APIs. If you need to deal with text using a different encoding then you will need to convert it to Unicode yourself before passing the text to the wx API. For the most part this should not be much of a problem for well written programs that support Unicode because they will typically only convert to/from Unicode when reading/writing text to a file or database, and will use Unicode objects throughout the rest of the code. The common exception to this is that string-literals are often used in the code for specifying labels, etc. for UI elements. If your text for the string literals in your code are all ascii or utf-8 then you should not need to make any changes at all. If you have literals with some other encoding then you’ll need to deal with them one way or another, either change the encoding of your source file to utf-8, or convert the literals from your encoding to Unicode before passing the text to the wx API. In Python 3.x, where strings are already Unicode objects, most of the above confusion goes away, however if you have bytes objects then the same rules of auto-converting only from utf-8 will still apply. Font, Pen, and Brush Styles¶The following aliases are currently added for backwards compatibility, but will be removed in a future release. You should migrate any code that is using the old names to use the new ones instead: wx.DEFAULT = wx.FONTFAMILY_DEFAULT wx.DECORATIVE = wx.FONTFAMILY_DECORATIVE wx.ROMAN = wx.FONTFAMILY_ROMAN wx.SCRIPT = wx.FONTFAMILY_SCRIPT wx.SWISS = wx.FONTFAMILY_SWISS wx.MODERN = wx.FONTFAMILY_MODERN wx.TELETYPE = wx.FONTFAMILY_TELETYPE wx.NORMAL = wx.FONTWEIGHT_NORMAL wx.LIGHT = wx.FONTWEIGHT_LIGHT wx.BOLD = wx.FONTWEIGHT_BOLD wx.NORMAL = wx.FONTSTYLE_NORMAL wx.ITALIC = wx.FONTSTYLE_ITALIC wx.SLANT = wx.FONTSTYLE_SLANT wx.SOLID = wx.PENSTYLE_SOLID wx.DOT = wx.PENSTYLE_DOT wx.LONG_DASH = wx.PENSTYLE_LONG_DASH wx.SHORT_DASH = wx.PENSTYLE_SHORT_DASH wx.DOT_DASH = wx.PENSTYLE_DOT_DASH wx.USER_DASH = wx.PENSTYLE_USER_DASH wx.TRANSPARENT = wx.PENSTYLE_TRANSPARENT wx.STIPPLE_MASK_OPAQUE = wx.BRUSHSTYLE_STIPPLE_MASK_OPAQUE wx.STIPPLE_MASK = wx.BRUSHSTYLE_STIPPLE_MASK wx.STIPPLE = wx.BRUSHSTYLE_STIPPLE wx.BDIAGONAL_HATCH = wx.BRUSHSTYLE_BDIAGONAL_HATCH wx.CROSSDIAG_HATCH = wx.BRUSHSTYLE_CROSSDIAG_HATCH wx.FDIAGONAL_HATCH = wx.BRUSHSTYLE_FDIAGONAL_HATCH wx.CROSS_HATCH = wx.BRUSHSTYLE_CROSS_HATCH wx.HORIZONTAL_HATCH = wx.BRUSHSTYLE_HORIZONTAL_HATCH wx.VERTICAL_HATCH = wx.BRUSHSTYLE_VERTICAL_HATCH wx.PyDeadObjectError –> RuntimeError¶Classic wxPython tracks when the C++ part of some types of objects (pretty
much just window types) is destroyed and then replaces the proxy object’s
class with one that raises a if someWindow: someWindow.doSomething() wx.PyAssertionError –> wx.wxAssertionError¶This is the exception raised when one of the The ‘wx’ namespace and submodules reorganized¶Some reorganization of what classes and functions goes in which internal wx extension module has been done. In Classic the organization of the extension modules was somewhat haphazard and chaotic. For example there were 5 separate modules whose contents were loaded into the main “wx” package namespace and several others that needed to be imported separately. However since there was not much organization of the core the C++ wxadv and wxhtml DLLs would need to be distributed with any applications built with a bundling tool even if the application did not use any of those classes. For Phoenix the location of the wrapper code for the classes and functions
will attempt to follow the same organization that wxWidgets uses for putting
those same classes and functions into DLLs or shared libraries. This means
that some things that were formerly in the core wx package namespace are no
longer there. They will have to be used by importing a wx submodule. Most of
them will be in the wx.ListCtrl¶In wx.TreeCtrl¶The wx.DragImage¶Phoenix is now providing both 2-Phase Create¶In Classic wxPython we had to do some fancy footwork to make use of wxWidget’s 2-Phase Create scheme for creating instances of a C++ widget class, but delaying the creation of the UI object until later. (This is needed for things like setting extended style flags that can not be set after creation, or with class factories like XRC.) The old trickery should no longer be needed, and instead you can write code that is much more sane. For example, instead of Classic code like this: class MyDialog(wx.Dialog): def __init__(self, parent, ID, title): pre = wx.PreDialog() pre.SetExtraStyle(wx.FRAME_EX_CONTEXTHELP) pre.Create(parent, ID, title) self.PostCreate(pre) # 4 In Phoenix that should now be done like this: class MyDialog(wx.Dialog): def __init__(self, parent, ID, title): wx.Dialog.__init__(self) # 1 self.SetExtraStyle(wx.FRAME_EX_CONTEXTHELP) # 2 self.Create(parent, ID, title) # 3 Notice that we are (#1) calling the base class wx.Image and Python Buffer Objects¶
Just as in Classic the wx.DropSource¶We don’t (yet) have an easy way to support different APIs per platform in the
wx class constructors, so wx.DataObject and derived classes¶The Python buffer objects are used for transferring data to/from the clipboard or
DnD partner. Anything that supports the buffer protocol can be used for
setting or providing data, and a Here is a simple example: class MyDataObject(wx.DataObjectSimple): def __init__(self, value=''): wx.DataObjectSimple.__init__(self) self.SetFormat(wx.DataFormat("my data format")) self.myData = bytes(value) def GetDataSize(self): return len(self.myData) def GetDataHere(self, buf): # copy our local data value to buf assert isinstance(buf, memoryview) buf[:] = self.myData return True def SetData(self, buf): # copy from buf to our local data value assert isinstance(buf, memoryview) self.myData = buf.tobytes() return True Multiple Inheritance¶The SIP tool currently does not support having more than one wrapped C++ class as the base classes of a Python class. In most cases this is not a problem because in wxPython you’re more likely to use multiple inheritance with simple mix-in classes or similar constructs than needing to inherit from more than one wrapped C++ class. However there is at least one use case where that can be a problem, and that
is with the ComboCtrl’s XRC¶The “ wx.PyEvent and wx.PyCommandEvent¶Unlike most other def __getattr__(self, name): d = self._getAttrDict() if name in d: return d[name] return doSomethingElse(name) MakeModal¶Since it is usually not a good idea to make arbitrary top-level windows be
modal, (you should normally just use a def MakeModal(self, modal=True): if modal and not hasattr(self, '_disabler'): self._disabler = wx.WindowDisabler(self) if not modal and hasattr(self, '_disabler'): del self._disabler The wxversion module¶The These days there are much better ways to handle the things that the old
multi-versioning and version selection features that the Property Grid¶In Classic, custom classes derived from Those problems are no longer present in Phoenix and so it is easiest to go
back to the way C++ handles selecting the cell editor and avoid needing to
awkwardly kludge things together in order to maintain full compatibility. If
you have a property class that implements the def DoGetEditorClass(self): return wx.propgrid.PropertyGridInterface.GetEditorByName(self.GetEditor()) wx.gizmos¶The Please note that the new wx.lib.pubsub is deprecated¶Although it originally started as part of this project, for a long time the
content of the Switching to the official PyPubSub is simple however, just install the package: pip install -U PyPubSub==3.3.0 And then change your import statements that are importing
wx.html.HtmlWindow.OnOpeningURL¶In wxPython Classic the return value of In Phoenix this has been changed to a simpler wrapper implementation which requires that both an enum value and a string be returned as a tuple. For example: def OnHTMLOpeningURL(self, urlType, url): if urlType == wx.html.HTML_URL_IMAGE and url != self.otherURL: return (wx.html.HTML_REDIRECT, self.otherURL) return (wx.html.HTML_OPEN, "") wx.NewId is deprecated¶
So a few years ago the wxWidgets team implemented a reference counting scheme
for the ID values, and started using it internally. In a more recent release the
The recommended alternative to wx.WS_EX_VALIDATE_RECURSIVELY is obsolete¶The wx.WS_EX_VALIDATE_RECURSIVELY extended style flag is obsolete, as it is now the default (and only) behavior. The style flag has been added back into wxPython for compatibility, but with a zero value. You can just stop using it in your code with no change in behavior. Parameter name changes in radial gradient methods¶The parameter names for the virtual wxGraphicsBrush CreateRadialGradientBrush(wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius, const wxGraphicsGradientStops& stops); And they now look like this: virtual wxGraphicsBrush CreateRadialGradientBrush(wxDouble startX, wxDouble startY, wxDouble endX, wxDouble endY, wxDouble radius, const wxGraphicsGradientStops& stops, const wxGraphicsMatrix& matrix = wxNullGraphicsMatrix); Possible Locale Mismatch on Windows¶On the Windows platform, prior to Python 3.8, it appears that Python did not do any initialization of the process locale settings, at least for the “en_US” based locales. For example, in Python 3.7: >>> import locale >>> locale.getdefaultlocale() ('en_US', 'cp1252') >>> locale.getlocale() (None, None) And in Python 3.8: >>> import locale >>> locale.getdefaultlocale() ('en_US', 'cp1252') >>> locale.getlocale() ('English_United States', '1252') Now, when you add in the wxWidgets class wxLocale, then it can get even more
confusing on Windows. It seems that this boils down to wxWidgets setting the
locale using a Windows-specific name like “en-US” (with a hyphen instead of an
underscore). Since Python’s locale module does not recognize this as a
legitimate locale alias, then calling locale.getlocale() after a So wxPython has added code in the There will be a new implementation of InitLocale in 4.1.1 which should be simpler and less likely to still have problems. But you’ll still be able to override InitLocale if needed. Sizer item flags validation¶Starting with wxPython 4.1, wxWidgets is now validating the flags passed when adding items to a sizer, to ensure that they are the correct flags for the type of the sizer. If the given flags do not make sense, for example using horizontal alignment flags in a horizontal box sizer, then a wxAssertionError error is raised. CheckListCtrlMixin Redundancy¶The wx.lib.mixins.listCtrl.CheckListCtrlMixin is now obsolete because wx.ListCtrl has new functionality which does pretty much the same thing. In fact there is some overlap in method names which may trip up some use cases. It is advised to drop the use of CheckListCtrlMixin and just use the wx.ListBox functionality. You will need to call EnableCheckBoxes to turn it on, and you may need to change some event handlers or overloaded methods.
©
Copyright
2012-2026, The wxPython Team.
Created using
Sphinx 9.1.0
and the python-docs-theme.
|
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |