dialogs.py 53 KB

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