dialogs.py 52 KB

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