[GRASS-SVN] r48692 -
grass/branches/releasebranch_6_4/gui/wxpython/gui_modules
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Oct 9 17:00:40 EDT 2011
Author: martinl
Date: 2011-10-09 14:00:40 -0700 (Sun, 09 Oct 2011)
New Revision: 48692
Modified:
grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/sqlbuilder.py
Log:
wxGUI/sqlbuilder: fix various bugs, sort values
(merge r48690 from trunk)
Modified: grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/sqlbuilder.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/sqlbuilder.py 2011-10-09 20:37:49 UTC (rev 48691)
+++ grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/sqlbuilder.py 2011-10-09 21:00:40 UTC (rev 48692)
@@ -6,8 +6,6 @@
Classes:
- SQLFrame
- at todo Various updates are required...
-
Usage:
@code
python sqlbuilder.py vector_map
@@ -20,7 +18,7 @@
for details.
@author Jachym Cepicky <jachym.cepicky gmail.com> (original author)
- at author Martin Landa <landa.martin gmail.com>,
+ at author Martin Landa <landa.martin gmail.com>
@author Hamish Bowman <hamish_b yahoo com>
"""
@@ -59,7 +57,7 @@
self.vectmap = vectmap # fullname
if not "@" in self.vectmap:
self.vectmap = self.vectmap + "@" + grass.gisenv()['MAPSET']
- self.mapname, self.mapset = self.vectmap.split("@")
+ self.mapname, self.mapset = self.vectmap.split("@", 1)
# db info
self.layer = layer
@@ -88,9 +86,6 @@
self.btn_verify = wx.Button(parent = self.panel, id = wx.ID_ANY,
label = _("Verify"))
self.btn_verify.SetToolTipString(_("Verify SQL statement"))
- # self.btn_help = wx.Button(self.panel, -1, "Help")
- # self.btn_load = wx.Button(self.panel, -1, "Load")
- # self.btn_save = wx.Button(self.panel, -1, "Save")
self.btn_apply = wx.Button(parent = self.panel, id = wx.ID_APPLY)
self.btn_apply.SetToolTipString(_("Apply SQL statement and close the dialog"))
self.btn_close = wx.Button(parent = self.panel, id = wx.ID_CLOSE)
@@ -124,7 +119,7 @@
# text areas
#
self.text_sql = wx.TextCtrl(parent = self.panel, id = wx.ID_ANY,
- value = '', size = (-1, 75),
+ value = '', size = (-1, 50),
style=wx.TE_MULTILINE)
if self.qtype.lower() == "select":
self.text_sql.SetValue("SELECT * FROM %s" % self.tablename)
@@ -170,11 +165,9 @@
self.text_sql.Bind(wx.EVT_TEXT, self.OnText)
- self.Bind(wx.EVT_CLOSE, self.OnClose)
+ self._doLayout()
- self.__doLayout()
-
- def __doLayout(self):
+ def _doLayout(self):
"""!Do dialog layout"""
# dbInfo
@@ -198,9 +191,6 @@
buttonsizer = wx.FlexGridSizer(cols = 4, hgap = 5, vgap = 5)
buttonsizer.Add(item = self.btn_clear)
buttonsizer.Add(item = self.btn_verify)
- # buttonsizer1.Add(self.btn_help, (0,2))
- # buttonsizer1.Add(self.btn_load, (0,2))
- # buttonsizer1.Add(self.btn_save, (0,3))
buttonsizer.Add(item = self.btn_apply)
buttonsizer.Add(item = self.btn_close)
@@ -262,13 +252,13 @@
# pagesizer.Add(self.btn_uniqe,0,wx.ALIGN_LEFT|wx.TOP,border=5)
# pagesizer.Add(self.btn_uniqesample,0,wx.ALIGN_LEFT|wx.TOP,border=5)
pagesizer.Add(item = buttonsizer2, proportion = 0,
- flag = wx.ALIGN_CENTER_HORIZONTAL | wx.BOTTOM, border = 5)
+ flag = wx.ALIGN_CENTER_HORIZONTAL)
pagesizer.Add(item = sqlboxsizer, proportion = 0,
- flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, border = 5)
+ flag = wx.EXPAND | wx.LEFT | wx.RIGHT, border = 5)
pagesizer.Add(item = buttonsizer, proportion = 0,
flag = wx.ALIGN_RIGHT | wx.ALL, border = 5)
pagesizer.Add(item = self.close_onapply, proportion = 0,
- flag = wx.LEFT | wx.RIGHT | wx.BOTTOM, border = 5)
+ flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 5)
self.panel.SetAutoLayout(True)
self.panel.SetSizer(pagesizer)
@@ -295,11 +285,18 @@
sql = querystring,
database = self.database,
driver = self.driver)
+ if not data:
+ return
+
+ desc = self.dbInfo.GetTableDesc(self.dbInfo.GetTable(self.layer))[column]
+
i = 0
- for line in data:
+ for item in sorted(map(desc['ctype'], data)):
if justsample and i < 256 or \
not justsample:
- self.list_values.Append(line.strip())
+ if desc['type'] != 'character':
+ item = str(item)
+ self.list_values.Append(item)
else:
break
i += 1
@@ -313,7 +310,7 @@
idx = self.list_columns.GetSelections()
for i in idx:
column = self.list_columns.GetString(i)
- self.__Add(element = 'column', value = column)
+ self._add(element = 'column', value = column)
if not self.btn_uniquesample.IsEnabled():
self.btn_uniquesample.Enable(True)
@@ -321,7 +318,12 @@
def OnAddValue(self, event):
"""!Add value"""
- idx = self.list_values.GetSelections()[0]
+ selection = self.list_values.GetSelections()
+ if not selection:
+ event.Skip()
+ return
+
+ idx = selection[0]
value = self.list_values.GetString(idx)
idx = self.list_columns.GetSelections()[0]
column = self.list_columns.GetString(idx)
@@ -331,7 +333,7 @@
if ctype == 'character':
value = "'%s'" % value
- self.__Add(element = 'value', value = value)
+ self._add(element = 'value', value = value)
def OnAddMark(self, event):
"""!Add mark"""
@@ -341,9 +343,9 @@
mark = value[0]
break
- self.__Add(element = 'mark', value = mark)
+ self._add(element = 'mark', value = mark)
- def __Add(self, element, value):
+ def _add(self, element, value):
"""!Add element to the query
@param element element to add (column, value)
@@ -417,15 +419,14 @@
flags = 't',
driver = self.driver,
database = self.database)
-
+
if ret != 0 and msg:
self.statusbar.SetStatusText(_("SQL statement is not valid"), 0)
- wx.MessageBox(parent=self,
- message=_("SQL statement is not valid.\n\n%s") % msg,
- caption=_("Warning"), style=wx.OK | wx.ICON_WARNING | wx.CENTRE)
+ gcmd.GError(parent = self,
+ message = _("SQL statement is not valid.\n\n%s") % msg)
else:
self.statusbar.SetStatusText(_("SQL statement is valid"), 0)
-
+
def OnClear(self, event):
"""!Clear button pressed"""
if self.qtype.lower() == "select":
@@ -437,8 +438,9 @@
"""!Close button pressed"""
if self.evtHeader:
self.evtHeader(event = 'close')
+
self.Destroy()
-
+
event.Skip()
if __name__ == "__main__":
More information about the grass-commit
mailing list