dialogs.py 55 KB

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