GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
wxplot/dialogs.py
Go to the documentation of this file.
1 """!
2 @package wxplot.dialogs
3 
4 @brief Dialogs for different plotting routines
5 
6 Classes:
7  - dialogs::ProfileRasterDialog
8  - dialogs::ScatterRasterDialog
9  - dialogs::PlotStatsFrame
10  - dialogs::HistRasterDialog
11  - dialogs::TextDialog
12  - dialogs::OptDialog
13 
14 (C) 2011-2012 by the GRASS Development Team
15 
16 This program is free software under the GNU General Public License
17 (>=v2). Read the file COPYING that comes with GRASS for details.
18 
19 @author Michael Barton, Arizona State University
20 """
21 
22 import wx
23 import wx.lib.colourselect as csel
24 import wx.lib.scrolledpanel as scrolled
25 
26 from core import globalvar
27 from core.settings import UserSettings
28 from gui_core.gselect import Select
29 
30 from grass.script import core as grass
31 
32 class ProfileRasterDialog(wx.Dialog):
33  def __init__(self, parent, id = wx.ID_ANY,
34  title = _("Select raster maps to profile"),
35  style = wx.DEFAULT_DIALOG_STYLE, **kwargs):
36  """!Dialog to select raster maps to profile.
37  """
38 
39  wx.Dialog.__init__(self, parent, id, title, style = style, **kwargs)
40 
41 
42  self.parent = parent
43  self.colorList = ["blue", "red", "green", "yellow", "magenta", "cyan", \
44  "aqua", "black", "grey", "orange", "brown", "purple", "violet", \
45  "indigo"]
46 
47  self.rasterList = self.parent.rasterList
48 
49  self._do_layout()
50 
51  def _do_layout(self):
52 
53  sizer = wx.BoxSizer(wx.VERTICAL)
54 
55  box = wx.GridBagSizer (hgap = 3, vgap = 3)
56 
57  rastText = ''
58  for r in self.rasterList:
59  rastText += '%s,' % r
60 
61  rastText = rastText.rstrip(',')
62 
63  txt = _("Select raster map(s) to profile:")
64  label = wx.StaticText(parent = self, id = wx.ID_ANY, label = txt)
65  box.Add(item = label,
66  flag = wx.ALIGN_CENTER_VERTICAL, pos = (0, 0))
67 
68  selection = Select(self, id = wx.ID_ANY,
69  size = globalvar.DIALOG_GSELECT_SIZE,
70  type = 'cell', multiple=True)
71  selection.SetValue(rastText)
72  selection.Bind(wx.EVT_TEXT, self.OnSelection)
73 
74  box.Add(item = selection, pos = (0, 1))
75 
76  sizer.Add(item = box, proportion = 0,
77  flag = wx.ALL, border = 10)
78 
79  line = wx.StaticLine(parent = self, id = wx.ID_ANY, size = (20, -1), style = wx.LI_HORIZONTAL)
80  sizer.Add(item = line, proportion = 0,
81  flag = wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.LEFT|wx.RIGHT, border = 5)
82 
83  btnsizer = wx.StdDialogButtonSizer()
84 
85  btn = wx.Button(self, wx.ID_OK)
86  btn.SetDefault()
87  btnsizer.AddButton(btn)
88 
89  btn = wx.Button(self, wx.ID_CANCEL)
90  btnsizer.AddButton(btn)
91  btnsizer.Realize()
92 
93  sizer.Add(item = btnsizer, proportion = 0, flag = wx.ALIGN_RIGHT | wx.ALL, border = 5)
94 
95  self.SetSizer(sizer)
96  sizer.Fit(self)
97 
98  def OnSelection(self, event):
99  """!Choose maps to profile. Convert these into a list
100  """
101  self.rasterList = []
102  self.rasterList = event.GetString().split(',')
103 
104 class PlotStatsFrame(wx.Frame):
105  def __init__(self, parent, id, message = '', title = '',
106  style = wx.DEFAULT_FRAME_STYLE, **kwargs):
107  """!Dialog to display and save statistics for plots
108  """
109  wx.Frame.__init__(self, parent, id, style = style, **kwargs)
110  self.SetLabel(_("Statistics"))
111 
112  sp = scrolled.ScrolledPanel(self, -1, size=(400, 400),
113  style = wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER, name="Statistics" )
114 
115 
116  #
117  # initialize variables
118  #
119  self.parent = parent
120  self.message = message
121  self.title = title
122  self.CenterOnParent()
123 
124  #
125  # Display statistics
126  #
127  sizer = wx.BoxSizer(wx.VERTICAL)
128  txtSizer = wx.BoxSizer(wx.VERTICAL)
129 
130  statstitle = wx.StaticText(parent = self, id = wx.ID_ANY, label = self.title)
131  sizer.Add(item = statstitle, proportion = 0,
132  flag = wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, border = 3)
133  line = wx.StaticLine(parent = self, id = wx.ID_ANY, size = (20, -1), style = wx.LI_HORIZONTAL)
134  sizer.Add(item = line, proportion = 0,
135  flag = wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, border = 3)
136  for stats in self.message:
137  statstxt = wx.StaticText(parent = sp, id = wx.ID_ANY, label = stats)
138  statstxt.SetBackgroundColour("WHITE")
139  txtSizer.Add(item = statstxt, proportion = 1,
140  flag = wx.EXPAND|wx.ALIGN_CENTER_VERTICAL|wx.LEFT|wx.RIGHT, border = 3)
141  line = wx.StaticLine(parent = sp, id = wx.ID_ANY, size = (20, -1), style = wx.LI_HORIZONTAL)
142  txtSizer.Add(item = line, proportion = 0,
143  flag = wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, border = 3)
144 
145  sp.SetSizer(txtSizer)
146  sp.SetAutoLayout(1)
147  sp.SetupScrolling()
148 
149  sizer.Add(item = sp, proportion = 1,
150  flag = wx.GROW | wx.LEFT | wx.RIGHT | wx.BOTTOM, border = 3)
151 
152  line = wx.StaticLine(parent = self, id = wx.ID_ANY, size = (20, -1), style = wx.LI_HORIZONTAL)
153  sizer.Add(item = line, proportion = 0,
154  flag = wx.GROW |wx.ALIGN_CENTER_VERTICAL|wx.LEFT|wx.RIGHT, border = 3)
155 
156  #
157  # buttons
158  #
159  btnSizer = wx.BoxSizer(wx.HORIZONTAL)
160 
161  btn_clipboard = wx.Button(self, id = wx.ID_COPY, label = _('C&opy'))
162  btn_clipboard.SetToolTipString(_("Copy regression statistics the clipboard (Ctrl+C)"))
163  btnSizer.Add(item = btn_clipboard, proportion = 0, flag = wx.ALIGN_LEFT | wx.ALL, border = 5)
164 
165  btnCancel = wx.Button(self, wx.ID_CLOSE)
166  btnCancel.SetDefault()
167  btnSizer.Add(item = btnCancel, proportion = 0, flag = wx.ALIGN_RIGHT | wx.ALL, border = 5)
168 
169  sizer.Add(item = btnSizer, proportion = 0, flag = wx.ALIGN_RIGHT | wx.ALL, border = 5)
170 
171  # bindings
172  btnCancel.Bind(wx.EVT_BUTTON, self.OnClose)
173  btn_clipboard.Bind(wx.EVT_BUTTON, self.OnCopy)
174 
175  self.SetSizer(sizer)
176  sizer.Fit(self)
177 
178  def OnCopy(self, event):
179  """!Copy the regression stats to the clipboard
180  """
181  str = self.title + '\n'
182  for item in self.message:
183  str += item
184 
185  rdata = wx.TextDataObject()
186  rdata.SetText(str)
187 
188  if wx.TheClipboard.Open():
189  wx.TheClipboard.SetData(rdata)
190  wx.TheClipboard.Close()
191  wx.MessageBox(_("Regression statistics copied to clipboard"))
192 
193  def OnClose(self, event):
194  """!Button 'Close' pressed
195  """
196  self.Close(True)
197 
198 class TextDialog(wx.Dialog):
199  def __init__(self, parent, id, title, plottype = '',
200  style = wx.DEFAULT_DIALOG_STYLE, **kwargs):
201  """!Dialog to set plot text options: font, title
202  and font size, axis labels and font size
203  """
204  wx.Dialog.__init__(self, parent, id, title, style = style, **kwargs)
205  #
206  # initialize variables
207  #
208  # combo box entry lists
209  self.ffamilydict = { 'default' : wx.FONTFAMILY_DEFAULT,
210  'decorative' : wx.FONTFAMILY_DECORATIVE,
211  'roman' : wx.FONTFAMILY_ROMAN,
212  'script' : wx.FONTFAMILY_SCRIPT,
213  'swiss' : wx.FONTFAMILY_SWISS,
214  'modern' : wx.FONTFAMILY_MODERN,
215  'teletype' : wx.FONTFAMILY_TELETYPE }
216 
217  self.fstyledict = { 'normal' : wx.FONTSTYLE_NORMAL,
218  'slant' : wx.FONTSTYLE_SLANT,
219  'italic' : wx.FONTSTYLE_ITALIC }
220 
221  self.fwtdict = { 'normal' : wx.FONTWEIGHT_NORMAL,
222  'light' : wx.FONTWEIGHT_LIGHT,
223  'bold' : wx.FONTWEIGHT_BOLD }
224 
225  self.parent = parent
226  self.plottype = plottype
227 
228  self.ptitle = self.parent.ptitle
229  self.xlabel = self.parent.xlabel
230  self.ylabel = self.parent.ylabel
231 
232  self.properties = self.parent.properties # read-only
233 
234  # font size
235  self.fontfamily = self.properties['font']['wxfont'].GetFamily()
236  self.fontstyle = self.properties['font']['wxfont'].GetStyle()
237  self.fontweight = self.properties['font']['wxfont'].GetWeight()
238 
239  self._do_layout()
240 
241  def _do_layout(self):
242  """!Do layout"""
243  # dialog layout
244  sizer = wx.BoxSizer(wx.VERTICAL)
245 
246  box = wx.StaticBox(parent = self, id = wx.ID_ANY,
247  label = " %s " % _("Text settings"))
248  boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
249  gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
250 
251  #
252  # profile title
253  #
254  label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Profile title:"))
255  gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (0, 0))
256  self.ptitleentry = wx.TextCtrl(parent = self, id = wx.ID_ANY, value = "", size = (250,-1))
257  # self.ptitleentry.SetFont(self.font)
258  self.ptitleentry.SetValue(self.ptitle)
259  gridSizer.Add(item = self.ptitleentry, pos = (0, 1))
260 
261  #
262  # title font
263  #
264  tlabel = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Title font size (pts):"))
265  gridSizer.Add(item = tlabel, flag = wx.ALIGN_CENTER_VERTICAL, pos = (1, 0))
266  self.ptitlesize = wx.SpinCtrl(parent = self, id = wx.ID_ANY, value = "", pos = (30, 50),
267  size = (50,-1), style = wx.SP_ARROW_KEYS)
268  self.ptitlesize.SetRange(5,100)
269  self.ptitlesize.SetValue(int(self.properties['font']['prop']['titleSize']))
270  gridSizer.Add(item = self.ptitlesize, pos = (1, 1))
271 
272  #
273  # x-axis label
274  #
275  label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("X-axis label:"))
276  gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (2, 0))
277  self.xlabelentry = wx.TextCtrl(parent = self, id = wx.ID_ANY, value = "", size = (250,-1))
278  # self.xlabelentry.SetFont(self.font)
279  self.xlabelentry.SetValue(self.xlabel)
280  gridSizer.Add(item = self.xlabelentry, pos = (2, 1))
281 
282  #
283  # y-axis label
284  #
285  label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Y-axis label:"))
286  gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (3, 0))
287  self.ylabelentry = wx.TextCtrl(parent = self, id = wx.ID_ANY, value = "", size = (250,-1))
288  # self.ylabelentry.SetFont(self.font)
289  self.ylabelentry.SetValue(self.ylabel)
290  gridSizer.Add(item = self.ylabelentry, pos = (3, 1))
291 
292  #
293  # font size
294  #
295  llabel = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Label font size (pts):"))
296  gridSizer.Add(item = llabel, flag = wx.ALIGN_CENTER_VERTICAL, pos = (4, 0))
297  self.axislabelsize = wx.SpinCtrl(parent = self, id = wx.ID_ANY, value = "", pos = (30, 50),
298  size = (50, -1), style = wx.SP_ARROW_KEYS)
299  self.axislabelsize.SetRange(5, 100)
300  self.axislabelsize.SetValue(int(self.properties['font']['prop']['axisSize']))
301  gridSizer.Add(item = self.axislabelsize, pos = (4,1))
302 
303  boxSizer.Add(item = gridSizer)
304  sizer.Add(item = boxSizer, flag = wx.ALL | wx.EXPAND, border = 3)
305 
306  #
307  # font settings
308  #
309  box = wx.StaticBox(parent = self, id = wx.ID_ANY,
310  label = " %s " % _("Font settings"))
311  boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
312  gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
313  gridSizer.AddGrowableCol(1)
314 
315  #
316  # font family
317  #
318  label1 = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Font family:"))
319  gridSizer.Add(item = label1, flag = wx.ALIGN_CENTER_VERTICAL, pos = (0, 0))
320  self.ffamilycb = wx.ComboBox(parent = self, id = wx.ID_ANY, size = (250, -1),
321  choices = self.ffamilydict.keys(), style = wx.CB_DROPDOWN)
322  self.ffamilycb.SetStringSelection('swiss')
323  for item in self.ffamilydict.items():
324  if self.fontfamily == item[1]:
325  self.ffamilycb.SetStringSelection(item[0])
326  break
327  gridSizer.Add(item = self.ffamilycb, pos = (0, 1), flag = wx.ALIGN_RIGHT)
328 
329  #
330  # font style
331  #
332  label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Style:"))
333  gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (1, 0))
334  self.fstylecb = wx.ComboBox(parent = self, id = wx.ID_ANY, size = (250, -1),
335  choices = self.fstyledict.keys(), style = wx.CB_DROPDOWN)
336  self.fstylecb.SetStringSelection('normal')
337  for item in self.fstyledict.items():
338  if self.fontstyle == item[1]:
339  self.fstylecb.SetStringSelection(item[0])
340  break
341  gridSizer.Add(item = self.fstylecb, pos = (1, 1), flag = wx.ALIGN_RIGHT)
342 
343  #
344  # font weight
345  #
346  label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Weight:"))
347  gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (2, 0))
348  self.fwtcb = wx.ComboBox(parent = self, size = (250, -1),
349  choices = self.fwtdict.keys(), style = wx.CB_DROPDOWN)
350  self.fwtcb.SetStringSelection('normal')
351  for item in self.fwtdict.items():
352  if self.fontweight == item[1]:
353  self.fwtcb.SetStringSelection(item[0])
354  break
355 
356  gridSizer.Add(item = self.fwtcb, pos = (2, 1), flag = wx.ALIGN_RIGHT)
357 
358  boxSizer.Add(item = gridSizer, flag = wx.EXPAND)
359  sizer.Add(item = boxSizer, flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 3)
360 
361  line = wx.StaticLine(parent = self, id = wx.ID_ANY, size = (20, -1), style = wx.LI_HORIZONTAL)
362  sizer.Add(item = line, proportion = 0,
363  flag = wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.LEFT|wx.RIGHT, border = 3)
364 
365  #
366  # buttons
367  #
368  btnSave = wx.Button(self, wx.ID_SAVE)
369  btnApply = wx.Button(self, wx.ID_APPLY)
370  btnOk = wx.Button(self, wx.ID_OK)
371  btnCancel = wx.Button(self, wx.ID_CANCEL)
372  btnOk.SetDefault()
373 
374  # bindings
375  btnApply.Bind(wx.EVT_BUTTON, self.OnApply)
376  btnApply.SetToolTipString(_("Apply changes for the current session"))
377  btnOk.Bind(wx.EVT_BUTTON, self.OnOk)
378  btnOk.SetToolTipString(_("Apply changes for the current session and close dialog"))
379  btnOk.SetDefault()
380  btnSave.Bind(wx.EVT_BUTTON, self.OnSave)
381  btnSave.SetToolTipString(_("Apply and save changes to user settings file (default for next sessions)"))
382  btnCancel.Bind(wx.EVT_BUTTON, self.OnCancel)
383  btnCancel.SetToolTipString(_("Close dialog and ignore changes"))
384 
385  # sizers
386  btnStdSizer = wx.StdDialogButtonSizer()
387  btnStdSizer.AddButton(btnOk)
388  btnStdSizer.AddButton(btnApply)
389  btnStdSizer.AddButton(btnCancel)
390  btnStdSizer.Realize()
391 
392  btnSizer = wx.BoxSizer(wx.HORIZONTAL)
393  btnSizer.Add(item = btnSave, proportion = 0, flag = wx.ALIGN_LEFT | wx.ALL, border = 5)
394  btnSizer.Add(item = btnStdSizer, proportion = 0, flag = wx.ALIGN_RIGHT | wx.ALL, border = 5)
395  sizer.Add(item = btnSizer, proportion = 0, flag = wx.ALIGN_RIGHT | wx.ALL, border = 5)
396 
397  #
398  # bindings
399  #
400  self.ptitleentry.Bind(wx.EVT_TEXT, self.OnTitle)
401  self.xlabelentry.Bind(wx.EVT_TEXT, self.OnXLabel)
402  self.ylabelentry.Bind(wx.EVT_TEXT, self.OnYLabel)
403 
404  self.SetSizer(sizer)
405  sizer.Fit(self)
406 
407  def OnTitle(self, event):
408  self.ptitle = event.GetString()
409 
410  def OnXLabel(self, event):
411  self.xlabel = event.GetString()
412 
413  def OnYLabel(self, event):
414  self.ylabel = event.GetString()
415 
416  def UpdateSettings(self):
417  self.properties['font']['prop']['titleSize'] = self.ptitlesize.GetValue()
418  self.properties['font']['prop']['axisSize'] = self.axislabelsize.GetValue()
419 
420  family = self.ffamilydict[self.ffamilycb.GetStringSelection()]
421  self.properties['font']['wxfont'].SetFamily(family)
422  style = self.fstyledict[self.fstylecb.GetStringSelection()]
423  self.properties['font']['wxfont'].SetStyle(style)
424  weight = self.fwtdict[self.fwtcb.GetStringSelection()]
425  self.properties['font']['wxfont'].SetWeight(weight)
426 
427  def OnSave(self, event):
428  """!Button 'Save' pressed"""
429  self.OnApply(None)
430  fileSettings = {}
431  UserSettings.ReadSettingsFile(settings = fileSettings)
432  fileSettings[self.plottype] = UserSettings.Get(group = self.plottype)
433  UserSettings.SaveToFile(fileSettings)
434  self.parent.parent.GetLayerManager().goutput.WriteLog(_('Plot text sizes saved to file \'%s\'.') % UserSettings.filePath)
435  self.EndModal(wx.ID_OK)
436 
437  def OnApply(self, event):
438  """!Button 'Apply' pressed"""
439  self.UpdateSettings()
440  self.parent.OnPlotText(self)
441 
442  def OnOk(self, event):
443  """!Button 'OK' pressed"""
444  self.OnApply(None)
445  self.EndModal(wx.ID_OK)
446 
447  def OnCancel(self, event):
448  """!Button 'Cancel' pressed"""
449  self.EndModal(wx.ID_CANCEL)
450 
451 class OptDialog(wx.Dialog):
452  def __init__(self, parent, id, title, plottype = '',
453  style = wx.DEFAULT_DIALOG_STYLE, **kwargs):
454  """!Dialog to set various options for data plotted, including: line
455  width, color, style; marker size, color, fill, and style; grid
456  and legend options.
457  """
458  wx.Dialog.__init__(self, parent, id, title, style = style, **kwargs)
459 
460  # init variables
461  self.parent = parent
462  self.linestyledict = parent.linestyledict
463  self.ptfilldict = parent.ptfilldict
464  self.parent = parent
465  self.plottype = plottype
466 
467  self.pttypelist = ['circle',
468  'dot',
469  'square',
470  'triangle',
471  'triangle_down',
472  'cross',
473  'plus']
474 
475  self.axislist = ['min',
476  'auto',
477  'custom']
478 
479  # widgets ids
480  self.wxId = {}
481 
482  self.parent = parent
483 
484  # read-only
485  self.raster = self.parent.raster
486  self.rasterList = self.parent.rasterList
487  self.properties = self.parent.properties
488  self.map = ''
489 
490  if len(self.rasterList) == 0:
491  wx.MessageBox(parent = self,
492  message = _("No map or image group selected to plot."),
493  caption = _("Warning"), style = wx.OK | wx.ICON_ERROR)
494 
495  self._do_layout()
496 
497  def _do_layout(self):
498  """!Options dialog layout
499  """
500  sizer = wx.BoxSizer(wx.VERTICAL)
501 
502  box = wx.StaticBox(parent = self, id = wx.ID_ANY,
503  label = " %s " % _("Plot settings"))
504  boxMainSizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
505 
506  self.wxId['pcolor'] = 0
507  self.wxId['pwidth'] = 0
508  self.wxId['pstyle'] = 0
509  self.wxId['psize'] = 0
510  self.wxId['ptype'] = 0
511  self.wxId['pfill'] = 0
512  self.wxId['plegend'] = 0
513  self.wxId['marker'] = {}
514  self.wxId['x-axis'] = {}
515  self.wxId['y-axis'] = {}
516 
517  #
518  # plot line settings and point settings
519  #
520  if len(self.rasterList) == 0: return
521 
522  box = wx.StaticBox(parent = self, id = wx.ID_ANY,
523  label = _("Map/image plotted"))
524  boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
525 
526  gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
527 
528  row = 0
529  choicelist = []
530  for i in self.rasterList:
531  choicelist.append(str(i))
532 
533  self.mapchoice = wx.Choice(parent = self, id = wx.ID_ANY, size = (300, -1),
534  choices = choicelist)
535  self.mapchoice.SetToolTipString(_("Settings for selected map"))
536 
537  if not self.map:
538  self.map = self.rasterList[self.mapchoice.GetCurrentSelection()]
539  else:
540  self.mapchoice.SetStringSelection(str(self.map))
541 
542 
543  gridSizer.Add(item = self.mapchoice, flag = wx.ALIGN_CENTER_VERTICAL,
544  pos = (row, 0), span = (1, 2))
545 
546  #
547  # options for profile
548  #
549  row +=1
550  label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Line color"))
551  gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (row, 0))
552  color = csel.ColourSelect(parent = self, id = wx.ID_ANY, colour = self.raster[self.map]['pcolor'])
553  self.wxId['pcolor'] = color.GetId()
554  gridSizer.Add(item = color, pos = (row, 1))
555 
556  row += 1
557  label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Line width"))
558  gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (row, 0))
559  width = wx.SpinCtrl(parent = self, id = wx.ID_ANY, value = "",
560  size = (50,-1), style = wx.SP_ARROW_KEYS)
561  width.SetRange(1, 10)
562  width.SetValue(self.raster[self.map]['pwidth'])
563  self.wxId['pwidth'] = width.GetId()
564  gridSizer.Add(item = width, pos = (row, 1))
565 
566  row +=1
567  label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Line style"))
568  gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (row, 0))
569  style = wx.Choice(parent = self, id = wx.ID_ANY,
570  size = (120, -1), choices = self.linestyledict.keys())
571  style.SetStringSelection(self.raster[self.map]['pstyle'])
572  self.wxId['pstyle'] = style.GetId()
573  gridSizer.Add(item = style, pos = (row, 1))
574 
575  row += 1
576  label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Legend"))
577  gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (row, 0))
578  legend = wx.TextCtrl(parent = self, id = wx.ID_ANY, value = "", size = (200,-1))
579  legend.SetValue(self.raster[self.map]['plegend'])
580  gridSizer.Add(item = legend, pos = (row, 1))
581  self.wxId['plegend'] = legend.GetId()
582 
583  boxSizer.Add(item = gridSizer)
584  boxMainSizer.Add(item = boxSizer, flag = wx.ALL, border = 3)
585 
586  #
587  # segment marker settings for profiles
588  #
589  box = wx.StaticBox(parent = self, id = wx.ID_ANY,
590  label = " %s " % _("Transect segment marker settings"))
591 
592  boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
593 
594  gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
595  label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Color"))
596  gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (0, 0))
597  ptcolor = csel.ColourSelect(parent = self, id = wx.ID_ANY, colour = self.properties['marker']['color'])
598  self.wxId['marker']['color'] = ptcolor.GetId()
599  gridSizer.Add(item = ptcolor, pos = (0, 1))
600 
601  label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Size"))
602  gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (1, 0))
603  ptsize = wx.SpinCtrl(parent = self, id = wx.ID_ANY, value = "",
604  size = (50, -1), style = wx.SP_ARROW_KEYS)
605  ptsize.SetRange(1, 10)
606  ptsize.SetValue(self.properties['marker']['size'])
607  self.wxId['marker']['size'] = ptsize.GetId()
608  gridSizer.Add(item = ptsize, pos = (1, 1))
609 
610  label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Fill"))
611  gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (2, 0))
612  ptfill = wx.Choice(parent = self, id = wx.ID_ANY,
613  size = (120, -1), choices = self.ptfilldict.keys())
614  ptfill.SetStringSelection(self.properties['marker']['fill'])
615  self.wxId['marker']['fill'] = ptfill.GetId()
616  gridSizer.Add(item = ptfill, pos = (2, 1))
617 
618  label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Legend"))
619  gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (3, 0))
620  ptlegend = wx.TextCtrl(parent = self, id = wx.ID_ANY, value = "", size = (200,-1))
621  ptlegend.SetValue(self.properties['marker']['legend'])
622  self.wxId['marker']['legend'] = ptlegend.GetId()
623  gridSizer.Add(item = ptlegend, pos = (3, 1))
624 
625  label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Style"))
626  gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (4, 0))
627  pttype = wx.Choice(parent = self, size = (200, -1), choices = self.pttypelist)
628  pttype.SetStringSelection(self.properties['marker']['type'])
629  self.wxId['marker']['type'] = pttype.GetId()
630  gridSizer.Add(item = pttype, pos = (4, 1))
631 
632  boxSizer.Add(item = gridSizer)
633  boxMainSizer.Add(item = boxSizer, flag = wx.ALL, border = 3)
634 
635  sizer.Add(item = boxMainSizer, flag = wx.ALL | wx.EXPAND, border = 3)
636 
637  #
638  # axis options for all plots
639  #
640  box = wx.StaticBox(parent = self, id = wx.ID_ANY,
641  label = " %s " % _("Axis settings"))
642  boxMainSizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
643 
644  middleSizer = wx.BoxSizer(wx.HORIZONTAL)
645 
646  idx = 0
647  for axis, atype in [(_("X-Axis"), 'x-axis'),
648  (_("Y-Axis"), 'y-axis')]:
649  box = wx.StaticBox(parent = self, id = wx.ID_ANY,
650  label = " %s " % axis)
651  boxSizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
652  gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
653 
654  prop = self.properties[atype]['prop']
655 
656  row = 0
657  label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Scale"))
658  gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (row, 0))
659  type = wx.Choice(parent = self, id = wx.ID_ANY,
660  size = (100, -1), choices = self.axislist)
661  type.SetStringSelection(prop['type'])
662  type.SetToolTipString(_("Automatic axis scaling, custom max and min, or scale matches data range (min)" ))
663  self.wxId[atype]['type'] = type.GetId()
664  gridSizer.Add(item = type, pos = (row, 1))
665 
666  row += 1
667  label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Custom min"))
668  gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (row, 0))
669  min = wx.TextCtrl(parent = self, id = wx.ID_ANY, value = "", size = (70, -1))
670  min.SetValue(str(prop['min']))
671  self.wxId[atype]['min'] = min.GetId()
672  gridSizer.Add(item = min, pos = (row, 1))
673 
674  row += 1
675  label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Custom max"))
676  gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (row, 0))
677  max = wx.TextCtrl(parent = self, id = wx.ID_ANY, value = "", size = (70, -1))
678  max.SetValue(str(prop['max']))
679  self.wxId[atype]['max'] = max.GetId()
680  gridSizer.Add(item = max, pos = (row, 1))
681 
682  row += 1
683  log = wx.CheckBox(parent = self, id = wx.ID_ANY, label = _("Log scale"))
684  log.SetValue(prop['log'])
685  self.wxId[atype]['log'] = log.GetId()
686  gridSizer.Add(item = log, pos = (row, 0), span = (1, 2))
687 
688  if idx == 0:
689  flag = wx.ALL | wx.EXPAND
690  else:
691  flag = wx.TOP | wx.BOTTOM | wx.RIGHT | wx.EXPAND
692 
693  boxSizer.Add(item = gridSizer, flag = wx.ALL, border = 3)
694  boxMainSizer.Add(item = boxSizer, flag = flag, border = 3)
695 
696  idx += 1
697 
698  middleSizer.Add(item = boxMainSizer, flag = wx.ALL | wx.EXPAND, border = 3)
699 
700  #
701  # grid & legend options for all plots
702  #
703  self.wxId['grid'] = {}
704  self.wxId['legend'] = {}
705  self.wxId['font'] = {}
706  box = wx.StaticBox(parent = self, id = wx.ID_ANY,
707  label = " %s " % _("Grid and Legend settings"))
708  boxMainSizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
709  gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
710 
711  row = 0
712  label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Grid color"))
713  gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (row, 0))
714  gridcolor = csel.ColourSelect(parent = self, id = wx.ID_ANY, colour = self.properties['grid']['color'])
715  self.wxId['grid']['color'] = gridcolor.GetId()
716  gridSizer.Add(item = gridcolor, pos = (row, 1))
717 
718  row +=1
719  gridshow = wx.CheckBox(parent = self, id = wx.ID_ANY, label = _("Show grid"))
720  gridshow.SetValue(self.properties['grid']['enabled'])
721  self.wxId['grid']['enabled'] = gridshow.GetId()
722  gridSizer.Add(item = gridshow, pos = (row, 0), span = (1, 2))
723 
724  row +=1
725  label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Legend font size"))
726  gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (row, 0))
727  legendfontsize = wx.SpinCtrl(parent = self, id = wx.ID_ANY, value = "",
728  size = (50, -1), style = wx.SP_ARROW_KEYS)
729  legendfontsize.SetRange(5,100)
730  legendfontsize.SetValue(int(self.properties['font']['prop']['legendSize']))
731  self.wxId['font']['legendSize'] = legendfontsize.GetId()
732  gridSizer.Add(item = legendfontsize, pos = (row, 1))
733 
734  row += 1
735  legendshow = wx.CheckBox(parent = self, id = wx.ID_ANY, label = _("Show legend"))
736  legendshow.SetValue(self.properties['legend']['enabled'])
737  self.wxId['legend']['enabled'] = legendshow.GetId()
738  gridSizer.Add(item = legendshow, pos = (row, 0), span = (1, 2))
739 
740  boxMainSizer.Add(item = gridSizer, flag = flag, border = 3)
741 
742  middleSizer.Add(item = boxMainSizer, flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 3)
743 
744  sizer.Add(item = middleSizer, flag = wx.ALL, border = 0)
745 
746  #
747  # line & buttons
748  #
749  line = wx.StaticLine(parent = self, id = wx.ID_ANY, size = (20, -1), style = wx.LI_HORIZONTAL)
750  sizer.Add(item = line, proportion = 0,
751  flag = wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.LEFT|wx.RIGHT, border = 3)
752 
753  #
754  # buttons
755  #
756  btnSave = wx.Button(self, wx.ID_SAVE)
757  btnApply = wx.Button(self, wx.ID_APPLY)
758  btnOk = wx.Button(self, wx.ID_OK)
759  btnCancel = wx.Button(self, wx.ID_CANCEL)
760  btnOk.SetDefault()
761 
762  # tooltips for buttons
763  btnApply.SetToolTipString(_("Apply changes for the current session"))
764  btnOk.SetToolTipString(_("Apply changes for the current session and close dialog"))
765  btnSave.SetToolTipString(_("Apply and save changes to user settings file (default for next sessions)"))
766  btnCancel.SetToolTipString(_("Close dialog and ignore changes"))
767 
768  # sizers
769  btnStdSizer = wx.StdDialogButtonSizer()
770  btnStdSizer.AddButton(btnOk)
771  btnStdSizer.AddButton(btnApply)
772  btnStdSizer.AddButton(btnCancel)
773  btnStdSizer.Realize()
774 
775  btnSizer = wx.BoxSizer(wx.HORIZONTAL)
776  btnSizer.Add(item = btnSave, proportion = 0, flag = wx.ALIGN_LEFT | wx.ALL, border = 5)
777  btnSizer.Add(item = btnStdSizer, proportion = 0, flag = wx.ALIGN_RIGHT | wx.ALL, border = 5)
778  sizer.Add(item = btnSizer, proportion = 0, flag = wx.ALIGN_RIGHT | wx.ALL, border = 5)
779 
780  #
781  # bindings for buttons and map plot settings controls
782  #
783  self.mapchoice.Bind(wx.EVT_CHOICE, self.OnSetMap)
784 
785  # bindings
786  btnApply.Bind(wx.EVT_BUTTON, self.OnApply)
787  btnOk.Bind(wx.EVT_BUTTON, self.OnOk)
788  btnOk.SetDefault()
789  btnSave.Bind(wx.EVT_BUTTON, self.OnSave)
790  btnCancel.Bind(wx.EVT_BUTTON, self.OnCancel)
791 
792  self.SetSizer(sizer)
793  sizer.Fit(self)
794 
795  def OnSetMap(self, event):
796  """!Handler for changing map selection"""
797  idx = event.GetSelection()
798  self.map = self.rasterList[idx]
799 
800  # update settings controls for all plots
801  self.FindWindowById(self.wxId['pcolor']).SetColour(self.raster[self.map]['pcolor'])
802  self.FindWindowById(self.wxId['plegend']).SetValue(self.raster[self.map]['plegend'])
803  self.FindWindowById(self.wxId['pwidth']).SetValue(self.raster[self.map]['pwidth'])
804  self.FindWindowById(self.wxId['pstyle']).SetStringSelection(self.raster[self.map]['pstyle'])
805 
806  self.Refresh()
807 
808  def OnSetOpt(self, event):
809  """!Handler for changing any other option"""
810  self.map = self.rasterList[self.mapchoice.GetCurrentSelection()]
811  self.UpdateSettings()
812  self.parent.SetGraphStyle()
813  p = self.parent.CreatePlotList()
814  self.parent.DrawPlot(p)
815 
816  def UpdateSettings(self):
817  """!Apply settings to each map and to entire plot"""
818  self.raster[self.map]['pcolor'] = self.FindWindowById(self.wxId['pcolor']).GetColour()
819  self.properties['raster']['pcolor'] = self.raster[self.map]['pcolor']
820 
821  self.raster[self.map]['plegend'] = self.FindWindowById(self.wxId['plegend']).GetValue()
822 
823  self.raster[self.map]['pwidth'] = int(self.FindWindowById(self.wxId['pwidth']).GetValue())
824  self.properties['raster']['pwidth'] = self.raster[self.map]['pwidth']
825  self.raster[self.map]['pstyle'] = self.FindWindowById(self.wxId['pstyle']).GetStringSelection()
826  self.properties['raster']['pstyle'] = self.raster[self.map]['pstyle']
827 
828  # update settings for entire plot
829  for axis in ('x-axis', 'y-axis'):
830  self.properties[axis]['prop']['type'] = self.FindWindowById(self.wxId[axis]['type']).GetStringSelection()
831  self.properties[axis]['prop']['min'] = float(self.FindWindowById(self.wxId[axis]['min']).GetValue())
832  self.properties[axis]['prop']['max'] = float(self.FindWindowById(self.wxId[axis]['max']).GetValue())
833  self.properties[axis]['prop']['log'] = self.FindWindowById(self.wxId[axis]['log']).IsChecked()
834 
835  if self.plottype == 'profile':
836  self.properties['marker']['color'] = self.FindWindowById(self.wxId['marker']['color']).GetColour()
837  self.properties['marker']['fill'] = self.FindWindowById(self.wxId['marker']['fill']).GetStringSelection()
838  self.properties['marker']['size'] = self.FindWindowById(self.wxId['marker']['size']).GetValue()
839  self.properties['marker']['type'] = self.FindWindowById(self.wxId['marker']['type']).GetStringSelection()
840  self.properties['marker']['legend'] = self.FindWindowById(self.wxId['marker']['legend']).GetValue()
841 
842  self.properties['grid']['color'] = self.FindWindowById(self.wxId['grid']['color']).GetColour()
843  self.properties['grid']['enabled'] = self.FindWindowById(self.wxId['grid']['enabled']).IsChecked()
844 
845  # this makes more sense in the text properties, including for settings update. But will need to change
846  # layout for controls to text dialog too.
847  self.properties['font']['prop']['legendSize'] = self.FindWindowById(self.wxId['font']['legendSize']).GetValue()
848  self.properties['legend']['enabled'] = self.FindWindowById(self.wxId['legend']['enabled']).IsChecked()
849 
850  def OnSave(self, event):
851  """!Button 'Save' pressed"""
852  self.OnApply(None)
853  fileSettings = {}
854  UserSettings.ReadSettingsFile(settings = fileSettings)
855  fileSettings[self.plottype] = UserSettings.Get(group = self.plottype)
856  UserSettings.SaveToFile(fileSettings)
857  self.parent.parent.GetLayerManager().goutput.WriteLog(_('Plot settings saved to file \'%s\'.') % UserSettings.filePath)
858  self.Close()
859 
860  def OnApply(self, event):
861  """!Button 'Apply' pressed. Does not close dialog"""
862  self.UpdateSettings()
863  self.parent.SetGraphStyle()
864  p = self.parent.CreatePlotList()
865  self.parent.DrawPlot(p)
866 
867  def OnOk(self, event):
868  """!Button 'OK' pressed"""
869  self.OnApply(None)
870  self.EndModal(wx.ID_OK)
871 
872  def OnCancel(self, event):
873  """!Button 'Cancel' pressed"""
874  self.Close()
875 
def OnSetMap
Handler for changing map selection.
def OnSave
Button 'Save' pressed.
def OnCancel
Button 'Cancel' pressed.
def GetValue
Definition: widgets.py:118
def OnSelection
Choose maps to profile.
def OnOk
Button 'OK' pressed.
def __init__
Dialog to set various options for data plotted, including: line width, color, style; marker size...
def OnCancel
Button 'Cancel' pressed.
def OnSetOpt
Handler for changing any other option.
def OnClose
Button 'Close' pressed.
def SetValue
Definition: widgets.py:115
def OnOk
Button 'OK' pressed.
def __init__
Dialog to select raster maps to profile.
Custom control that selects elements.
def __init__
Dialog to display and save statistics for plots.
def split
Platform spefic shlex.split.
Definition: core/utils.py:37
def OnSave
Button 'Save' pressed.
def UpdateSettings
Apply settings to each map and to entire plot.
def OnCopy
Copy the regression stats to the clipboard.
def OnApply
Button 'Apply' pressed.
Default GUI settings.
def _do_layout
Do layout.
def OnApply
Button 'Apply' pressed.
def _do_layout
Options dialog layout.