dabo Commit
Revision 4099
Date: 2008-05-27 15:51:06 -0700 (Tue, 27 May 2008)
Author: Paul
Trac: http://svn.dabodev.com/trac/dabo/changeset/4099
Changed:
U trunk/dabo/db/dCursorMixin.py
U trunk/dabo/lib/utils.py
U trunk/dabo/ui/uiwx/dGrid.py
Log:
Refactored the sort functions used by both dGrid and dCursor into
dabo.lib.utils,
as I just got bitten again by something I fixed in dCursor but not dGrid (a
column
which is normally a string having None as a value for one row).
Diff:
Modified: trunk/dabo/db/dCursorMixin.py
===================================================================
--- trunk/dabo/db/dCursorMixin.py 2008-05-27 22:35:12 UTC (rev 4098)
+++ trunk/dabo/db/dCursorMixin.py 2008-05-27 22:51:06 UTC (rev 4099)
@@ -24,8 +24,8 @@
from dabo.db import dTable
from dabo.db.dDataSet import dDataSet
from dabo.lib import dates
+from dabo.lib.utils import noneSort, caseInsensitiveSort
-
class dCursorMixin(dObject):
"""Dabo's cursor class, representing the lowest tier."""
_call_initProperties = False
@@ -579,26 +579,6 @@
compString = isinstance(sortList[0][0], basestring)
sortfunc = None
- # can't compare NoneType to some types: sort None lower than
anything else:
- def noneSort(vv, ww):
- xx, yy = vv[0], ww[0]
- if xx is None and yy is None:
- return 0
- elif xx is None and yy is not None:
- return -1
- elif xx is not None and yy is None:
- return 1
- else:
- return cmp(xx, yy)
-
- def caseInsensitiveSort(vv, ww):
- vv, ww = vv[0], ww[0]
- if vv is None:
- vv = ""
- if ww is None:
- ww = ""
- return cmp(vv.lower(), ww.lower())
-
if compString and not caseSensitive:
sortfunc = caseInsensitiveSort
else:
Modified: trunk/dabo/lib/utils.py
===================================================================
--- trunk/dabo/lib/utils.py 2008-05-27 22:35:12 UTC (rev 4098)
+++ trunk/dabo/lib/utils.py 2008-05-27 22:51:06 UTC (rev 4099)
@@ -19,6 +19,25 @@
shell, shellcon = None, None
+# can't compare NoneType to some types: sort None lower than anything else:
+def noneSort(vv, ww):
+ xx, yy = vv[0], ww[0]
+ if xx is None and yy is None:
+ return 0
+ if xx is None and yy is not None:
+ return -1
+ if xx is not None and yy is None:
+ return 1
+ return cmp(xx, yy)
+
+def caseInsensitiveSort(vv, ww):
+ vv, ww = vv[0], ww[0]
+ if vv is None:
+ vv = ""
+ if ww is None:
+ ww = ""
+ return cmp(vv.lower(), ww.lower())
+
def reverseText(tx):
"""Takes a string and returns it reversed. Example:
Modified: trunk/dabo/ui/uiwx/dGrid.py
===================================================================
--- trunk/dabo/ui/uiwx/dGrid.py 2008-05-27 22:35:12 UTC (rev 4098)
+++ trunk/dabo/ui/uiwx/dGrid.py 2008-05-27 22:51:06 UTC (rev 4099)
@@ -22,6 +22,7 @@
from dabo.dObject import dObject
from dabo.ui import makeDynamicProperty
import dabo.lib.dates
+from dabo.lib.utils import noneSort, caseInsensitiveSort
# from dabo.lib.profilehooks import profile
# from dabo.dBug import loggit
@@ -2662,9 +2663,9 @@
if compString and not caseSensitive:
# Use a case-insensitive sort.
- sortList.sort(lambda x, y: cmp(x[0].lower(),
y[0].lower()))
+ sortfunc = caseInsensitiveSort
else:
- sortList.sort()
+ sortfunc = noneSort
# Now iterate through the list to find the matching value. I
know that
# there are more efficient search algorithms, but for this
purpose, we'll
_______________________________________________
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]