wxplot_dialogs.py 48 KB

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