dabo Commit
Revision 4443
Date: 2008-08-25 14:27:26 -0700 (Mon, 25 Aug 2008)
Author: Ed
Trac: http://svn.dabodev.com/trac/dabo/changeset/4443
Changed:
U trunk/dabo/ui/__init__.py
U trunk/dabo/ui/uiwx/dGrid.py
Log:
Created a decorator to detect dead objects so that we no longer encounter
wx._core.PyDeadObjectError exceptions. I created it in the dabo.ui module, as
it needs to be able to be referenced during loadUI().
Replaced the dead object trapping code in dGrid.py and decorated the affected
methods instead.
Diff:
Modified: trunk/dabo/ui/__init__.py
===================================================================
--- trunk/dabo/ui/__init__.py 2008-08-25 19:25:22 UTC (rev 4442)
+++ trunk/dabo/ui/__init__.py 2008-08-25 21:27:26 UTC (rev 4443)
@@ -25,8 +25,22 @@
return uiType["shortName"]
except (AttributeError, NameError, KeyError):
return None
-
-
+
+
+def deadCheck(fn, *args, **kwargs):
+ """This decorator is intended to detect dead objects (objects in the
process of being
+ destroyed) from attempts to call their methods. Currently this only
supports wxPython,
+ but if needed in other toolkits, different functionality will need to
be coded.
+ """
+ def retfn(self, *args, **kwargs):
+ if not self:
+ # For testing, uncomment the print line below:
+# print "FOUND DEAD OBJECT"
+ return
+ return fn(self, *args, **kwargs)
+ return retfn
+
+
def loadUI(uiType):
""" Load the given UI into the global namespace."""
retVal = False
Modified: trunk/dabo/ui/uiwx/dGrid.py
===================================================================
--- trunk/dabo/ui/uiwx/dGrid.py 2008-08-25 19:25:22 UTC (rev 4442)
+++ trunk/dabo/ui/uiwx/dGrid.py 2008-08-25 21:27:26 UTC (rev 4443)
@@ -5,6 +5,8 @@
import time
import operator
import re
+from decimal import Decimal
+from decimal import InvalidOperation
import wx
import wx.grid
from wx._core import PyAssertionError
@@ -24,25 +26,8 @@
import dabo.lib.dates
from dabo.lib.utils import noneSort, caseInsensitiveSort
-# from dabo.lib.profilehooks import profile
-# from dabo.dBug import loggit
-# See if the new decimal module is present. This is necessary
-# because if running under Python 2.4 or later and using MySQLdb,
-# some values will be returned as decimals, and we need to
-# conditionally convert them for display.
-_USE_DECIMAL = True
-try:
- from decimal import Decimal
- from decimal import InvalidOperation
-except ImportError:
- _USE_DECIMAL = False
- # This is needed so that references to this class don't throw
- # errors when running in Python 2.3
- Decimal = float
-
-
class dGridDataTable(wx.grid.PyGridTableBase):
def __init__(self, parent):
super(dGridDataTable, self).__init__()
@@ -154,9 +139,8 @@
long : "long",
datetime.date : "date",
datetime.datetime : "datetime",
- datetime.time : "time" }
- if _USE_DECIMAL:
- typeDict[Decimal] = "decimal"
+ datetime.time : "time",
+ Decimal: "decimal"}
try:
col.DataType = typeDict[col.DataType]
except KeyError:
@@ -192,9 +176,8 @@
lowtyp = typ.lower()
else:
lowtyp = typ
- if _USE_DECIMAL:
- if typ is Decimal:
- lowtyp = "decimal"
+ if typ is Decimal:
+ lowtyp = "decimal"
if lowtyp in (bool, "bool", "boolean", "logical", "l"):
ret = wx.grid.GRID_VALUE_BOOL
if lowtyp in (int, long, "int", "integer", "bigint", "i",
"long"):
@@ -517,6 +500,7 @@
int : self.intRendererClass,
long : self.longRendererClass,
float : self.floatRendererClass,
+ Decimal: self.decimalRendererClass,
list : self.listRendererClass}
self.defaultEditors = {
"str" : self.stringEditorClass,
@@ -533,10 +517,8 @@
int : self.intEditorClass,
long : self.longEditorClass,
float : self.floatEditorClass,
+ Decimal: self.decimalEditorClass,
list : self.listEditorClass}
- if _USE_DECIMAL:
- self.defaultRenderers[Decimal] =
self.decimalRendererClass
- self.defaultEditors[Decimal] = self.decimalEditorClass
# Default to string renderer
self._rendererClass = self.stringRendererClass
@@ -559,6 +541,7 @@
setattr(self, prop, func(*args))
+ @dabo.ui.deadCheck
def _updateCellDynamicProps(self, row):
kwargs = {"row": row}
self._cellDynamicRow = row
@@ -575,15 +558,9 @@
oldVal = getattr(self, prop)
except AttributeError:
needRefresh = True
- try:
- setattr(self, prop, func(*args,
**kwargs))
- except dabo.ui.deadObjectException:
- pass
- try:
- if needRefresh or oldVal !=
getattr(self, prop):
- needRefresh = True
- except dabo.ui.deadObjectException:
- needRefresh = False
+ setattr(self, prop, func(*args, **kwargs))
+ if needRefresh or oldVal != getattr(self, prop):
+ needRefresh = True
if needRefresh:
dabo.ui.callAfterInterval(200, self._refreshGrid)
del self._cellDynamicRow
@@ -2207,13 +2184,11 @@
dabo.ui.callAfter(self._updateColumnWidths)
+ @dabo.ui.deadCheck
def _updateColumnWidths(self):
"""See if there are any dynamically-sized columns, and resize
them
accordingly.
"""
- if not self:
- # This can be called in a callAfter(), and perhaps we
are already dead.
- return
dynCols = [col for col in self.Columns
if col.Expand]
if not dynCols:
@@ -2591,7 +2566,7 @@
dataType = "long"
elif isinstance(f, int):
dataType = "int"
- elif _USE_DECIMAL and isinstance(f,
Decimal):
+ elif isinstance(f, Decimal):
dataType = "decimal"
else:
dataType = None
@@ -2858,10 +2833,7 @@
typFunc = type(val)
if typFunc(findString) == val:
# We can replace if replaceString can
be the correct type
- if _USE_DECIMAL:
- errors = (ValueError,
InvalidOperation)
- else:
- errors = (ValueError, )
+ errors = (ValueError, InvalidOperation)
try:
newval = typFunc(replaceString)
self.SetValue(currRow, currCol,
newval)
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message: http://leafe.com/archives/byMID/[EMAIL PROTECTED]