dialogs.py 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615
  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-2016 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 os
  17. import wx
  18. import wx.lib.colourselect as csel
  19. import wx.lib.scrolledpanel as scrolled
  20. from core import globalvar
  21. from core.settings import UserSettings
  22. from core.globalvar import ICONDIR
  23. from core.utils import _
  24. from gui_core.gselect import Select
  25. from gui_core.wrap import SpinCtrl
  26. from grass.script import core as grass
  27. class ProfileRasterDialog(wx.Dialog):
  28. def __init__(self, parent, id=wx.ID_ANY,
  29. title=_("Select raster maps to profile"),
  30. style=wx.DEFAULT_DIALOG_STYLE, **kwargs):
  31. """Dialog to select raster maps to profile.
  32. """
  33. wx.Dialog.__init__(self, parent, id, title, style=style, **kwargs)
  34. self.parent = parent
  35. self.colorList = [
  36. "blue",
  37. "red",
  38. "green",
  39. "yellow",
  40. "magenta",
  41. "cyan",
  42. "aqua",
  43. "black",
  44. "grey",
  45. "orange",
  46. "brown",
  47. "purple",
  48. "violet",
  49. "indigo"]
  50. self.rasterList = self.parent.rasterList
  51. self._do_layout()
  52. def _do_layout(self):
  53. sizer = wx.BoxSizer(wx.VERTICAL)
  54. box = wx.GridBagSizer(hgap=3, vgap=3)
  55. rastText = ''
  56. for r in self.rasterList:
  57. rastText += '%s,' % r
  58. rastText = rastText.rstrip(',')
  59. txt = _("Select raster map(s) to profile:")
  60. label = wx.StaticText(parent=self, id=wx.ID_ANY, label=txt)
  61. box.Add(label,
  62. flag=wx.ALIGN_CENTER_VERTICAL, pos=(0, 0))
  63. selection = Select(self, id=wx.ID_ANY,
  64. size=globalvar.DIALOG_GSELECT_SIZE,
  65. type='cell', multiple=True)
  66. selection.SetValue(rastText)
  67. selection.Bind(wx.EVT_TEXT, self.OnSelection)
  68. box.Add(selection, pos=(0, 1))
  69. sizer.Add(box, proportion=0,
  70. flag=wx.ALL, border=10)
  71. line = wx.StaticLine(
  72. parent=self, id=wx.ID_ANY, size=(
  73. 20, -1), style=wx.LI_HORIZONTAL)
  74. sizer.Add(line, proportion=0, flag=wx.GROW |
  75. wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.RIGHT, border=5)
  76. btnsizer = wx.StdDialogButtonSizer()
  77. btn = wx.Button(self, wx.ID_OK)
  78. btn.SetDefault()
  79. btnsizer.AddButton(btn)
  80. btn = wx.Button(self, wx.ID_CANCEL)
  81. btnsizer.AddButton(btn)
  82. btnsizer.Realize()
  83. sizer.Add(
  84. btnsizer,
  85. proportion=0,
  86. flag=wx.ALIGN_RIGHT | wx.ALL,
  87. border=5)
  88. self.SetSizer(sizer)
  89. sizer.Fit(self)
  90. def OnSelection(self, event):
  91. """Choose maps to profile. Convert these into a list
  92. """
  93. self.rasterList = self.FindWindowById(
  94. event.GetId()).GetValue().split(',')
  95. class ScatterRasterDialog(wx.Dialog):
  96. def __init__(self, parent, id=wx.ID_ANY,
  97. title=_("Select pairs of raster maps for scatterplots"),
  98. style=wx.DEFAULT_DIALOG_STYLE, **kwargs):
  99. """Dialog to select raster maps to profile.
  100. """
  101. wx.Dialog.__init__(self, parent, id, title, style=style, **kwargs)
  102. self.parent = parent
  103. self.rasterList = self.parent.rasterList
  104. self.bins = self.parent.bins
  105. self.scattertype = self.parent.scattertype
  106. self.maptype = self.parent.maptype
  107. self.spinbins = ''
  108. self.colorList = [
  109. "blue",
  110. "red",
  111. "green",
  112. "yellow",
  113. "magenta",
  114. "cyan",
  115. "aqua",
  116. "black",
  117. "grey",
  118. "orange",
  119. "brown",
  120. "purple",
  121. "violet",
  122. "indigo"]
  123. self._do_layout()
  124. def _do_layout(self):
  125. sizer = wx.BoxSizer(wx.VERTICAL)
  126. box = wx.GridBagSizer(hgap=3, vgap=3)
  127. # parse raster pair tuples
  128. rastText = ''
  129. if len(self.rasterList) > 0:
  130. for r in self.rasterList:
  131. if isinstance(r, tuple):
  132. rastText += '%s,%s,' % r
  133. else:
  134. rastText += '%s,' % r
  135. rastText = rastText.rstrip(',')
  136. # select rasters
  137. txt = _("Select pairs of raster maps for bivariate scatterplots:")
  138. label = wx.StaticText(parent=self, id=wx.ID_ANY, label=txt)
  139. box.Add(label,
  140. flag=wx.ALIGN_CENTER_VERTICAL, pos=(0, 0))
  141. selection = Select(self, id=wx.ID_ANY,
  142. size=globalvar.DIALOG_GSELECT_SIZE,
  143. type='cell', multiple=True)
  144. selection.SetValue(rastText)
  145. selection.Bind(wx.EVT_TEXT, self.OnSelection)
  146. box.Add(selection, pos=(0, 1))
  147. # Nsteps for FP maps
  148. label = wx.StaticText(parent=self, id=wx.ID_ANY,
  149. label=_("Number of bins (for FP maps)"))
  150. box.Add(label,
  151. flag=wx.ALIGN_CENTER_VERTICAL, pos=(1, 0))
  152. self.spinbins = SpinCtrl(
  153. parent=self, id=wx.ID_ANY, value="", pos=(
  154. 30, 50), size=(
  155. 100, -1), style=wx.SP_ARROW_KEYS)
  156. self.spinbins.SetRange(1, 1000)
  157. self.spinbins.SetValue(self.bins)
  158. box.Add(self.spinbins,
  159. flag=wx.ALIGN_CENTER_VERTICAL, pos=(1, 1))
  160. # TODO possibly make bubble plots with marker size proportional to cell counts
  161. # # scatterplot type
  162. # label = wx.StaticText(parent = self, id = wx.ID_ANY,
  163. # label = _("Scatterplot type"))
  164. # box.Add(item = label,
  165. # flag = wx.ALIGN_CENTER_VERTICAL, pos = (2, 0))
  166. # types = ['normal', 'bubble']
  167. # scattertype = wx.ComboBox(parent = self, id = wx.ID_ANY, size = (250, -1),
  168. # choices = types, style = wx.CB_DROPDOWN)
  169. # scattertype.SetStringSelection(self.scattertype)
  170. # box.Add(item = scattertype,
  171. # flag = wx.ALIGN_CENTER_VERTICAL, pos = (2, 1))
  172. sizer.Add(box, proportion=0,
  173. flag=wx.ALL, border=10)
  174. line = wx.StaticLine(
  175. parent=self, id=wx.ID_ANY, size=(
  176. 20, -1), style=wx.LI_HORIZONTAL)
  177. sizer.Add(line, proportion=0, flag=wx.GROW |
  178. wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.RIGHT, border=5)
  179. btnsizer = wx.StdDialogButtonSizer()
  180. btn = wx.Button(self, wx.ID_OK)
  181. btn.SetDefault()
  182. btnsizer.AddButton(btn)
  183. btn = wx.Button(self, wx.ID_CANCEL)
  184. btnsizer.AddButton(btn)
  185. btnsizer.Realize()
  186. sizer.Add(
  187. btnsizer,
  188. proportion=0,
  189. flag=wx.ALIGN_RIGHT | wx.ALL,
  190. border=5)
  191. self.spinbins.Bind(wx.EVT_TEXT, self.OnSetBins)
  192. self.spinbins.Bind(wx.EVT_SPINCTRL, self.OnSetBins)
  193. # scattertype.Bind(wx.EVT_TEXT, self.OnSetScattertypes)
  194. self.SetSizer(sizer)
  195. sizer.Fit(self)
  196. def OnSelection(self, event):
  197. """Select raster maps for scatterplot. Must select maps in pairs.
  198. """
  199. self.rasterList = self.FindWindowById(
  200. event.GetId()).GetValue().split(',', 1)
  201. def OnSetBins(self, event):
  202. """Bins for histogramming FP maps (=nsteps in r.stats)
  203. """
  204. self.bins = self.spinbins.GetValue()
  205. def OnSetScattertypes(self, event):
  206. self.scattertype = event.GetString()
  207. def GetRasterPairs(self):
  208. """Get raster pairs"""
  209. pairsList = list()
  210. pair = list()
  211. for r in self.rasterList:
  212. pair.append(r)
  213. if len(pair) == 2:
  214. pairsList.append(tuple(pair))
  215. pair = list()
  216. return list(pairsList)
  217. def GetSettings(self):
  218. """Get type and bins"""
  219. return self.scattertype, self.bins
  220. class PlotStatsFrame(wx.Frame):
  221. def __init__(self, parent, id, message='', title='',
  222. style=wx.DEFAULT_FRAME_STYLE, **kwargs):
  223. """Dialog to display and save statistics for plots
  224. """
  225. wx.Frame.__init__(self, parent, id, style=style, **kwargs)
  226. self.SetLabel(_("Statistics"))
  227. self.SetIcon(
  228. wx.Icon(
  229. os.path.join(
  230. ICONDIR,
  231. 'grass.ico'),
  232. wx.BITMAP_TYPE_ICO))
  233. self.panel = wx.Panel(self)
  234. sp = scrolled.ScrolledPanel(
  235. self.panel, -1, size=(400, 400),
  236. style=wx.TAB_TRAVERSAL | wx.SUNKEN_BORDER, name="Statistics")
  237. #
  238. # initialize variables
  239. #
  240. self.parent = parent
  241. self.message = message
  242. self.title = title
  243. self.CenterOnParent()
  244. #
  245. # Display statistics
  246. #
  247. sizer = wx.BoxSizer(wx.VERTICAL)
  248. txtSizer = wx.BoxSizer(wx.VERTICAL)
  249. statstitle = wx.StaticText(
  250. parent=self.panel,
  251. id=wx.ID_ANY,
  252. label=self.title)
  253. sizer.Add(statstitle, proportion=0,
  254. flag=wx.GROW | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=3)
  255. line = wx.StaticLine(
  256. parent=self.panel, id=wx.ID_ANY, size=(
  257. 20, -1), style=wx.LI_HORIZONTAL)
  258. sizer.Add(line, proportion=0,
  259. flag=wx.GROW | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=3)
  260. for stats in self.message:
  261. statstxt = wx.StaticText(parent=sp, id=wx.ID_ANY, label=stats)
  262. statstxt.SetBackgroundColour("WHITE")
  263. txtSizer.Add(
  264. statstxt,
  265. proportion=1,
  266. flag=wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.RIGHT,
  267. border=3)
  268. line = wx.StaticLine(
  269. parent=sp, id=wx.ID_ANY, size=(
  270. 20, -1), style=wx.LI_HORIZONTAL)
  271. txtSizer.Add(line, proportion=0, flag=wx.GROW |
  272. wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=3)
  273. sp.SetSizer(txtSizer)
  274. sp.SetAutoLayout(1)
  275. sp.SetupScrolling()
  276. sizer.Add(sp, proportion=1,
  277. flag=wx.GROW | wx.LEFT | wx.RIGHT | wx.BOTTOM, border=3)
  278. line = wx.StaticLine(
  279. parent=self.panel, id=wx.ID_ANY, size=(
  280. 20, -1), style=wx.LI_HORIZONTAL)
  281. sizer.Add(line, proportion=0, flag=wx.GROW |
  282. wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.RIGHT, border=3)
  283. #
  284. # buttons
  285. #
  286. btnSizer = wx.BoxSizer(wx.HORIZONTAL)
  287. btn_clipboard = wx.Button(self.panel, id=wx.ID_COPY, label=_('C&opy'))
  288. btn_clipboard.SetToolTipString(
  289. _("Copy regression statistics the clipboard (Ctrl+C)"))
  290. btnSizer.Add(
  291. btn_clipboard,
  292. proportion=0,
  293. flag=wx.ALIGN_LEFT | wx.ALL,
  294. border=5)
  295. btnCancel = wx.Button(self.panel, wx.ID_CLOSE)
  296. btnCancel.SetDefault()
  297. btnSizer.Add(
  298. btnCancel,
  299. proportion=0,
  300. flag=wx.ALIGN_RIGHT | wx.ALL,
  301. border=5)
  302. sizer.Add(
  303. btnSizer,
  304. proportion=0,
  305. flag=wx.ALIGN_RIGHT | wx.ALL,
  306. border=5)
  307. # bindings
  308. btnCancel.Bind(wx.EVT_BUTTON, self.OnClose)
  309. btn_clipboard.Bind(wx.EVT_BUTTON, self.OnCopy)
  310. self.panel.SetSizer(sizer)
  311. sizer.Fit(self)
  312. def OnCopy(self, event):
  313. """Copy the regression stats to the clipboard
  314. """
  315. str = self.title + '\n'
  316. for item in self.message:
  317. str += item
  318. rdata = wx.TextDataObject()
  319. rdata.SetText(str)
  320. if wx.TheClipboard.Open():
  321. wx.TheClipboard.SetData(rdata)
  322. wx.TheClipboard.Close()
  323. wx.MessageBox(_("Regression statistics copied to clipboard"))
  324. def OnClose(self, event):
  325. """Button 'Close' pressed
  326. """
  327. self.Close(True)
  328. class HistRasterDialog(wx.Dialog):
  329. def __init__(self, parent, id=wx.ID_ANY,
  330. title=_("Select raster map or imagery group to histogram"),
  331. style=wx.DEFAULT_DIALOG_STYLE, **kwargs):
  332. """Dialog to select raster maps to histogram.
  333. """
  334. wx.Dialog.__init__(self, parent, id, title, style=style, **kwargs)
  335. self.parent = parent
  336. self.rasterList = self.parent.rasterList
  337. self.group = self.parent.group
  338. self.bins = self.parent.bins
  339. self.histtype = self.parent.histtype
  340. self.maptype = self.parent.maptype
  341. self.spinbins = ''
  342. self._do_layout()
  343. def _do_layout(self):
  344. sizer = wx.BoxSizer(wx.VERTICAL)
  345. box = wx.GridBagSizer(hgap=3, vgap=3)
  346. #
  347. # select single raster or image group to histogram radio buttons
  348. #
  349. self.rasterRadio = wx.RadioButton(
  350. self, id=wx.ID_ANY, label=" %s " %
  351. _("Histogram single raster"), style=wx.RB_GROUP)
  352. self.groupRadio = wx.RadioButton(
  353. self, id=wx.ID_ANY, label=" %s " %
  354. _("Histogram imagery group"))
  355. if self.maptype == 'raster':
  356. self.rasterRadio.SetValue(True)
  357. elif self.maptype == 'group':
  358. self.groupRadio.SetValue(True)
  359. box.Add(
  360. self.rasterRadio,
  361. flag=wx.ALIGN_CENTER_VERTICAL,
  362. pos=(
  363. 0,
  364. 0))
  365. box.Add(
  366. self.groupRadio,
  367. flag=wx.ALIGN_CENTER_VERTICAL,
  368. pos=(
  369. 0,
  370. 1))
  371. #
  372. # Select a raster to histogram
  373. #
  374. label = wx.StaticText(parent=self, id=wx.ID_ANY,
  375. label=_("Select raster map:"))
  376. box.Add(label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(1, 0))
  377. self.rselection = Select(self, id=wx.ID_ANY,
  378. size=globalvar.DIALOG_GSELECT_SIZE,
  379. type='cell')
  380. if self.groupRadio.GetValue() == True:
  381. self.rselection.Disable()
  382. else:
  383. rastText = ''
  384. for r in self.rasterList:
  385. rastText += '%s,' % r
  386. rastText = rastText.rstrip(',')
  387. self.rselection.SetValue(rastText)
  388. box.Add(self.rselection, pos=(1, 1))
  389. #
  390. # Select an image group to histogram
  391. #
  392. label = wx.StaticText(parent=self, id=wx.ID_ANY,
  393. label=_("Select image group:"))
  394. box.Add(label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(2, 0))
  395. self.gselection = Select(self, id=wx.ID_ANY,
  396. size=globalvar.DIALOG_GSELECT_SIZE,
  397. type='group')
  398. if self.rasterRadio.GetValue() == True:
  399. self.gselection.Disable()
  400. else:
  401. if self.group is not None:
  402. self.gselection.SetValue(self.group)
  403. box.Add(self.gselection, pos=(2, 1))
  404. #
  405. # Nsteps for FP maps and histogram type selection
  406. #
  407. label = wx.StaticText(parent=self, id=wx.ID_ANY,
  408. label=_("Number of bins (for FP maps)"))
  409. box.Add(label,
  410. flag=wx.ALIGN_CENTER_VERTICAL, pos=(3, 0))
  411. self.spinbins = SpinCtrl(
  412. parent=self, id=wx.ID_ANY, value="", pos=(
  413. 30, 50), size=(
  414. 100, -1), style=wx.SP_ARROW_KEYS)
  415. self.spinbins.SetRange(1, 1000)
  416. self.spinbins.SetValue(self.bins)
  417. box.Add(self.spinbins,
  418. flag=wx.ALIGN_CENTER_VERTICAL, pos=(3, 1))
  419. label = wx.StaticText(parent=self, id=wx.ID_ANY,
  420. label=_("Histogram type"))
  421. box.Add(label,
  422. flag=wx.ALIGN_CENTER_VERTICAL, pos=(4, 0))
  423. types = ['count', 'percent', 'area']
  424. histtype = wx.ComboBox(parent=self, id=wx.ID_ANY, size=(250, -1),
  425. choices=types, style=wx.CB_DROPDOWN)
  426. histtype.SetStringSelection(self.histtype)
  427. box.Add(histtype,
  428. flag=wx.ALIGN_CENTER_VERTICAL, pos=(4, 1))
  429. sizer.Add(box, proportion=0,
  430. flag=wx.ALL, border=10)
  431. line = wx.StaticLine(
  432. parent=self, id=wx.ID_ANY, size=(
  433. 20, -1), style=wx.LI_HORIZONTAL)
  434. sizer.Add(line, proportion=0, flag=wx.GROW |
  435. wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.RIGHT, border=5)
  436. btnsizer = wx.StdDialogButtonSizer()
  437. btn = wx.Button(self, wx.ID_OK)
  438. btn.SetDefault()
  439. btnsizer.AddButton(btn)
  440. btn = wx.Button(self, wx.ID_CANCEL)
  441. btnsizer.AddButton(btn)
  442. btnsizer.Realize()
  443. sizer.Add(
  444. btnsizer,
  445. proportion=0,
  446. flag=wx.ALIGN_RIGHT | wx.ALL,
  447. border=5)
  448. #
  449. # bindings
  450. #
  451. self.Bind(wx.EVT_RADIOBUTTON, self.OnHistMap, self.rasterRadio)
  452. self.Bind(wx.EVT_RADIOBUTTON, self.OnHistMap, self.groupRadio)
  453. self.rselection.Bind(wx.EVT_TEXT, self.OnRasterSelection)
  454. self.gselection.Bind(wx.EVT_TEXT, self.OnGroupSelection)
  455. self.spinbins.Bind(wx.EVT_TEXT, self.OnSetBins)
  456. self.spinbins.Bind(wx.EVT_SPINCTRL, self.OnSetBins)
  457. histtype.Bind(wx.EVT_TEXT, self.OnSetHisttypes)
  458. self.SetSizer(sizer)
  459. sizer.Fit(self)
  460. def OnHistMap(self, event):
  461. """Hander for radio buttons to choose between histogramming a
  462. single raster and an imagery group
  463. """
  464. if self.rasterRadio.GetValue() is True:
  465. self.maptype = 'raster'
  466. self.rselection.Enable()
  467. self.gselection.Disable()
  468. self.gselection.SetValue('')
  469. elif self.groupRadio.GetValue() is True:
  470. self.maptype = 'group'
  471. self.gselection.Enable()
  472. self.rselection.Disable()
  473. self.rselection.SetValue('')
  474. else:
  475. pass
  476. def OnRasterSelection(self, event):
  477. """Handler for selecting a single raster map
  478. """
  479. self.rasterList = []
  480. self.rasterList.append(event.GetString())
  481. def OnGroupSelection(self, event):
  482. """Handler for selecting imagery group
  483. """
  484. self.rasterList = []
  485. self.group = event.GetString()
  486. ret = grass.read_command('i.group',
  487. group='%s' % self.group,
  488. quiet=True,
  489. flags='g').strip().splitlines()
  490. if ret not in [None, '', ['']]:
  491. self.rasterList = ret
  492. else:
  493. wx.MessageBox(
  494. message=_("Selected group must be in current mapset"),
  495. caption=_('Invalid input'),
  496. style=wx.OK | wx.ICON_ERROR)
  497. def OnSetBins(self, event):
  498. """Bins for histogramming FP maps (=nsteps in r.stats)
  499. """
  500. self.bins = self.spinbins.GetValue()
  501. def OnSetHisttypes(self, event):
  502. self.histtype = event.GetString()
  503. class TextDialog(wx.Dialog):
  504. def __init__(self, parent, id, title, plottype='',
  505. style=wx.DEFAULT_DIALOG_STYLE, **kwargs):
  506. """Dialog to set histogram text options: font, title
  507. and font size, axis labels and font size
  508. """
  509. wx.Dialog.__init__(self, parent, id, title, style=style, **kwargs)
  510. #
  511. # initialize variables
  512. #
  513. # combo box entry lists
  514. self.ffamilydict = {'default': wx.FONTFAMILY_DEFAULT,
  515. 'decorative': wx.FONTFAMILY_DECORATIVE,
  516. 'roman': wx.FONTFAMILY_ROMAN,
  517. 'script': wx.FONTFAMILY_SCRIPT,
  518. 'swiss': wx.FONTFAMILY_SWISS,
  519. 'modern': wx.FONTFAMILY_MODERN,
  520. 'teletype': wx.FONTFAMILY_TELETYPE}
  521. self.fstyledict = {'normal': wx.FONTSTYLE_NORMAL,
  522. 'slant': wx.FONTSTYLE_SLANT,
  523. 'italic': wx.FONTSTYLE_ITALIC}
  524. self.fwtdict = {'normal': wx.FONTWEIGHT_NORMAL,
  525. 'light': wx.FONTWEIGHT_LIGHT,
  526. 'bold': wx.FONTWEIGHT_BOLD}
  527. self.parent = parent
  528. self.plottype = plottype
  529. self.ptitle = self.parent.ptitle
  530. self.xlabel = self.parent.xlabel
  531. self.ylabel = self.parent.ylabel
  532. self.properties = self.parent.properties # read-only
  533. # font size
  534. self.fontfamily = self.properties['font']['wxfont'].GetFamily()
  535. self.fontstyle = self.properties['font']['wxfont'].GetStyle()
  536. self.fontweight = self.properties['font']['wxfont'].GetWeight()
  537. self._do_layout()
  538. def _do_layout(self):
  539. """Do layout"""
  540. # dialog layout
  541. sizer = wx.BoxSizer(wx.VERTICAL)
  542. box = wx.StaticBox(parent=self, id=wx.ID_ANY,
  543. label=" %s " % _("Text settings"))
  544. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  545. gridSizer = wx.GridBagSizer(vgap=5, hgap=5)
  546. #
  547. # profile title
  548. #
  549. label = wx.StaticText(
  550. parent=self,
  551. id=wx.ID_ANY,
  552. label=_("Profile title:"))
  553. gridSizer.Add(label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(0, 0))
  554. self.ptitleentry = wx.TextCtrl(
  555. parent=self, id=wx.ID_ANY, value="", size=(250, -1))
  556. # self.ptitleentry.SetFont(self.font)
  557. self.ptitleentry.SetValue(self.ptitle)
  558. gridSizer.Add(self.ptitleentry, pos=(0, 1))
  559. #
  560. # title font
  561. #
  562. tlabel = wx.StaticText(
  563. parent=self,
  564. id=wx.ID_ANY,
  565. label=_("Title font size (pts):"))
  566. gridSizer.Add(tlabel, flag=wx.ALIGN_CENTER_VERTICAL, pos=(1, 0))
  567. self.ptitlesize = SpinCtrl(
  568. parent=self, id=wx.ID_ANY, value="", pos=(
  569. 30, 50), size=(
  570. 50, -1), style=wx.SP_ARROW_KEYS)
  571. self.ptitlesize.SetRange(5, 100)
  572. self.ptitlesize.SetValue(
  573. int(self.properties['font']['prop']['titleSize']))
  574. gridSizer.Add(self.ptitlesize, pos=(1, 1))
  575. #
  576. # x-axis label
  577. #
  578. label = wx.StaticText(
  579. parent=self,
  580. id=wx.ID_ANY,
  581. label=_("X-axis label:"))
  582. gridSizer.Add(label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(2, 0))
  583. self.xlabelentry = wx.TextCtrl(
  584. parent=self, id=wx.ID_ANY, value="", size=(250, -1))
  585. # self.xlabelentry.SetFont(self.font)
  586. self.xlabelentry.SetValue(self.xlabel)
  587. gridSizer.Add(self.xlabelentry, pos=(2, 1))
  588. #
  589. # y-axis label
  590. #
  591. label = wx.StaticText(
  592. parent=self,
  593. id=wx.ID_ANY,
  594. label=_("Y-axis label:"))
  595. gridSizer.Add(label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(3, 0))
  596. self.ylabelentry = wx.TextCtrl(
  597. parent=self, id=wx.ID_ANY, value="", size=(250, -1))
  598. # self.ylabelentry.SetFont(self.font)
  599. self.ylabelentry.SetValue(self.ylabel)
  600. gridSizer.Add(self.ylabelentry, pos=(3, 1))
  601. #
  602. # font size
  603. #
  604. llabel = wx.StaticText(
  605. parent=self,
  606. id=wx.ID_ANY,
  607. label=_("Label font size (pts):"))
  608. gridSizer.Add(llabel, flag=wx.ALIGN_CENTER_VERTICAL, pos=(4, 0))
  609. self.axislabelsize = SpinCtrl(
  610. parent=self, id=wx.ID_ANY, value="", pos=(
  611. 30, 50), size=(
  612. 50, -1), style=wx.SP_ARROW_KEYS)
  613. self.axislabelsize.SetRange(5, 100)
  614. self.axislabelsize.SetValue(
  615. int(self.properties['font']['prop']['axisSize']))
  616. gridSizer.Add(self.axislabelsize, pos=(4, 1))
  617. boxSizer.Add(gridSizer)
  618. sizer.Add(boxSizer, flag=wx.ALL | wx.EXPAND, border=3)
  619. #
  620. # font settings
  621. #
  622. box = wx.StaticBox(parent=self, id=wx.ID_ANY,
  623. label=" %s " % _("Font settings"))
  624. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  625. gridSizer = wx.GridBagSizer(vgap=5, hgap=5)
  626. #
  627. # font family
  628. #
  629. label1 = wx.StaticText(
  630. parent=self,
  631. id=wx.ID_ANY,
  632. label=_("Font family:"))
  633. gridSizer.Add(label1, flag=wx.ALIGN_CENTER_VERTICAL, pos=(0, 0))
  634. self.ffamilycb = wx.ComboBox(
  635. parent=self, id=wx.ID_ANY, size=(250, -1),
  636. choices=self.ffamilydict.keys(),
  637. style=wx.CB_DROPDOWN)
  638. self.ffamilycb.SetStringSelection('swiss')
  639. for item in self.ffamilydict.items():
  640. if self.fontfamily == item[1]:
  641. self.ffamilycb.SetStringSelection(item[0])
  642. break
  643. gridSizer.Add(self.ffamilycb, pos=(0, 1), flag=wx.ALIGN_RIGHT)
  644. #
  645. # font style
  646. #
  647. label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_("Style:"))
  648. gridSizer.Add(label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(1, 0))
  649. self.fstylecb = wx.ComboBox(
  650. parent=self, id=wx.ID_ANY, size=(250, -1),
  651. choices=self.fstyledict.keys(),
  652. style=wx.CB_DROPDOWN)
  653. self.fstylecb.SetStringSelection('normal')
  654. for item in self.fstyledict.items():
  655. if self.fontstyle == item[1]:
  656. self.fstylecb.SetStringSelection(item[0])
  657. break
  658. gridSizer.Add(self.fstylecb, pos=(1, 1), flag=wx.ALIGN_RIGHT)
  659. #
  660. # font weight
  661. #
  662. label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_("Weight:"))
  663. gridSizer.Add(label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(2, 0))
  664. self.fwtcb = wx.ComboBox(
  665. parent=self, size=(250, -1),
  666. choices=self.fwtdict.keys(),
  667. style=wx.CB_DROPDOWN)
  668. self.fwtcb.SetStringSelection('normal')
  669. for item in self.fwtdict.items():
  670. if self.fontweight == item[1]:
  671. self.fwtcb.SetStringSelection(item[0])
  672. break
  673. gridSizer.Add(self.fwtcb, pos=(2, 1), flag=wx.ALIGN_RIGHT)
  674. gridSizer.AddGrowableCol(1)
  675. boxSizer.Add(gridSizer, flag=wx.EXPAND)
  676. sizer.Add(boxSizer, flag=wx.LEFT | wx.RIGHT |
  677. wx.BOTTOM | wx.EXPAND, border=3)
  678. line = wx.StaticLine(
  679. parent=self, id=wx.ID_ANY, size=(
  680. 20, -1), style=wx.LI_HORIZONTAL)
  681. sizer.Add(line, proportion=0, flag=wx.GROW |
  682. wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.RIGHT, border=3)
  683. #
  684. # buttons
  685. #
  686. btnSave = wx.Button(self, wx.ID_SAVE)
  687. btnApply = wx.Button(self, wx.ID_APPLY)
  688. btnOk = wx.Button(self, wx.ID_OK)
  689. btnCancel = wx.Button(self, wx.ID_CANCEL)
  690. btnOk.SetDefault()
  691. # bindings
  692. btnApply.Bind(wx.EVT_BUTTON, self.OnApply)
  693. btnApply.SetToolTipString(_("Apply changes for the current session"))
  694. btnOk.Bind(wx.EVT_BUTTON, self.OnOk)
  695. btnOk.SetToolTipString(
  696. _("Apply changes for the current session and close dialog"))
  697. btnOk.SetDefault()
  698. btnSave.Bind(wx.EVT_BUTTON, self.OnSave)
  699. btnSave.SetToolTipString(
  700. _("Apply and save changes to user settings file (default for next sessions)"))
  701. btnCancel.Bind(wx.EVT_BUTTON, self.OnCancel)
  702. btnCancel.SetToolTipString(_("Close dialog and ignore changes"))
  703. # sizers
  704. btnStdSizer = wx.StdDialogButtonSizer()
  705. btnStdSizer.AddButton(btnOk)
  706. btnStdSizer.AddButton(btnApply)
  707. btnStdSizer.AddButton(btnCancel)
  708. btnStdSizer.Realize()
  709. btnSizer = wx.BoxSizer(wx.HORIZONTAL)
  710. btnSizer.Add(
  711. btnSave,
  712. proportion=0,
  713. flag=wx.ALIGN_LEFT | wx.ALL,
  714. border=5)
  715. btnSizer.Add(
  716. btnStdSizer,
  717. proportion=0,
  718. flag=wx.ALIGN_RIGHT | wx.ALL,
  719. border=5)
  720. sizer.Add(
  721. btnSizer,
  722. proportion=0,
  723. flag=wx.ALIGN_RIGHT | wx.ALL,
  724. border=5)
  725. #
  726. # bindings
  727. #
  728. self.ptitleentry.Bind(wx.EVT_TEXT, self.OnTitle)
  729. self.xlabelentry.Bind(wx.EVT_TEXT, self.OnXLabel)
  730. self.ylabelentry.Bind(wx.EVT_TEXT, self.OnYLabel)
  731. self.SetSizer(sizer)
  732. sizer.Fit(self)
  733. def OnTitle(self, event):
  734. self.ptitle = event.GetString()
  735. def OnXLabel(self, event):
  736. self.xlabel = event.GetString()
  737. def OnYLabel(self, event):
  738. self.ylabel = event.GetString()
  739. def UpdateSettings(self):
  740. self.properties['font']['prop'][
  741. 'titleSize'] = self.ptitlesize.GetValue()
  742. self.properties['font']['prop'][
  743. 'axisSize'] = self.axislabelsize.GetValue()
  744. family = self.ffamilydict[self.ffamilycb.GetStringSelection()]
  745. self.properties['font']['wxfont'].SetFamily(family)
  746. style = self.fstyledict[self.fstylecb.GetStringSelection()]
  747. self.properties['font']['wxfont'].SetStyle(style)
  748. weight = self.fwtdict[self.fwtcb.GetStringSelection()]
  749. self.properties['font']['wxfont'].SetWeight(weight)
  750. def OnSave(self, event):
  751. """Button 'Save' pressed"""
  752. self.OnApply(None)
  753. fileSettings = {}
  754. UserSettings.ReadSettingsFile(settings=fileSettings)
  755. fileSettings[self.plottype] = UserSettings.Get(group=self.plottype)
  756. UserSettings.SaveToFile(fileSettings)
  757. self.parent.parent.GetLayerManager().GetLogWindow().WriteLog(
  758. _('Plot text sizes saved to file \'%s\'.') % UserSettings.filePath)
  759. self.EndModal(wx.ID_OK)
  760. def OnApply(self, event):
  761. """Button 'Apply' pressed"""
  762. self.UpdateSettings()
  763. self.parent.OnPlotText(self)
  764. def OnOk(self, event):
  765. """Button 'OK' pressed"""
  766. self.OnApply(None)
  767. self.EndModal(wx.ID_OK)
  768. def OnCancel(self, event):
  769. """Button 'Cancel' pressed"""
  770. self.EndModal(wx.ID_CANCEL)
  771. class OptDialog(wx.Dialog):
  772. def __init__(self, parent, id, title, plottype='',
  773. style=wx.DEFAULT_DIALOG_STYLE, **kwargs):
  774. """Dialog to set various options for data plotted, including: line
  775. width, color, style; marker size, color, fill, and style; grid
  776. and legend options.
  777. """
  778. wx.Dialog.__init__(self, parent, id, title, style=style, **kwargs)
  779. # init variables
  780. self.parent = parent
  781. self.linestyledict = parent.linestyledict
  782. self.ptfilldict = parent.ptfilldict
  783. self.parent = parent
  784. self.plottype = plottype
  785. self.pttypelist = ['circle',
  786. 'dot',
  787. 'square',
  788. 'triangle',
  789. 'triangle_down',
  790. 'cross',
  791. 'plus']
  792. self.axislist = ['min',
  793. 'auto',
  794. 'custom']
  795. # widgets ids
  796. self.wxId = {}
  797. self.parent = parent
  798. # read-only
  799. self.raster = self.parent.raster
  800. self.rasterList = self.parent.rasterList
  801. self.properties = self.parent.properties
  802. self.map = ''
  803. if len(self.rasterList) == 0:
  804. wx.MessageBox(parent=self,
  805. message=_("No map or image group selected to plot."),
  806. caption=_("Warning"), style=wx.OK | wx.ICON_ERROR)
  807. self._do_layout()
  808. def ConvertTuples(self, tlist):
  809. """Converts tuples to strings when rasterList contains raster
  810. pairs for scatterplot
  811. """
  812. list = []
  813. for i in tlist:
  814. i = str(i).strip('()')
  815. list.append(i)
  816. return list
  817. def _do_layout(self):
  818. """Options dialog layout
  819. """
  820. sizer = wx.BoxSizer(wx.VERTICAL)
  821. box = wx.StaticBox(parent=self, id=wx.ID_ANY,
  822. label=" %s " % _("Plot settings"))
  823. boxMainSizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
  824. self.wxId['pcolor'] = 0
  825. self.wxId['pwidth'] = 0
  826. self.wxId['pstyle'] = 0
  827. self.wxId['psize'] = 0
  828. self.wxId['ptype'] = 0
  829. self.wxId['pfill'] = 0
  830. self.wxId['plegend'] = 0
  831. self.wxId['marker'] = {}
  832. self.wxId['x-axis'] = {}
  833. self.wxId['y-axis'] = {}
  834. #
  835. # plot line settings and point settings
  836. #
  837. if len(self.rasterList) == 0:
  838. return
  839. box = wx.StaticBox(parent=self, id=wx.ID_ANY,
  840. label=_("Map/image plotted"))
  841. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  842. gridSizer = wx.GridBagSizer(vgap=5, hgap=5)
  843. row = 0
  844. choicelist = []
  845. for i in self.rasterList:
  846. choicelist.append(str(i))
  847. self.mapchoice = wx.Choice(parent=self, id=wx.ID_ANY, size=(300, -1),
  848. choices=choicelist)
  849. self.mapchoice.SetToolTipString(_("Settings for selected map"))
  850. if not self.map:
  851. self.map = self.rasterList[self.mapchoice.GetCurrentSelection()]
  852. else:
  853. self.mapchoice.SetStringSelection(str(self.map))
  854. gridSizer.Add(self.mapchoice, flag=wx.ALIGN_CENTER_VERTICAL,
  855. pos=(row, 0), span=(1, 2))
  856. #
  857. # options for line plots (profiles and histograms)
  858. #
  859. if self.plottype != 'scatter':
  860. row += 1
  861. label = wx.StaticText(
  862. parent=self,
  863. id=wx.ID_ANY,
  864. label=_("Line color"))
  865. gridSizer.Add(
  866. label,
  867. flag=wx.ALIGN_CENTER_VERTICAL,
  868. pos=(
  869. row,
  870. 0))
  871. color = csel.ColourSelect(
  872. parent=self, id=wx.ID_ANY, colour=self.raster[
  873. self.map]['pcolor'])
  874. self.wxId['pcolor'] = color.GetId()
  875. gridSizer.Add(color, pos=(row, 1))
  876. row += 1
  877. label = wx.StaticText(
  878. parent=self,
  879. id=wx.ID_ANY,
  880. label=_("Line width"))
  881. gridSizer.Add(
  882. label,
  883. flag=wx.ALIGN_CENTER_VERTICAL,
  884. pos=(
  885. row,
  886. 0))
  887. width = SpinCtrl(parent=self, id=wx.ID_ANY, value="",
  888. size=(50, -1), style=wx.SP_ARROW_KEYS)
  889. width.SetRange(1, 10)
  890. width.SetValue(self.raster[self.map]['pwidth'])
  891. self.wxId['pwidth'] = width.GetId()
  892. gridSizer.Add(width, pos=(row, 1))
  893. row += 1
  894. label = wx.StaticText(
  895. parent=self,
  896. id=wx.ID_ANY,
  897. label=_("Line style"))
  898. gridSizer.Add(
  899. label,
  900. flag=wx.ALIGN_CENTER_VERTICAL,
  901. pos=(
  902. row,
  903. 0))
  904. style = wx.Choice(
  905. parent=self, id=wx.ID_ANY, size=(
  906. 120, -1), choices=self.linestyledict.keys())
  907. style.SetStringSelection(self.raster[self.map]['pstyle'])
  908. self.wxId['pstyle'] = style.GetId()
  909. gridSizer.Add(style, pos=(row, 1))
  910. row += 1
  911. label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_("Legend"))
  912. gridSizer.Add(label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(row, 0))
  913. legend = wx.TextCtrl(parent=self, id=wx.ID_ANY,
  914. value="", size=(200, -1))
  915. legend.SetValue(self.raster[self.map]['plegend'])
  916. gridSizer.Add(legend, pos=(row, 1))
  917. self.wxId['plegend'] = legend.GetId()
  918. boxSizer.Add(gridSizer)
  919. boxMainSizer.Add(boxSizer, flag=wx.ALL, border=3)
  920. #
  921. # segment marker settings for profiles only
  922. #
  923. if self.plottype == 'profile':
  924. box = wx.StaticBox(
  925. parent=self, id=wx.ID_ANY, label=" %s " %
  926. _("Transect segment marker settings"))
  927. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  928. gridSizer = wx.GridBagSizer(vgap=5, hgap=5)
  929. label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_("Color"))
  930. gridSizer.Add(
  931. label,
  932. flag=wx.ALIGN_CENTER_VERTICAL,
  933. pos=(
  934. 0,
  935. 0))
  936. ptcolor = csel.ColourSelect(
  937. parent=self,
  938. id=wx.ID_ANY,
  939. colour=self.properties['marker']['color'])
  940. self.wxId['marker']['color'] = ptcolor.GetId()
  941. gridSizer.Add(ptcolor, pos=(0, 1))
  942. label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_("Size"))
  943. gridSizer.Add(
  944. label,
  945. flag=wx.ALIGN_CENTER_VERTICAL,
  946. pos=(
  947. 1,
  948. 0))
  949. ptsize = SpinCtrl(parent=self, id=wx.ID_ANY, value="",
  950. size=(50, -1), style=wx.SP_ARROW_KEYS)
  951. ptsize.SetRange(1, 10)
  952. ptsize.SetValue(self.properties['marker']['size'])
  953. self.wxId['marker']['size'] = ptsize.GetId()
  954. gridSizer.Add(ptsize, pos=(1, 1))
  955. label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_("Fill"))
  956. gridSizer.Add(
  957. label,
  958. flag=wx.ALIGN_CENTER_VERTICAL,
  959. pos=(
  960. 2,
  961. 0))
  962. ptfill = wx.Choice(parent=self, id=wx.ID_ANY,
  963. size=(120, -1), choices=self.ptfilldict.keys())
  964. ptfill.SetStringSelection(self.properties['marker']['fill'])
  965. self.wxId['marker']['fill'] = ptfill.GetId()
  966. gridSizer.Add(ptfill, pos=(2, 1))
  967. label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_("Legend"))
  968. gridSizer.Add(
  969. label,
  970. flag=wx.ALIGN_CENTER_VERTICAL,
  971. pos=(
  972. 3,
  973. 0))
  974. ptlegend = wx.TextCtrl(
  975. parent=self, id=wx.ID_ANY, value="", size=(
  976. 200, -1))
  977. ptlegend.SetValue(self.properties['marker']['legend'])
  978. self.wxId['marker']['legend'] = ptlegend.GetId()
  979. gridSizer.Add(ptlegend, pos=(3, 1))
  980. label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_("Style"))
  981. gridSizer.Add(
  982. label,
  983. flag=wx.ALIGN_CENTER_VERTICAL,
  984. pos=(
  985. 4,
  986. 0))
  987. pttype = wx.Choice(
  988. parent=self, size=(200, -1),
  989. choices=self.pttypelist)
  990. pttype.SetStringSelection(self.properties['marker']['type'])
  991. self.wxId['marker']['type'] = pttype.GetId()
  992. gridSizer.Add(pttype, pos=(4, 1))
  993. boxSizer.Add(gridSizer)
  994. boxMainSizer.Add(boxSizer, flag=wx.ALL, border=3)
  995. #
  996. # point options for scatterplots
  997. #
  998. elif self.plottype == 'scatter':
  999. box = wx.StaticBox(parent=self, id=wx.ID_ANY,
  1000. label=" %s " % _("Scatterplot points"))
  1001. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1002. gridSizer = wx.GridBagSizer(vgap=5, hgap=5)
  1003. label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_("Color"))
  1004. gridSizer.Add(
  1005. label,
  1006. flag=wx.ALIGN_CENTER_VERTICAL,
  1007. pos=(
  1008. 0,
  1009. 0))
  1010. ptcolor = csel.ColourSelect(
  1011. parent=self, id=wx.ID_ANY, colour=self.raster[
  1012. self.map]['pcolor'])
  1013. self.wxId['pcolor'] = ptcolor.GetId()
  1014. gridSizer.Add(ptcolor, pos=(0, 1))
  1015. label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_("Size"))
  1016. gridSizer.Add(
  1017. label,
  1018. flag=wx.ALIGN_CENTER_VERTICAL,
  1019. pos=(
  1020. 1,
  1021. 0))
  1022. ptsize = SpinCtrl(parent=self, id=wx.ID_ANY, value="",
  1023. size=(50, -1), style=wx.SP_ARROW_KEYS)
  1024. ptsize.SetRange(1, 10)
  1025. ptsize.SetValue(self.raster[self.map]['psize'])
  1026. self.wxId['psize'] = ptsize.GetId()
  1027. gridSizer.Add(ptsize, pos=(1, 1))
  1028. label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_("Fill"))
  1029. gridSizer.Add(
  1030. label,
  1031. flag=wx.ALIGN_CENTER_VERTICAL,
  1032. pos=(
  1033. 2,
  1034. 0))
  1035. ptfill = wx.Choice(parent=self, id=wx.ID_ANY,
  1036. size=(120, -1), choices=self.ptfilldict.keys())
  1037. ptfill.SetStringSelection(self.raster[self.map]['pfill'])
  1038. self.wxId['pfill'] = ptfill.GetId()
  1039. gridSizer.Add(ptfill, pos=(2, 1))
  1040. label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_("Legend"))
  1041. gridSizer.Add(
  1042. label,
  1043. flag=wx.ALIGN_CENTER_VERTICAL,
  1044. pos=(
  1045. 3,
  1046. 0))
  1047. ptlegend = wx.TextCtrl(
  1048. parent=self, id=wx.ID_ANY, value="", size=(
  1049. 200, -1))
  1050. ptlegend.SetValue(self.raster[self.map]['plegend'])
  1051. self.wxId['plegend'] = ptlegend.GetId()
  1052. gridSizer.Add(ptlegend, pos=(3, 1))
  1053. label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_("Style"))
  1054. gridSizer.Add(
  1055. label,
  1056. flag=wx.ALIGN_CENTER_VERTICAL,
  1057. pos=(
  1058. 4,
  1059. 0))
  1060. pttype = wx.Choice(
  1061. parent=self, size=(200, -1),
  1062. choices=self.pttypelist)
  1063. pttype.SetStringSelection(self.raster[self.map]['ptype'])
  1064. self.wxId['ptype'] = pttype.GetId()
  1065. gridSizer.Add(pttype, pos=(4, 1))
  1066. boxSizer.Add(gridSizer)
  1067. boxMainSizer.Add(boxSizer, flag=wx.ALL, border=3)
  1068. sizer.Add(boxMainSizer, flag=wx.ALL | wx.EXPAND, border=3)
  1069. #
  1070. # axis options for all plots
  1071. #
  1072. box = wx.StaticBox(parent=self, id=wx.ID_ANY,
  1073. label=" %s " % _("Axis settings"))
  1074. boxMainSizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
  1075. middleSizer = wx.BoxSizer(wx.HORIZONTAL)
  1076. idx = 0
  1077. for axis, atype in [(_("X-Axis"), 'x-axis'),
  1078. (_("Y-Axis"), 'y-axis')]:
  1079. box = wx.StaticBox(parent=self, id=wx.ID_ANY,
  1080. label=" %s " % axis)
  1081. boxSizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
  1082. gridSizer = wx.GridBagSizer(vgap=5, hgap=5)
  1083. prop = self.properties[atype]['prop']
  1084. row = 0
  1085. label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_("Scale"))
  1086. gridSizer.Add(
  1087. label,
  1088. flag=wx.ALIGN_CENTER_VERTICAL,
  1089. pos=(
  1090. row,
  1091. 0))
  1092. type = wx.Choice(
  1093. parent=self, id=wx.ID_ANY, size=(
  1094. 100, -1), choices=self.axislist)
  1095. type.SetStringSelection(prop['type'])
  1096. type.SetToolTipString(
  1097. _("Automatic axis scaling, custom max and min, or scale matches data range (min)"))
  1098. self.wxId[atype]['type'] = type.GetId()
  1099. gridSizer.Add(type, pos=(row, 1))
  1100. row += 1
  1101. label = wx.StaticText(
  1102. parent=self,
  1103. id=wx.ID_ANY,
  1104. label=_("Custom min"))
  1105. gridSizer.Add(
  1106. label,
  1107. flag=wx.ALIGN_CENTER_VERTICAL,
  1108. pos=(
  1109. row,
  1110. 0))
  1111. min = wx.TextCtrl(parent=self, id=wx.ID_ANY,
  1112. value="", size=(70, -1))
  1113. min.SetValue(str(prop['min']))
  1114. self.wxId[atype]['min'] = min.GetId()
  1115. gridSizer.Add(min, pos=(row, 1))
  1116. row += 1
  1117. label = wx.StaticText(
  1118. parent=self,
  1119. id=wx.ID_ANY,
  1120. label=_("Custom max"))
  1121. gridSizer.Add(
  1122. label,
  1123. flag=wx.ALIGN_CENTER_VERTICAL,
  1124. pos=(
  1125. row,
  1126. 0))
  1127. max = wx.TextCtrl(parent=self, id=wx.ID_ANY,
  1128. value="", size=(70, -1))
  1129. max.SetValue(str(prop['max']))
  1130. self.wxId[atype]['max'] = max.GetId()
  1131. gridSizer.Add(max, pos=(row, 1))
  1132. row += 1
  1133. log = wx.CheckBox(parent=self, id=wx.ID_ANY, label=_("Log scale"))
  1134. log.SetValue(prop['log'])
  1135. self.wxId[atype]['log'] = log.GetId()
  1136. gridSizer.Add(log, pos=(row, 0), span=(1, 2))
  1137. if idx == 0:
  1138. flag = wx.ALL | wx.EXPAND
  1139. else:
  1140. flag = wx.TOP | wx.BOTTOM | wx.RIGHT | wx.EXPAND
  1141. boxSizer.Add(gridSizer, flag=wx.ALL, border=3)
  1142. boxMainSizer.Add(boxSizer, flag=flag, border=3)
  1143. idx += 1
  1144. middleSizer.Add(boxMainSizer, flag=wx.ALL | wx.EXPAND, border=3)
  1145. #
  1146. # grid & legend options for all plots
  1147. #
  1148. self.wxId['grid'] = {}
  1149. self.wxId['legend'] = {}
  1150. self.wxId['font'] = {}
  1151. box = wx.StaticBox(parent=self, id=wx.ID_ANY,
  1152. label=" %s " % _("Grid and Legend settings"))
  1153. boxMainSizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
  1154. gridSizer = wx.GridBagSizer(vgap=5, hgap=5)
  1155. row = 0
  1156. label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_("Grid color"))
  1157. gridSizer.Add(label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(row, 0))
  1158. gridcolor = csel.ColourSelect(
  1159. parent=self,
  1160. id=wx.ID_ANY,
  1161. colour=self.properties['grid']['color'])
  1162. self.wxId['grid']['color'] = gridcolor.GetId()
  1163. gridSizer.Add(gridcolor, pos=(row, 1))
  1164. row += 1
  1165. gridshow = wx.CheckBox(parent=self, id=wx.ID_ANY, label=_("Show grid"))
  1166. gridshow.SetValue(self.properties['grid']['enabled'])
  1167. self.wxId['grid']['enabled'] = gridshow.GetId()
  1168. gridSizer.Add(gridshow, pos=(row, 0), span=(1, 2))
  1169. row += 1
  1170. label = wx.StaticText(
  1171. parent=self,
  1172. id=wx.ID_ANY,
  1173. label=_("Legend font size"))
  1174. gridSizer.Add(label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(row, 0))
  1175. legendfontsize = SpinCtrl(parent=self, id=wx.ID_ANY, value="",
  1176. size=(50, -1), style=wx.SP_ARROW_KEYS)
  1177. legendfontsize.SetRange(5, 100)
  1178. legendfontsize.SetValue(
  1179. int(self.properties['font']['prop']['legendSize']))
  1180. self.wxId['font']['legendSize'] = legendfontsize.GetId()
  1181. gridSizer.Add(legendfontsize, pos=(row, 1))
  1182. row += 1
  1183. legendshow = wx.CheckBox(
  1184. parent=self,
  1185. id=wx.ID_ANY,
  1186. label=_("Show legend"))
  1187. legendshow.SetValue(self.properties['legend']['enabled'])
  1188. self.wxId['legend']['enabled'] = legendshow.GetId()
  1189. gridSizer.Add(legendshow, pos=(row, 0), span=(1, 2))
  1190. boxMainSizer.Add(gridSizer, flag=flag, border=3)
  1191. middleSizer.Add(boxMainSizer, flag=wx.LEFT |
  1192. wx.RIGHT | wx.BOTTOM | wx.EXPAND, border=3)
  1193. sizer.Add(middleSizer, flag=wx.ALL, border=0)
  1194. #
  1195. # line & buttons
  1196. #
  1197. line = wx.StaticLine(
  1198. parent=self, id=wx.ID_ANY, size=(
  1199. 20, -1), style=wx.LI_HORIZONTAL)
  1200. sizer.Add(line, proportion=0, flag=wx.GROW |
  1201. wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.RIGHT, border=3)
  1202. #
  1203. # buttons
  1204. #
  1205. btnSave = wx.Button(self, wx.ID_SAVE)
  1206. btnApply = wx.Button(self, wx.ID_APPLY)
  1207. btnOk = wx.Button(self, wx.ID_OK)
  1208. btnCancel = wx.Button(self, wx.ID_CANCEL)
  1209. btnOk.SetDefault()
  1210. # tooltips for buttons
  1211. btnApply.SetToolTipString(_("Apply changes for the current session"))
  1212. btnOk.SetToolTipString(
  1213. _("Apply changes for the current session and close dialog"))
  1214. btnSave.SetToolTipString(
  1215. _("Apply and save changes to user settings file (default for next sessions)"))
  1216. btnCancel.SetToolTipString(_("Close dialog and ignore changes"))
  1217. # sizers
  1218. btnStdSizer = wx.StdDialogButtonSizer()
  1219. btnStdSizer.AddButton(btnOk)
  1220. btnStdSizer.AddButton(btnApply)
  1221. btnStdSizer.AddButton(btnCancel)
  1222. btnStdSizer.Realize()
  1223. btnSizer = wx.BoxSizer(wx.HORIZONTAL)
  1224. btnSizer.Add(
  1225. btnSave,
  1226. proportion=0,
  1227. flag=wx.ALIGN_LEFT | wx.ALL,
  1228. border=5)
  1229. btnSizer.Add(
  1230. btnStdSizer,
  1231. proportion=0,
  1232. flag=wx.ALIGN_RIGHT | wx.ALL,
  1233. border=5)
  1234. sizer.Add(
  1235. btnSizer,
  1236. proportion=0,
  1237. flag=wx.ALIGN_RIGHT | wx.ALL,
  1238. border=5)
  1239. #
  1240. # bindings for buttons and map plot settings controls
  1241. #
  1242. self.mapchoice.Bind(wx.EVT_CHOICE, self.OnSetMap)
  1243. btnApply.Bind(wx.EVT_BUTTON, self.OnApply)
  1244. btnOk.Bind(wx.EVT_BUTTON, self.OnOk)
  1245. btnOk.SetDefault()
  1246. btnSave.Bind(wx.EVT_BUTTON, self.OnSave)
  1247. btnCancel.Bind(wx.EVT_BUTTON, self.OnCancel)
  1248. self.SetSizer(sizer)
  1249. sizer.Fit(self)
  1250. def OnSetMap(self, event):
  1251. """Handler for changing map selection"""
  1252. idx = event.GetSelection()
  1253. self.map = self.rasterList[idx]
  1254. # update settings controls for all plots
  1255. self.FindWindowById(
  1256. self.wxId['pcolor']).SetColour(
  1257. self.raster[self.map]['pcolor'])
  1258. self.FindWindowById(
  1259. self.wxId['plegend']).SetValue(
  1260. self.raster[self.map]['plegend'])
  1261. # update settings controls for histograms and profiles
  1262. if self.plottype != 'scatter':
  1263. self.FindWindowById(
  1264. self.wxId['pwidth']).SetValue(
  1265. self.raster[self.map]['pwidth'])
  1266. self.FindWindowById(
  1267. self.wxId['pstyle']).SetStringSelection(
  1268. self.raster[
  1269. self.map]['pstyle'])
  1270. # update settings controls for scatterplots
  1271. elif self.plottype == 'scatter':
  1272. self.FindWindowById(
  1273. self.wxId['psize']).SetValue(
  1274. self.raster[self.map]['psize'])
  1275. self.FindWindowById(
  1276. self.wxId['ptype']).SetStringSelection(
  1277. self.raster[
  1278. self.map]['ptype'])
  1279. self.FindWindowById(
  1280. self.wxId['pfill']).SetStringSelection(
  1281. self.raster[
  1282. self.map]['pfill'])
  1283. self.Refresh()
  1284. def OnSetOpt(self, event):
  1285. """Handler for changing any other option"""
  1286. self.map = self.rasterList[self.mapchoice.GetCurrentSelection()]
  1287. self.UpdateSettings()
  1288. self.parent.SetGraphStyle()
  1289. p = self.parent.CreatePlotList()
  1290. self.parent.DrawPlot(p)
  1291. def UpdateSettings(self):
  1292. """Apply settings to each map and to entire plot"""
  1293. self.raster[self.map]['pcolor'] = self.FindWindowById(
  1294. self.wxId['pcolor']).GetColour()
  1295. self.properties['raster']['pcolor'] = self.raster[self.map]['pcolor']
  1296. self.raster[self.map]['plegend'] = self.FindWindowById(
  1297. self.wxId['plegend']).GetValue()
  1298. if self.plottype != 'scatter':
  1299. self.raster[
  1300. self.map]['pwidth'] = int(
  1301. self.FindWindowById(
  1302. self.wxId['pwidth']).GetValue())
  1303. self.properties['raster'][
  1304. 'pwidth'] = self.raster[self.map]['pwidth']
  1305. self.raster[self.map]['pstyle'] = self.FindWindowById(
  1306. self.wxId['pstyle']).GetStringSelection()
  1307. self.properties['raster'][
  1308. 'pstyle'] = self.raster[self.map]['pstyle']
  1309. elif self.plottype == 'scatter':
  1310. self.raster[
  1311. self.map]['psize'] = self.FindWindowById(
  1312. self.wxId['psize']).GetValue()
  1313. self.properties['raster']['psize'] = self.raster[self.map]['psize']
  1314. self.raster[self.map]['ptype'] = self.FindWindowById(
  1315. self.wxId['ptype']).GetStringSelection()
  1316. self.properties['raster']['ptype'] = self.raster[self.map]['ptype']
  1317. self.raster[self.map]['pfill'] = self.FindWindowById(
  1318. self.wxId['pfill']).GetStringSelection()
  1319. self.properties['raster']['pfill'] = self.raster[self.map]['pfill']
  1320. # update settings for entire plot
  1321. for axis in ('x-axis', 'y-axis'):
  1322. self.properties[axis]['prop']['type'] = self.FindWindowById(
  1323. self.wxId[axis]['type']).GetStringSelection()
  1324. self.properties[axis]['prop']['min'] = float(
  1325. self.FindWindowById(self.wxId[axis]['min']).GetValue())
  1326. self.properties[axis]['prop']['max'] = float(
  1327. self.FindWindowById(self.wxId[axis]['max']).GetValue())
  1328. self.properties[axis]['prop']['log'] = self.FindWindowById(
  1329. self.wxId[axis]['log']).IsChecked()
  1330. if self.plottype == 'profile':
  1331. self.properties['marker']['color'] = self.FindWindowById(
  1332. self.wxId['marker']['color']).GetColour()
  1333. self.properties['marker']['fill'] = self.FindWindowById(
  1334. self.wxId['marker']['fill']).GetStringSelection()
  1335. self.properties['marker']['size'] = self.FindWindowById(
  1336. self.wxId['marker']['size']).GetValue()
  1337. self.properties['marker']['type'] = self.FindWindowById(
  1338. self.wxId['marker']['type']).GetStringSelection()
  1339. self.properties['marker']['legend'] = self.FindWindowById(
  1340. self.wxId['marker']['legend']).GetValue()
  1341. self.properties['grid']['color'] = self.FindWindowById(
  1342. self.wxId['grid']['color']).GetColour()
  1343. self.properties['grid']['enabled'] = self.FindWindowById(
  1344. self.wxId['grid']['enabled']).IsChecked()
  1345. # this makes more sense in the text properties, including for settings update. But will need to change
  1346. # layout for controls to text dialog too.
  1347. self.properties['font']['prop']['legendSize'] = self.FindWindowById(
  1348. self.wxId['font']['legendSize']).GetValue()
  1349. self.properties['legend']['enabled'] = self.FindWindowById(
  1350. self.wxId['legend']['enabled']).IsChecked()
  1351. self.parent.UpdateLabels()
  1352. def OnSave(self, event):
  1353. """Button 'Save' pressed"""
  1354. self.OnApply(None)
  1355. fileSettings = {}
  1356. UserSettings.ReadSettingsFile(settings=fileSettings)
  1357. fileSettings[self.plottype] = UserSettings.Get(group=self.plottype)
  1358. UserSettings.SaveToFile(fileSettings)
  1359. self.parent.parent.GetLayerManager().GetLogWindow().WriteLog(
  1360. _('Plot settings saved to file \'%s\'.') % UserSettings.filePath)
  1361. self.Close()
  1362. def OnApply(self, event):
  1363. """Button 'Apply' pressed. Does not close dialog"""
  1364. self.UpdateSettings()
  1365. self.parent.SetGraphStyle()
  1366. p = self.parent.CreatePlotList()
  1367. self.parent.DrawPlot(p)
  1368. def OnOk(self, event):
  1369. """Button 'OK' pressed"""
  1370. self.OnApply(None)
  1371. self.EndModal(wx.ID_OK)
  1372. def OnCancel(self, event):
  1373. """Button 'Cancel' pressed"""
  1374. self.Close()