dabo Commit
Revision 4855
Date: 2008-12-17 08:17:02 -0800 (Wed, 17 Dec 2008)
Author: Cito
Trac: http://trac.dabodev.com/dabo/changeset/4855

Changed:
U   trunk/dabo/biz/dBizobj.py
U   trunk/dabo/db/dCursorMixin.py
U   trunk/dabo/lib/datanav/Page.py
U   trunk/dabo/lib/reportWriter.py
U   trunk/dabo/lib/utils.py
U   trunk/dabo/ui/uiwx/dEditor.py
U   trunk/dabo/ui/uiwx/dGrid.py
U   trunk/dabo/ui/uiwx/dSlidePanelControl.py
U   trunk/dabo/ui/uiwx/test.py
U   trunk/demo/DaboDemo.cdxml
U   trunk/ide/mover.cdxml

Log:
Since Py 2.4 is now required, sorted() can be used, and sort should use the key 
and reverse arguments. Not yet changed in list controls.

Diff:
Modified: trunk/dabo/biz/dBizobj.py
===================================================================
--- trunk/dabo/biz/dBizobj.py   2008-12-17 14:30:01 UTC (rev 4854)
+++ trunk/dabo/biz/dBizobj.py   2008-12-17 16:17:02 UTC (rev 4855)
@@ -757,8 +757,7 @@
                for key, cursor in cursors.iteritems():
                        self._CurrentCursor = key
                        changedRows = self.getChangedRows(includeNewUnchanged)
-                       changedRows.sort(reverse=True)
-                       for row in changedRows:
+                       for row in sorted(changedRows, reverse=True):
                                self._moveToRowNum(row)
                                try:
                                        func(*args, **kwargs)

Modified: trunk/dabo/db/dCursorMixin.py
===================================================================
--- trunk/dabo/db/dCursorMixin.py       2008-12-17 14:30:01 UTC (rev 4854)
+++ trunk/dabo/db/dCursorMixin.py       2008-12-17 16:17:02 UTC (rev 4855)
@@ -18,7 +18,7 @@
 from dabo.db import dTable
 from dabo.db.dDataSet import dDataSet
 from dabo.lib import dates
-from dabo.lib.utils import noneSort, caseInsensitiveSort
+from dabo.lib.utils import noneSortKey, caseInsensitiveSortKey
 
 
 class dCursorMixin(dObject):
@@ -579,21 +579,15 @@
                # the first element.
                # First, see if we are comparing strings
                compString = isinstance(sortList[0][0], basestring)
-               sortfunc = None
 
                if compString and not caseSensitive:
-                       sortfunc = caseInsensitiveSort
+                       sortKey = caseInsensitiveSortKey
                else:
-                       sortfunc = noneSort
-               sortList.sort(sortfunc)
+                       sortKey = noneSortKey
+               sortList.sort(key=sortKey, reverse=(ord == "DESC"))
 
-               # Unless DESC was specified as the sort order, we're done 
sorting
-               if ord == "DESC":
-                       sortList.reverse()
                # Extract the rows into a new list, then convert them back to 
the _records tuple
-               newRows = []
-               for elem in sortList:
-                       newRows.append(elem[1])
+               newRows = [elem[1] for elem in sortList]
                self._records = dDataSet(newRows)
 
                # restore the RowNumber
@@ -1738,19 +1732,7 @@
                                        val = float(0)
 
                if compString and not caseSensitive:
-                       # Use a case-insensitive sort.
-                       def case_insensitive(x, y):
-                               x = x[0]
-                               y = y[0]
-                               if x is None and y is None:
-                                       return 0
-                               elif x is None:
-                                       return -1
-                               elif y is None:
-                                       return 1
-                               else:
-                                       return cmp(x.lower(), y.lower())
-                       sortList.sort(case_insensitive)
+                       sortList.sort(key=caseInsensitiveSortKey)
                else:
                        sortList.sort()
 

Modified: trunk/dabo/lib/datanav/Page.py
===================================================================
--- trunk/dabo/lib/datanav/Page.py      2008-12-17 14:30:01 UTC (rev 4854)
+++ trunk/dabo/lib/datanav/Page.py      2008-12-17 16:17:02 UTC (rev 4855)
@@ -172,8 +172,7 @@
                        sfk = sf.keys()
                        dd = [(sf[kk][0], kk, "%s %s" % (sf[kk][2], sf[kk][1]))
                                        for kk in sfk ]
