[GRASS-SVN] r37889 - in grass/branches/develbranch_6/gui/wxpython:
. gui_modules
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Jun 15 14:10:42 EDT 2009
Author: martinl
Date: 2009-06-15 14:10:42 -0400 (Mon, 15 Jun 2009)
New Revision: 37889
Modified:
grass/branches/develbranch_6/gui/wxpython/gui_modules/dbm.py
grass/branches/develbranch_6/gui/wxpython/gui_modules/gselect.py
grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp_window.py
grass/branches/develbranch_6/gui/wxpython/gui_modules/vdigit.py
grass/branches/develbranch_6/gui/wxpython/wxgui.py
Log:
Refresh button / auto refresh button for Attribute Table viewer while using wxvdigit (trac #642)
TODO: use AddDataRow() instead, reloading data is very expensive task
(merge from trunk, r37888)
Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/dbm.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/dbm.py 2009-06-15 18:06:59 UTC (rev 37888)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/dbm.py 2009-06-15 18:10:42 UTC (rev 37889)
@@ -245,58 +245,14 @@
record = outFile.readline().replace('\n', '')
if not record:
break
-
- self.itemDataMap[i] = []
- j = 0
-
- for value in record.split('|'):
- if self.columns[columns[j]]['ctype'] != type(''):
- try:
- ### casting disabled (2009/03)
- ### self.itemDataMap[i].append(self.columns[columns[j]]['ctype'](value))
- self.itemDataMap[i].append(value)
- except ValueError:
- self.itemDataMap[i].append(_('Unknown value'))
- else:
- # encode string values
- try:
- self.itemDataMap[i].append(unicodeValue(value))
- except UnicodeDecodeError:
- self.itemDataMap[i].append(_("Unable to decode value. "
- "Set encoding in GUI preferences ('Attributes')."))
-
- if keyId > -1 and keyId == j:
- try:
- cat = self.columns[columns[j]]['ctype'] (value)
- except ValueError, e:
- cat = -1
- wx.MessageBox(parent=self,
- message=_("Error loading attribute data. "
- "Record number: %(rec)d. Unable to convert value '%(val)s' in "
- "key column (%(key)s) to integer.\n\n"
- "Details: %(detail)s") % \
- { 'rec' : i + 1, 'val' : value,
- 'key' : keyColumn, 'detail' : e},
- caption=_("Error"),
- style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
- j += 1
+
+ self.AddDataRow(i, record, columns, keyId)
- # insert to table
- # index = self.InsertStringItem(index=sys.maxint, label=str(self.itemDataMap[i][0]))
- # for j in range(len(self.itemDataMap[i][1:])):
- # self.SetStringItem(index=index, col=j+1, label=str(self.itemDataMap[i][j+1]))
-
- # self.SetItemData(item=index, data=i)
-
- self.itemIndexMap.append(i)
- if keyId > -1: # load cats only when LoadData() is called first time
- self.itemCatsMap[i] = cat
-
i += 1
if i >= 100000:
self.log.write(_("Limit 100000 records."))
break
-
+
self.SetItemCount(i)
i = 0
@@ -308,14 +264,62 @@
width = 300
self.SetColumnWidth(col=i, width=width)
i += 1
-
+
self.SendSizeEvent()
-
+
self.log.write(_("Number of loaded records: %d") % \
self.GetItemCount())
return keyId
+ def AddDataRow(self, i, record, columns, keyId):
+ """!Add row to the data list"""
+ self.itemDataMap[i] = []
+ j = 0
+
+ for value in record.split('|'):
+ if self.columns[columns[j]]['ctype'] != type(str):
+ try:
+ ### casting disabled (2009/03)
+ ### self.itemDataMap[i].append(self.columns[columns[j]]['ctype'](value))
+ self.itemDataMap[i].append(value)
+ except ValueError:
+ self.itemDataMap[i].append(_('Unknown value'))
+ else:
+ # encode string values
+ try:
+ self.itemDataMap[i].append(unicodeValue(value))
+ except UnicodeDecodeError:
+ self.itemDataMap[i].append(_("Unable to decode value. "
+ "Set encoding in GUI preferences ('Attributes')."))
+
+ if keyId > -1 and keyId == j:
+ try:
+ cat = self.columns[columns[j]]['ctype'] (value)
+ except ValueError, e:
+ cat = -1
+ wx.MessageBox(parent=self,
+ message=_("Error loading attribute data. "
+ "Record number: %(rec)d. Unable to convert value '%(val)s' in "
+ "key column (%(key)s) to integer.\n\n"
+ "Details: %(detail)s") % \
+ { 'rec' : i + 1, 'val' : value,
+ 'key' : keyColumn, 'detail' : e},
+ caption=_("Error"),
+ style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
+ j += 1
+
+ # insert to table
+ # index = self.InsertStringItem(index=sys.maxint, label=str(self.itemDataMap[i][0]))
+ # for j in range(len(self.itemDataMap[i][1:])):
+ # self.SetStringItem(index=index, col=j+1, label=str(self.itemDataMap[i][j+1]))
+
+ # self.SetItemData(item=index, data=i)
+
+ self.itemIndexMap.append(i)
+ if keyId > -1: # load cats only when LoadData() is called first time
+ self.itemCatsMap[i] = cat
+
def OnItemSelected(self, event):
"""!Item selected. Add item to selected cats..."""
# cat = int(self.GetItemText(event.m_itemIndex))
@@ -1870,6 +1874,10 @@
def OnCloseWindow(self, event):
"""!Cancel button pressed"""
self.Close()
+ if self.parent.GetName() == 'LayerManager':
+ # deregister ATM
+ self.parent.dialogs['atm'].remove(self)
+
event.Skip()
def OnBuilder(self,event):
@@ -2014,7 +2022,24 @@
### modify layer
self.manageLayerBook.modifyLayerWidgets['layer'][1].SetItems(listOfLayers)
self.manageLayerBook.OnChangeLayer(event=None)
+
+ def GetVectorName(self):
+ """!Get vector name"""
+ return self.vectorName
+
+ def LoadData(self, layer, columns=None, where=None):
+ """!Load data into list
+
+ @param layer layer number
+ @param columns list of columns for output
+ @param where where statement
+ @return id of key column
+ @return -1 if key column is not displayed
+ """
+ listWin = self.FindWindowById(self.layerPage[layer]['data'])
+ return listWin.LoadData(layer, columns, where)
+
class TableListCtrl(wx.ListCtrl,
listmix.ListCtrlAutoWidthMixin):
# listmix.TextEditMixin):
Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/gselect.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/gselect.py 2009-06-15 18:06:59 UTC (rev 37888)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/gselect.py 2009-06-15 18:10:42 UTC (rev 37889)
@@ -402,7 +402,11 @@
for name in self.tables[table].keys():
self.tables[table][name]['values'] = []
self.tables[table][name]['ids'] = []
-
+
+ def GetName(self):
+ """!Get vector name"""
+ return self.map
+
class LayerSelect(wx.Choice):
"""
Creates combo box for selecting data layers defined for vector.
Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp_window.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp_window.py 2009-06-15 18:06:59 UTC (rev 37888)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp_window.py 2009-06-15 18:10:42 UTC (rev 37889)
@@ -160,6 +160,7 @@
self.Map = Map
self.tree = tree
+ self.lmgr = lmgr # Layer Manager
#
# Flags
@@ -1128,7 +1129,7 @@
return
self.UpdateMap(render=False) # redraw map
-
+
# add new record into atribute table
if UserSettings.Get(group='vdigit', key="addRecord", subkey='enabled') is True:
# select attributes based on layer and category
@@ -1144,22 +1145,43 @@
cats=cats,
pos=posWindow,
action="add")
+
if addRecordDlg.mapDBInfo and \
addRecordDlg.ShowModal() == wx.ID_OK:
sqlfile = tempfile.NamedTemporaryFile(mode="w")
for sql in addRecordDlg.GetSQLString():
sqlfile.file.write(sql + ";\n")
sqlfile.file.flush()
+
gcmd.RunCommand('db.execute',
parent = self,
quiet = True,
input = sqlfile.name)
-
+
+ if addRecordDlg.mapDBInfo:
+ self.__updateATM()
+
elif digitToolbar.GetAction('type') in ["line", "boundary"]:
# add new point to the line
self.polycoords.append(self.Pixel2Cell(event.GetPositionTuple()[:]))
self.DrawLines(pdc=self.pdcTmp)
+ def __updateATM(self):
+ """!Update open Attribute Table Manager
+
+ @todo: use AddDataRow() instead
+ """
+ # update ATM
+ digitToolbar = self.parent.toolbars['vdigit']
+ digitVector = digitToolbar.GetLayer().GetName()
+
+ for atm in self.lmgr.dialogs['atm']:
+ atmVector = atm.GetVectorName()
+ if atmVector == digitVector:
+ layer = UserSettings.Get(group='vdigit', key="layer", subkey='value')
+ # TODO: use AddDataRow instead
+ atm.LoadData(layer)
+
def OnLeftDownVDigitEditLine(self, event):
"""
Left mouse button down - vector digitizer edit linear feature
@@ -1942,10 +1964,14 @@
quiet = True,
input = sqlfile.name)
+ if addRecordDlg.mapDBInfo:
+ self.__updateATM()
+
elif digitToolbar.GetAction() == "deleteLine":
# -> delete selected vector features
if digitClass.DeleteSelectedLines() < 0:
return
+ self.__updateATM()
elif digitToolbar.GetAction() == "splitLine":
# split line
if digitClass.SplitLine(self.Pixel2Cell(self.mouse['begin'])) < 0:
@@ -1973,6 +1999,9 @@
del self.copyCatsIds
except AttributeError:
pass
+
+ self.__updateATM()
+
elif digitToolbar.GetAction() == "editLine" and \
hasattr(self, "vdigitMove"):
line = digitClass.driver.GetSelected()
Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/vdigit.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/vdigit.py 2009-06-15 18:06:59 UTC (rev 37888)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/vdigit.py 2009-06-15 18:10:42 UTC (rev 37889)
@@ -1,15 +1,13 @@
-"""
+"""!
@package vdigit
@brief Vector digitizer extension
-Progress:
- (1) v.edit called on the background (class VEdit) (removed in r?)
- (2) Reimplentation of v.digit (VDigit)
-
Import:
+ at code
from vdigit import VDigit as VDigit
+ at endcode
Classes:
- AbstractDigit
Modified: grass/branches/develbranch_6/gui/wxpython/wxgui.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/wxgui.py 2009-06-15 18:06:59 UTC (rev 37888)
+++ grass/branches/develbranch_6/gui/wxpython/wxgui.py 2009-06-15 18:10:42 UTC (rev 37889)
@@ -120,8 +120,11 @@
self.curr_pagenum = '' # currently selected page number for layer tree notebook
self.encoding = 'ISO-8859-1' # default encoding for display fonts
self.workspaceFile = workspace # workspace file
- self.menucmd = {} # menuId / cmd
+ self.menucmd = dict() # menuId / cmd
self.georectifying = None # reference to GCP class or None
+ # list of open dialogs
+ self.dialogs = dict()
+ self.dialogs['atm'] = list()
# creating widgets
# -> self.notebook, self.goutput, self.outpage
@@ -1065,19 +1068,19 @@
if not self.curr_page:
self.MsgNoLayerSelected()
return
-
+
layer = self.curr_page.maptree.layer_selected
# no map layer selected
if not layer:
self.MsgNoLayerSelected()
return
-
+
# available only for vector map layers
try:
maptype = self.curr_page.maptree.GetPyData(layer)[0]['maplayer'].type
except:
maptype = None
-
+
if not maptype or maptype != 'vector':
wx.MessageBox(parent=self,
message=_("Attribute management is available only "
@@ -1085,7 +1088,7 @@
caption=_("Message"),
style=wx.OK | wx.ICON_INFORMATION | wx.CENTRE)
return
-
+
if not self.curr_page.maptree.GetPyData(layer)[0]:
return
dcmd = self.curr_page.maptree.GetPyData(layer)[0]['cmd']
@@ -1096,14 +1099,18 @@
parent=self)
wx.Yield()
- self.dbmanager = dbm.AttributeManager(parent=self, id=wx.ID_ANY,
- size=wx.Size(500, 300),
- item=layer, log=self.goutput)
-
+ dbmanager = dbm.AttributeManager(parent=self, id=wx.ID_ANY,
+ size=wx.Size(500, 300),
+ item=layer, log=self.goutput)
+
busy.Destroy()
-
- self.dbmanager.Show()
-
+
+ # register ATM dialog
+ self.dialogs['atm'].append(dbmanager)
+
+ # show ATM window
+ dbmanager.Show()
+
def OnNewDisplay(self, event=None):
"""!Create new layer tree and map display instance"""
self.NewDisplay()
More information about the grass-commit
mailing list