]> git.saurik.com Git - wxWidgets.git/blob - wxPython/wx/__init__.py
replaced wxAppTraits::GetOSVersion with GetToolkitInfo with richer information that...
[wxWidgets.git] / wxPython / wx / __init__.py
1 """wx package
2
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:
7
8 import wx
9 class MyFrame(wx.Frame):
10 ...
11
12 instead of:
13
14 from wxPython.wx import *
15 class MyFrame(wxFrame):
16 ...
17
18 or:
19
20 from wxPython import wx
21 class MyFrame(wx.wxFrame):
22 ...
23
24
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
31 sub-packages.
32
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.
39
40 """
41
42 __cvsid__ = "$Id$"
43 __revision__ = "$Revision$"[11:-2]
44
45 from wxPython import wx
46
47 _newnames = {}
48
49 def _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__)
72 del wx
73