The large quantity of wxPython constants are an obvious place to look
in considering breaking up the wx namespace. And a lot of the
constants have prefixes, making them logical candidates for a separate
namespace (with the potential to drop the prefix as well). So I did an
analysis and got the following results (the code is included
below). This list shows a count of any prefix having more than 9
occurences:
231 LANGUAGE
103 WXK
90 SYS
67 PAPER
57 ID
48 FONTENCODING
44 LIST
37 ART
33 BITMAP
30 CURSOR
20 LC
20 DF
18 TE
16 TR
16 HT
14 TREE
12 SP
10 SL
10 MM
10 LOG
10 ALIGN
The first three seem like easy candidates for separate submodules,
perhaps lang, key, and sys. If we did move them, would we also want to
strip off their prefixes? The results would look like this:
lang.ABKHAZIAN
lang.AFAR
lang.AFRIKAANS
lang.ALBANIAN
...
key.ADD
key.ALT
key.BACK
key.CANCEL
...
sys.ANSI_FIXED_FONT
sys.ANSI_VAR_FONT
sys.BORDER_X
sys.BORDER_Y
...
Like everything in life, there are some issues with this approach that
need resolving, and questions that need answering:
* If we don't strip off the prefix, we get ugly redundant stuff like:
lang.LANGUAGE_ABKHAZIAN
key.WXK_ADD
* ``key`` is a common variable name in key handlers, but you could do:
if key == wx.key.ADD: ...
* ``sys`` is in the Python library, but you could do:
import sys
import wx
import wx.sys
wx.sys.BORDER_X
* where do we draw the line? Do we move PAPER, ID, FONTENCODING? Or do
we not move anything, and leave them all in one constants module?
* what about constants defined in other modules, like stc, html, etc?
···
----
Here is the code that generated the counts. Note that I have the
constants all going into a "con" module at the moment:
>>> import wx
>>> len(dir(wx))
821
>>> from wx import con
>>> len(dir(con))
1407
>>> d = {}
>>> for item in dir(con):
... l = item.split('_')
... if len(l) > 1:
... pre = l[0]
... d[pre] = d.get(pre, 0) + 1
...
>>> l = [(value, key) for key, value in d.items()]
>>> l.sort()
>>> l.reverse()
>>> for item in l:
... if item[0] > 9:
... print item[0], item[1]
...
--
Patrick K. O'Brien
Orbtech http://www.orbtech.com/web/pobrien
-----------------------------------------------
"Your source for Python programming expertise."
-----------------------------------------------