GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
gmodeler/preferences.py
Go to the documentation of this file.
1 """!
2 @package gmodeler.preferences
3 
4 @brief wxGUI Graphical Modeler - preferences
5 
6 Classes:
7  - preferences::PreferencesDialog
8  - preferences::PropertiesDialog
9 
10 (C) 2010-2012 by the GRASS Development Team
11 
12 This program is free software under the GNU General Public License
13 (>=v2). Read the file COPYING that comes with GRASS for details.
14 
15 @author Martin Landa <landa.martin gmail.com>
16 """
17 
18 import wx
19 import wx.lib.colourselect as csel
20 
21 from core import globalvar
22 from gui_core.preferences import PreferencesBaseDialog
23 from core.settings import UserSettings
24 
26  """!User preferences dialog"""
27  def __init__(self, parent, settings = UserSettings,
28  title = _("Modeler settings")):
29 
30  PreferencesBaseDialog.__init__(self, parent = parent, title = title,
31  settings = settings)
32 
33  # create notebook pages
34  self._createGeneralPage(self.notebook)
35  self._createActionPage(self.notebook)
36  self._createDataPage(self.notebook)
37  self._createLoopPage(self.notebook)
38 
39  self.SetMinSize(self.GetBestSize())
40  self.SetSize(self.size)
41 
42  def _createGeneralPage(self, notebook):
43  """!Create notebook page for action settings"""
44  panel = wx.Panel(parent = notebook, id = wx.ID_ANY)
45  notebook.AddPage(page = panel, text = _("General"))
46 
47  # colors
48  border = wx.BoxSizer(wx.VERTICAL)
49  box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
50  label = " %s " % _("Item properties"))
51  sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
52 
53  gridSizer = wx.GridBagSizer (hgap = 3, vgap = 3)
54  gridSizer.AddGrowableCol(0)
55 
56  row = 0
57  gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
58  label = _("Disabled:")),
59  flag = wx.ALIGN_LEFT |
60  wx.ALIGN_CENTER_VERTICAL,
61  pos = (row, 0))
62  rColor = csel.ColourSelect(parent = panel, id = wx.ID_ANY,
63  colour = self.settings.Get(group='modeler', key='disabled', subkey='color'),
64  size = globalvar.DIALOG_COLOR_SIZE)
65  rColor.SetName('GetColour')
66  self.winId['modeler:disabled:color'] = rColor.GetId()
67 
68  gridSizer.Add(item = rColor,
69  flag = wx.ALIGN_RIGHT |
70  wx.ALIGN_CENTER_VERTICAL,
71  pos = (row, 1))
72 
73  sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5)
74  border.Add(item = sizer, proportion = 0, flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 3)
75 
76  panel.SetSizer(border)
77 
78  return panel
79 
80  def _createActionPage(self, notebook):
81  """!Create notebook page for action settings"""
82  panel = wx.Panel(parent = notebook, id = wx.ID_ANY)
83  notebook.AddPage(page = panel, text = _("Action"))
84 
85  # colors
86  border = wx.BoxSizer(wx.VERTICAL)
87  box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
88  label = " %s " % _("Color"))
89  sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
90 
91  gridSizer = wx.GridBagSizer (hgap = 3, vgap = 3)
92  gridSizer.AddGrowableCol(0)
93 
94  row = 0
95  gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
96  label = _("Valid:")),
97  flag = wx.ALIGN_LEFT |
98  wx.ALIGN_CENTER_VERTICAL,
99  pos = (row, 0))
100  vColor = csel.ColourSelect(parent = panel, id = wx.ID_ANY,
101  colour = self.settings.Get(group='modeler', key='action', subkey=('color', 'valid')),
102  size = globalvar.DIALOG_COLOR_SIZE)
103  vColor.SetName('GetColour')
104  self.winId['modeler:action:color:valid'] = vColor.GetId()
105 
106  gridSizer.Add(item = vColor,
107  flag = wx.ALIGN_RIGHT |
108  wx.ALIGN_CENTER_VERTICAL,
109  pos = (row, 1))
110 
111  row += 1
112  gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
113  label = _("Invalid:")),
114  flag = wx.ALIGN_LEFT |
115  wx.ALIGN_CENTER_VERTICAL,
116  pos = (row, 0))
117  iColor = csel.ColourSelect(parent = panel, id = wx.ID_ANY,
118  colour = self.settings.Get(group='modeler', key='action', subkey=('color', 'invalid')),
119  size = globalvar.DIALOG_COLOR_SIZE)
120  iColor.SetName('GetColour')
121  self.winId['modeler:action:color:invalid'] = iColor.GetId()
122 
123  gridSizer.Add(item = iColor,
124  flag = wx.ALIGN_RIGHT |
125  wx.ALIGN_CENTER_VERTICAL,
126  pos = (row, 1))
127 
128  row += 1
129  gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
130  label = _("Running:")),
131  flag = wx.ALIGN_LEFT |
132  wx.ALIGN_CENTER_VERTICAL,
133  pos = (row, 0))
134  rColor = csel.ColourSelect(parent = panel, id = wx.ID_ANY,
135  colour = self.settings.Get(group='modeler', key='action', subkey=('color', 'running')),
136  size = globalvar.DIALOG_COLOR_SIZE)
137  rColor.SetName('GetColour')
138  self.winId['modeler:action:color:running'] = rColor.GetId()
139 
140  gridSizer.Add(item = rColor,
141  flag = wx.ALIGN_RIGHT |
142  wx.ALIGN_CENTER_VERTICAL,
143  pos = (row, 1))
144 
145  sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5)
146  border.Add(item = sizer, proportion = 0, flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 3)
147 
148  # size
149  box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
150  label = " %s " % _("Shape size"))
151  sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
152 
153  gridSizer = wx.GridBagSizer (hgap=3, vgap=3)
154  gridSizer.AddGrowableCol(0)
155 
156  row = 0
157  gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
158  label = _("Width:")),
159  flag = wx.ALIGN_LEFT |
160  wx.ALIGN_CENTER_VERTICAL,
161  pos = (row, 0))
162 
163  width = wx.SpinCtrl(parent = panel, id = wx.ID_ANY,
164  min = 0, max = 500,
165  initial = self.settings.Get(group='modeler', key='action', subkey=('size', 'width')))
166  width.SetName('GetValue')
167  self.winId['modeler:action:size:width'] = width.GetId()
168 
169  gridSizer.Add(item = width,
170  flag = wx.ALIGN_RIGHT |
171  wx.ALIGN_CENTER_VERTICAL,
172  pos = (row, 1))
173 
174  row += 1
175  gridSizer.Add(item = wx.StaticText(parent=panel, id=wx.ID_ANY,
176  label=_("Height:")),
177  flag = wx.ALIGN_LEFT |
178  wx.ALIGN_CENTER_VERTICAL,
179  pos=(row, 0))
180 
181  height = wx.SpinCtrl(parent = panel, id = wx.ID_ANY,
182  min = 0, max = 500,
183  initial = self.settings.Get(group='modeler', key='action', subkey=('size', 'height')))
184  height.SetName('GetValue')
185  self.winId['modeler:action:size:height'] = height.GetId()
186 
187  gridSizer.Add(item = height,
188  flag = wx.ALIGN_RIGHT |
189  wx.ALIGN_CENTER_VERTICAL,
190  pos = (row, 1))
191 
192  sizer.Add(item=gridSizer, proportion=1, flag=wx.ALL | wx.EXPAND, border=5)
193  border.Add(item=sizer, proportion=0, flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border=3)
194 
195  panel.SetSizer(border)
196 
197  return panel
198 
199  def _createDataPage(self, notebook):
200  """!Create notebook page for data settings"""
201  panel = wx.Panel(parent = notebook, id = wx.ID_ANY)
202  notebook.AddPage(page = panel, text = _("Data"))
203 
204  # colors
205  border = wx.BoxSizer(wx.VERTICAL)
206  box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
207  label = " %s " % _("Type"))
208  sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
209 
210  gridSizer = wx.GridBagSizer (hgap = 3, vgap = 3)
211  gridSizer.AddGrowableCol(0)
212 
213  row = 0
214  gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
215  label = _("Raster:")),
216  flag = wx.ALIGN_LEFT |
217  wx.ALIGN_CENTER_VERTICAL,
218  pos = (row, 0))
219  rColor = csel.ColourSelect(parent = panel, id = wx.ID_ANY,
220  colour = self.settings.Get(group='modeler', key='data', subkey=('color', 'raster')),
221  size = globalvar.DIALOG_COLOR_SIZE)
222  rColor.SetName('GetColour')
223  self.winId['modeler:data:color:raster'] = rColor.GetId()
224 
225  gridSizer.Add(item = rColor,
226  flag = wx.ALIGN_RIGHT |
227  wx.ALIGN_CENTER_VERTICAL,
228  pos = (row, 1))
229 
230  row += 1
231  gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
232  label = _("3D raster:")),
233  flag = wx.ALIGN_LEFT |
234  wx.ALIGN_CENTER_VERTICAL,
235  pos = (row, 0))
236  r3Color = csel.ColourSelect(parent = panel, id = wx.ID_ANY,
237  colour = self.settings.Get(group='modeler', key='data', subkey=('color', 'raster3d')),
238  size = globalvar.DIALOG_COLOR_SIZE)
239  r3Color.SetName('GetColour')
240  self.winId['modeler:data:color:raster3d'] = r3Color.GetId()
241 
242  gridSizer.Add(item = r3Color,
243  flag = wx.ALIGN_RIGHT |
244  wx.ALIGN_CENTER_VERTICAL,
245  pos = (row, 1))
246 
247  row += 1
248  gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
249  label = _("Vector:")),
250  flag = wx.ALIGN_LEFT |
251  wx.ALIGN_CENTER_VERTICAL,
252  pos = (row, 0))
253  vColor = csel.ColourSelect(parent = panel, id = wx.ID_ANY,
254  colour = self.settings.Get(group='modeler', key='data', subkey=('color', 'vector')),
255  size = globalvar.DIALOG_COLOR_SIZE)
256  vColor.SetName('GetColour')
257  self.winId['modeler:data:color:vector'] = vColor.GetId()
258 
259  gridSizer.Add(item = vColor,
260  flag = wx.ALIGN_RIGHT |
261  wx.ALIGN_CENTER_VERTICAL,
262  pos = (row, 1))
263 
264  sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5)
265  border.Add(item = sizer, proportion = 0, flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 3)
266 
267  # size
268  box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
269  label = " %s " % _("Shape size"))
270  sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
271 
272  gridSizer = wx.GridBagSizer (hgap=3, vgap=3)
273  gridSizer.AddGrowableCol(0)
274 
275  row = 0
276  gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
277  label = _("Width:")),
278  flag = wx.ALIGN_LEFT |
279  wx.ALIGN_CENTER_VERTICAL,
280  pos = (row, 0))
281 
282  width = wx.SpinCtrl(parent = panel, id = wx.ID_ANY,
283  min = 0, max = 500,
284  initial = self.settings.Get(group='modeler', key='data', subkey=('size', 'width')))
285  width.SetName('GetValue')
286  self.winId['modeler:data:size:width'] = width.GetId()
287 
288  gridSizer.Add(item = width,
289  flag = wx.ALIGN_RIGHT |
290  wx.ALIGN_CENTER_VERTICAL,
291  pos = (row, 1))
292 
293  row += 1
294  gridSizer.Add(item = wx.StaticText(parent=panel, id=wx.ID_ANY,
295  label=_("Height:")),
296  flag = wx.ALIGN_LEFT |
297  wx.ALIGN_CENTER_VERTICAL,
298  pos=(row, 0))
299 
300  height = wx.SpinCtrl(parent = panel, id = wx.ID_ANY,
301  min = 0, max = 500,
302  initial = self.settings.Get(group='modeler', key='data', subkey=('size', 'height')))
303  height.SetName('GetValue')
304  self.winId['modeler:data:size:height'] = height.GetId()
305 
306  gridSizer.Add(item = height,
307  flag = wx.ALIGN_RIGHT |
308  wx.ALIGN_CENTER_VERTICAL,
309  pos = (row, 1))
310 
311  sizer.Add(item=gridSizer, proportion=1, flag=wx.ALL | wx.EXPAND, border=5)
312  border.Add(item=sizer, proportion=0, flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border=3)
313 
314  panel.SetSizer(border)
315 
316  return panel
317 
318  def _createLoopPage(self, notebook):
319  """!Create notebook page for loop settings"""
320  panel = wx.Panel(parent = notebook, id = wx.ID_ANY)
321  notebook.AddPage(page = panel, text = _("Loop"))
322 
323  # colors
324  border = wx.BoxSizer(wx.VERTICAL)
325  box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
326  label = " %s " % _("Color"))
327  sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
328 
329  gridSizer = wx.GridBagSizer (hgap = 3, vgap = 3)
330  gridSizer.AddGrowableCol(0)
331 
332  row = 0
333  gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
334  label = _("Valid:")),
335  flag = wx.ALIGN_LEFT |
336  wx.ALIGN_CENTER_VERTICAL,
337  pos = (row, 0))
338  vColor = csel.ColourSelect(parent = panel, id = wx.ID_ANY,
339  colour = self.settings.Get(group='modeler', key='loop', subkey=('color', 'valid')),
340  size = globalvar.DIALOG_COLOR_SIZE)
341  vColor.SetName('GetColour')
342  self.winId['modeler:loop:color:valid'] = vColor.GetId()
343 
344  gridSizer.Add(item = vColor,
345  flag = wx.ALIGN_RIGHT |
346  wx.ALIGN_CENTER_VERTICAL,
347  pos = (row, 1))
348 
349  sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5)
350  border.Add(item = sizer, proportion = 0, flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 3)
351 
352  # size
353  box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
354  label = " %s " % _("Shape size"))
355  sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
356 
357  gridSizer = wx.GridBagSizer (hgap=3, vgap=3)
358  gridSizer.AddGrowableCol(0)
359 
360  row = 0
361  gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
362  label = _("Width:")),
363  flag = wx.ALIGN_LEFT |
364  wx.ALIGN_CENTER_VERTICAL,
365  pos = (row, 0))
366 
367  width = wx.SpinCtrl(parent = panel, id = wx.ID_ANY,
368  min = 0, max = 500,
369  initial = self.settings.Get(group='modeler', key='loop', subkey=('size', 'width')))
370  width.SetName('GetValue')
371  self.winId['modeler:loop:size:width'] = width.GetId()
372 
373  gridSizer.Add(item = width,
374  flag = wx.ALIGN_RIGHT |
375  wx.ALIGN_CENTER_VERTICAL,
376  pos = (row, 1))
377 
378  row += 1
379  gridSizer.Add(item = wx.StaticText(parent=panel, id=wx.ID_ANY,
380  label=_("Height:")),
381  flag = wx.ALIGN_LEFT |
382  wx.ALIGN_CENTER_VERTICAL,
383  pos=(row, 0))
384 
385  height = wx.SpinCtrl(parent = panel, id = wx.ID_ANY,
386  min = 0, max = 500,
387  initial = self.settings.Get(group='modeler', key='loop', subkey=('size', 'height')))
388  height.SetName('GetValue')
389  self.winId['modeler:loop:size:height'] = height.GetId()
390 
391  gridSizer.Add(item = height,
392  flag = wx.ALIGN_RIGHT |
393  wx.ALIGN_CENTER_VERTICAL,
394  pos = (row, 1))
395 
396  sizer.Add(item=gridSizer, proportion=1, flag=wx.ALL | wx.EXPAND, border=5)
397  border.Add(item=sizer, proportion=0, flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border=3)
398 
399  panel.SetSizer(border)
400 
401  return panel
402 
403  def OnApply(self, event):
404  """!Button 'Apply' pressed"""
405  PreferencesBaseDialog.OnApply(self, event)
406 
407  self.parent.GetModel().Update()
408  self.parent.GetCanvas().Refresh()
409 
410  def OnSave(self, event):
411  """!Button 'Save' pressed"""
412  PreferencesBaseDialog.OnSave(self, event)
413 
414  self.parent.GetModel().Update()
415  self.parent.GetCanvas().Refresh()
416 
417 class PropertiesDialog(wx.Dialog):
418  """!Model properties dialog
419  """
420  def __init__(self, parent, id = wx.ID_ANY,
421  title = _('Model properties'),
422  size = (350, 400),
423  style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER):
424  wx.Dialog.__init__(self, parent, id, title, size = size,
425  style = style)
426 
427  self.metaBox = wx.StaticBox(parent = self, id = wx.ID_ANY,
428  label=" %s " % _("Metadata"))
429  self.cmdBox = wx.StaticBox(parent = self, id = wx.ID_ANY,
430  label=" %s " % _("Commands"))
431 
432  self.name = wx.TextCtrl(parent = self, id = wx.ID_ANY,
433  size = (300, 25))
434  self.desc = wx.TextCtrl(parent = self, id = wx.ID_ANY,
435  style = wx.TE_MULTILINE,
436  size = (300, 50))
437  self.author = wx.TextCtrl(parent = self, id = wx.ID_ANY,
438  size = (300, 25))
439 
440  # commands
441  self.overwrite = wx.CheckBox(parent = self, id=wx.ID_ANY,
442  label=_("Allow output files to overwrite existing files"))
443  self.overwrite.SetValue(UserSettings.Get(group='cmd', key='overwrite', subkey='enabled'))
444 
445  # buttons
446  self.btnOk = wx.Button(self, wx.ID_OK)
447  self.btnCancel = wx.Button(self, wx.ID_CANCEL)
448  self.btnOk.SetDefault()
449 
450  self.btnOk.SetToolTipString(_("Apply properties"))
451  self.btnOk.SetDefault()
452  self.btnCancel.SetToolTipString(_("Close dialog and ignore changes"))
453 
454  self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
455 
456  self._layout()
457 
458  def _layout(self):
459  metaSizer = wx.StaticBoxSizer(self.metaBox, wx.VERTICAL)
460  gridSizer = wx.GridBagSizer(hgap = 3, vgap = 3)
461  gridSizer.AddGrowableCol(1)
462  gridSizer.AddGrowableRow(1)
463  gridSizer.Add(item = wx.StaticText(parent = self, id = wx.ID_ANY,
464  label = _("Name:")),
465  flag = wx.ALIGN_LEFT |
466  wx.ALIGN_CENTER_VERTICAL,
467  pos = (0, 0))
468  gridSizer.Add(item = self.name,
469  flag = wx.ALIGN_LEFT |
470  wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
471  pos = (0, 1))
472  gridSizer.Add(item = wx.StaticText(parent = self, id = wx.ID_ANY,
473  label = _("Description:")),
474  flag = wx.ALIGN_LEFT |
475  wx.ALIGN_CENTER_VERTICAL,
476  pos = (1, 0))
477  gridSizer.Add(item = self.desc,
478  flag = wx.ALIGN_LEFT |
479  wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
480  pos = (1, 1))
481  gridSizer.Add(item = wx.StaticText(parent = self, id = wx.ID_ANY,
482  label = _("Author(s):")),
483  flag = wx.ALIGN_LEFT |
484  wx.ALIGN_CENTER_VERTICAL,
485  pos = (2, 0))
486  gridSizer.Add(item = self.author,
487  flag = wx.ALIGN_LEFT |
488  wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
489  pos = (2, 1))
490  metaSizer.Add(item = gridSizer, proportion = 1, flag = wx.EXPAND)
491 
492  cmdSizer = wx.StaticBoxSizer(self.cmdBox, wx.VERTICAL)
493  cmdSizer.Add(item = self.overwrite,
494  flag = wx.EXPAND | wx.ALL, border = 3)
495 
496  btnStdSizer = wx.StdDialogButtonSizer()
497  btnStdSizer.AddButton(self.btnCancel)
498  btnStdSizer.AddButton(self.btnOk)
499  btnStdSizer.Realize()
500 
501  mainSizer = wx.BoxSizer(wx.VERTICAL)
502  mainSizer.Add(item=metaSizer, proportion=1,
503  flag=wx.EXPAND | wx.ALL, border=5)
504  mainSizer.Add(item=cmdSizer, proportion=0,
505  flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, border=5)
506  mainSizer.Add(item=btnStdSizer, proportion=0,
507  flag=wx.EXPAND | wx.ALL | wx.ALIGN_RIGHT, border=5)
508 
509  self.SetSizer(mainSizer)
510  mainSizer.Fit(self)
511 
512  def OnCloseWindow(self, event):
513  self.Hide()
514 
515  def GetValues(self):
516  """!Get values"""
517  return { 'name' : self.name.GetValue(),
518  'description' : self.desc.GetValue(),
519  'author' : self.author.GetValue(),
520  'overwrite' : self.overwrite.IsChecked() }
521 
522  def Init(self, prop):
523  """!Initialize dialog"""
524  self.name.SetValue(prop['name'])
525  self.desc.SetValue(prop['description'])
526  self.author.SetValue(prop['author'])
527  if 'overwrite' in prop:
528  self.overwrite.SetValue(prop['overwrite'])
def _createActionPage
Create notebook page for action settings.
User preferences dialog.
def OnApply
Button &#39;Apply&#39; pressed.
def OnSave
Button &#39;Save&#39; pressed.
def _createLoopPage
Create notebook page for loop settings.
def _createDataPage
Create notebook page for data settings.
def _createGeneralPage
Create notebook page for action settings.
Model properties dialog.
User preferences dialog.
Default GUI settings.