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