dialogs.py 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244
  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-2012 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 not in [None, '', ['']]:
  376. self.rasterList = ret
  377. else:
  378. wx.MessageBox(message = _("Selected group must be in current mapset"),
  379. caption = _('Invalid input'),
  380. style = wx.OK|wx.ICON_ERROR)
  381. def OnSetBins(self, event):
  382. """!Bins for histogramming FP maps (=nsteps in r.stats)
  383. """
  384. self.bins = self.spinbins.GetValue()
  385. def OnSetHisttypes(self, event):
  386. self.histtype = event.GetString()
  387. class TextDialog(wx.Dialog):
  388. def __init__(self, parent, id, title, plottype = '',
  389. style = wx.DEFAULT_DIALOG_STYLE, **kwargs):
  390. """!Dialog to set histogram text options: font, title
  391. and font size, axis labels and font size
  392. """
  393. wx.Dialog.__init__(self, parent, id, title, style = style, **kwargs)
  394. #
  395. # initialize variables
  396. #
  397. # combo box entry lists
  398. self.ffamilydict = { 'default' : wx.FONTFAMILY_DEFAULT,
  399. 'decorative' : wx.FONTFAMILY_DECORATIVE,
  400. 'roman' : wx.FONTFAMILY_ROMAN,
  401. 'script' : wx.FONTFAMILY_SCRIPT,
  402. 'swiss' : wx.FONTFAMILY_SWISS,
  403. 'modern' : wx.FONTFAMILY_MODERN,
  404. 'teletype' : wx.FONTFAMILY_TELETYPE }
  405. self.fstyledict = { 'normal' : wx.FONTSTYLE_NORMAL,
  406. 'slant' : wx.FONTSTYLE_SLANT,
  407. 'italic' : wx.FONTSTYLE_ITALIC }
  408. self.fwtdict = { 'normal' : wx.FONTWEIGHT_NORMAL,
  409. 'light' : wx.FONTWEIGHT_LIGHT,
  410. 'bold' : wx.FONTWEIGHT_BOLD }
  411. self.parent = parent
  412. self.plottype = plottype
  413. self.ptitle = self.parent.ptitle
  414. self.xlabel = self.parent.xlabel
  415. self.ylabel = self.parent.ylabel
  416. self.properties = self.parent.properties # read-only
  417. # font size
  418. self.fontfamily = self.properties['font']['wxfont'].GetFamily()
  419. self.fontstyle = self.properties['font']['wxfont'].GetStyle()
  420. self.fontweight = self.properties['font']['wxfont'].GetWeight()
  421. self._do_layout()
  422. def _do_layout(self):
  423. """!Do layout"""
  424. # dialog layout
  425. sizer = wx.BoxSizer(wx.VERTICAL)
  426. box = wx.StaticBox(parent = self, id = wx.ID_ANY,
  427. label = " %s " % _("Text settings"))
  428. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  429. gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
  430. #
  431. # profile title
  432. #
  433. label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Profile title:"))
  434. gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (0, 0))
  435. self.ptitleentry = wx.TextCtrl(parent = self, id = wx.ID_ANY, value = "", size = (250,-1))
  436. # self.ptitleentry.SetFont(self.font)
  437. self.ptitleentry.SetValue(self.ptitle)
  438. gridSizer.Add(item = self.ptitleentry, pos = (0, 1))
  439. #
  440. # title font
  441. #
  442. tlabel = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Title font size (pts):"))
  443. gridSizer.Add(item = tlabel, flag = wx.ALIGN_CENTER_VERTICAL, pos = (1, 0))
  444. self.ptitlesize = wx.SpinCtrl(parent = self, id = wx.ID_ANY, value = "", pos = (30, 50),
  445. size = (50,-1), style = wx.SP_ARROW_KEYS)
  446. self.ptitlesize.SetRange(5,100)
  447. self.ptitlesize.SetValue(int(self.properties['font']['prop']['titleSize']))
  448. gridSizer.Add(item = self.ptitlesize, pos = (1, 1))
  449. #
  450. # x-axis label
  451. #
  452. label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("X-axis label:"))
  453. gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (2, 0))
  454. self.xlabelentry = wx.TextCtrl(parent = self, id = wx.ID_ANY, value = "", size = (250,-1))
  455. # self.xlabelentry.SetFont(self.font)
  456. self.xlabelentry.SetValue(self.xlabel)
  457. gridSizer.Add(item = self.xlabelentry, pos = (2, 1))
  458. #
  459. # y-axis label
  460. #
  461. label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Y-axis label:"))
  462. gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (3, 0))
  463. self.ylabelentry = wx.TextCtrl(parent = self, id = wx.ID_ANY, value = "", size = (250,-1))
  464. # self.ylabelentry.SetFont(self.font)
  465. self.ylabelentry.SetValue(self.ylabel)
  466. gridSizer.Add(item = self.ylabelentry, pos = (3, 1))
  467. #
  468. # font size
  469. #
  470. llabel = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Label font size (pts):"))
  471. gridSizer.Add(item = llabel, flag = wx.ALIGN_CENTER_VERTICAL, pos = (4, 0))
  472. self.axislabelsize = wx.SpinCtrl(parent = self, id = wx.ID_ANY, value = "", pos = (30, 50),
  473. size = (50, -1), style = wx.SP_ARROW_KEYS)
  474. self.axislabelsize.SetRange(5, 100)
  475. self.axislabelsize.SetValue(int(self.properties['font']['prop']['axisSize']))
  476. gridSizer.Add(item = self.axislabelsize, pos = (4,1))
  477. boxSizer.Add(item = gridSizer)
  478. sizer.Add(item = boxSizer, flag = wx.ALL | wx.EXPAND, border = 3)
  479. #
  480. # font settings
  481. #
  482. box = wx.StaticBox(parent = self, id = wx.ID_ANY,
  483. label = " %s " % _("Font settings"))
  484. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  485. gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
  486. gridSizer.AddGrowableCol(1)
  487. #
  488. # font family
  489. #
  490. label1 = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Font family:"))
  491. gridSizer.Add(item = label1, flag = wx.ALIGN_CENTER_VERTICAL, pos = (0, 0))
  492. self.ffamilycb = wx.ComboBox(parent = self, id = wx.ID_ANY, size = (250, -1),
  493. choices = self.ffamilydict.keys(), style = wx.CB_DROPDOWN)
  494. self.ffamilycb.SetStringSelection('swiss')
  495. for item in self.ffamilydict.items():
  496. if self.fontfamily == item[1]:
  497. self.ffamilycb.SetStringSelection(item[0])
  498. break
  499. gridSizer.Add(item = self.ffamilycb, pos = (0, 1), flag = wx.ALIGN_RIGHT)
  500. #
  501. # font style
  502. #
  503. label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Style:"))
  504. gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (1, 0))
  505. self.fstylecb = wx.ComboBox(parent = self, id = wx.ID_ANY, size = (250, -1),
  506. choices = self.fstyledict.keys(), style = wx.CB_DROPDOWN)
  507. self.fstylecb.SetStringSelection('normal')
  508. for item in self.fstyledict.items():
  509. if self.fontstyle == item[1]:
  510. self.fstylecb.SetStringSelection(item[0])
  511. break
  512. gridSizer.Add(item = self.fstylecb, pos = (1, 1), flag = wx.ALIGN_RIGHT)
  513. #
  514. # font weight
  515. #
  516. label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Weight:"))
  517. gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (2, 0))
  518. self.fwtcb = wx.ComboBox(parent = self, size = (250, -1),
  519. choices = self.fwtdict.keys(), style = wx.CB_DROPDOWN)
  520. self.fwtcb.SetStringSelection('normal')
  521. for item in self.fwtdict.items():
  522. if self.fontweight == item[1]:
  523. self.fwtcb.SetStringSelection(item[0])
  524. break
  525. gridSizer.Add(item = self.fwtcb, pos = (2, 1), flag = wx.ALIGN_RIGHT)
  526. boxSizer.Add(item = gridSizer, flag = wx.EXPAND)
  527. sizer.Add(item = boxSizer, flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 3)
  528. line = wx.StaticLine(parent = self, id = wx.ID_ANY, size = (20, -1), style = wx.LI_HORIZONTAL)
  529. sizer.Add(item = line, proportion = 0,
  530. flag = wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.LEFT|wx.RIGHT, border = 3)
  531. #
  532. # buttons
  533. #
  534. btnSave = wx.Button(self, wx.ID_SAVE)
  535. btnApply = wx.Button(self, wx.ID_APPLY)
  536. btnOk = wx.Button(self, wx.ID_OK)
  537. btnCancel = wx.Button(self, wx.ID_CANCEL)
  538. btnOk.SetDefault()
  539. # bindings
  540. btnApply.Bind(wx.EVT_BUTTON, self.OnApply)
  541. btnApply.SetToolTipString(_("Apply changes for the current session"))
  542. btnOk.Bind(wx.EVT_BUTTON, self.OnOk)
  543. btnOk.SetToolTipString(_("Apply changes for the current session and close dialog"))
  544. btnOk.SetDefault()
  545. btnSave.Bind(wx.EVT_BUTTON, self.OnSave)
  546. btnSave.SetToolTipString(_("Apply and save changes to user settings file (default for next sessions)"))
  547. btnCancel.Bind(wx.EVT_BUTTON, self.OnCancel)
  548. btnCancel.SetToolTipString(_("Close dialog and ignore changes"))
  549. # sizers
  550. btnStdSizer = wx.StdDialogButtonSizer()
  551. btnStdSizer.AddButton(btnOk)
  552. btnStdSizer.AddButton(btnApply)
  553. btnStdSizer.AddButton(btnCancel)
  554. btnStdSizer.Realize()
  555. btnSizer = wx.BoxSizer(wx.HORIZONTAL)
  556. btnSizer.Add(item = btnSave, proportion = 0, flag = wx.ALIGN_LEFT | wx.ALL, border = 5)
  557. btnSizer.Add(item = btnStdSizer, proportion = 0, flag = wx.ALIGN_RIGHT | wx.ALL, border = 5)
  558. sizer.Add(item = btnSizer, proportion = 0, flag = wx.ALIGN_RIGHT | wx.ALL, border = 5)
  559. #
  560. # bindings
  561. #
  562. self.ptitleentry.Bind(wx.EVT_TEXT, self.OnTitle)
  563. self.xlabelentry.Bind(wx.EVT_TEXT, self.OnXLabel)
  564. self.ylabelentry.Bind(wx.EVT_TEXT, self.OnYLabel)
  565. self.SetSizer(sizer)
  566. sizer.Fit(self)
  567. def OnTitle(self, event):
  568. self.ptitle = event.GetString()
  569. def OnXLabel(self, event):
  570. self.xlabel = event.GetString()
  571. def OnYLabel(self, event):
  572. self.ylabel = event.GetString()
  573. def UpdateSettings(self):
  574. self.properties['font']['prop']['titleSize'] = self.ptitlesize.GetValue()
  575. self.properties['font']['prop']['axisSize'] = self.axislabelsize.GetValue()
  576. family = self.ffamilydict[self.ffamilycb.GetStringSelection()]
  577. self.properties['font']['wxfont'].SetFamily(family)
  578. style = self.fstyledict[self.fstylecb.GetStringSelection()]
  579. self.properties['font']['wxfont'].SetStyle(style)
  580. weight = self.fwtdict[self.fwtcb.GetStringSelection()]
  581. self.properties['font']['wxfont'].SetWeight(weight)
  582. def OnSave(self, event):
  583. """!Button 'Save' pressed"""
  584. self.OnApply(None)
  585. fileSettings = {}
  586. UserSettings.ReadSettingsFile(settings = fileSettings)
  587. fileSettings[self.plottype] = UserSettings.Get(group = self.plottype)
  588. UserSettings.SaveToFile(fileSettings)
  589. self.parent.parent.GetLayerManager().GetLogWindow().WriteLog(_('Plot text sizes saved to file \'%s\'.') % UserSettings.filePath)
  590. self.EndModal(wx.ID_OK)
  591. def OnApply(self, event):
  592. """!Button 'Apply' pressed"""
  593. self.UpdateSettings()
  594. self.parent.OnPlotText(self)
  595. def OnOk(self, event):
  596. """!Button 'OK' pressed"""
  597. self.OnApply(None)
  598. self.EndModal(wx.ID_OK)
  599. def OnCancel(self, event):
  600. """!Button 'Cancel' pressed"""
  601. self.EndModal(wx.ID_CANCEL)
  602. class OptDialog(wx.Dialog):
  603. def __init__(self, parent, id, title, plottype = '',
  604. style = wx.DEFAULT_DIALOG_STYLE, **kwargs):
  605. """!Dialog to set various options for data plotted, including: line
  606. width, color, style; marker size, color, fill, and style; grid
  607. and legend options.
  608. """
  609. wx.Dialog.__init__(self, parent, id, title, style = style, **kwargs)
  610. # init variables
  611. self.parent = parent
  612. self.linestyledict = parent.linestyledict
  613. self.ptfilldict = parent.ptfilldict
  614. self.parent = parent
  615. self.plottype = plottype
  616. self.pttypelist = ['circle',
  617. 'dot',
  618. 'square',
  619. 'triangle',
  620. 'triangle_down',
  621. 'cross',
  622. 'plus']
  623. self.axislist = ['min',
  624. 'auto',
  625. 'custom']
  626. # widgets ids
  627. self.wxId = {}
  628. self.parent = parent
  629. # read-only
  630. self.raster = self.parent.raster
  631. self.rasterList = self.parent.rasterList
  632. self.properties = self.parent.properties
  633. self.map = ''
  634. if len(self.rasterList) == 0:
  635. wx.MessageBox(parent = self,
  636. message = _("No map or image group selected to plot."),
  637. caption = _("Warning"), style = wx.OK | wx.ICON_ERROR)
  638. self._do_layout()
  639. def ConvertTuples(self, tlist):
  640. """!Converts tuples to strings when rasterList contains raster pairs
  641. for scatterplot
  642. """
  643. list = []
  644. for i in tlist:
  645. i = str(i).strip('()')
  646. list.append(i)
  647. return list
  648. def _do_layout(self):
  649. """!Options dialog layout
  650. """
  651. sizer = wx.BoxSizer(wx.VERTICAL)
  652. box = wx.StaticBox(parent = self, id = wx.ID_ANY,
  653. label = " %s " % _("Plot settings"))
  654. boxMainSizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
  655. self.wxId['pcolor'] = 0
  656. self.wxId['pwidth'] = 0
  657. self.wxId['pstyle'] = 0
  658. self.wxId['psize'] = 0
  659. self.wxId['ptype'] = 0
  660. self.wxId['pfill'] = 0
  661. self.wxId['plegend'] = 0
  662. self.wxId['marker'] = {}
  663. self.wxId['x-axis'] = {}
  664. self.wxId['y-axis'] = {}
  665. #
  666. # plot line settings and point settings
  667. #
  668. if len(self.rasterList) == 0: return
  669. box = wx.StaticBox(parent = self, id = wx.ID_ANY,
  670. label = _("Map/image plotted"))
  671. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  672. gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
  673. row = 0
  674. choicelist = []
  675. for i in self.rasterList:
  676. choicelist.append(str(i))
  677. self.mapchoice = wx.Choice(parent = self, id = wx.ID_ANY, size = (300, -1),
  678. choices = choicelist)
  679. self.mapchoice.SetToolTipString(_("Settings for selected map"))
  680. if not self.map:
  681. self.map = self.rasterList[self.mapchoice.GetCurrentSelection()]
  682. else:
  683. self.mapchoice.SetStringSelection(str(self.map))
  684. gridSizer.Add(item = self.mapchoice, flag = wx.ALIGN_CENTER_VERTICAL,
  685. pos = (row, 0), span = (1, 2))
  686. #
  687. # options for line plots (profiles and histograms)
  688. #
  689. if self.plottype != 'scatter':
  690. row +=1
  691. label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Line color"))
  692. gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (row, 0))
  693. color = csel.ColourSelect(parent = self, id = wx.ID_ANY, colour = self.raster[self.map]['pcolor'])
  694. self.wxId['pcolor'] = color.GetId()
  695. gridSizer.Add(item = color, pos = (row, 1))
  696. row += 1
  697. label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Line width"))
  698. gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (row, 0))
  699. width = wx.SpinCtrl(parent = self, id = wx.ID_ANY, value = "",
  700. size = (50,-1), style = wx.SP_ARROW_KEYS)
  701. width.SetRange(1, 10)
  702. width.SetValue(self.raster[self.map]['pwidth'])
  703. self.wxId['pwidth'] = width.GetId()
  704. gridSizer.Add(item = width, pos = (row, 1))
  705. row +=1
  706. label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Line style"))
  707. gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (row, 0))
  708. style = wx.Choice(parent = self, id = wx.ID_ANY,
  709. size = (120, -1), choices = self.linestyledict.keys())
  710. style.SetStringSelection(self.raster[self.map]['pstyle'])
  711. self.wxId['pstyle'] = style.GetId()
  712. gridSizer.Add(item = style, pos = (row, 1))
  713. row += 1
  714. label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Legend"))
  715. gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (row, 0))
  716. legend = wx.TextCtrl(parent = self, id = wx.ID_ANY, value = "", size = (200,-1))
  717. legend.SetValue(self.raster[self.map]['plegend'])
  718. gridSizer.Add(item = legend, pos = (row, 1))
  719. self.wxId['plegend'] = legend.GetId()
  720. boxSizer.Add(item = gridSizer)
  721. boxMainSizer.Add(item = boxSizer, flag = wx.ALL, border = 3)
  722. #
  723. # segment marker settings for profiles only
  724. #
  725. if self.plottype == 'profile':
  726. box = wx.StaticBox(parent = self, id = wx.ID_ANY,
  727. label = " %s " % _("Transect segment marker settings"))
  728. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  729. gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
  730. label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Color"))
  731. gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (0, 0))
  732. ptcolor = csel.ColourSelect(parent = self, id = wx.ID_ANY, colour = self.properties['marker']['color'])
  733. self.wxId['marker']['color'] = ptcolor.GetId()
  734. gridSizer.Add(item = ptcolor, pos = (0, 1))
  735. label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Size"))
  736. gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (1, 0))
  737. ptsize = wx.SpinCtrl(parent = self, id = wx.ID_ANY, value = "",
  738. size = (50, -1), style = wx.SP_ARROW_KEYS)
  739. ptsize.SetRange(1, 10)
  740. ptsize.SetValue(self.properties['marker']['size'])
  741. self.wxId['marker']['size'] = ptsize.GetId()
  742. gridSizer.Add(item = ptsize, pos = (1, 1))
  743. label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Fill"))
  744. gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (2, 0))
  745. ptfill = wx.Choice(parent = self, id = wx.ID_ANY,
  746. size = (120, -1), choices = self.ptfilldict.keys())
  747. ptfill.SetStringSelection(self.properties['marker']['fill'])
  748. self.wxId['marker']['fill'] = ptfill.GetId()
  749. gridSizer.Add(item = ptfill, pos = (2, 1))
  750. label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Legend"))
  751. gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (3, 0))
  752. ptlegend = wx.TextCtrl(parent = self, id = wx.ID_ANY, value = "", size = (200,-1))
  753. ptlegend.SetValue(self.properties['marker']['legend'])
  754. self.wxId['marker']['legend'] = ptlegend.GetId()
  755. gridSizer.Add(item = ptlegend, pos = (3, 1))
  756. label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Style"))
  757. gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (4, 0))
  758. pttype = wx.Choice(parent = self, size = (200, -1), choices = self.pttypelist)
  759. pttype.SetStringSelection(self.properties['marker']['type'])
  760. self.wxId['marker']['type'] = pttype.GetId()
  761. gridSizer.Add(item = pttype, pos = (4, 1))
  762. boxSizer.Add(item = gridSizer)
  763. boxMainSizer.Add(item = boxSizer, flag = wx.ALL, border = 3)
  764. #
  765. # point options for scatterplots
  766. #
  767. elif self.plottype == 'scatter':
  768. box = wx.StaticBox(parent = self, id = wx.ID_ANY,
  769. label = " %s " % _("Scatterplot points"))
  770. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  771. gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
  772. label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Color"))
  773. gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (0, 0))
  774. ptcolor = csel.ColourSelect(parent = self, id = wx.ID_ANY, colour = self.raster[self.map]['pcolor'])
  775. self.wxId['pcolor'] = ptcolor.GetId()
  776. gridSizer.Add(item = ptcolor, pos = (0, 1))
  777. label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Size"))
  778. gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (1, 0))
  779. ptsize = wx.SpinCtrl(parent = self, id = wx.ID_ANY, value = "",
  780. size = (50, -1), style = wx.SP_ARROW_KEYS)
  781. ptsize.SetRange(1, 10)
  782. ptsize.SetValue(self.raster[self.map]['psize'])
  783. self.wxId['psize'] = ptsize.GetId()
  784. gridSizer.Add(item = ptsize, pos = (1, 1))
  785. label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Fill"))
  786. gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (2, 0))
  787. ptfill = wx.Choice(parent = self, id = wx.ID_ANY,
  788. size = (120, -1), choices = self.ptfilldict.keys())
  789. ptfill.SetStringSelection(self.raster[self.map]['pfill'])
  790. self.wxId['pfill'] = ptfill.GetId()
  791. gridSizer.Add(item = ptfill, pos = (2, 1))
  792. label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Legend"))
  793. gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (3, 0))
  794. ptlegend = wx.TextCtrl(parent = self, id = wx.ID_ANY, value = "", size = (200,-1))
  795. ptlegend.SetValue(self.raster[self.map]['plegend'])
  796. self.wxId['plegend'] = ptlegend.GetId()
  797. gridSizer.Add(item = ptlegend, pos = (3, 1))
  798. label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Style"))
  799. gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (4, 0))
  800. pttype = wx.Choice(parent = self, size = (200, -1), choices = self.pttypelist)
  801. pttype.SetStringSelection(self.raster[self.map]['ptype'])
  802. self.wxId['ptype'] = pttype.GetId()
  803. gridSizer.Add(item = pttype, pos = (4, 1))
  804. boxSizer.Add(item = gridSizer)
  805. boxMainSizer.Add(item = boxSizer, flag = wx.ALL, border = 3)
  806. sizer.Add(item = boxMainSizer, flag = wx.ALL | wx.EXPAND, border = 3)
  807. #
  808. # axis options for all plots
  809. #
  810. box = wx.StaticBox(parent = self, id = wx.ID_ANY,
  811. label = " %s " % _("Axis settings"))
  812. boxMainSizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
  813. middleSizer = wx.BoxSizer(wx.HORIZONTAL)
  814. idx = 0
  815. for axis, atype in [(_("X-Axis"), 'x-axis'),
  816. (_("Y-Axis"), 'y-axis')]:
  817. box = wx.StaticBox(parent = self, id = wx.ID_ANY,
  818. label = " %s " % axis)
  819. boxSizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
  820. gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
  821. prop = self.properties[atype]['prop']
  822. row = 0
  823. label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Scale"))
  824. gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (row, 0))
  825. type = wx.Choice(parent = self, id = wx.ID_ANY, size = (100, -1), choices = self.axislist)
  826. type.SetStringSelection(prop['type'])
  827. type.SetToolTipString(_("Automatic axis scaling, custom max and min, or scale matches data range (min)" ))
  828. self.wxId[atype]['type'] = type.GetId()
  829. gridSizer.Add(item = type, pos = (row, 1))
  830. row += 1
  831. label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Custom min"))
  832. gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (row, 0))
  833. min = wx.TextCtrl(parent = self, id = wx.ID_ANY, value = "", size = (70, -1))
  834. min.SetValue(str(prop['min']))
  835. self.wxId[atype]['min'] = min.GetId()
  836. gridSizer.Add(item = min, pos = (row, 1))
  837. row += 1
  838. label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Custom max"))
  839. gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (row, 0))
  840. max = wx.TextCtrl(parent = self, id = wx.ID_ANY, value = "", size = (70, -1))
  841. max.SetValue(str(prop['max']))
  842. self.wxId[atype]['max'] = max.GetId()
  843. gridSizer.Add(item = max, pos = (row, 1))
  844. row += 1
  845. log = wx.CheckBox(parent = self, id = wx.ID_ANY, label = _("Log scale"))
  846. log.SetValue(prop['log'])
  847. self.wxId[atype]['log'] = log.GetId()
  848. gridSizer.Add(item = log, pos = (row, 0), span = (1, 2))
  849. if idx == 0:
  850. flag = wx.ALL | wx.EXPAND
  851. else:
  852. flag = wx.TOP | wx.BOTTOM | wx.RIGHT | wx.EXPAND
  853. boxSizer.Add(item = gridSizer, flag = wx.ALL, border = 3)
  854. boxMainSizer.Add(item = boxSizer, flag = flag, border = 3)
  855. idx += 1
  856. middleSizer.Add(item = boxMainSizer, flag = wx.ALL | wx.EXPAND, border = 3)
  857. #
  858. # grid & legend options for all plots
  859. #
  860. self.wxId['grid'] = {}
  861. self.wxId['legend'] = {}
  862. self.wxId['font'] = {}
  863. box = wx.StaticBox(parent = self, id = wx.ID_ANY,
  864. label = " %s " % _("Grid and Legend settings"))
  865. boxMainSizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
  866. gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
  867. row = 0
  868. label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Grid color"))
  869. gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (row, 0))
  870. gridcolor = csel.ColourSelect(parent = self, id = wx.ID_ANY, colour = self.properties['grid']['color'])
  871. self.wxId['grid']['color'] = gridcolor.GetId()
  872. gridSizer.Add(item = gridcolor, pos = (row, 1))
  873. row +=1
  874. gridshow = wx.CheckBox(parent = self, id = wx.ID_ANY, label = _("Show grid"))
  875. gridshow.SetValue(self.properties['grid']['enabled'])
  876. self.wxId['grid']['enabled'] = gridshow.GetId()
  877. gridSizer.Add(item = gridshow, pos = (row, 0), span = (1, 2))
  878. row +=1
  879. label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Legend font size"))
  880. gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (row, 0))
  881. legendfontsize = wx.SpinCtrl(parent = self, id = wx.ID_ANY, value = "",
  882. size = (50, -1), style = wx.SP_ARROW_KEYS)
  883. legendfontsize.SetRange(5,100)
  884. legendfontsize.SetValue(int(self.properties['font']['prop']['legendSize']))
  885. self.wxId['font']['legendSize'] = legendfontsize.GetId()
  886. gridSizer.Add(item = legendfontsize, pos = (row, 1))
  887. row += 1
  888. legendshow = wx.CheckBox(parent = self, id = wx.ID_ANY, label = _("Show legend"))
  889. legendshow.SetValue(self.properties['legend']['enabled'])
  890. self.wxId['legend']['enabled'] = legendshow.GetId()
  891. gridSizer.Add(item = legendshow, pos = (row, 0), span = (1, 2))
  892. boxMainSizer.Add(item = gridSizer, flag = flag, border = 3)
  893. middleSizer.Add(item = boxMainSizer, flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 3)
  894. sizer.Add(item = middleSizer, flag = wx.ALL, border = 0)
  895. #
  896. # line & buttons
  897. #
  898. line = wx.StaticLine(parent = self, id = wx.ID_ANY, size = (20, -1), style = wx.LI_HORIZONTAL)
  899. sizer.Add(item = line, proportion = 0,
  900. flag = wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.LEFT|wx.RIGHT, border = 3)
  901. #
  902. # buttons
  903. #
  904. btnSave = wx.Button(self, wx.ID_SAVE)
  905. btnApply = wx.Button(self, wx.ID_APPLY)
  906. btnOk = wx.Button(self, wx.ID_OK)
  907. btnCancel = wx.Button(self, wx.ID_CANCEL)
  908. btnOk.SetDefault()
  909. # tooltips for buttons
  910. btnApply.SetToolTipString(_("Apply changes for the current session"))
  911. btnOk.SetToolTipString(_("Apply changes for the current session and close dialog"))
  912. btnSave.SetToolTipString(_("Apply and save changes to user settings file (default for next sessions)"))
  913. btnCancel.SetToolTipString(_("Close dialog and ignore changes"))
  914. # sizers
  915. btnStdSizer = wx.StdDialogButtonSizer()
  916. btnStdSizer.AddButton(btnOk)
  917. btnStdSizer.AddButton(btnApply)
  918. btnStdSizer.AddButton(btnCancel)
  919. btnStdSizer.Realize()
  920. btnSizer = wx.BoxSizer(wx.HORIZONTAL)
  921. btnSizer.Add(item = btnSave, proportion = 0, flag = wx.ALIGN_LEFT | wx.ALL, border = 5)
  922. btnSizer.Add(item = btnStdSizer, proportion = 0, flag = wx.ALIGN_RIGHT | wx.ALL, border = 5)
  923. sizer.Add(item = btnSizer, proportion = 0, flag = wx.ALIGN_RIGHT | wx.ALL, border = 5)
  924. #
  925. # bindings for buttons and map plot settings controls
  926. #
  927. self.mapchoice.Bind(wx.EVT_CHOICE, self.OnSetMap)
  928. btnApply.Bind(wx.EVT_BUTTON, self.OnApply)
  929. btnOk.Bind(wx.EVT_BUTTON, self.OnOk)
  930. btnOk.SetDefault()
  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. p = self.parent.CreatePlotList()
  958. self.parent.DrawPlot(p)
  959. def UpdateSettings(self):
  960. """!Apply settings to each map and to entire plot"""
  961. self.raster[self.map]['pcolor'] = self.FindWindowById(self.wxId['pcolor']).GetColour()
  962. self.properties['raster']['pcolor'] = self.raster[self.map]['pcolor']
  963. self.raster[self.map]['plegend'] = self.FindWindowById(self.wxId['plegend']).GetValue()
  964. if self.plottype != 'scatter':
  965. self.raster[self.map]['pwidth'] = int(self.FindWindowById(self.wxId['pwidth']).GetValue())
  966. self.properties['raster']['pwidth'] = self.raster[self.map]['pwidth']
  967. self.raster[self.map]['pstyle'] = self.FindWindowById(self.wxId['pstyle']).GetStringSelection()
  968. self.properties['raster']['pstyle'] = self.raster[self.map]['pstyle']
  969. elif self.plottype == 'scatter':
  970. self.raster[self.map]['psize'] = self.FindWindowById(self.wxId['psize']).GetValue()
  971. self.properties['raster']['psize'] = self.raster[self.map]['psize']
  972. self.raster[self.map]['ptype'] = self.FindWindowById(self.wxId['ptype']).GetStringSelection()
  973. self.properties['raster']['ptype'] = self.raster[self.map]['ptype']
  974. self.raster[self.map]['pfill'] = self.FindWindowById(self.wxId['pfill']).GetStringSelection()
  975. self.properties['raster']['pfill'] = self.raster[self.map]['pfill']
  976. # update settings for entire plot
  977. for axis in ('x-axis', 'y-axis'):
  978. self.properties[axis]['prop']['type'] = self.FindWindowById(self.wxId[axis]['type']).GetStringSelection()
  979. self.properties[axis]['prop']['min'] = float(self.FindWindowById(self.wxId[axis]['min']).GetValue())
  980. self.properties[axis]['prop']['max'] = float(self.FindWindowById(self.wxId[axis]['max']).GetValue())
  981. self.properties[axis]['prop']['log'] = self.FindWindowById(self.wxId[axis]['log']).IsChecked()
  982. if self.plottype == 'profile':
  983. self.properties['marker']['color'] = self.FindWindowById(self.wxId['marker']['color']).GetColour()
  984. self.properties['marker']['fill'] = self.FindWindowById(self.wxId['marker']['fill']).GetStringSelection()
  985. self.properties['marker']['size'] = self.FindWindowById(self.wxId['marker']['size']).GetValue()
  986. self.properties['marker']['type'] = self.FindWindowById(self.wxId['marker']['type']).GetStringSelection()
  987. self.properties['marker']['legend'] = self.FindWindowById(self.wxId['marker']['legend']).GetValue()
  988. self.properties['grid']['color'] = self.FindWindowById(self.wxId['grid']['color']).GetColour()
  989. self.properties['grid']['enabled'] = self.FindWindowById(self.wxId['grid']['enabled']).IsChecked()
  990. # this makes more sense in the text properties, including for settings update. But will need to change
  991. # layout for controls to text dialog too.
  992. self.properties['font']['prop']['legendSize'] = self.FindWindowById(self.wxId['font']['legendSize']).GetValue()
  993. self.properties['legend']['enabled'] = self.FindWindowById(self.wxId['legend']['enabled']).IsChecked()
  994. def OnSave(self, event):
  995. """!Button 'Save' pressed"""
  996. self.OnApply(None)
  997. fileSettings = {}
  998. UserSettings.ReadSettingsFile(settings = fileSettings)
  999. fileSettings[self.plottype] = UserSettings.Get(group = self.plottype)
  1000. UserSettings.SaveToFile(fileSettings)
  1001. self.parent.parent.GetLayerManager().GetLogWindow().WriteLog(_('Plot settings saved to file \'%s\'.') % UserSettings.filePath)
  1002. self.Close()
  1003. def OnApply(self, event):
  1004. """!Button 'Apply' pressed. Does not close dialog"""
  1005. self.UpdateSettings()
  1006. self.parent.SetGraphStyle()
  1007. p = self.parent.CreatePlotList()
  1008. self.parent.DrawPlot(p)
  1009. def OnOk(self, event):
  1010. """!Button 'OK' pressed"""
  1011. self.OnApply(None)
  1012. self.EndModal(wx.ID_OK)
  1013. def OnCancel(self, event):
  1014. """!Button 'Cancel' pressed"""
  1015. self.Close()