-                       dd.sort()
-                       sortDesc = [itm[2] for itm in dd]
+                       sortDesc = [itm[2] for itm in sorted(dd)]
                        sortedList = dabo.ui.sortList(sortDesc)
                        newPos = 0
                        for itm in sortedList:
@@ -223,9 +222,8 @@
                else:
                        parts = lambda (k): (k, sf[k][1].upper())
 
-               flds = [(self.sortFields[k][0], k, " ".join(parts(k)))
-                       for k in self.sortFields.keys()]
-               flds.sort()
+               flds = sorted((self.sortFields[k][0], k, " ".join(parts(k)))
+                       for k in self.sortFields.keys())
                if infoOnly:
                        return [e[1:] for e in flds]
                else:

Modified: trunk/dabo/lib/reportWriter.py
===================================================================
--- trunk/dabo/lib/reportWriter.py      2008-12-17 14:30:01 UTC (rev 4854)
+++ trunk/dabo/lib/reportWriter.py      2008-12-17 16:17:02 UTC (rev 4855)
@@ -1710,10 +1710,8 @@
                        elif element.lower() == "testcursor":
                                cursor = []
                                for row in form["testcursor"]:
-                                       fields = row.keys()
-                                       fields.sort()
                                        attr = {}
-                                       for field in fields:
+                                       for field in sorted(row):
                                                attr[field] = row[field]
                                        cursor.append({"name": "record", 
"attributes": attr})
                                        child["children"] = cursor

Modified: trunk/dabo/lib/utils.py
===================================================================
--- trunk/dabo/lib/utils.py     2008-12-17 14:30:01 UTC (rev 4854)
+++ trunk/dabo/lib/utils.py     2008-12-17 16:17:02 UTC (rev 4855)
@@ -20,24 +20,18 @@
 
 
 # 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]
+def noneSortKey(vv):
+       vv = vv[0]
        if vv is None:
-               vv = ""
-       if ww is None:
-               ww = ""
-       return cmp(vv.lower(), ww.lower())
+               return (0, None)
+       else:
+               return (1, vv)
 
