[GRASS-SVN] r52654 - grass-addons/grass7/gui/wxpython/wx.vnet/vnet
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Aug 13 04:00:39 PDT 2012
Author: turek
Date: 2012-08-13 04:00:39 -0700 (Mon, 13 Aug 2012)
New Revision: 52654
Modified:
grass-addons/grass7/gui/wxpython/wx.vnet/vnet/dialogs.py
grass-addons/grass7/gui/wxpython/wx.vnet/vnet/widgets.py
Log:
vnet: PointsList class - improvements, bugs fixing and added comments
Modified: grass-addons/grass7/gui/wxpython/wx.vnet/vnet/dialogs.py
===================================================================
--- grass-addons/grass7/gui/wxpython/wx.vnet/vnet/dialogs.py 2012-08-13 10:39:52 UTC (rev 52653)
+++ grass-addons/grass7/gui/wxpython/wx.vnet/vnet/dialogs.py 2012-08-13 11:00:39 UTC (rev 52654)
@@ -41,6 +41,8 @@
from core.settings import UserSettings
from core.gcmd import RunCommand, GMessage
+from dbmgr.base import DbMgrBase
+
from gui_core.widgets import GNotebook
from gui_core.goutput import GMConsole, CmdThread, EVT_CMD_DONE
from gui_core.gselect import Select, LayerSelect, ColumnSelect
@@ -104,8 +106,8 @@
# Columns in points list
self.cols = [
- ['type', ["", _("Start point"), _("End point")], ""], #TODO init dynamically, translation problem
- ['topology', None, ""]
+ ['type', _('type'), [_(""), _("Start point"), _("End point")], 0], #TODO init dynamically
+ ['topology', _('topology'), None, ""]
]
self.mainPanel = wx.Panel(parent=self)
@@ -117,6 +119,7 @@
self._createPointsPage()
self._createParametersPage()
self._createOutputPage()
+ #self._createInputAtmPage()
self._addPanes()
self._doDialogLayout()
@@ -125,12 +128,10 @@
self.handlerRegistered = False
self.tmpResultLayer = None
-
# adds 2 points into list
for i in range(2):
self.list.AddItem()
- colNum = self.list.GetColumnNum('type')
- self.list.EditCellIndex(i, colNum, self.cols[1][1][1 + i])
+ self.list.EditCellIndex(i, 'type', self.cols[1][2][1 + i])
self.list.CheckItem(i, True)
# selects first point
@@ -310,13 +311,13 @@
self.goutput = GMConsole(parent = outputPanel, margin = False)
- self.outputSizer = wx.BoxSizer(wx.VERTICAL)
+ outputSizer = wx.BoxSizer(wx.VERTICAL)
- self.outputSizer.Add(item = self.goutput, proportion = 1, flag = wx.EXPAND)
+ outputSizer.Add(item = self.goutput, proportion = 1, flag = wx.EXPAND)
# overridden outputSizer.SetSizeHints(self) in GMConsole _layout
self.goutput.SetMinSize((-1,-1))
- outputPanel.SetSizer(self.outputSizer)
+ outputPanel.SetSizer(outputSizer)
def _createParametersPage(self):
"""!Tab with output console"""
@@ -640,23 +641,20 @@
if self.snapping:
coords = [e, n]
if self._snapPoint(coords):
- colNum = self.list.GetColumnNum('topology')
self.list.EditCellKey(key = self.list.selected ,
- col = colNum,
+ colName = 'topology',
cellData = _("snapped to node"))
else:
- colNum = self.list.GetColumnNum('topology')
self.list.EditCellKey(key = self.list.selected ,
- col = colNum,
+ colName = 'topology',
cellData = _("new point"))
e = coords[0]
n = coords[1]
else:
- colNum = self.list.GetColumnNum('topology')
self.list.EditCellKey(key = self.list.selected ,
- col = colNum,
+ colName = 'topology',
cellData = _("new point"))
self.pointsToDraw.GetItem(key).SetCoords([e, n])
@@ -1128,7 +1126,7 @@
break
if self.currAnModule == "v.net.path":
- self.list._updateCheckedItems(index = -1)
+ self.list.UpdateCheckedItems(index = None)
# self.anSettings['line_id'].GetParent().Show()
#else:
# self.anSettings['line_id'].GetParent().Hide()
@@ -1167,7 +1165,7 @@
# If module has only one category -> hide type column in points list otherwise show it
if len(self.vnetParams[self.currAnModule]["cmdParams"]["cats"]) > 1:
- if self.list.GetColumnNum('type') == -1:
+ if not self.list.IsShown('type'):
self.list.ShowColumn('type', 1)
prevParamsCats = self.vnetParams[self.prev2catsAnModule]["cmdParams"]["cats"]
@@ -1176,7 +1174,7 @@
self.list._adaptPointsList(currParamsCats, prevParamsCats)
self.prev2catsAnModule = self.currAnModule
else:
- if self.list.GetColumnNum('type') != -1:
+ if self.list.IsShown('type'):
self.list.HideColumn('type')
def OnSnapping(self, event):
@@ -1300,14 +1298,13 @@
subkey = [ptName, "coords"],
value = coords)
- colNum = self.list.GetColumnNum('type')
- if colNum != -1:
- cat = self.list.GetCellText(iPt, 1)#TODO
+ if self.list.IsShown('type'):
+ cat = self.list.GetCellText(iPt, 'type')
self.history.Add(key = "points",
subkey = [ptName, "cat"],
value = cat)
- topology = self.list.GetCellText(iPt, 2)
+ topology = self.list.GetCellText(iPt, 'topology')
self.history.Add(key = "points",
subkey = [ptName, "topology"],
value = topology)
@@ -1369,13 +1366,12 @@
if ptData.has_key('cat'):
self.list.ShowColumn('type', 1)
- colNum = self.list.GetColumnNum('type')
- self.list.EditCellKey(iPt, colNum, ptData["cat"])
+ self.list.EditCellKey(iPt, 'type', ptData["cat"])
else:
+ pass
self.list.HideColumn('type')
- topologyNum = self.list.GetColumnNum('topology')
- self.list.EditCellKey(iPt, topologyNum, ptData["topology"])
+ self.list.EditCellKey(iPt, 'topology', ptData["topology"])
if ptData["checked"]:
self.list.CheckItem(iPt, True)
@@ -1650,9 +1646,8 @@
PointsList.AddItem(self, event)
- colNum = self.GetColumnNum('topology')
self.EditCellKey(key = self.selected ,
- col = colNum,
+ colName = 'topology',
cellData = _("new point"))
def DeleteItem(self, event = None):
@@ -1678,22 +1673,21 @@
def _adaptPointsList(self, currParamsCats, prevParamsCats):
"""Rename category values when module is changed. Expample: Start point -> Sink point"""
- for item in enumerate(self.itemDataMap):
+ for iItem, item in enumerate(self.itemDataMap):
iCat = 0
for ptCat in prevParamsCats:
- if self.itemDataMap[item[0]][1] == ptCat[1]:
- colNum = self.GetColumnNum('type')
- self.EditCellKey(item[0], colNum, currParamsCats[iCat][1])
+ if self.itemDataMap[iItem][1] == ptCat[1]:
+ self.EditCellKey(iItem, 'type', currParamsCats[iCat][1])
iCat += 1
- if not item[1][1]:
- self.CheckItem(item[0], False)
+ if not item[1]:
+ self.CheckItem(iItem, False)
colValues = [""]
for ptCat in currParamsCats:
colValues.append(ptCat[1])
- self.ChangeColType(1, colValues)
-
+ self.ChangeColEditable('type', colValues)
+
def OnCheckItem(self, index, flag):
"""!Item is checked/unchecked"""
@@ -1714,9 +1708,9 @@
return
if currModule == "v.net.path" and flag:
- self._updateCheckedItems(index)
+ self.UpdateCheckedItems(index)
- def _updateCheckedItems(self, index):
+ def UpdateCheckedItems(self, index):
"""!For v.net.path - max. just one checked start point and end point """
alreadyChecked = []
if index:
Modified: grass-addons/grass7/gui/wxpython/wx.vnet/vnet/widgets.py
===================================================================
--- grass-addons/grass7/gui/wxpython/wx.vnet/vnet/widgets.py 2012-08-13 10:39:52 UTC (rev 52653)
+++ grass-addons/grass7/gui/wxpython/wx.vnet/vnet/widgets.py 2012-08-13 11:00:39 UTC (rev 52654)
@@ -12,7 +12,10 @@
This program is free software under the GNU General Public License
(>=v2). Read the file COPYING that comes with GRASS for details.
- at author Stepan Turek <stepan.turek seznam.cz> (GSoC 2012, mentor: Martin Landa)
+ at author Original author Michael Barton
+ at author Original version improved by Martin Landa <landa.martin gmail.com>
+ at author Rewritten by Markus Metz redesign georectfier -> GCP Manage
+ at author Stepan Turek <stepan.turek seznam.cz> (Created PointsList from GCPList) (GSoC 2012, mentor: Martin Landa)
"""
import os
@@ -45,30 +48,32 @@
Class will add as first column "use" with number of point and checkbox.
Structure of list item must be this:
-1. item: column name
- -2. item: If column is editable by user, it must contain convert function to convert
- inserted string to it's type for sorting. Use None for non editable
- columns.
- -3. item: Default value for column cell. Value should be given in it's type
- in order to sorting would work properly.
+ -2. item: column label
+ -3. item: If column is editable by user, it must contain convert function to convert
+ inserted string to it's type for sorting. Use None for not editable
+ columns. Values for insertion can be in list. This allows insert
+ just values in the list during user edits.
+ -4. item: Default value for column cell. Value should be given in it's type
+ in order to sorting would work properly. If 3. item is list, it must be index
+ of some item in the list.
Example of cols parameter:
- column name, convert function, default val
+ column name, column label, convert function, default val
@code
cols = [
- ['source E', float, 0.0],
- ['source N', float, 0.0],
- ['target E', float, 0.0],
- ['target N', float, 0.0],
- ['Forward error', None, 0],
- ['Backward error', None, 0]
- ['type', ["", "Start point", "End point"], ""] # Select from 3 choices ("Start point", "End point"),
- # choice "" is default.
+ ['E', _('source E'), float, 0.0],
+ ['N', _('source N'), float, 0.0],
+ ['E', _('target E'), float, 0.0],
+ ['N', _('target N'), float, 0.0],
+ ['F_Err', _('Forward error'), None, 0],
+ ['B_Err', _(Backward error'), None, 0]
+ ['type', _('type'), [_(""), _("Start point"), _("End point")], 0] # Select from 3 choices ("Start point", "End point"),
+ # Choice with index 0 ("") is default.
]
@endcode
List self.itemDataMap stores data for sorting comparison, it can be used
- for getting present data in list. If you do not know what you are doing,
- do not modify it.
+ for getting present data in list. It should not be modified.
"""
@@ -80,24 +85,19 @@
# TextEditMixin.__init__(self)
# inserts first column with points numbers and checkoboxes
- cols.insert(0, ['use', False, '0', 0])
+ cols.insert(0, ['use', _('use'), False, 0])
- # initialization of dict whith data
- self.cols_data = {}
- self.cols_data["colsNames"] = []
- self.cols_data["colsEditable"] = []
- self.cols_data["itemDefaultVals"] = []
+ self.colsData = cols
+ self.dataTypes = {"colName" : 0,
+ "colLabel" : 1,
+ "colEditable" : 2,
+ "itemDefaultVal" : 3} # just for better understanding
- for col in cols:
- self.cols_data["colsNames"].append(col[0])
- self.cols_data["colsEditable"].append(col[1])
- self.cols_data["itemDefaultVals"].append(col[2])
-
# tracks whether list items are checked or not
self.CheckList = []
- self._CreateCols()
- self.hiddenCols = []
+ self._createCols()
+ self.hiddenCols = {}
self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected)
self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnItemActivated)
@@ -127,14 +127,14 @@
self.ResizeColumns()
self.SetColumnWidth(0, 50)
- def _CreateCols(self):
- """! Creates columns in list"""
+ def _createCols(self):
+ """!Creates columns in list
+ """
if 0:
# normal, simple columns
- idx_col = 0
- for col in self.cols_data["colsNames"]:
- self.InsertColumn(idx_col, _(col))
- idx_col += 1
+ for col in enumerate(self.colsData):
+ iLabel = self.dataTypes["colLabel"]
+ self.InsertColumn(col[0], col[1][iLabel])
else:
# the hard way: we want images on the column header
info = wx.ListItem()
@@ -142,18 +142,26 @@
info.SetImage(-1)
info.m_format = wx.LIST_FORMAT_LEFT
- idx_col = 0
- for lbl in self.cols_data["colsNames"]:
- info.SetText(_(lbl))
- self.InsertColumnInfo(idx_col, info)
- idx_col += 1
+ for col in enumerate(self.colsData):
+ iLabel = self.dataTypes["colLabel"]
+ info.SetText(col[1][iLabel])
+ self.InsertColumnInfo(col[0], info)
-
def AddItem(self, event):
- """! Appends an item to list whith default values"""
+ """!Appends an item to list with default values
+ """
+ iDefVal = self.dataTypes["itemDefaultVal"]
+ iColEd = self.dataTypes["colEditable"]
+ itemData = []
+ for col in self.colsData:
+ if type(col[iColEd]).__name__ == "list":
+ itemData.append(col[iColEd][col[iDefVal]])
+ else:
+ itemData.append(col[iDefVal])
+ for hCol in self.hiddenCols.itervalues():
+ defVal = hCol['colsData'][iDefVal]
+ hCol['itemDataMap'].append(defVal)
- itemData = copy(self.cols_data["itemDefaultVals"])
-
self.selectedkey = self.GetItemCount()
itemData[0] = self.selectedkey + 1
@@ -167,34 +175,40 @@
self.SetItemState(self.selected,
wx.LIST_STATE_SELECTED,
wx.LIST_STATE_SELECTED)
-
self.ResizeColumns()
return self.selected
- def GetCellText(self, key, col):
-
- return self.itemDataMap[key][col]
+ def GetCellText(self, key, colName):
+ """!Get value in cell of list using key (same regardless of sorting)
+ """
+ colNum = self._getColumnNum(colName)
+ return self.itemDataMap[key][colNum]
- def EditCellIndex(self, index, col, cellData):
- """! Changes value in list using key (same regardless sorting)"""
-
- self.itemDataMap[self.GetItemData(index)][col] = cellData
- self.SetStringItem(index, col, str(cellData))
+ def EditCellIndex(self, index, colName, cellData):
+ """!Changes value in list using key (same regardless of sorting)
+ """
+ colNum = self._getColumnNum(colName)
+ self.itemDataMap[self.GetItemData(index)][colNum] = cellData
+ self.SetStringItem(index, colNum, str(cellData))
- def EditCellKey(self, key, col, cellData):
- """! Changes value in list using index (changes during sorting)"""
-
+ def EditCellKey(self, key, colName, cellData):
+ """!Changes value in list using index (changes during sorting)
+ """
+ colNum = self._getColumnNum(colName)
index = self.FindItemData(-1, key)
- self.itemDataMap[key][col] = cellData
- self.SetStringItem(index, col, str(cellData))
+ self.itemDataMap[key][colNum] = cellData
+ self.SetStringItem(index, colNum, str(cellData))
- def ChangeColType(self, col, colType):
+ def ChangeColEditable(self, colName, colType):
+ """!Changes 3. item in constructor parameter cols (see the class constructor hint)
+ """
+ colNum = self._getColumnNum(colName)
+ iColEd = self.dataTypes["colEditable"]
+ self.colsData[colNum][iColEd] = colType
- self.cols_data["colsEditable"][col] = colType
-
def DeleteItem(self, event = None):
- """! Deletes selected item in list"""
+ """!Deletes selected item in list"""
if self.selected == wx.NOT_FOUND:
return
@@ -203,6 +217,10 @@
del self.itemDataMap[key]
+ # update hidden columns
+ for hCol in self.hiddenCols.itervalues():
+ hCol['itemDataMap'].pop(key)
+
# update key and point number
for newkey in range(key, len(self.itemDataMap)):
index = self.FindItemData(-1, newkey + 1)
@@ -227,21 +245,28 @@
def ClearItem(self, event):
- """"! Clears all values in selected item of points list and unchecks it."""
+ """"!Clears all values in selected item of points list and unchecks it."""
if self.selected == wx.NOT_FOUND:
return
index = self.selected
+
+ iDefVal = self.dataTypes["itemDefaultVal"]
+ iColEd = self.dataTypes["colEditable"]
+
i = 0
- for value in self.self.cols_data["itemDefaultVals"]:
+ for col in self.colsData:
if i == 0:
i += 1
continue
- self.EditCell(index, i, value)
+ if type(col[iColEd]).__name__ == "list":
+ self.EditCell(index, i, col[iColEd][col[iDefVal]])
+ else:
+ self.EditCell(index, i, col[iDefVal])
i += 1
self.CheckItem(index, False)
def ResizeColumns(self, minWidth = [90, 120]):
- """! Resize columns"""
+ """!Resize columns"""
for i in range(self.GetColumnCount()):
self.SetColumnWidth(i, wx.LIST_AUTOSIZE)
# first column is checkbox, don't set to minWidth
@@ -262,20 +287,20 @@
def GetListCtrl(self):
return self
-
def OnItemActivated(self, event):
- """! When item is double clicked, open editor to update coordinate values. """
+ """!When item is double clicked, open editor to edit editable columns."""
data = []
index = event.GetIndex()
key = self.GetItemData(index)
changed = False
+ iColEd = self.dataTypes["colEditable"]
- for i in range(self.GetColumnCount()):
- if self.cols_data["colsEditable"][i]:
- data.append([i, #culumn number
- self.GetItem(index, i).GetText(), #cell value
- self.cols_data["colsEditable"][i]]) #convert function for type check
+ for col in enumerate(self.colsData):
+ if col[1][iColEd]:
+ data.append([col[0], #culumn number
+ self.GetItem(index, col[0]).GetText(), #cell value
+ col[1][iColEd]]) #convert function for type check
if not data:
return
@@ -299,7 +324,7 @@
return changed
def CreateEditDialog(self, data, pointNo):
- """!
+ """!Helper function
It is possible to define in child derived class
and adapt created dialog (e. g. it's title...)
"""
@@ -315,7 +340,8 @@
event.Skip()
def OnItemSelected(self, event):
-
+ """!Updates class attributes holding information about selected item
+ """
if self.selected != event.GetIndex():
self.selected = event.GetIndex()
self.selectedkey = self.GetItemData(self.selected)
@@ -323,7 +349,8 @@
event.Skip()
def getSmallUpArrowImage(self):
-
+ """!Get arrow up symbol for indication of sorting
+ """
stream = open(os.path.join(globalvar.ETCIMGDIR, 'small_up_arrow.png'), 'rb')
try:
img = wx.ImageFromStream(stream)
@@ -332,7 +359,8 @@
return img
def getSmallDnArrowImage(self):
-
+ """!Get arrow down symbol for indication of sorting
+ """
stream = open(os.path.join(globalvar.ETCIMGDIR, 'small_down_arrow.png'), 'rb')
try:
img = wx.ImageFromStream(stream)
@@ -340,41 +368,87 @@
stream.close()
return img
- def GetColumnNum(self, colName):
+ def _getColumnNum(self, colName):
+ """!Get position of column among showed columns
- for iCol in range(self.GetColumnCount()):
- if colName == self.GetColumn(iCol).GetText():
- return iCol
+ @param colName - name of column
+ @return index of columns or -1 if col was not found
+ """
+
+ for iCol, col in enumerate(self.colsData):
+ if colName == col[0]:
+ return iCol
+
return -1
def HideColumn(self, colName):
+ """!Hide column (hidden columns are not editable)
- colNum = self.GetColumnNum(colName)
- if not colNum:
+ @param colName - name of column
+
+ @return True - if column was hidden
+ @return False - if position is not valid or column is not showed
+ """
+ colNum = self._getColumnNum(colName)
+ if colNum == -1:
return False
hiddenCol = self.GetColumn(colNum)
- self.hiddenCols.append(hiddenCol)
self.DeleteColumn(colNum)
+
+ self.hiddenCols[colName] = {}
+ self.hiddenCols[colName]['wxCol'] = hiddenCol
+ hiddenMaps = []
+ for item in self.itemDataMap:
+ hiddenMaps.append(item.pop(colNum))
+
+ self.hiddenCols[colName]['itemDataMap'] = hiddenMaps
+ self.hiddenCols[colName]['colsData'] = self.colsData.pop(colNum)
self.ResizeColumns()
return True
def ShowColumn(self, colName, pos):
+ """!Show column
+ @param colName - name of column
+ @param pos - zero based index of position among showed columns (including added 'use' column)
+
+ @return True - if column was shown
+ @return False - if position is not valid or column is not hidden
+ """
if pos < 0 and pos >= self.self.GetColumnCount():
return False
+ if self.hiddenCols.has_key(colName):
+ col = self.hiddenCols[colName]
- for col in self.hiddenCols:
- if colName == col.GetText():
- self.InsertColumnItem(pos, col)
- self.ResizeColumns()
- self.hiddenCols.remove(col)
- return True
+ for item in enumerate(self.itemDataMap):
+ item[1].insert(pos, col['itemDataMap'][item[0]])
+ self.colsData.insert(pos, col['colsData'])
+
+ self.InsertColumnItem(pos, col['wxCol'])
+ self.ResizeColumns()
+ del self.hiddenCols[colName]
+ return True
+
return False
+ def IsShown(self, colName):
+ """!Is column shown
+
+ @param colName - name of column
+
+ @return True - if is shown
+ @return False - if is not shown
+ """
+
+ if self._getColumnNum(colName) == -1:
+ return False
+ else:
+ return True
+
class EditItem(wx.Dialog):
def __init__(self, parent, data, pointNo, itemCap = "Point No." ,id=wx.ID_ANY,
More information about the grass-commit
mailing list