Hi,
For a long time I have wondered what could be the point of hard coding id numbers into an application but have never bothered to ask. Seems inelegant and hard to maintain to me. For instance in java when you want to identify a particular object you just use the name of the object, not some arbitrary number you have to remember and could change. I see this is why people are setting these numbers at the top of the app, but why bother?```
In any case, personally I try to avoid using these numbers
at all and this is how I do it . . . though it’s not beautiful:```
Menu item 1:
id = wxNewId(); self.menu.Append(id, 'host load'); EVT_MENU(self, id, self.OnHostLoad)
Menu item 2:
id = wxNewId(); self.menu.Append(id, 'get info'); EVT_MENU(self, id, self.OnTimmy)
or:
`EVT_BUTTON(self, self.but.GetId(), self.Onbut)```
`…etc. Am I missing out on any functionality by scorning
these numbers?```
-Mike
``
``
···
–––
Message: 1From: “Robin Dunn” robin@alldunn.com
To: wxpython-users@lists.wxwindows.org
Subject: Re: [wxPython] Method for generating IDs
Date: Sat, 31 Mar 2001 12:07:05 -0800
Reply-To: wxpython-users@lists.wxwindows.org
How do you people generate unique IDs for your apps? Trying
not to do it manually, I use this:
_idlist = (
'ID_EXIT',
'ID_ABOUT',
[ list all ids used in the app ]
)
def setup_ids():
i = 101
d = globals()
for name in _idlist:
d[name] = i
i = i + 1
Is this “elegant” enough? Am I missing something else, easier?
ID_EXIT = wxNewId()
ID_ABOUT = wxNewId()
…
Or how about this trick that Boa uses:
ID_EXIT, ID_ABOUT, ID_FOO, ID_SPAM, ID_EGGS = \
map(lambda foo: wxNewId(), range(5))
–
Robin Dunn
Software Craftsman
robin@AllDunn.com Java give you
jitters?http://wxPython.org
Relax with wxPython!