dabo Commit
Revision 1278
Date: 2005-09-09 08:10:24 -0700 (Fri, 09 Sep 2005)
Author: ed
Changed:
U trunk/dabo/ui/uiwx/dFormMixin.py
Log:
OK, I realize that this is an about-face from my morning commit, but I figured
out a good use case for being able to retrieve objects by their RegID. I
modified my montana demo so that each card had a RegID equal to its suit+rank:
e.g., the 4 of spades would have an id of 'S4'. This way, when I need to locate
a card reference in order to switch the appropriate card, I can just grab it by
RegID instead of having to do a list comprehension that queries each card's
suit and rank. The dot notation works great when you know the id ahead of time,
but when using a variable, it's useless without resorting to eval(). That just
seemed hokey to me, so I added back _objectRegistry and getObjectByRegID().
I also updated the WindowState code to be case-insensitive.
Diff:
Modified: trunk/dabo/ui/uiwx/dFormMixin.py
===================================================================
--- trunk/dabo/ui/uiwx/dFormMixin.py 2005-09-09 11:12:58 UTC (rev 1277)
+++ trunk/dabo/ui/uiwx/dFormMixin.py 2005-09-09 15:10:24 UTC (rev 1278)
@@ -22,6 +22,7 @@
# No style was explicitly set
style = wx.DEFAULT_FRAME_STYLE
kwargs["style"] = style
+ self._objectRegistry = {}
super(dFormMixin, self).__init__(preClass, parent, properties,
*args, **kwargs)
@@ -348,12 +349,25 @@
"""
if hasattr(obj, "RegID"):
id = obj.RegID
+ if self._objectRegistry.has_key(id):
+ raise KeyError, _("Duplicate RegID '%s' found")
% id
+ self._objectRegistry[id] = obj
if hasattr(self, id) or self.__dict__.has_key(id):
dabo.errorLog.write(_("RegID '%s' conflicts
with existing name") % id)
else:
self.__dict__[id] = obj
-
+
+ def getObjectByRegID(self, id):
+ """Given a RegID value, this will return a reference to the
+ associated object, if any. If not, returns None.
+ """
+ if self._objectRegistry.has_key(id):
+ return self._objectRegistry[id]
+ else:
+ return None
+
+
def _appendToMenu(self, menu, caption, function, bitmap=wx.NullBitmap,
menuId=-1):
menu.append(caption, bindfunc=function, bmp=bitmap)
@@ -570,21 +584,21 @@
def _getWindowState(self):
try:
if self.IsFullScreen():
- return 'FullScreen'
+ return "FullScreen"
elif self.IsMaximized():
- return 'Maximized'
+ return "Maximized"
elif self.IsMinimized():
- return 'Minimized'
+ return "Minimized"
else:
- return 'Normal'
+ return "Normal"
except AttributeError:
# These only work on Windows, I fear
- return 'Normal'
+ return "Normal"
def _setWindowState(self, value):
if self._constructed():
- value = str(value)
- if value == 'Normal':
+ lowvalue = str(value).lower().strip()
+ if lowvalue == "normal":
if self.IsFullScreen():
self.ShowFullScreen(False)
elif self.IsMaximized():
@@ -594,11 +608,11 @@
else:
# window already normal, but just in
case:
self.Maximize(False)
- elif value == 'Minimized':
+ elif lowvalue == "minimized":
self.Iconize()
- elif value == 'Maximized':
+ elif lowvalue == "maximized":
self.Maximize()
- elif value == 'FullScreen':
+ elif lowvalue == "fullscreen":
self.ShowFullScreen()
else:
raise ValueError, ("The only possible values
are "
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev