dialogs.py 52 KB

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