+
+def caseInsensitiveSortKey(vv):
+       return (vv[0] or "").lower()
+
+
 def reverseText(tx):
        """Takes a string and returns it reversed. Example:
        

Modified: trunk/dabo/ui/uiwx/dEditor.py
===================================================================
--- trunk/dabo/ui/uiwx/dEditor.py       2008-12-17 14:30:01 UTC (rev 4854)
+++ trunk/dabo/ui/uiwx/dEditor.py       2008-12-17 16:17:02 UTC (rev 4855)
@@ -1243,7 +1243,7 @@
                                if not k.startswith("_")]
                        
                        # Sort upper case:
-                       kw.sort(lambda a,b: cmp(a.upper(), b.upper()))
+                       kw.sort(key=lambda k: k.upper())
                        # Images are specified with a appended "?type"
                        for i in range(len(kw)):
                                try:
@@ -1673,7 +1673,7 @@
                        self.AutoCompCancel()
                        return
                if words:
-                       words.sort(lambda a,b: cmp(a.upper(), b.upper()))
+                       words.sort(key=lambda word: word.upper())
                        # For some reason, the STC editor in Windows likes to 
add icons
                        # even if they aren't requested. This explicitly 
removes them.
                        wds = ["%s?0" % wd for wd in words]                     
        

Modified: trunk/dabo/ui/uiwx/dGrid.py
===================================================================
--- trunk/dabo/ui/uiwx/dGrid.py 2008-12-17 14:30:01 UTC (rev 4854)
+++ trunk/dabo/ui/uiwx/dGrid.py 2008-12-17 16:17:02 UTC (rev 4855)
@@ -24,7 +24,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.utils import noneSortkey, caseInsensitiveSortkey
 
 
 class dGridDataTable(wx.grid.PyGridTableBase):
@@ -2649,33 +2649,12 @@
 
                                sortfunc = None
                                if sortingStrings and not caseSensitive:
-                                       def sortfunc(x, y):
-                                               if x[0] is None and y[0] is 
None:
-                                                       return 0
-                                               elif x[0] is None:
-                                                       return -1
-                                               elif y[0] is None:
-                                                       return 1
-                                               else:
-                                                       return 
cmp(x[0].lower(), y[0].lower())
+                                       sortKey = caseInsensitiveSortkey
                                elif dataType in ("date", "datetime"):
                                        # can't compare NoneType to these types:
-                                       def datetimesort(v,w):
-                                               x, y = v[0], w[0]
-                                               if x is None and y is None:
-                                                       return 0
-                                               elif x is None and y is not 
None:
-                                                       return -1
-                                               elif x is not None and y is 
None:
-                                                       return 1
-                                               else:
-                                                       return cmp(x,y)
-                                       sortfunc = datetimesort
-                               sortList.sort(sortfunc)
+                                       sortKey = noneSortkey
+                               sortList.sort(key=sortKey, reverse=(sortOrder 
== "DESC"))
 
-                               # Unless DESC was specified as the sort order, 
we're done sorting
-                               if sortOrder == "DESC":
-                                       sortList.reverse()
                                # Extract the rows into a new list, then set 
the dataSet to the new list
                                newRows = []
                                newLabels = []

Modified: trunk/dabo/ui/uiwx/dSlidePanelControl.py
===================================================================
--- trunk/dabo/ui/uiwx/dSlidePanelControl.py    2008-12-17 14:30:01 UTC (rev 
4854)
+++ trunk/dabo/ui/uiwx/dSlidePanelControl.py    2008-12-17 16:17:02 UTC (rev 
4855)
@@ -572,7 +572,7 @@
                        return
                if self.CollapseToBottom:
                        # Sort so that the first panel is the expanded one.
-                       pnlList.sort(lambda x, y: cmp(x.Collapsed, y.Collapsed))
+                       pnlList.sort(key=lambda x: x.Collapsed)
                fp = pnlList[0]         
                fp.Reposition(0)
                self.RefreshPanelsFrom(fp)

Modified: trunk/dabo/ui/uiwx/test.py
===================================================================
--- trunk/dabo/ui/uiwx/test.py  2008-12-17 14:30:01 UTC (rev 4854)
+++ trunk/dabo/ui/uiwx/test.py  2008-12-17 16:17:02 UTC (rev 4855)
@@ -89,9 +89,8 @@
 
                # Get all the python modules in this directory into a list:
                modules = [modname.split(".")[0] for modname in os.listdir(".") 
if modname[-3:] == ".py"]
-               modules.sort()
 
-               for modname in modules:
+               for modname in sorted(modules):
                        print "==> ", modname
                        # if the module has a test class, instantiate it:
                        if modname == "__init__":

Modified: trunk/demo/DaboDemo.cdxml
===================================================================
--- trunk/demo/DaboDemo.cdxml   2008-12-17 14:30:01 UTC (rev 4854)
+++ trunk/demo/DaboDemo.cdxml   2008-12-17 16:17:02 UTC (rev 4855)
@@ -84,13 +84,9 @@
        tree = self.tree
        tree.clear()
        root = tree.setRootNode(_("Dabo Overview"))
-       mKeys = demos.keys()
-       mKeys.sort()
-       for mc in mKeys:
+       for mc in sorted(demos):
                nd = tree.appendNode(root, mc)
-               sKeys = demos[mc].keys()
-               sKeys.sort()
-               for sc in sKeys:
+               for sc in sorted(demos[mc]):
                        sn = tree.appendNode(nd, sc)
                        sn._obj = demos[mc][sc]
        tree.expandAll()

Modified: trunk/ide/mover.cdxml
===================================================================
--- trunk/ide/mover.cdxml       2008-12-17 14:30:01 UTC (rev 4854)
+++ trunk/ide/mover.cdxml       2008-12-17 16:17:02 UTC (rev 4855)
@@ -89,14 +89,14 @@
 def sortLists(self):
        chc = self.lstSource.Choices[:]
        if self.CaseSensitiveSort:
-               chc.sort(lambda x, y: cmp(x[0].lower(), y[0].lower()))
+               chc.sort(key=lambda x: x[0].lower())
        else:
                chc.sort()
        self.lstSource.Choices = chc
        
        chc = self.lstTarget.Choices[:]
        if self.CaseSensitiveSort:
-               chc.sort(lambda x, y: cmp(x[0].lower(), y[0].lower()))
+               chc.sort(key=lambda x: x[0].lower())
        else:
                chc.sort()
        self.lstTarget.Choices = chc




_______________________________________________
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]

Reply via email to