]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/wx/__init__.py
3 Provides a way to drop the wx prefix from wxPython objects by
4 dynamically loading and renaming objects from the real wxPython
5 package. This is the first phase of a transition to a new style of
6 using wxPython. For example:
9 class MyFrame(wx.Frame):
14 from wxPython.wx import *
15 class MyFrame(wxFrame):
20 from wxPython import wx
21 class MyFrame(wx.wxFrame):
25 Internally, this package contains only one function, called _rename,
26 and one dictionary, called _newnames. These are used by wx itself and
27 by its sub-modules whenever they are imported. The _rename function
28 changes the names in the real wxPython module being imported according
29 to the rules that have been decided, e.g. most wx prefixes are
30 removed, and the new names are made visible in the wx package or
33 The _newnames dictionary holds the set of new names (from wx and ALL
34 sub-modules), keyed by the original name. This serves two purposes,
35 duplicate old names in different modules are eliminated, the survivor
36 being the name in wx itself; and the dictionary is accessible to
37 external scripts whose purpose is to change occurrences of the
38 corresponding names in application programs that use wx.
43 __revision__
= "$Revision$"[11:-2]
45 from wxPython
import wx
49 def _rename(d_new
, d_old
, modulename
=None):
50 " copy the names from d_old to d_new according to the rules"
55 prefix
+= modulename
+ '.'
56 for old
, obj
in d_old
.items():
57 if type(obj
) is types
.ModuleType
or old
.startswith('_'):
58 # Skip modules and private names.
60 if old
.startswith('wx') and not old
.startswith('wxEVT_'):
61 # remove all wx prefixes except wxEVT_
64 # add everything else unchanged
66 if not _newnames
.has_key(old
):
68 _newnames
[old
] = prefix
+ new
# add fully qualified new name to lookup using old name as key
70 # rename the wx namespace itself
71 _rename(globals(), wx
.__dict
__)