81
77
except ImportError:
82
78
import elementtree.ElementTree as etree # Python <= 2.4
80
from grass.pydispatch.signal import Signal
84
82
from grass.script import core as grass
85
83
from grass.script import task as gtask
87
from gui_core.widgets import StaticWrapText, ScrolledPanel
85
from core import globalvar
86
from gui_core.widgets import StaticWrapText, ScrolledPanel, ColorTablesComboBox, \
87
BarscalesComboBox, NArrowsComboBox
88
88
from gui_core.ghelp import HelpPanel
89
89
from gui_core import gselect
90
90
from core import gcmd
91
91
from core import utils
92
from core.utils import _
92
93
from core.settings import UserSettings
93
from gui_core.widgets import FloatValidator, GNotebook
94
from gui_core.widgets import FloatValidator, GNotebook, FormNotebook, FormListbook
95
from core.giface import Notification
95
97
wxUpdateDialog, EVT_DIALOG_UPDATE = NewEvent()
97
# From lib/gis/col_str.c, except purple which is mentioned
98
# there but not given RGB values
99
str2rgb = {'aqua': (100, 128, 255),
102
'brown': (180, 77, 25),
103
'cyan': (0, 255, 255),
104
'gray': (128, 128, 128),
105
'green': (0, 255, 0),
106
'grey': (128, 128, 128),
107
'indigo': (0, 128, 255),
108
'magenta': (255, 0, 255),
109
'orange': (255, 128, 0),
110
'purple': (128, 0, 128),
112
'violet': (128, 0, 255),
113
'white': (255, 255, 255),
114
'yellow': (255, 255, 0)}
116
for (s,r) in str2rgb.items():
119
"""!Hide some options in the GUI"""
100
"""Hide some options in the GUI"""
101
#_blackList = { 'enabled' : False,
102
# 'items' : { 'r.buffer' : {'params' : ['input', 'output'],
103
# 'flags' : ['z', 'overwrite']}}}
120
104
_blackList = { 'enabled' : False,
121
'items' : { 'd.legend' : { 'flags' : ['m'] } }
124
def color_resolve(color):
125
if len(color) > 0 and color[0] in "0123456789":
126
rgb = tuple(map(int, color.split(':')))
129
# Convert color names to RGB
131
rgb = str2rgb[ color ]
135
label = _('Select Color')
138
108
def text_beautify(someString , width = 70):
140
Make really long texts shorter, clean up whitespace and
141
remove trailing punctuation.
109
"""Make really long texts shorter, clean up whitespace and remove
110
trailing punctuation.
144
113
return escape_ampersand(string.strip(
213
183
name = win.GetName()
185
### @todo: replace name by isinstance() and signals
214
187
pBind = self.task.get_param(uid, element = 'wxId', raiseError = False)
216
189
pBind['value'] = ''
191
# set appropriate types in t.* modules and g.list/remove element selections
193
type_param = self.task.get_param('type', element='name', raiseError=False)
195
if 'all' in type_param.get('value'):
196
etype = type_param.get('values')
199
etype = ','.join(etype)
201
etype = type_param.get('value')
203
if globalvar.CheckWxVersion([3]):
204
self.data[win.SetElementList] = {'type': etype}
206
self.data[win.GetParent().SetElementList] = {'type': etype}
208
# t.(un)register has one type for 'input', 'maps'
209
maps_param = self.task.get_param('maps', element='name', raiseError=False)
210
if self.task.get_name().startswith('t') and maps_param is not None:
211
if maps_param['wxId'][0] != uid:
212
element_dict = {'raster': 'strds', 'vector': 'stvds', 'raster_3d': 'str3ds'}
213
self.data[win.GetParent().SetType] = {'etype': element_dict[type_param.get('value')]}
217
if name in ('LayerSelect', 'ColumnSelect'):
218
if p.get('element', '') == 'vector': # -> vector
220
map = p.get('value', '')
223
for bid in p['wxId-bind']:
224
p = self.task.get_param(bid, element = 'wxId', raiseError = False)
228
if p.get('element', '') in ['layer', 'layer_all']:
229
layer = p.get('value', '')
231
layer = p.get('value', '')
233
layer = p.get('default', '')
236
elif p.get('element', '') in ['layer', 'layer_all']: # -> layer
238
layer = p.get('value', '')
240
layer = p.get('value', '')
242
layer = p.get('default', '')
245
pMapL = self.task.get_param(p['wxId'][0], element = 'wxId-bind', raiseError = False)
247
map = pMapL.get('value', '')
249
if name == 'TableSelect' or \
250
(name == 'ColumnSelect' and not map):
251
pDriver = self.task.get_param('dbdriver', element = 'prompt', raiseError = False)
253
driver = pDriver.get('value', '')
254
pDb = self.task.get_param('dbname', element = 'prompt', raiseError = False)
256
db = pDb.get('value', '')
257
if name == 'ColumnSelect':
258
pTable = self.task.get_param('dbtable', element = 'element', raiseError = False)
260
table = pTable.get('value', '')
218
262
if name == 'LayerSelect':
219
if map in cparams and not cparams[map]['layers']:
220
win.InsertLayers(vector = map)
221
cparams[map]['layers'] = win.GetItems()
266
for id in pMap['wxId']:
267
winVec = self.parent.FindWindowById(id)
268
if winVec.GetName() == 'VectorFormat' and \
269
winVec.GetSelection() != 0:
272
# TODO: update only if needed
275
self.data[win.InsertLayers] = { 'vector' : map }
277
self.data[win.InsertLayers] = { }
280
self.data[win.InsertLayers] = { 'dsn' : map.rstrip('@OGR') }
282
self.data[win.InsertLayers] = { }
223
284
elif name == 'TableSelect':
224
pDriver = self.task.get_param('dbdriver', element='prompt', raiseError=False)
227
driver = pDriver['value']
228
pDb = self.task.get_param('dbname', element='prompt', raiseError=False)
232
285
self.data[win.InsertTables] = { 'driver' : driver,
233
286
'database' : db }
235
288
elif name == 'ColumnSelect':
236
pLayer = self.task.get_param('layer', element='element', raiseError=False)
238
if pLayer.get('value', '') != '':
239
layer = pLayer.get('value', '')
241
layer = pLayer.get('default', '')
246
290
if map in cparams:
247
291
if not cparams[map]['dbInfo']:
248
292
cparams[map]['dbInfo'] = gselect.VectorDBInfo(map)
249
self.data[win.InsertColumns] = { 'vector' : map, 'layer' : layer,
250
'dbInfo' : cparams[map]['dbInfo'] }
293
self.data[win.GetParent().InsertColumns] = { 'vector' : map, 'layer' : layer,
294
'dbInfo' : cparams[map]['dbInfo'] }
253
pDriver = self.task.get_param('dbdriver', element='prompt', raiseError=False)
255
driver = pDriver.get('value', None)
256
pDb = self.task.get_param('dbname', element='prompt', raiseError=False)
258
db = pDb.get('value', None)
259
pTable = self.task.get_param('dbtable', element='element', raiseError=False)
261
pTable.get('value', '') != '':
263
self.data[win.InsertTableColumns] = { 'table' : pTable.get('value'),
267
self.data[win.InsertTableColumns] = { 'table' : pTable.get('value') }
297
self.data[win.GetParent().InsertTableColumns] = { 'table' : pTable.get('value'),
301
self.data[win.GetParent().InsertTableColumns] = { 'table' : pTable.get('value') }
269
303
elif name == 'SubGroupSelect':
270
304
self.data[win.Insert] = { 'group' : p.get('value', '')}
306
elif name == 'SignatureSelect':
307
if p.get('prompt', 'group') == 'group':
308
group = p.get('value', '')
309
pSubGroup = self.task.get_param('subgroup', element = 'prompt', raiseError = False)
311
subgroup = pSubGroup.get('value', '')
315
subgroup = p.get('value', '')
316
pGroup = self.task.get_param('group', element = 'prompt', raiseError = False)
318
group = pGroup.get('value', '')
322
self.data[win.Insert] = { 'group' : group,
323
'subgroup' : subgroup}
272
325
elif name == 'LocationSelect':
273
326
pDbase = self.task.get_param('dbase', element = 'element', raiseError = False)
544
620
min(height, 500)))
546
622
# fix goutput's pane size (required for Mac OSX)
548
624
self.goutput.SetSashPosition(int(self.GetSize()[1] * .75))
550
626
def updateValuesHook(self, event = None):
551
"""!Update status bar data"""
627
"""Update status bar data"""
552
628
self.SetStatusText(' '.join(self.notebookpanel.createCmd(ignoreErrors = True)))
556
def OnKeyUp(self, event):
557
"""!Key released (check hot-keys)"""
559
kc = chr(event.GetKeyCode())
564
if not event.ControlDown():
581
632
def OnDone(self, cmd, returncode):
582
"""!This function is launched from OnRun() when command is
633
"""This function is launched from OnRun() when command is
585
@param returncode command's return code (0 for success)
587
if not self.parent or returncode != 0:
589
if self.parent.GetName() not in ('LayerTree', 'LayerManager'):
592
if self.parent.GetName() == 'LayerTree':
593
display = self.parent.GetMapDisplay()
594
else: # Layer Manager
596
tree = self.parent.GetLayerTree()
598
display = tree.GetMapDisplay()
600
if not display or not display.IsAutoRendered():
603
mapLayers = map(lambda x: x.GetName(),
604
display.GetMap().GetListOfLayers(l_type = 'raster') +
605
display.GetMap().GetListOfLayers(l_type = 'vector'))
607
task = GUI(show = None).ParseCommand(cmd)
608
for p in task.get_options()['params']:
609
if p.get('prompt', '') not in ('raster', 'vector'):
611
mapName = p.get('value', '')
612
if '@' not in mapName:
613
mapName = mapName + '@' + grass.gisenv()['MAPSET']
614
if mapName in mapLayers:
615
display.GetWindow().UpdateMap(render = True)
636
:param returncode: command's return code (0 for success)
639
if hasattr(self, "btn_cancel"):
640
self.btn_cancel.Enable(True)
642
if hasattr(self, "btn_clipboard"):
643
self.btn_clipboard.Enable(True)
645
if hasattr(self, "btn_help"):
646
self.btn_help.Enable(True)
648
if hasattr(self, "btn_run"):
649
self.btn_run.Enable(True)
651
if hasattr(self, "get_dcmd") and \
652
self.get_dcmd is None and \
653
hasattr(self, "closebox") and \
654
self.closebox.IsChecked() and \
656
# was closed also when aborted but better is leave it open
657
wx.FutureCall(2000, self.Close)
659
def OnMapCreated(self, name, ltype):
660
"""Map created or changed
662
:param name: map name
663
:param ltype: layer type (prompt value)
665
if hasattr(self, "addbox") and self.addbox.IsChecked():
671
self._giface.mapCreated.emit(name=name, ltype=ltype, add=add)
618
673
def OnOK(self, event):
619
"""!OK button pressed"""
674
"""OK button pressed"""
620
675
cmd = self.OnApply(event)
621
676
if cmd is not None and self.get_dcmd is not None:
622
677
self.OnCancel(event)
624
679
def OnApply(self, event):
625
"""!Apply the command"""
680
"""Apply the command"""
681
if self._giface and hasattr(self._giface, "_model"):
627
682
cmd = self.createCmd(ignoreErrors = True, ignoreRequired = True)
629
684
cmd = self.createCmd()
718
790
def createCmd(self, ignoreErrors = False, ignoreRequired = False):
719
"""!Create command string (python list)"""
791
"""Create command string (python list)"""
720
792
return self.notebookpanel.createCmd(ignoreErrors = ignoreErrors,
721
793
ignoreRequired = ignoreRequired)
723
795
class CmdPanel(wx.Panel):
724
"""!A panel containing a notebook dividing in tabs the different
796
"""A panel containing a notebook dividing in tabs the different
725
797
guisections of the GRASS cmd.
727
def __init__(self, parent, task, id = wx.ID_ANY, frame = None, *args, **kwargs):
799
def __init__(self, parent, giface, task, id = wx.ID_ANY, frame = None, *args, **kwargs):
729
801
self.parent = frame
731
803
self.parent = parent
805
self._giface = giface
734
807
wx.Panel.__init__(self, parent, id = id, *args, **kwargs)
809
self.mapCreated = Signal
810
self.updateMap = Signal
736
812
# Determine tab layout
739
not_hidden = [ p for p in self.task.params + self.task.flags if not p.get('hidden', False) == True ]
815
not_hidden = [ p for p in self.task.params + self.task.flags if not p.get('hidden', False) == True ]
741
817
self.label_id = [] # wrap titles on resize
743
819
self.Bind(wx.EVT_SIZE, self.OnSize)
745
821
for task in not_hidden:
746
if task.get('required', False):
822
if task.get('required', False) and not task.get('guisection', ''):
747
823
# All required go into Main, even if they had defined another guisection
748
824
task['guisection'] = _('Required')
749
if task.get('guisection','') == '':
825
if task.get('guisection','') == '':
750
826
# Undefined guisections end up into Options
751
827
task['guisection'] = _('Optional')
752
828
if task['guisection'] not in is_section:
906
982
self.label_id.append(title_txt.GetId())
908
984
# title expansion
909
if p.get('multiple', False) and len(p.get('values','')) == 0:
985
if p.get('multiple', False) and len(p.get('values','')) == 0:
910
986
title = _("[multiple]") + " " + title
911
if p.get('value','') == '' :
987
if p.get('value','') == '' :
912
988
p['value'] = p.get('default','')
914
990
if (len(p.get('values', [])) > 0):
915
991
valuelist = map(str, p.get('values',[]))
916
992
valuelist_desc = map(unicode, p.get('values_desc',[]))
993
required_text = "*" if p.get('required', False) else ""
918
994
if p.get('multiple', False) and \
919
p.get('gisprompt',False) == False and \
920
p.get('type', '') == 'string':
921
title_txt.SetLabel(" %s: (%s, %s) " % (title, p['name'], p['type']))
995
p.get('gisprompt',False) == False and \
996
p.get('type', '') == 'string':
997
title_txt.SetLabel(" %s:%s (%s=%s) " % (title, required_text, p['name'], p['type']))
998
stSizer = wx.StaticBoxSizer(box = title_txt, orient = wx.VERTICAL)
922
999
if valuelist_desc:
923
hSizer = wx.StaticBoxSizer(box = title_txt, orient = wx.VERTICAL)
1000
hSizer = wx.FlexGridSizer(cols = 1, vgap = 1)
925
hSizer = wx.StaticBoxSizer(box = title_txt, orient = wx.HORIZONTAL)
1002
hSizer = wx.FlexGridSizer(cols = 6, vgap = 1, hgap = 1)
927
1004
# copy default values
1005
if p['value'] == '':
929
1006
p['value'] = p.get('default', '')
931
1008
for defval in p.get('value', '').split(','):
932
1009
isEnabled[ defval ] = 'yes'
933
1010
# for multi checkboxes, this is an array of all wx IDs
934
1011
# for each individual checkbox
1012
p[ 'wxId' ] = list()
937
1014
for val in valuelist:
945
1022
p[ 'wxId' ].append(chkbox.GetId())
946
1023
if val in isEnabled:
947
1024
chkbox.SetValue(True)
948
hSizer.Add(item = chkbox, proportion = 0,
949
flag = wx.ADJUST_MINSIZE | wx.ALL, border = 1)
1025
hSizer.Add(item = chkbox, proportion = 0)
1026
chkbox.Bind(wx.EVT_CHECKBOX, self.OnUpdateSelection)
950
1027
chkbox.Bind(wx.EVT_CHECKBOX, self.OnCheckBoxMulti)
953
which_sizer.Add(item = hSizer, proportion = 0,
1030
stSizer.Add(item = hSizer, proportion = 0,
1031
flag = wx.ADJUST_MINSIZE | wx.ALL, border = 1)
1032
which_sizer.Add(item = stSizer, proportion = 0,
954
1033
flag = wx.EXPAND | wx.TOP | wx.RIGHT | wx.LEFT, border = 5)
955
elif p.get('gisprompt', False) == False:
956
if len(valuelist) == 1: # -> textctrl
1034
elif p.get('gisprompt', False) is False:
1035
if len(valuelist) == 1: # -> textctrl
957
1036
title_txt.SetLabel("%s (%s %s):" % (title, _('valid range'),
958
1037
str(valuelist[0])))
960
if p.get('type', '') == 'integer' and \
1038
if p.get('type', '') == 'integer' and \
961
1039
not p.get('multiple', False):
963
1041
# for multiple integers use textctrl instead of spinsctrl
965
minValue, maxValue = map(int, valuelist[0].split('-'))
1043
minValue, maxValue = map(int, valuelist[0].rsplit('-', 1))
966
1044
except ValueError:
969
1047
txt2 = wx.SpinCtrl(parent = which_panel, id = wx.ID_ANY, size = globalvar.DIALOG_SPIN_SIZE,
970
1048
min = minValue, max = maxValue)
971
txt2.SetName("SpinCtrl")
972
1049
style = wx.BOTTOM | wx.LEFT
974
1051
txt2 = wx.TextCtrl(parent = which_panel, value = p.get('default',''))
975
txt2.SetName("TextCtrl")
976
1052
style = wx.EXPAND | wx.BOTTOM | wx.LEFT
978
1054
value = self._getValue(p)
979
1055
# parameter previously set
981
if txt2.GetName() == "SpinCtrl":
982
txt2.SetValue(int(value))
1057
if isinstance(txt2, wx.SpinCtrl):
1058
txt2.SetValue(int(value))
984
1060
txt2.SetValue(value)
1041
1120
txt3.Bind(wx.EVT_TEXT, self.OnSetValue)
1042
1121
style = wx.EXPAND | wx.BOTTOM | wx.LEFT | wx.RIGHT
1122
elif p.get('type', '') == 'integer':
1044
1123
minValue = -1e9
1046
if p.get('type', '') == 'integer':
1047
txt3 = wx.SpinCtrl(parent = which_panel, value = p.get('default',''),
1048
size = globalvar.DIALOG_SPIN_SIZE,
1049
min = minValue, max = maxValue)
1050
style = wx.BOTTOM | wx.LEFT | wx.RIGHT
1052
value = self._getValue(p)
1054
txt3.SetValue(int(value)) # parameter previously set
1125
value = self._getValue(p)
1127
txt3 = wx.SpinCtrl(parent = which_panel, value = p.get('default', ''),
1128
size = globalvar.DIALOG_SPIN_SIZE,
1129
min = minValue, max = maxValue)
1131
txt3.SetValue(int(value)) # parameter previously set
1056
1132
txt3.Bind(wx.EVT_SPINCTRL, self.OnSetValue)
1058
txt3 = wx.TextCtrl(parent = which_panel, value = p.get('default',''),
1059
validator = FloatValidator())
1060
style = wx.EXPAND | wx.BOTTOM | wx.LEFT | wx.RIGHT
1062
value = self._getValue(p)
1064
txt3.SetValue(str(value)) # parameter previously set
1134
style = wx.BOTTOM | wx.LEFT | wx.RIGHT
1136
txt3 = wx.TextCtrl(parent = which_panel, value = p.get('default',''),
1137
validator = FloatValidator())
1138
style = wx.EXPAND | wx.BOTTOM | wx.LEFT | wx.RIGHT
1140
value = self._getValue(p)
1142
txt3.SetValue(str(value)) # parameter previously set
1066
1144
txt3.Bind(wx.EVT_TEXT, self.OnSetValue)
1068
1146
which_sizer.Add(item = txt3, proportion = 0,
1106
1188
selection.Bind(wx.EVT_COMBOBOX, self.OnSetValue)
1107
1189
selection.Bind(wx.EVT_TEXT, self.OnUpdateSelection)
1191
elem = p.get('element', None)
1192
# hack for t.* modules
1193
if elem in ('stds', 'map'):
1195
type_param = self.task.get_param('type', element = 'name', raiseError = False)
1197
elem = type_param.get('default', None)
1198
# for t.(un)register:
1199
maps_param = self.task.get_param('maps', element = 'name', raiseError = False)
1200
if maps_param and orig_elem == 'stds':
1201
element_dict = {'raster': 'strds', 'vector': 'stvds', 'raster_3d': 'str3ds'}
1202
elem = element_dict[type_param.get('default')]
1204
if self._giface and hasattr(self._giface, "_model"):
1205
extraItems = {_('Graphical Modeler') : self._giface.GetLayerList(p.get('prompt'))}
1109
1208
selection = gselect.Select(parent = which_panel, id = wx.ID_ANY,
1110
1209
size = globalvar.DIALOG_GSELECT_SIZE,
1111
type = p.get('element', ''),
1112
multiple = multiple, mapsets = mapsets,
1113
fullyQualified = p.get('age', 'old') == 'old')
1116
# A select.Select is a combobox with two children: a textctl and a popupwindow;
1210
type = elem, multiple = multiple, nmaps = len(p.get('key_desc', [])),
1211
mapsets = mapsets, fullyQualified = p.get('age', 'old') == 'old',
1212
extraItems = extraItems)
1214
value = self._getValue(p)
1216
selection.SetValue(value)
1218
formatSelector = True
1219
# A gselect.Select is a combobox with two children: a textctl and a popupwindow;
1117
1220
# we target the textctl here
1118
1221
textWin = selection.GetTextCtrl()
1119
p['wxId'] = [ textWin.GetId(), ]
1120
textWin.Bind(wx.EVT_TEXT, self.OnSetValue)
1122
value = self._getValue(p)
1124
selection.SetValue(value) # parameter previously set
1126
which_sizer.Add(item=selection, proportion=0,
1127
flag=wx.ADJUST_MINSIZE| wx.BOTTOM | wx.LEFT | wx.RIGHT, border=5)
1129
if p.get('prompt', '') in ('vector', 'group'):
1130
selection.Bind(wx.EVT_TEXT, self.OnUpdateSelection)
1222
if globalvar.CheckWxVersion([3]):
1223
p['wxId'] = [selection.GetId(), ]
1225
p['wxId'] = [textWin.GetId(), ]
1226
if prompt != 'vector':
1227
self.FindWindowById(p['wxId'][0]).Bind(wx.EVT_TEXT, self.OnSetValue)
1229
if prompt == 'vector':
1230
win = self.FindWindowById(p['wxId'][0])
1231
# handlers should be bound in this order
1232
# OnUpdateSelection depends on calling OnSetValue first which is bad
1233
win.Bind(wx.EVT_TEXT, self.OnUpdateSelection)
1234
win.Bind(wx.EVT_TEXT, self.OnSetValue)
1236
# if formatSelector and p.get('age', 'old') == 'old':
1237
# # OGR supported (read-only)
1238
# self.hsizer = wx.BoxSizer(wx.HORIZONTAL)
1240
# self.hsizer.Add(item = selection,
1241
# flag = wx.ADJUST_MINSIZE | wx.BOTTOM | wx.LEFT | wx.RIGHT | wx.TOP | wx.ALIGN_TOP,
1244
# # format (native / ogr)
1245
# rbox = wx.RadioBox(parent = which_panel, id = wx.ID_ANY,
1246
# label = " %s " % _("Format"),
1247
# style = wx.RA_SPECIFY_ROWS,
1248
# choices = [_("Native / Linked OGR"), _("Direct OGR")])
1249
# if p.get('value', '').lower().rfind('@ogr') > -1:
1250
# rbox.SetSelection(1)
1251
# rbox.SetName('VectorFormat')
1252
# rbox.Bind(wx.EVT_RADIOBOX, self.OnVectorFormat)
1254
# self.hsizer.Add(item = rbox,
1255
# flag = wx.ADJUST_MINSIZE | wx.BOTTOM | wx.LEFT |
1256
# wx.RIGHT | wx.ALIGN_TOP,
1259
# ogrSelection = gselect.GdalSelect(parent = self, panel = which_panel, ogr = True,
1261
# exclude = ['file'])
1262
# self.Bind(gselect.EVT_GDALSELECT, self.OnUpdateSelection)
1263
# self.Bind(gselect.EVT_GDALSELECT, self.OnSetValue)
1265
# ogrSelection.SetName('OgrSelect')
1266
# ogrSelection.Hide()
1268
# which_sizer.Add(item = self.hsizer, proportion = 0)
1270
# p['wxId'].append(rbox.GetId())
1271
# p['wxId'].append(ogrSelection.GetId())
1272
# for win in ogrSelection.GetDsnWin():
1273
# p['wxId'].append(win.GetId())
1275
which_sizer.Add(item = selection, proportion = 0,
1276
flag = wx.ADJUST_MINSIZE | wx.BOTTOM | wx.LEFT | wx.RIGHT | wx.TOP | wx.ALIGN_CENTER_VERTICAL,
1278
elif prompt == 'group':
1279
win = self.FindWindowById(p['wxId'][0])
1280
win.Bind(wx.EVT_TEXT, self.OnUpdateSelection)
1281
win.Bind(wx.EVT_TEXT, self.OnSetValue)
1282
which_sizer.Add(item = selection, proportion = 0,
1283
flag = wx.ADJUST_MINSIZE | wx.BOTTOM | wx.LEFT | wx.RIGHT | wx.TOP | wx.ALIGN_CENTER_VERTICAL,
1286
if prompt in ('stds', 'strds', 'stvds', 'str3ds'):
1289
# if matplotlib is there
1290
from timeline import frame
1297
iconTheme = UserSettings.Get(group='appearance', key='iconTheme', subkey='type')
1298
bitmap = wx.Bitmap(os.path.join(globalvar.ICONDIR, iconTheme, 'map-info.png'))
1299
bb = wx.BitmapButton(parent=which_panel, bitmap=bitmap)
1300
bb.Bind(wx.EVT_BUTTON, self.OnTimelineTool)
1301
bb.SetToolTipString(_("Show graphical representation of temporal extent of dataset(s) ."))
1302
p['wxId'].append(bb.GetId())
1304
hSizer = wx.BoxSizer(wx.HORIZONTAL)
1305
hSizer.Add(item=selection, proportion=0,
1306
flag=wx.ADJUST_MINSIZE | wx.BOTTOM | wx.LEFT | wx.RIGHT | wx.TOP | wx.ALIGN_CENTER_VERTICAL,
1308
hSizer.Add(item=bb, proportion=0,
1309
flag=wx.EXPAND|wx.BOTTOM | wx.RIGHT | wx.TOP | wx.ALIGN_CENTER_VERTICAL,
1311
which_sizer.Add(hSizer)
1313
which_sizer.Add(item=selection, proportion=0,
1314
flag=wx.ADJUST_MINSIZE | wx.BOTTOM | wx.LEFT | wx.RIGHT | wx.TOP | wx.ALIGN_CENTER_VERTICAL,
1132
elif p.get('prompt', '') == 'subgroup':
1318
elif prompt == 'subgroup':
1133
1319
selection = gselect.SubGroupSelect(parent = which_panel)
1134
1320
p['wxId'] = [ selection.GetId() ]
1135
selection.Bind(wx.EVT_COMBOBOX, self.OnSetValue)
1136
selection.Bind(wx.EVT_TEXT, self.OnSetValue)
1137
which_sizer.Add(item = selection, proportion = 0,
1321
selection.Bind(wx.EVT_TEXT, self.OnUpdateSelection)
1322
selection.Bind(wx.EVT_TEXT, self.OnSetValue)
1323
which_sizer.Add(item = selection, proportion = 0,
1324
flag = wx.ADJUST_MINSIZE | wx.BOTTOM | wx.LEFT | wx.RIGHT | wx.TOP | wx.ALIGN_CENTER_VERTICAL,
1328
elif prompt == 'sigfile':
1329
selection = gselect.SignatureSelect(parent = which_panel, element = p.get('element', 'sig'))
1330
p['wxId'] = [ selection.GetId() ]
1331
selection.Bind(wx.EVT_TEXT, self.OnSetValue)
1332
which_sizer.Add(item = selection, proportion = 0,
1333
flag = wx.ADJUST_MINSIZE | wx.BOTTOM | wx.LEFT | wx.RIGHT | wx.TOP | wx.ALIGN_CENTER_VERTICAL,
1337
elif prompt == 'separator':
1338
win = gselect.SeparatorSelect(parent = which_panel)
1339
value = self._getValue(p)
1341
p['wxId'] = [ win.GetId() ]
1342
win.Bind(wx.EVT_TEXT, self.OnSetValue)
1343
which_sizer.Add(item = win, proportion = 0,
1138
1344
flag = wx.ADJUST_MINSIZE | wx.BOTTOM | wx.LEFT | wx.RIGHT | wx.TOP | wx.ALIGN_CENTER_VERTICAL,
1141
1347
# layer, dbdriver, dbname, dbcolumn, dbtable entry
1142
elif p.get('prompt', '') in ('dbdriver',
1152
if p.get('multiple', 'no') == 'yes':
1348
elif prompt in ('dbdriver',
1356
if p.get('multiple', 'no') == 'yes':
1153
1357
win = wx.TextCtrl(parent = which_panel, value = p.get('default',''),
1154
1358
size = globalvar.DIALOG_TEXTCTRL_SIZE)
1155
1359
win.Bind(wx.EVT_TEXT, self.OnSetValue)
1157
1361
value = self._getValue(p)
1159
if p.get('prompt', '') in ('layer',
1163
if p.get('age', 'old_layer') == 'old_layer':
1165
if p.get('prompt', '') == 'layer_all':
1166
initial.insert(0, '-1')
1167
elif p.get('prompt', '') == 'layer_zero':
1168
initial.insert(0, '0')
1169
lyrvalue = p.get('default')
1171
if lyrvalue not in initial:
1172
initial.append(str(lyrvalue))
1173
lyrvalue = p.get('value')
1175
if lyrvalue not in initial:
1176
initial.append(str(lyrvalue))
1363
if prompt == 'layer':
1364
if p.get('element', 'layer') == 'layer_all':
1368
if p.get('age', 'old') == 'old':
1178
1369
win = gselect.LayerSelect(parent = which_panel,
1180
1371
default = p['default'])
1181
p['wxGetValue'] = win.GetStringSelection
1182
1372
win.Bind(wx.EVT_TEXT, self.OnUpdateSelection)
1183
1373
win.Bind(wx.EVT_TEXT, self.OnSetValue)
1184
1374
win.SetValue(str(value)) # default or previously set value
1188
1378
win.Bind(wx.EVT_SPINCTRL, self.OnSetValue)
1189
1379
win.SetValue(int(value)) # default or previously set value
1191
elif p.get('prompt', '') == 'dbdriver':
1381
p['wxId'] = [ win.GetId() ]
1383
elif prompt == 'dbdriver':
1192
1384
win = gselect.DriverSelect(parent = which_panel,
1193
1385
choices = p.get('values', []),
1195
p['wxGetValue'] = win.GetStringSelection
1196
1387
win.Bind(wx.EVT_COMBOBOX, self.OnUpdateSelection)
1197
1388
win.Bind(wx.EVT_COMBOBOX, self.OnSetValue)
1198
elif p.get('prompt', '') == 'dbname':
1389
elif prompt == 'dbname':
1199
1390
win = gselect.DatabaseSelect(parent = which_panel,
1201
1392
win.Bind(wx.EVT_TEXT, self.OnUpdateSelection)
1202
1393
win.Bind(wx.EVT_TEXT, self.OnSetValue)
1204
elif p.get('prompt', '') == 'dbtable':
1205
if p.get('age', 'old_dbtable') == 'old_dbtable':
1206
win = gselect.TableSelect(parent=which_panel)
1208
p['wxGetValue'] = win.GetStringSelection
1394
elif prompt == 'dbtable':
1395
if p.get('age', 'old') == 'old':
1396
win = gselect.TableSelect(parent = which_panel)
1209
1397
win.Bind(wx.EVT_COMBOBOX, self.OnUpdateSelection)
1210
1398
win.Bind(wx.EVT_COMBOBOX, self.OnSetValue)
1212
1400
win = wx.TextCtrl(parent = which_panel, value = p.get('default',''),
1213
1401
size = globalvar.DIALOG_TEXTCTRL_SIZE)
1214
1402
win.Bind(wx.EVT_TEXT, self.OnSetValue)
1215
elif p.get('prompt', '') == 'dbcolumn':
1403
elif prompt == 'dbcolumn':
1216
1404
win = gselect.ColumnSelect(parent = which_panel,
1219
win.Bind(wx.EVT_COMBOBOX, self.OnSetValue)
1220
win.Bind(wx.EVT_TEXT, self.OnSetValue)
1407
multiple = p.get('multiple', False))
1409
# A gselect.ColumnSelect is a combobox
1410
# with two children: a textctl and a
1411
# popupwindow; we target the textctl here
1412
textWin = win.GetTextCtrl()
1413
p['wxId'] = [ textWin.GetId(), ]
1415
textWin.Bind(wx.EVT_TEXT, self.OnSetValue)
1416
win.Bind(wx.EVT_TEXT, self.OnUpdateSelection)
1222
elif p.get('prompt', '') == 'location':
1418
elif prompt == 'location':
1223
1419
win = gselect.LocationSelect(parent = which_panel,
1225
1421
win.Bind(wx.EVT_COMBOBOX, self.OnUpdateSelection)
1226
1422
win.Bind(wx.EVT_COMBOBOX, self.OnSetValue)
1228
elif p.get('prompt', '') == 'mapset':
1424
elif prompt == 'mapset':
1425
if p.get('age', 'old') == 'old':
1229
1430
win = gselect.MapsetSelect(parent = which_panel,
1231
win.Bind(wx.EVT_COMBOBOX, self.OnUpdateSelection)
1232
win.Bind(wx.EVT_COMBOBOX, self.OnSetValue)
1234
elif p.get('prompt', '') == 'dbase':
1431
value = value, new = new,
1432
multiple = p.get('multiple', False))
1433
textWin = win.GetTextCtrl()
1434
p['wxId'] = [ textWin.GetId(), win.GetId() ]
1436
textWin.Bind(wx.EVT_TEXT, self.OnSetValue)
1437
win.Bind(wx.EVT_TEXT, self.OnUpdateSelection)
1439
elif prompt == 'dbase':
1235
1440
win = gselect.DbaseSelect(parent = which_panel,
1236
1441
changeCallback = self.OnSetValue)
1237
1442
win.Bind(wx.EVT_TEXT, self.OnUpdateSelection)
1352
1578
p['wxId'].append(btnLoad.GetId())
1353
1579
p['wxId'].append(btnSave.GetId())
1355
if self.parent.GetName() == 'MainFrame' and self.parent.modeler:
1581
# directory selector
1582
elif p.get('prompt','') != 'color' and p.get('prompt', '') == 'dir':
1583
fbb = filebrowse.DirBrowseButton(parent = which_panel, id = wx.ID_ANY,
1584
size = globalvar.DIALOG_GSELECT_SIZE, labelText = '',
1585
dialogTitle = _('Choose %s') % \
1586
p.get('description', _('Directory')),
1587
buttonText = _('Browse'),
1588
startDirectory = os.getcwd(),
1589
changeCallback = self.OnSetValue)
1590
value = self._getValue(p)
1592
fbb.SetValue(value) # parameter previously set
1593
which_sizer.Add(item = fbb, proportion = 0,
1594
flag = wx.EXPAND | wx.RIGHT, border = 5)
1596
# A file browse button is a combobox with two children:
1597
# a textctl and a button;
1598
# we have to target the button here
1599
p['wxId'] = [ fbb.GetChildren()[1].GetId() ]
1601
# interactive inserting of coordinates from map window
1602
elif prompt == 'coords':
1603
# interactive inserting if layer manager is accessible
1605
win = gselect.CoordinatesSelect(parent = which_panel,
1606
giface = self._giface,
1607
multiple = p.get('multiple', False),
1609
p['wxId'] = [win.GetTextWin().GetId()]
1610
win.GetTextWin().Bind(wx.EVT_TEXT, self.OnSetValue)
1611
# bind closing event because destructor is not working properly
1612
if hasattr(self.parent, 'dialogClosing'):
1613
self.parent.dialogClosing.connect(win.OnClose)
1617
win = wx.TextCtrl(parent = which_panel)
1618
p['wxId'] = [win.GetId()]
1619
win.Bind(wx.EVT_TEXT, self.OnSetValue)
1621
which_sizer.Add(item = win,
1623
flag = wx.EXPAND | wx.BOTTOM | wx.LEFT | wx.RIGHT,
1625
elif prompt in ('colortable', 'barscale', 'northarrow'):
1626
if prompt == 'colortable':
1627
cb = ColorTablesComboBox(parent=which_panel, value=p.get('default',''),
1628
size=globalvar.DIALOG_COMBOBOX_SIZE,
1630
elif prompt == 'barscale':
1631
cb = BarscalesComboBox(parent=which_panel, value=p.get('default',''),
1632
size=globalvar.DIALOG_COMBOBOX_SIZE,
1634
elif prompt == 'northarrow':
1635
cb = NArrowsComboBox(parent=which_panel, value=p.get('default',''),
1636
size=globalvar.DIALOG_COMBOBOX_SIZE,
1639
value = self._getValue(p)
1641
cb.SetValue(value) # parameter previously set
1642
which_sizer.Add(item = cb, proportion = 0,
1643
flag = wx.ADJUST_MINSIZE | wx.BOTTOM | wx.LEFT, border = 5)
1644
p['wxId'] = [cb.GetId(), cb.GetTextCtrl().GetId()]
1645
cb.Bind(wx.EVT_COMBOBOX, self.OnSetValue)
1646
cb.GetTextCtrl().Bind(wx.EVT_TEXT, self.OnSetValue)
1647
if p.get('guidependency', ''):
1648
cb.Bind(wx.EVT_COMBOBOX, self.OnUpdateSelection)
1650
if self.parent.GetName() == 'MainFrame' and (self._giface and hasattr(self._giface, "_model")):
1356
1651
parChk = wx.CheckBox(parent = which_panel, id = wx.ID_ANY,
1357
1652
label = _("Parameterized in model"))
1358
1653
parChk.SetName('ModelParam')
1482
1801
for section in sections:
1483
1802
tab[section].SetMinSize((self.constrained_size[0], self.panelMinHeight))
1485
if self.manual_tab.IsLoaded():
1486
self.manual_tab.SetMinSize((self.constrained_size[0], self.panelMinHeight))
1805
# add pages to notebook
1806
imageList = wx.ImageList(16, 16)
1807
self.notebook.AssignImageList(imageList)
1809
for section in sections:
1810
self.notebook.AddPage(page = tab[section], text = section, name = section)
1811
index = self.AddBitmapToImageList(section, imageList)
1813
self.notebook.SetPageImage(section, index)
1815
# are we running from command line?
1816
### add 'command output' tab regardless standalone dialog
1817
if self.parent.GetName() == "MainFrame" and self.parent.get_dcmd is None:
1818
from core.gconsole import GConsole, EVT_CMD_RUN, EVT_CMD_DONE
1819
from gui_core.goutput import GConsoleWindow
1820
self._gconsole = GConsole(guiparent = self.notebook, giface = self._giface)
1821
self.goutput = GConsoleWindow(parent = self.notebook, gconsole = self._gconsole, margin = False)
1822
self._gconsole.Bind(EVT_CMD_RUN,
1824
self._switchPageHandler(event=event, notification=Notification.MAKE_VISIBLE))
1825
self._gconsole.Bind(EVT_CMD_DONE,
1827
self._switchPageHandler(event = event, notification=Notification.RAISE_WINDOW))
1828
self.outpage = self.notebook.AddPage(page = self.goutput, text = _("Command output"), name = 'output')
1831
self._gconsole = None
1833
self.manualTab = HelpPanel(parent = self.notebook, command = self.task.get_name())
1834
if not self.manualTab.GetFile():
1835
self.manualTab.Hide()
1837
self.notebook.AddPage(page = self.manualTab, text = _("Manual"), name = 'manual')
1838
index = self.AddBitmapToImageList(section = 'manual', imageList = imageList)
1840
self.notebook.SetPageImage('manual', index)
1842
if self.manualTab.IsLoaded():
1843
self.manualTab.SetMinSize((self.constrained_size[0], self.panelMinHeight))
1845
self.notebook.SetSelection(0)
1847
panelsizer.Add(item = self.notebook, proportion = 1, flag = wx.EXPAND)
1488
1848
self.SetSizer(panelsizer)
1489
1849
panelsizer.Fit(self.notebook)
1491
1851
self.Bind(EVT_DIALOG_UPDATE, self.OnUpdateDialog)
1493
1853
def _getValue(self, p):
1494
"""!Get value or default value of given parameter
1854
"""Get value or default value of given parameter
1496
@param p parameter directory
1856
:param p: parameter directory
1498
1858
if p.get('value', '') != '':
1499
1859
return p['value']
1500
1860
return p.get('default', '')
1502
1862
def OnFileLoad(self, event):
1503
"""!Load file to interactive input"""
1863
"""Load file to interactive input"""
1504
1864
me = event.GetId()
1506
1866
for p in self.task.params:
1616
2043
sel = event.GetSelection()
1618
2045
idx = self.notebook.GetPageIndexByName('manual')
1619
if idx > -1 and sel == idx:
2046
if idx > -1 and sel == idx:
1620
2047
# calling LoadPage() is strangely time-consuming (only first call)
1621
2048
# FIXME: move to helpPage.__init__()
1622
if not self.manual_tab.IsLoaded():
2049
if not self.manualTab.IsLoaded():
1624
self.manual_tab.LoadPage()
2051
self.manualTab.LoadPage()
2056
# skip is needed for wx.Notebook on Windows
2058
# this is needed for dialogs launched from layer manager
2059
# event is somehow propagated?
2060
event.StopPropagation()
2062
def _switchPageHandler(self, event, notification):
2063
self._switchPage(notification=notification)
2066
def _switchPage(self, notification):
2067
"""Manages @c 'output' notebook page according to event notification."""
2068
if notification == Notification.HIGHLIGHT:
2069
self.notebook.HighlightPageByName('output')
2070
if notification == Notification.MAKE_VISIBLE:
2071
self.notebook.SetSelectionByName('output')
2072
if notification == Notification.RAISE_WINDOW:
2073
self.notebook.SetSelectionByName('output')
1628
2077
def OnColorChange(self, event):
1629
2078
myId = event.GetId()
1630
2079
for p in self.task.params:
1631
2080
if 'wxId' in p and myId in p['wxId']:
1632
2081
multiple = p['wxId'][1] is not None # multiple colors
1633
hasTransp = p['wxId'][2] is not None
2082
hasTansp = p['wxId'][2] is not None
1635
2084
# selected color is added at the end of textCtrl
1636
2085
colorchooser = wx.FindWindowById(p['wxId'][0])
1637
2086
new_color = colorchooser.GetValue()[:]
1638
new_label = rgb2str.get(new_color, ':'.join(map(str, new_color)))
2087
new_label = utils.rgb2str.get(new_color, ':'.join(map(str, new_color)))
1639
2088
textCtrl = wx.FindWindowById(p['wxId'][1])
1640
2089
val = textCtrl.GetValue()