]> git.saurik.com Git - wxWidgets.git/blame - wxPython/wx/__init__.py
updated
[wxWidgets.git] / wxPython / wx / __init__.py
CommitLineData
1fded56b
RD
1"""wx package
2
3Provides a way to drop the wx prefix from wxPython objects by
4dynamically loading and renaming objects from the real wxPython
5package. This is the first phase of a transition to a new style of
6using wxPython. For example:
7
8 import wx
9 class MyFrame(wx.Frame):
10 ...
11
12instead of:
13
14 from wxPython.wx import *
15 class MyFrame(wxFrame):
16 ...
17
18or:
19
20 from wxPython import wx
21 class MyFrame(wx.wxFrame):
22 ...
23
24
25Internally, this package contains only one function, called _rename,
26and one dictionary, called _newnames. These are used by wx itself and
27by its sub-modules whenever they are imported. The _rename function
28changes the names in the real wxPython module being imported according
29to the rules that have been decided, e.g. most wx prefixes are
30removed, and the new names are made visible in the wx package or
31sub-packages.
32
33The _newnames dictionary holds the set of new names (from wx and ALL
34sub-modules), keyed by the original name. This serves two purposes,
35duplicate old names in different modules are eliminated, the survivor
36being the name in wx itself; and the dictionary is accessible to
37external scripts whose purpose is to change occurrences of the
38corresponding names in application programs that use wx.
39
40"""
41
42__cvsid__ = "$Id$"
43__revision__ = "$Revision$"[11:-2]
44
45from wxPython import wx
46
47_newnames = {}
48
49def _rename(d_new, d_old, modulename=None):
50 " copy the names from d_old to d_new according to the rules"
51 global _newnames
52 import types
53 prefix = 'wx.'
54 if modulename:
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.
59 continue
60 if old.startswith('wx') and not old.startswith('wxEVT_'):
61 # remove all wx prefixes except wxEVT_
62 new = old[2:]
63 else:
64 # add everything else unchanged
65 new = old
66 if not _newnames.has_key(old):
67 d_new[new] = obj
68 _newnames[old] = prefix + new # add fully qualified new name to lookup using old name as key
69
70# rename the wx namespace itself
71_rename(globals(), wx.__dict__)
72del wx
73