wxplot_dialogs.py 48 KB

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