[GRASS-SVN] r47212 - in grass/branches/develbranch_6:
gui/wxpython/gui_modules lib/python
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Jul 21 15:01:22 EDT 2011
Author: martinl
Date: 2011-07-21 12:01:22 -0700 (Thu, 21 Jul 2011)
New Revision: 47212
Modified:
grass/branches/develbranch_6/gui/wxpython/gui_modules/gdialogs.py
grass/branches/develbranch_6/gui/wxpython/gui_modules/gmodeler.py
grass/branches/develbranch_6/gui/wxpython/gui_modules/gselect.py
grass/branches/develbranch_6/gui/wxpython/gui_modules/menuform.py
grass/branches/develbranch_6/lib/python/task.py
Log:
wxGUI/modeler: start model with data item
(merge r47210 from trunk)
Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/gdialogs.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/gdialogs.py 2011-07-21 18:53:22 UTC (rev 47211)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/gdialogs.py 2011-07-21 19:01:22 UTC (rev 47212)
@@ -48,13 +48,21 @@
from preferences import globalSettings as UserSettings
class ElementDialog(wx.Dialog):
- """!General dialog to choose given element (location, mapset, vector map, etc.)"""
def __init__(self, parent, title, label, id = wx.ID_ANY,
- style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER,
+ etype = False, style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER,
**kwargs):
+ """!General dialog to choose given element (location, mapset, vector map, etc.)
+ @param parent window
+ @param title window title
+ @param label element label
+ @param etype show also ElementSelect
+ """
wx.Dialog.__init__(self, parent, id, title, style = style, **kwargs)
+ self.etype = etype
+ self.label = label
+
self.panel = wx.Panel(parent = self, id = wx.ID_ANY)
self.btnCancel = wx.Button(parent = self.panel, id = wx.ID_CANCEL)
@@ -62,17 +70,26 @@
self.btnOK.SetDefault()
self.btnOK.Enable(False)
- self.label = wx.StaticText(parent = self.panel, id = wx.ID_ANY,
- label = label)
+ if self.etype:
+ self.typeSelect = gselect.ElementSelect(parent = self.panel,
+ size = globalvar.DIALOG_GSELECT_SIZE)
+ self.typeSelect.Bind(wx.EVT_CHOICE, self.OnType)
self.element = None # must be defined
- self.__Layout()
+ self.__layout()
def PostInit(self):
self.element.SetFocus()
self.element.Bind(wx.EVT_TEXT, self.OnElement)
+ def OnType(self, event):
+ """!Select element type"""
+ if not self.etype:
+ return
+ evalue = self.typeSelect.GetValue(event.GetString())
+ self.element.SetType(evalue)
+
def OnElement(self, event):
"""!Name for vector map layer given"""
if len(event.GetString()) > 0:
@@ -80,14 +97,23 @@
else:
self.btnOK.Enable(False)
- def __Layout(self):
+ def __layout(self):
"""!Do layout"""
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.dataSizer = wx.BoxSizer(wx.VERTICAL)
- self.dataSizer.Add(self.label, proportion=0,
- flag=wx.ALL, border=1)
+ if self.etype:
+ self.dataSizer.Add(item = wx.StaticText(parent = self.panel, id = wx.ID_ANY,
+ label = _("Type of element:")),
+ proportion=0, flag=wx.ALL, border=1)
+ self.dataSizer.Add(item = self.typeSelect,
+ proportion=0, flag=wx.ALL, border=1)
+
+ self.dataSizer.Add(item = wx.StaticText(parent = self.panel, id = wx.ID_ANY,
+ label = self.label),
+ proportion=0, flag=wx.ALL, border=1)
+
# buttons
btnSizer = wx.StdDialogButtonSizer()
btnSizer.AddButton(self.btnCancel)
@@ -104,6 +130,10 @@
"""!Return (mapName, overwrite)"""
return self.element.GetValue()
+ def GetType(self):
+ """!Get element type"""
+ return self.element.tcp.GetType()
+
class LocationDialog(ElementDialog):
"""!Dialog used to select location"""
def __init__(self, parent, title = _("Select GRASS location and mapset"), id = wx.ID_ANY):
Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/gmodeler.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/gmodeler.py 2011-07-21 18:53:22 UTC (rev 47211)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/gmodeler.py 2011-07-21 19:01:22 UTC (rev 47212)
@@ -32,7 +32,7 @@
- ModelConditionDialog
- WritePythonFile
-(C) 2010 by the GRASS Development Team
+(C) 2010-2011 by the GRASS Development Team
This program is free software under the GNU General Public License
(>=v2). Read the file COPYING that comes with GRASS for details.
@@ -134,7 +134,14 @@
return len(self.GetItems(objType = ModelAction))
return len(self.GetItems())
-
+
+ def GetNextId(self):
+ """!Get next id (data ignored)"""
+ currId = self.items[-1].GetId()
+ if currId > 0:
+ return currId + 1
+ return 1
+
def GetProperties(self):
"""!Get model properties"""
return self.properties
@@ -196,12 +203,18 @@
def GetData(self):
"""!Get list of data items"""
result = list()
+ dataItems = self.GetItems(objType = ModelData)
for action in self.GetItems(objType = ModelAction):
for rel in action.GetRelations():
dataItem = rel.GetData()
if dataItem not in result:
result.append(dataItem)
+ dataItems.remove(dataItem)
+ # standalone data
+ if dataItems:
+ result += dataItems
+
return result
def FindData(self, value, prompt):
@@ -356,7 +369,7 @@
"""!Add item to the list"""
iId = newItem.GetId()
- i = 0
+ i = 0
for item in self.items:
if item.GetId() > iId:
self.items.insert(i, newItem)
@@ -1179,7 +1192,7 @@
return
action = ModelAction(self.model, cmd = cmd, x = width/2, y = height/2,
- id = self.model.GetNumItems() + 1)
+ id = self.model.GetNextId())
overwrite = self.model.GetProperties().get('overwrite', None)
if overwrite is not None:
action.GetTask().set_flag('overwrite', overwrite)
@@ -1207,20 +1220,27 @@
def OnAddData(self, event):
"""!Add data item to model
-
- @todo
"""
# add action to canvas
width, height = self.canvas.GetSize()
data = ModelData(self, x = width/2, y = height/2)
+
self.canvas.diagram.AddShape(data)
data.Show(True)
+ self.ModelChanged()
+
self._addEvent(data)
- # self.model.AddData(data)
+ self.model.AddItem(data)
self.canvas.Refresh()
+ # show data properties dialog
+ dlg = ModelDataDialog(parent = self, shape = data)
+ data.SetPropDialog(dlg)
+ dlg.CentreOnParent()
+ dlg.Show()
+
def OnHelp(self, event):
"""!Display manual page"""
grass.run_command('g.manual',
@@ -1242,22 +1262,22 @@
def GetOptData(self, dcmd, layer, params, propwin):
"""!Process action data"""
if params: # add data items
- for p in params['params']:
- if p.get('prompt', '') in ('raster', 'vector', 'raster3d'):
- try:
- name, mapset = p.get('value', '').split('@', 1)
- except (ValueError, IndexError):
- continue
+ # for p in params['params']:
+ # if p.get('prompt', '') in ('raster', 'vector', 'raster3d'):
+ # try:
+ # name, mapset = p.get('value', '').split('@', 1)
+ # except (ValueError, IndexError):
+ # continue
- if mapset != grass.gisenv()['MAPSET']:
- continue
+ # if mapset != grass.gisenv()['MAPSET']:
+ # continue
- # don't use fully qualified names
- p['value'] = p.get('value', '').split('@')[0]
- for idx in range(1, len(dcmd)):
- if p.get('name', '') in dcmd[idx]:
- dcmd[idx] = p.get('name', '') + '=' + p.get('value', '')
- break
+ # # don't use fully qualified names
+ # p['value'] = p.get('value', '').split('@')[0]
+ # for idx in range(1, len(dcmd)):
+ # if p.get('name', '') in dcmd[idx]:
+ # dcmd[idx] = p.get('name', '') + '=' + p.get('value', '')
+ # break
width, height = self.canvas.GetSize()
x = [width/2 + 200, width/2 - 200]
@@ -1740,7 +1760,8 @@
def GetLog(self, string = True):
"""!Get logging info"""
- cmd = self.task.getCmd(ignoreErrors = True)
+ cmd = self.task.getCmd(ignoreErrors = True, ignoreRequired = True)
+
# substitute variables
variables = self.parent.GetVariables()
fparams = self.parent.GetVariables(params = True)
@@ -1910,7 +1931,7 @@
if name:
return '/'.join(name) + '=' + self.value + ' (' + self.prompt + ')'
else:
- return _('unknown')
+ return self.value + ' (' + self.prompt + ')'
def GetName(self):
"""!Get list of names"""
@@ -1924,12 +1945,22 @@
"""!Get prompt"""
return self.prompt
+ def SetPrompt(self, prompt):
+ """!Set prompt
+
+ @param prompt
+ """
+ self.prompt = prompt
+
def GetValue(self):
"""!Get value"""
return self.value
def SetValue(self, value):
- """!Set value"""
+ """!Set value
+
+ @param value
+ """
self.value = value
self._setText()
for direction in ('from', 'to'):
@@ -2022,19 +2053,11 @@
style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER):
self.parent = parent
self.shape = shape
- prompt = shape.GetPrompt()
- if prompt == 'raster':
- label = _('Name of raster map:')
- elif prompt == 'vector':
- label = _('Name of vector map:')
- else:
- label = _('Name of element:')
-
- ElementDialog.__init__(self, parent, title, label = label)
-
- self.element = gselect.Select(parent = self.panel, id = wx.ID_ANY,
- size = globalvar.DIALOG_GSELECT_SIZE,
+ label, etype = self._getLabel()
+ ElementDialog.__init__(self, parent, title, label = label, etype = etype)
+
+ self.element = gselect.Select(parent = self.panel,
type = prompt)
self.element.SetValue(shape.GetValue())
@@ -2049,6 +2072,19 @@
self._layout()
self.SetMinSize(self.GetSize())
+ def _getLabel(self):
+ etype = False
+ prompt = self.shape.GetPrompt()
+ if prompt == 'raster':
+ label = _('Name of raster map:')
+ elif prompt == 'vector':
+ label = _('Name of vector map:')
+ else:
+ etype = True
+ label = _('Name of element:')
+
+ return label, etype
+
def _layout(self):
"""!Do layout"""
self.dataSizer.Add(self.element, proportion=0,
@@ -2060,6 +2096,13 @@
def OnOK(self, event):
"""!Ok pressed"""
self.shape.SetValue(self.GetElement())
+ if self.etype:
+ elem = self.GetType()
+ if elem == 'rast':
+ self.shape.SetPrompt('raster')
+ elif elem == 'vect':
+ self.shape.SetPrompt('raster')
+
self.parent.canvas.Refresh()
self.parent.SetStatusText('', 0)
self.OnCancel(event)
@@ -4004,6 +4047,7 @@
def Populate(self, data):
"""!Populate the list"""
self.itemDataMap = dict()
+
if self.shape:
if isinstance(self.shape, ModelCondition):
if self.GetName() == 'ElseBlockList':
@@ -4018,6 +4062,9 @@
if len(self.columns) == 3: # ItemCheckList
checked = list()
for action in data:
+ if isinstance(action, ModelData):
+ continue
+
if len(self.columns) == 3:
self.itemDataMap[i] = [str(action.GetId()),
action.GetName(),
Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/gselect.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/gselect.py 2011-07-21 18:53:22 UTC (rev 47211)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/gselect.py 2011-07-21 19:01:22 UTC (rev 47212)
@@ -19,7 +19,8 @@
- FormatSelect
- GdalSelect
- ProjSelect
-
+ - ElementSelect
+
(C) 2007-2011 by the GRASS Development Team This program is free
software under the GNU General Public License (>=v2). Read the file
COPYING that comes with GRASS for details.
@@ -42,6 +43,7 @@
sys.path.append(os.path.join(globalvar.ETCDIR, "python"))
import grass.script as grass
+from grass.script import task as gtask
import gcmd
import utils
@@ -98,6 +100,16 @@
"""!Load elements"""
self.tcp.GetElementList()
+ def SetType(self, etype, multiple = False, mapsets = None,
+ updateOnPopup = True, onPopup = None):
+ """!Param set element type for widget
+
+ @param etype element type, see gselect.ElementSelect
+ """
+ self.tcp.SetData(type = etype, mapsets = mapsets,
+ multiple = multiple,
+ updateOnPopup = updateOnPopup, onPopup = onPopup)
+
class VectorSelect(Select):
def __init__(self, parent, ftype, **kwargs):
"""!Custom to create a ComboBox with a tree control to display and
@@ -511,7 +523,12 @@
self.updateOnPopup = kargs['updateOnPopup']
if 'onPopup' in kargs:
self.onPopup = kargs['onPopup']
-
+
+ def GetType(self):
+ """!Get element type
+ """
+ return self.type
+
class VectorDBInfo:
"""!Class providing information about attribute tables
linked to a vector map"""
@@ -1581,3 +1598,27 @@
self.SetItems(listMaps)
self.SetValue('')
+
+class ElementSelect(wx.Choice):
+ def __init__(self, parent, id = wx.ID_ANY, size = globalvar.DIALOG_COMBOBOX_SIZE,
+ **kwargs):
+ """!Widget for selecting GIS element
+
+ @param parent parent window
+ """
+ super(ElementSelect, self).__init__(parent, id, size = size,
+ style = wx.CB_READONLY, **kwargs)
+ self.SetName("ElementSelect")
+
+ task = gtask.parse_interface('g.list')
+ p = task.get_param(value = 'type')
+ self.values = p.get('values', [])
+
+ self.SetItems(self.values)
+
+ def GetValue(self, name):
+ """!Translate value
+
+ @param name element name
+ """
+ return name
Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/menuform.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/menuform.py 2011-07-21 18:53:22 UTC (rev 47211)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/menuform.py 2011-07-21 19:01:22 UTC (rev 47212)
@@ -623,10 +623,10 @@
def OnApply(self, event):
"""!Apply the command"""
if self.modeler:
- cmd = self.createCmd(ignoreErrors = True)
+ cmd = self.createCmd(ignoreErrors = True, ignoreRequired = True)
else:
cmd = self.createCmd()
-
+
if cmd is not None and self.get_dcmd is not None:
# return d.* command to layer tree for rendering
self.get_dcmd(cmd, self.layer, {"params": self.task.params,
@@ -713,9 +713,10 @@
if event:
event.Skip()
- def createCmd(self, ignoreErrors = False):
+ def createCmd(self, ignoreErrors = False, ignoreRequired = False):
"""!Create command string (python list)"""
- return self.notebookpanel.createCmd(ignoreErrors = ignoreErrors)
+ return self.notebookpanel.createCmd(ignoreErrors = ignoreErrors,
+ ignoreRequired = ignoreRequired)
class cmdPanel(wx.Panel):
"""!A panel containing a notebook dividing in tabs the different
@@ -1621,15 +1622,16 @@
None,
self.task)
- def createCmd(self, ignoreErrors = False):
+ def createCmd(self, ignoreErrors = False, ignoreRequired = False):
"""!Produce a command line string (list) or feeding into GRASS.
- If ignoreErrors == True then it will return whatever has been
+ @param ignoreErrors True then it will return whatever has been
built so far, even though it would not be a correct command
- for GRASS.
+ for GRASS
"""
try:
- cmd = self.task.getCmd(ignoreErrors = ignoreErrors)
+ cmd = self.task.getCmd(ignoreErrors = ignoreErrors,
+ ignoreRequired = ignoreRequired)
except ValueError, err:
dlg = wx.MessageDialog(parent = self,
message = unicode(err),
@@ -1710,7 +1712,7 @@
"""
start = time.time()
dcmd_params = {}
- if completed == None:
+ if completed == None:
get_dcmd = None
layer = None
dcmd_params = None
Modified: grass/branches/develbranch_6/lib/python/task.py
===================================================================
--- grass/branches/develbranch_6/lib/python/task.py 2011-07-21 18:53:22 UTC (rev 47211)
+++ grass/branches/develbranch_6/lib/python/task.py 2011-07-21 19:01:22 UTC (rev 47212)
@@ -191,12 +191,14 @@
return errorList
- def getCmd(self, ignoreErrors = False):
+ def getCmd(self, ignoreErrors = False, ignoreRequired = False):
"""!Produce an array of command name and arguments for feeding
into some execve-like command processor.
@param ignoreErrors True to return whatever has been built so
far, even though it would not be a correct command for GRASS
+ @param ignoreRequired True to ignore required flags, otherwise
+ '<required>' is shown
"""
cmd = [self.name]
@@ -213,7 +215,7 @@
if p.get('value','') == '' and p.get('required', False):
if p.get('default', '') != '':
cmd += [ '%s=%s' % (p['name'], p['default']) ]
- elif ignoreErrors is True and not suppress_required:
+ elif ignoreErrors and not suppress_required and not ignoreRequired:
cmd += [ '%s=%s' % (p['name'], _('<required>')) ]
elif p.get('value','') != '' and p['value'] != p.get('default','') :
# Output only values that have been set, and different from defaults
More information about the grass-commit
mailing list