dialogs.py 56 KB

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