[GRASS-SVN] r72562 - grass/branches/releasebranch_7_4/gui/wxpython/dbmgr

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Mar 25 03:59:38 PDT 2018


Author: martinl
Date: 2018-03-25 03:59:38 -0700 (Sun, 25 Mar 2018)
New Revision: 72562

Modified:
   grass/branches/releasebranch_7_4/gui/wxpython/dbmgr/base.py
   grass/branches/releasebranch_7_4/gui/wxpython/dbmgr/sqlbuilder.py
Log:
dbmgr: don't show db info connection by default, it's just occupying space in the dialog
       better handling of text values in SQLBuilder
       fix sorting unicode issue
       set busy cursor when soring values
       get sample/all values tuning
       (merge r72532:72535, r72537 from trunk)


Modified: grass/branches/releasebranch_7_4/gui/wxpython/dbmgr/base.py
===================================================================
--- grass/branches/releasebranch_7_4/gui/wxpython/dbmgr/base.py	2018-03-25 10:56:32 UTC (rev 72561)
+++ grass/branches/releasebranch_7_4/gui/wxpython/dbmgr/base.py	2018-03-25 10:59:38 UTC (rev 72562)
@@ -639,6 +639,7 @@
 
     def SortItems(self, sorter=cmp):
         """Sort items"""
+        wx.BeginBusyCursor()
         items = list(self.itemDataMap.keys())
         items.sort(self.Sorter)
         self.itemIndexMap = items
@@ -645,7 +646,8 @@
 
         # redraw the list
         self.Refresh()
-
+        wx.EndBusyCursor()
+        
     def Sorter(self, key1, key2):
         colName = self.GetColumn(self._col).GetText()
         ascending = self._colSortFlag[self._col]
@@ -661,7 +663,7 @@
         if isinstance(
                 item1, types.StringType) or isinstance(
                 item2, types.StringTypes):
-            cmpVal = locale.strcoll(str(item1), str(item2))
+            cmpVal = locale.strcoll(GetUnicodeValue(item1), GetUnicodeValue(item2))
         else:
             cmpVal = cmp(item1, item2)
 

Modified: grass/branches/releasebranch_7_4/gui/wxpython/dbmgr/sqlbuilder.py
===================================================================
--- grass/branches/releasebranch_7_4/gui/wxpython/dbmgr/sqlbuilder.py	2018-03-25 10:56:32 UTC (rev 72561)
+++ grass/branches/releasebranch_7_4/gui/wxpython/dbmgr/sqlbuilder.py	2018-03-25 10:59:38 UTC (rev 72562)
@@ -85,24 +85,25 @@
         self.SetClientSize(self.panel.GetSize())
         self.CenterOnParent()
 
-    def _doLayout(self, modeChoices):
+    def _doLayout(self, modeChoices, showDbInfo=False):
         """Do dialog layout"""
 
         self.pagesizer = wx.BoxSizer(wx.VERTICAL)
 
         # dbInfo
-        databasebox = wx.StaticBox(parent=self.panel, id=wx.ID_ANY,
+        if showDbInfo:
+            databasebox = wx.StaticBox(parent=self.panel, id=wx.ID_ANY,
                                    label=" %s " % _("Database connection"))
-        databaseboxsizer = wx.StaticBoxSizer(databasebox, wx.VERTICAL)
-        databaseboxsizer.Add(
-            CreateDbInfoDesc(
-                self.panel,
-                self.dbInfo,
-                layer=self.layer),
-            proportion=1,
-            flag=wx.EXPAND | wx.ALL,
-            border=3)
-
+            databaseboxsizer = wx.StaticBoxSizer(databasebox, wx.VERTICAL)
+            databaseboxsizer.Add(
+                CreateDbInfoDesc(
+                    self.panel,
+                    self.dbInfo,
+                    layer=self.layer),
+                proportion=1,
+                flag=wx.EXPAND | wx.ALL,
+                border=3)
+        
         #
         # text areas
         #
@@ -296,8 +297,9 @@
                                          label=_("Close dialog on apply"))
         self.close_onapply.SetValue(True)
 
-        self.pagesizer.Add(databaseboxsizer,
-                           flag=wx.ALL | wx.EXPAND, border=5)
+        if showDbInfo:
+            self.pagesizer.Add(databaseboxsizer,
+                               flag=wx.ALL | wx.EXPAND, border=5)
         self.pagesizer.Add(
             modesizer,
             proportion=0,
@@ -355,10 +357,12 @@
 
         self.list_values.Clear()
 
+        sql = "SELECT DISTINCT {column} FROM {table} ORDER BY {column}".format(
+            column=column, table=self.tablename)
+        if justsample:
+            sql += " LIMIT {}".format(255)
         data = grass.db_select(
-            sql="SELECT %s FROM %s" %
-            (column,
-             self.tablename),
+            sql=sql,
             database=self.database,
             driver=self.driver,
             sep='{_sep_}')
@@ -369,17 +373,16 @@
             self.dbInfo.GetTable(self.layer))[column]
 
         i = 0
-        for item in sorted(set(map(lambda x: desc['ctype'](x[0]), data))):
-            if justsample and i > 255:
-                break
-
-            if desc['type'] != 'character':
-                item = str(item)
+        items = []
+        for item in data: #sorted(set(map(lambda x: desc['ctype'](x[0]), data))):
+            if desc['type'] not in ('character', 'text'):
+                items.append(str(item[0]))
             else:
-                item = GetUnicodeValue(item)
-            self.list_values.Append(item)
+                items.append(u"'{}'".format(GetUnicodeValue(item[0])))
             i += 1
 
+        self.list_values.AppendItems(items)
+        
     def OnSampleValues(self, event):
         """Get sample values"""
         self.OnUniqueValues(None, True)



More information about the grass-commit mailing list