|
GRASS Programmer's Manual
6.5.svn(2012)-r51648
|
00001 """! 00002 @package wxplot.dialogs 00003 00004 @brief Dialogs for different plotting routines 00005 00006 Classes: 00007 - dialogs::ProfileRasterDialog 00008 - dialogs::PlotStatsFrame 00009 - dialogs::TextDialog 00010 - dialogs::OptDialog 00011 00012 (C) 2011 by the GRASS Development Team 00013 00014 This program is free software under the GNU General Public License 00015 (>=v2). Read the file COPYING that comes with GRASS for details. 00016 00017 @author Michael Barton, Arizona State University 00018 """ 00019 00020 import wx 00021 import wx.lib.colourselect as csel 00022 import wx.lib.scrolledpanel as scrolled 00023 00024 from core import globalvar 00025 from core.settings import UserSettings 00026 from gui_core.gselect import Select 00027 00028 from grass.script import core as grass 00029 00030 class ProfileRasterDialog(wx.Dialog): 00031 def __init__(self, parent, id = wx.ID_ANY, 00032 title = _("Select raster maps to profile"), 00033 style = wx.DEFAULT_DIALOG_STYLE, **kwargs): 00034 """!Dialog to select raster maps to profile. 00035 """ 00036 00037 wx.Dialog.__init__(self, parent, id, title, style = style, **kwargs) 00038 00039 00040 self.parent = parent 00041 self.colorList = ["blue", "red", "green", "yellow", "magenta", "cyan", \ 00042 "aqua", "black", "grey", "orange", "brown", "purple", "violet", \ 00043 "indigo"] 00044 00045 self.rasterList = self.parent.rasterList 00046 00047 self._do_layout() 00048 00049 def _do_layout(self): 00050 00051 sizer = wx.BoxSizer(wx.VERTICAL) 00052 00053 box = wx.GridBagSizer (hgap = 3, vgap = 3) 00054 00055 rastText = '' 00056 for r in self.rasterList: 00057 rastText += '%s,' % r 00058 00059 rastText = rastText.rstrip(',') 00060 00061 txt = _("Select raster map(s) to profile:") 00062 label = wx.StaticText(parent = self, id = wx.ID_ANY, label = txt) 00063 box.Add(item = label, 00064 flag = wx.ALIGN_CENTER_VERTICAL, pos = (0, 0)) 00065 00066 selection = Select(self, id = wx.ID_ANY, 00067 size = globalvar.DIALOG_GSELECT_SIZE, 00068 type = 'cell', multiple=True) 00069 selection.SetValue(rastText) 00070 selection.Bind(wx.EVT_TEXT, self.OnSelection) 00071 00072 box.Add(item = selection, pos = (0, 1)) 00073 00074 sizer.Add(item = box, proportion = 0, 00075 flag = wx.ALL, border = 10) 00076 00077 line = wx.StaticLine(parent = self, id = wx.ID_ANY, size = (20, -1), style = wx.LI_HORIZONTAL) 00078 sizer.Add(item = line, proportion = 0, 00079 flag = wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.LEFT|wx.RIGHT, border = 5) 00080 00081 btnsizer = wx.StdDialogButtonSizer() 00082 00083 btn = wx.Button(self, wx.ID_OK) 00084 btn.SetDefault() 00085 btnsizer.AddButton(btn) 00086 00087 btn = wx.Button(self, wx.ID_CANCEL) 00088 btnsizer.AddButton(btn) 00089 btnsizer.Realize() 00090 00091 sizer.Add(item = btnsizer, proportion = 0, flag = wx.ALIGN_RIGHT | wx.ALL, border = 5) 00092 00093 self.SetSizer(sizer) 00094 sizer.Fit(self) 00095 00096 def OnSelection(self, event): 00097 """!Choose maps to profile. Convert these into a list 00098 """ 00099 self.rasterList = [] 00100 self.rasterList = event.GetString().split(',') 00101 00102 class PlotStatsFrame(wx.Frame): 00103 def __init__(self, parent, id, message = '', title = '', 00104 style = wx.DEFAULT_FRAME_STYLE, **kwargs): 00105 """!Dialog to display and save statistics for plots 00106 """ 00107 wx.Frame.__init__(self, parent, id, style = style, **kwargs) 00108 self.SetLabel(_("Statistics")) 00109 00110 sp = scrolled.ScrolledPanel(self, -1, size=(400, 400), 00111 style = wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER, name="Statistics" ) 00112 00113 00114 # 00115 # initialize variables 00116 # 00117 self.parent = parent 00118 self.message = message 00119 self.title = title 00120 self.CenterOnParent() 00121 00122 # 00123 # Display statistics 00124 # 00125 sizer = wx.BoxSizer(wx.VERTICAL) 00126 txtSizer = wx.BoxSizer(wx.VERTICAL) 00127 00128 statstitle = wx.StaticText(parent = self, id = wx.ID_ANY, label = self.title) 00129 sizer.Add(item = statstitle, proportion = 0, 00130 flag = wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, border = 3) 00131 line = wx.StaticLine(parent = self, id = wx.ID_ANY, size = (20, -1), style = wx.LI_HORIZONTAL) 00132 sizer.Add(item = line, proportion = 0, 00133 flag = wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, border = 3) 00134 for stats in self.message: 00135 statstxt = wx.StaticText(parent = sp, id = wx.ID_ANY, label = stats) 00136 statstxt.SetBackgroundColour("WHITE") 00137 txtSizer.Add(item = statstxt, proportion = 1, 00138 flag = wx.EXPAND|wx.ALIGN_CENTER_VERTICAL|wx.LEFT|wx.RIGHT, border = 3) 00139 line = wx.StaticLine(parent = sp, id = wx.ID_ANY, size = (20, -1), style = wx.LI_HORIZONTAL) 00140 txtSizer.Add(item = line, proportion = 0, 00141 flag = wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, border = 3) 00142 00143 sp.SetSizer(txtSizer) 00144 sp.SetAutoLayout(1) 00145 sp.SetupScrolling() 00146 00147 sizer.Add(item = sp, proportion = 1, 00148 flag = wx.GROW | wx.LEFT | wx.RIGHT | wx.BOTTOM, border = 3) 00149 00150 line = wx.StaticLine(parent = self, id = wx.ID_ANY, size = (20, -1), style = wx.LI_HORIZONTAL) 00151 sizer.Add(item = line, proportion = 0, 00152 flag = wx.GROW |wx.ALIGN_CENTER_VERTICAL|wx.LEFT|wx.RIGHT, border = 3) 00153 00154 # 00155 # buttons 00156 # 00157 btnSizer = wx.BoxSizer(wx.HORIZONTAL) 00158 00159 btn_clipboard = wx.Button(self, id = wx.ID_COPY, label = _('C&opy')) 00160 btn_clipboard.SetToolTipString(_("Copy regression statistics the clipboard (Ctrl+C)")) 00161 btnSizer.Add(item = btn_clipboard, proportion = 0, flag = wx.ALIGN_LEFT | wx.ALL, border = 5) 00162 00163 btnCancel = wx.Button(self, wx.ID_CLOSE) 00164 btnCancel.SetDefault() 00165 btnSizer.Add(item = btnCancel, proportion = 0, flag = wx.ALIGN_RIGHT | wx.ALL, border = 5) 00166 00167 sizer.Add(item = btnSizer, proportion = 0, flag = wx.ALIGN_RIGHT | wx.ALL, border = 5) 00168 00169 # bindings 00170 btnCancel.Bind(wx.EVT_BUTTON, self.OnClose) 00171 btn_clipboard.Bind(wx.EVT_BUTTON, self.OnCopy) 00172 00173 self.SetSizer(sizer) 00174 sizer.Fit(self) 00175 00176 def OnCopy(self, event): 00177 """!Copy the regression stats to the clipboard 00178 """ 00179 str = self.title + '\n' 00180 for item in self.message: 00181 str += item 00182 00183 rdata = wx.TextDataObject() 00184 rdata.SetText(str) 00185 00186 if wx.TheClipboard.Open(): 00187 wx.TheClipboard.SetData(rdata) 00188 wx.TheClipboard.Close() 00189 wx.MessageBox(_("Regression statistics copied to clipboard")) 00190 00191 def OnClose(self, event): 00192 """!Button 'Close' pressed 00193 """ 00194 self.Close(True) 00195 00196 class TextDialog(wx.Dialog): 00197 def __init__(self, parent, id, title, 00198 style = wx.DEFAULT_DIALOG_STYLE, **kwargs): 00199 """!Dialog to set profile text options: font, title 00200 and font size, axis labels and font size 00201 """ 00202 wx.Dialog.__init__(self, parent, id, title, style = style, **kwargs) 00203 # 00204 # initialize variables 00205 # 00206 # combo box entry lists 00207 self.ffamilydict = { 'default' : wx.FONTFAMILY_DEFAULT, 00208 'decorative' : wx.FONTFAMILY_DECORATIVE, 00209 'roman' : wx.FONTFAMILY_ROMAN, 00210 'script' : wx.FONTFAMILY_SCRIPT, 00211 'swiss' : wx.FONTFAMILY_SWISS, 00212 'modern' : wx.FONTFAMILY_MODERN, 00213 'teletype' : wx.FONTFAMILY_TELETYPE } 00214 00215 self.fstyledict = { 'normal' : wx.FONTSTYLE_NORMAL, 00216 'slant' : wx.FONTSTYLE_SLANT, 00217 'italic' : wx.FONTSTYLE_ITALIC } 00218 00219 self.fwtdict = { 'normal' : wx.FONTWEIGHT_NORMAL, 00220 'light' : wx.FONTWEIGHT_LIGHT, 00221 'bold' : wx.FONTWEIGHT_BOLD } 00222 00223 self.parent = parent 00224 00225 self.ptitle = self.parent.ptitle 00226 self.xlabel = self.parent.xlabel 00227 self.ylabel = self.parent.ylabel 00228 00229 self.properties = self.parent.properties # read-only 00230 00231 # font size 00232 self.fontfamily = self.properties['font']['wxfont'].GetFamily() 00233 self.fontstyle = self.properties['font']['wxfont'].GetStyle() 00234 self.fontweight = self.properties['font']['wxfont'].GetWeight() 00235 00236 self._do_layout() 00237 00238 def _do_layout(self): 00239 """!Do layout""" 00240 # dialog layout 00241 sizer = wx.BoxSizer(wx.VERTICAL) 00242 00243 box = wx.StaticBox(parent = self, id = wx.ID_ANY, 00244 label = " %s " % _("Text settings")) 00245 boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL) 00246 gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5) 00247 00248 # 00249 # profile title 00250 # 00251 label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Profile title:")) 00252 gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (0, 0)) 00253 self.ptitleentry = wx.TextCtrl(parent = self, id = wx.ID_ANY, value = "", size = (250,-1)) 00254 # self.ptitleentry.SetFont(self.font) 00255 self.ptitleentry.SetValue(self.ptitle) 00256 gridSizer.Add(item = self.ptitleentry, pos = (0, 1)) 00257 00258 # 00259 # title font 00260 # 00261 tlabel = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Title font size (pts):")) 00262 gridSizer.Add(item = tlabel, flag = wx.ALIGN_CENTER_VERTICAL, pos = (1, 0)) 00263 self.ptitlesize = wx.SpinCtrl(parent = self, id = wx.ID_ANY, value = "", pos = (30, 50), 00264 size = (50,-1), style = wx.SP_ARROW_KEYS) 00265 self.ptitlesize.SetRange(5,100) 00266 self.ptitlesize.SetValue(int(self.properties['font']['prop']['titleSize'])) 00267 gridSizer.Add(item = self.ptitlesize, pos = (1, 1)) 00268 00269 # 00270 # x-axis label 00271 # 00272 label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("X-axis label:")) 00273 gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (2, 0)) 00274 self.xlabelentry = wx.TextCtrl(parent = self, id = wx.ID_ANY, value = "", size = (250,-1)) 00275 # self.xlabelentry.SetFont(self.font) 00276 self.xlabelentry.SetValue(self.xlabel) 00277 gridSizer.Add(item = self.xlabelentry, pos = (2, 1)) 00278 00279 # 00280 # y-axis label 00281 # 00282 label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Y-axis label:")) 00283 gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (3, 0)) 00284 self.ylabelentry = wx.TextCtrl(parent = self, id = wx.ID_ANY, value = "", size = (250,-1)) 00285 # self.ylabelentry.SetFont(self.font) 00286 self.ylabelentry.SetValue(self.ylabel) 00287 gridSizer.Add(item = self.ylabelentry, pos = (3, 1)) 00288 00289 # 00290 # font size 00291 # 00292 llabel = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Label font size (pts):")) 00293 gridSizer.Add(item = llabel, flag = wx.ALIGN_CENTER_VERTICAL, pos = (4, 0)) 00294 self.axislabelsize = wx.SpinCtrl(parent = self, id = wx.ID_ANY, value = "", pos = (30, 50), 00295 size = (50, -1), style = wx.SP_ARROW_KEYS) 00296 self.axislabelsize.SetRange(5, 100) 00297 self.axislabelsize.SetValue(int(self.properties['font']['prop']['axisSize'])) 00298 gridSizer.Add(item = self.axislabelsize, pos = (4,1)) 00299 00300 boxSizer.Add(item = gridSizer) 00301 sizer.Add(item = boxSizer, flag = wx.ALL | wx.EXPAND, border = 3) 00302 00303 # 00304 # font settings 00305 # 00306 box = wx.StaticBox(parent = self, id = wx.ID_ANY, 00307 label = " %s " % _("Font settings")) 00308 boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL) 00309 gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5) 00310 gridSizer.AddGrowableCol(1) 00311 00312 # 00313 # font family 00314 # 00315 label1 = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Font family:")) 00316 gridSizer.Add(item = label1, flag = wx.ALIGN_CENTER_VERTICAL, pos = (0, 0)) 00317 self.ffamilycb = wx.ComboBox(parent = self, id = wx.ID_ANY, size = (250, -1), 00318 choices = self.ffamilydict.keys(), style = wx.CB_DROPDOWN) 00319 self.ffamilycb.SetStringSelection('swiss') 00320 for item in self.ffamilydict.items(): 00321 if self.fontfamily == item[1]: 00322 self.ffamilycb.SetStringSelection(item[0]) 00323 break 00324 gridSizer.Add(item = self.ffamilycb, pos = (0, 1), flag = wx.ALIGN_RIGHT) 00325 00326 # 00327 # font style 00328 # 00329 label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Style:")) 00330 gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (1, 0)) 00331 self.fstylecb = wx.ComboBox(parent = self, id = wx.ID_ANY, size = (250, -1), 00332 choices = self.fstyledict.keys(), style = wx.CB_DROPDOWN) 00333 self.fstylecb.SetStringSelection('normal') 00334 for item in self.fstyledict.items(): 00335 if self.fontstyle == item[1]: 00336 self.fstylecb.SetStringSelection(item[0]) 00337 break 00338 gridSizer.Add(item = self.fstylecb, pos = (1, 1), flag = wx.ALIGN_RIGHT) 00339 00340 # 00341 # font weight 00342 # 00343 label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Weight:")) 00344 gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (2, 0)) 00345 self.fwtcb = wx.ComboBox(parent = self, size = (250, -1), 00346 choices = self.fwtdict.keys(), style = wx.CB_DROPDOWN) 00347 self.fwtcb.SetStringSelection('normal') 00348 for item in self.fwtdict.items(): 00349 if self.fontweight == item[1]: 00350 self.fwtcb.SetStringSelection(item[0]) 00351 break 00352 00353 gridSizer.Add(item = self.fwtcb, pos = (2, 1), flag = wx.ALIGN_RIGHT) 00354 00355 boxSizer.Add(item = gridSizer, flag = wx.EXPAND) 00356 sizer.Add(item = boxSizer, flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 3) 00357 00358 line = wx.StaticLine(parent = self, id = wx.ID_ANY, size = (20, -1), style = wx.LI_HORIZONTAL) 00359 sizer.Add(item = line, proportion = 0, 00360 flag = wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.LEFT|wx.RIGHT, border = 3) 00361 00362 # 00363 # buttons 00364 # 00365 btnSave = wx.Button(self, wx.ID_SAVE) 00366 btnApply = wx.Button(self, wx.ID_APPLY) 00367 btnOk = wx.Button(self, wx.ID_OK) 00368 btnCancel = wx.Button(self, wx.ID_CANCEL) 00369 btnOk.SetDefault() 00370 00371 # bindigs 00372 btnApply.Bind(wx.EVT_BUTTON, self.OnApply) 00373 btnApply.SetToolTipString(_("Apply changes for the current session")) 00374 btnOk.Bind(wx.EVT_BUTTON, self.OnOk) 00375 btnOk.SetToolTipString(_("Apply changes for the current session and close dialog")) 00376 btnOk.SetDefault() 00377 btnSave.Bind(wx.EVT_BUTTON, self.OnSave) 00378 btnSave.SetToolTipString(_("Apply and save changes to user settings file (default for next sessions)")) 00379 btnCancel.Bind(wx.EVT_BUTTON, self.OnCancel) 00380 btnCancel.SetToolTipString(_("Close dialog and ignore changes")) 00381 00382 # sizers 00383 btnStdSizer = wx.StdDialogButtonSizer() 00384 btnStdSizer.AddButton(btnOk) 00385 btnStdSizer.AddButton(btnApply) 00386 btnStdSizer.AddButton(btnCancel) 00387 btnStdSizer.Realize() 00388 00389 btnSizer = wx.BoxSizer(wx.HORIZONTAL) 00390 btnSizer.Add(item = btnSave, proportion = 0, flag = wx.ALIGN_LEFT | wx.ALL, border = 5) 00391 btnSizer.Add(item = btnStdSizer, proportion = 0, flag = wx.ALIGN_RIGHT | wx.ALL, border = 5) 00392 sizer.Add(item = btnSizer, proportion = 0, flag = wx.ALIGN_RIGHT | wx.ALL, border = 5) 00393 00394 # 00395 # bindings 00396 # 00397 self.ptitleentry.Bind(wx.EVT_TEXT, self.OnTitle) 00398 self.xlabelentry.Bind(wx.EVT_TEXT, self.OnXLabel) 00399 self.ylabelentry.Bind(wx.EVT_TEXT, self.OnYLabel) 00400 00401 self.SetSizer(sizer) 00402 sizer.Fit(self) 00403 00404 def OnTitle(self, event): 00405 self.ptitle = event.GetString() 00406 00407 def OnXLabel(self, event): 00408 self.xlabel = event.GetString() 00409 00410 def OnYLabel(self, event): 00411 self.ylabel = event.GetString() 00412 00413 def UpdateSettings(self): 00414 self.properties['font']['prop']['titleSize'] = self.ptitlesize.GetValue() 00415 self.properties['font']['prop']['axisSize'] = self.axislabelsize.GetValue() 00416 00417 family = self.ffamilydict[self.ffamilycb.GetStringSelection()] 00418 self.properties['font']['wxfont'].SetFamily(family) 00419 style = self.fstyledict[self.fstylecb.GetStringSelection()] 00420 self.properties['font']['wxfont'].SetStyle(style) 00421 weight = self.fwtdict[self.fwtcb.GetStringSelection()] 00422 self.properties['font']['wxfont'].SetWeight(weight) 00423 00424 def OnSave(self, event): 00425 """!Button 'Save' pressed""" 00426 self.UpdateSettings() 00427 fileSettings = {} 00428 UserSettings.ReadSettingsFile(settings = fileSettings) 00429 fileSettings['profile'] = UserSettings.Get(group = 'profile') 00430 file = UserSettings.SaveToFile(fileSettings) 00431 self.parent.parent.GetLayerManager().goutput.WriteLog(_('Profile settings saved to file \'%s\'.') % file) 00432 self.EndModal(wx.ID_OK) 00433 00434 def OnApply(self, event): 00435 """!Button 'Apply' pressed""" 00436 self.UpdateSettings() 00437 self.parent.OnPText(self) 00438 00439 def OnOk(self, event): 00440 """!Button 'OK' pressed""" 00441 self.UpdateSettings() 00442 self.EndModal(wx.ID_OK) 00443 00444 def OnCancel(self, event): 00445 """!Button 'Cancel' pressed""" 00446 self.EndModal(wx.ID_CANCEL) 00447 00448 class OptDialog(wx.Dialog): 00449 def __init__(self, parent, id, title, 00450 style = wx.DEFAULT_DIALOG_STYLE, **kwargs): 00451 """!Dialog to set various profile options, including: line 00452 width, color, style; marker size, color, fill, and style; grid 00453 and legend options. 00454 """ 00455 wx.Dialog.__init__(self, parent, id, title, style = style, **kwargs) 00456 # init variables 00457 self.pstyledict = parent.pstyledict 00458 self.ptfilldict = parent.ptfilldict 00459 00460 self.pttypelist = ['circle', 00461 'dot', 00462 'square', 00463 'triangle', 00464 'triangle_down', 00465 'cross', 00466 'plus'] 00467 00468 self.axislist = ['min', 00469 'auto', 00470 'custom'] 00471 00472 # widgets ids 00473 self.wxId = {} 00474 00475 self.parent = parent 00476 00477 # read-only 00478 self.raster = self.parent.raster 00479 self.properties = self.parent.properties 00480 00481 self._do_layout() 00482 00483 def _do_layout(self): 00484 """!Do layout""" 00485 # dialog layout 00486 sizer = wx.BoxSizer(wx.VERTICAL) 00487 00488 # 00489 # profile line settings 00490 # 00491 box = wx.StaticBox(parent = self, id = wx.ID_ANY, 00492 label = " %s " % _("Profile line settings")) 00493 boxMainSizer = wx.StaticBoxSizer(box, wx.HORIZONTAL) 00494 00495 idx = 1 00496 self.wxId['pcolor'] = [] 00497 self.wxId['pwidth'] = [] 00498 self.wxId['pstyle'] = [] 00499 self.wxId['plegend'] = [] 00500 for r in self.raster.itervalues(): 00501 box = wx.StaticBox(parent = self, id = wx.ID_ANY, 00502 label = " %s %d " % (_("Profile"), idx)) 00503 boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL) 00504 00505 gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5) 00506 row = 0 00507 label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Line color")) 00508 gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (row, 0)) 00509 pcolor = csel.ColourSelect(parent = self, id = wx.ID_ANY, colour = r['prop']['pcolor']) 00510 self.wxId['pcolor'].append(pcolor.GetId()) 00511 gridSizer.Add(item = pcolor, pos = (row, 1)) 00512 00513 row += 1 00514 label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Line width")) 00515 gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (row, 0)) 00516 pwidth = wx.SpinCtrl(parent = self, id = wx.ID_ANY, value = "", 00517 size = (50,-1), style = wx.SP_ARROW_KEYS) 00518 pwidth.SetRange(1, 10) 00519 pwidth.SetValue(r['prop']['pwidth']) 00520 self.wxId['pwidth'].append(pwidth.GetId()) 00521 gridSizer.Add(item = pwidth, pos = (row, 1)) 00522 00523 row +=1 00524 label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Line style")) 00525 gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (row, 0)) 00526 pstyle = wx.ComboBox(parent = self, id = wx.ID_ANY, 00527 size = (120, -1), choices = self.pstyledict.keys(), style = wx.CB_DROPDOWN) 00528 pstyle.SetStringSelection(r['prop']['pstyle']) 00529 self.wxId['pstyle'].append(pstyle.GetId()) 00530 gridSizer.Add(item = pstyle, pos = (row, 1)) 00531 00532 row += 1 00533 label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Legend")) 00534 gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (row, 0)) 00535 plegend = wx.TextCtrl(parent = self, id = wx.ID_ANY, value = "", size = (200,-1)) 00536 plegend.SetValue(r['plegend']) 00537 gridSizer.Add(item = plegend, pos = (row, 1)) 00538 self.wxId['plegend'].append(plegend.GetId()) 00539 boxSizer.Add(item = gridSizer) 00540 00541 if idx == 0: 00542 flag = wx.ALL 00543 else: 00544 flag = wx.TOP | wx.BOTTOM | wx.RIGHT 00545 boxMainSizer.Add(item = boxSizer, flag = flag, border = 3) 00546 00547 idx += 1 00548 00549 sizer.Add(item = boxMainSizer, flag = wx.ALL | wx.EXPAND, border = 3) 00550 00551 middleSizer = wx.BoxSizer(wx.HORIZONTAL) 00552 00553 # 00554 # segment marker settings 00555 # 00556 box = wx.StaticBox(parent = self, id = wx.ID_ANY, 00557 label = " %s " % _("Transect segment marker settings")) 00558 boxMainSizer = wx.StaticBoxSizer(box, wx.HORIZONTAL) 00559 00560 self.wxId['marker'] = {} 00561 gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5) 00562 label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Color")) 00563 gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (0, 0)) 00564 ptcolor = csel.ColourSelect(parent = self, id = wx.ID_ANY, colour = self.properties['marker']['color']) 00565 self.wxId['marker']['color'] = ptcolor.GetId() 00566 gridSizer.Add(item = ptcolor, pos = (0, 1)) 00567 00568 label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Size")) 00569 gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (1, 0)) 00570 ptsize = wx.SpinCtrl(parent = self, id = wx.ID_ANY, value = "", 00571 size = (50, -1), style = wx.SP_ARROW_KEYS) 00572 ptsize.SetRange(1, 10) 00573 ptsize.SetValue(self.properties['marker']['size']) 00574 self.wxId['marker']['size'] = ptsize.GetId() 00575 gridSizer.Add(item = ptsize, pos = (1, 1)) 00576 00577 label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Style")) 00578 gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (2, 0)) 00579 ptfill = wx.ComboBox(parent = self, id = wx.ID_ANY, 00580 size = (120, -1), choices = self.ptfilldict.keys(), style = wx.CB_DROPDOWN) 00581 ptfill.SetStringSelection(self.properties['marker']['fill']) 00582 self.wxId['marker']['fill'] = ptfill.GetId() 00583 gridSizer.Add(item = ptfill, pos = (2, 1)) 00584 00585 label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Legend")) 00586 gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (3, 0)) 00587 ptlegend = wx.TextCtrl(parent = self, id = wx.ID_ANY, value = "", size = (200,-1)) 00588 ptlegend.SetValue(self.properties['marker']['legend']) 00589 self.wxId['marker']['legend'] = ptlegend.GetId() 00590 gridSizer.Add(item = ptlegend, pos = (3, 1)) 00591 00592 label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Type")) 00593 gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (4, 0)) 00594 pttype = wx.ComboBox(parent = self, 00595 size = (200, -1), choices = self.pttypelist, style = wx.CB_DROPDOWN) 00596 pttype.SetStringSelection(self.properties['marker']['type']) 00597 self.wxId['marker']['type'] = pttype.GetId() 00598 gridSizer.Add(item = pttype, pos = (4, 1)) 00599 00600 boxMainSizer.Add(item = gridSizer, flag = wx.ALL, border = 3) 00601 middleSizer.Add(item = boxMainSizer, flag = wx.ALL | wx.EXPAND, border = 3) 00602 00603 # 00604 # axis options 00605 # 00606 box = wx.StaticBox(parent = self, id = wx.ID_ANY, 00607 label = " %s " % _("Axis settings")) 00608 boxMainSizer = wx.StaticBoxSizer(box, wx.HORIZONTAL) 00609 00610 self.wxId['x-axis'] = {} 00611 self.wxId['y-axis'] = {} 00612 idx = 0 00613 for axis, atype in [(_("X-Axis"), 'x-axis'), 00614 (_("Y-Axis"), 'y-axis')]: 00615 box = wx.StaticBox(parent = self, id = wx.ID_ANY, 00616 label = " %s " % axis) 00617 boxSizer = wx.StaticBoxSizer(box, wx.HORIZONTAL) 00618 gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5) 00619 00620 prop = self.properties[atype]['prop'] 00621 00622 row = 0 00623 label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Style")) 00624 gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (row, 0)) 00625 type = wx.ComboBox(parent = self, id = wx.ID_ANY, 00626 size = (100, -1), choices = self.axislist, style = wx.CB_DROPDOWN) 00627 type.SetStringSelection(prop['type']) 00628 self.wxId[atype]['type'] = type.GetId() 00629 gridSizer.Add(item = type, pos = (row, 1)) 00630 00631 row += 1 00632 label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Custom min")) 00633 gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (row, 0)) 00634 min = wx.TextCtrl(parent = self, id = wx.ID_ANY, value = "", size = (70, -1)) 00635 min.SetValue(str(prop['min'])) 00636 self.wxId[atype]['min'] = min.GetId() 00637 gridSizer.Add(item = min, pos = (row, 1)) 00638 00639 row += 1 00640 label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Custom max")) 00641 gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (row, 0)) 00642 max = wx.TextCtrl(parent = self, id = wx.ID_ANY, value = "", size = (70, -1)) 00643 max.SetValue(str(prop['max'])) 00644 self.wxId[atype]['max'] = max.GetId() 00645 gridSizer.Add(item = max, pos = (row, 1)) 00646 00647 row += 1 00648 log = wx.CheckBox(parent = self, id = wx.ID_ANY, label = _("Log scale")) 00649 log.SetValue(prop['log']) 00650 self.wxId[atype]['log'] = log.GetId() 00651 gridSizer.Add(item = log, pos = (row, 0), span = (1, 2)) 00652 00653 if idx == 0: 00654 flag = wx.ALL | wx.EXPAND 00655 else: 00656 flag = wx.TOP | wx.BOTTOM | wx.RIGHT | wx.EXPAND 00657 00658 boxSizer.Add(item = gridSizer, flag = wx.ALL, border = 3) 00659 boxMainSizer.Add(item = boxSizer, flag = flag, border = 3) 00660 00661 idx += 1 00662 00663 middleSizer.Add(item = boxMainSizer, flag = wx.ALL | wx.EXPAND, border = 3) 00664 00665 # 00666 # grid & legend options 00667 # 00668 self.wxId['grid'] = {} 00669 self.wxId['legend'] = {} 00670 self.wxId['font'] = {} 00671 box = wx.StaticBox(parent = self, id = wx.ID_ANY, 00672 label = " %s " % _("Grid and Legend settings")) 00673 boxMainSizer = wx.StaticBoxSizer(box, wx.HORIZONTAL) 00674 gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5) 00675 00676 row = 0 00677 label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Grid color")) 00678 gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (row, 0)) 00679 gridcolor = csel.ColourSelect(parent = self, id = wx.ID_ANY, colour = self.properties['grid']['color']) 00680 self.wxId['grid']['color'] = gridcolor.GetId() 00681 gridSizer.Add(item = gridcolor, pos = (row, 1)) 00682 00683 row +=1 00684 gridshow = wx.CheckBox(parent = self, id = wx.ID_ANY, label = _("Show grid")) 00685 gridshow.SetValue(self.properties['grid']['enabled']) 00686 self.wxId['grid']['enabled'] = gridshow.GetId() 00687 gridSizer.Add(item = gridshow, pos = (row, 0), span = (1, 2)) 00688 00689 row +=1 00690 label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Legend font size")) 00691 gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (row, 0)) 00692 legendfontsize = wx.SpinCtrl(parent = self, id = wx.ID_ANY, value = "", 00693 size = (50, -1), style = wx.SP_ARROW_KEYS) 00694 legendfontsize.SetRange(5,100) 00695 legendfontsize.SetValue(int(self.properties['font']['prop']['legendSize'])) 00696 self.wxId['font']['legendSize'] = legendfontsize.GetId() 00697 gridSizer.Add(item = legendfontsize, pos = (row, 1)) 00698 00699 row += 1 00700 legendshow = wx.CheckBox(parent = self, id = wx.ID_ANY, label = _("Show legend")) 00701 legendshow.SetValue(self.properties['legend']['enabled']) 00702 self.wxId['legend']['enabled'] = legendshow.GetId() 00703 gridSizer.Add(item = legendshow, pos = (row, 0), span = (1, 2)) 00704 00705 boxMainSizer.Add(item = gridSizer, flag = flag, border = 3) 00706 00707 middleSizer.Add(item = boxMainSizer, flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 3) 00708 00709 sizer.Add(item = middleSizer, flag = wx.ALL, border = 0) 00710 00711 # 00712 # line & buttons 00713 # 00714 line = wx.StaticLine(parent = self, id = wx.ID_ANY, size = (20, -1), style = wx.LI_HORIZONTAL) 00715 sizer.Add(item = line, proportion = 0, 00716 flag = wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.LEFT|wx.RIGHT, border = 3) 00717 00718 # 00719 # buttons 00720 # 00721 btnSave = wx.Button(self, wx.ID_SAVE) 00722 btnApply = wx.Button(self, wx.ID_APPLY) 00723 btnCancel = wx.Button(self, wx.ID_CANCEL) 00724 btnSave.SetDefault() 00725 00726 # bindigs 00727 btnApply.Bind(wx.EVT_BUTTON, self.OnApply) 00728 btnApply.SetToolTipString(_("Apply changes for the current session")) 00729 btnSave.Bind(wx.EVT_BUTTON, self.OnSave) 00730 btnSave.SetToolTipString(_("Apply and save changes to user settings file (default for next sessions)")) 00731 btnSave.SetDefault() 00732 btnCancel.Bind(wx.EVT_BUTTON, self.OnCancel) 00733 btnCancel.SetToolTipString(_("Close dialog and ignore changes")) 00734 00735 # sizers 00736 btnStdSizer = wx.StdDialogButtonSizer() 00737 btnStdSizer.AddButton(btnCancel) 00738 btnStdSizer.AddButton(btnSave) 00739 btnStdSizer.AddButton(btnApply) 00740 btnStdSizer.Realize() 00741 00742 sizer.Add(item = btnStdSizer, proportion = 0, flag = wx.ALIGN_RIGHT | wx.ALL, border = 5) 00743 00744 self.SetSizer(sizer) 00745 sizer.Fit(self) 00746 00747 def UpdateSettings(self): 00748 idx = 0 00749 for r in self.raster.itervalues(): 00750 r['prop']['pcolor'] = self.FindWindowById(self.wxId['pcolor'][idx]).GetColour() 00751 r['prop']['pwidth'] = int(self.FindWindowById(self.wxId['pwidth'][idx]).GetValue()) 00752 r['prop']['pstyle'] = self.FindWindowById(self.wxId['pstyle'][idx]).GetStringSelection() 00753 r['plegend'] = self.FindWindowById(self.wxId['plegend'][idx]).GetValue() 00754 idx +=1 00755 00756 self.properties['marker']['color'] = self.FindWindowById(self.wxId['marker']['color']).GetColour() 00757 self.properties['marker']['fill'] = self.FindWindowById(self.wxId['marker']['fill']).GetStringSelection() 00758 self.properties['marker']['size'] = self.FindWindowById(self.wxId['marker']['size']).GetValue() 00759 self.properties['marker']['type'] = self.FindWindowById(self.wxId['marker']['type']).GetValue() 00760 self.properties['marker']['legend'] = self.FindWindowById(self.wxId['marker']['legend']).GetValue() 00761 00762 for axis in ('x-axis', 'y-axis'): 00763 self.properties[axis]['prop']['type'] = self.FindWindowById(self.wxId[axis]['type']).GetValue() 00764 self.properties[axis]['prop']['min'] = float(self.FindWindowById(self.wxId[axis]['min']).GetValue()) 00765 self.properties[axis]['prop']['max'] = float(self.FindWindowById(self.wxId[axis]['max']).GetValue()) 00766 self.properties[axis]['prop']['log'] = self.FindWindowById(self.wxId[axis]['log']).IsChecked() 00767 00768 self.properties['grid']['color'] = self.FindWindowById(self.wxId['grid']['color']).GetColour() 00769 self.properties['grid']['enabled'] = self.FindWindowById(self.wxId['grid']['enabled']).IsChecked() 00770 00771 self.properties['font']['prop']['legendSize'] = self.FindWindowById(self.wxId['font']['legendSize']).GetValue() 00772 self.properties['legend']['enabled'] = self.FindWindowById(self.wxId['legend']['enabled']).IsChecked() 00773 00774 def OnSave(self, event): 00775 """!Button 'Save' pressed""" 00776 self.UpdateSettings() 00777 fileSettings = {} 00778 UserSettings.ReadSettingsFile(settings = fileSettings) 00779 fileSettings['profile'] = UserSettings.Get(group = 'profile') 00780 file = UserSettings.SaveToFile(fileSettings) 00781 self.parent.parent.GetLayerManager().goutput.WriteLog(_('Profile settings saved to file \'%s\'.') % file) 00782 self.parent.SetGraphStyle() 00783 if self.parent.profile: 00784 self.parent.DrawPlot() 00785 self.Close() 00786 00787 def OnApply(self, event): 00788 """!Button 'Apply' pressed. Does not close dialog""" 00789 self.UpdateSettings() 00790 self.parent.SetGraphStyle() 00791 if self.parent.profile: 00792 self.parent.DrawPlot() 00793 00794 def OnCancel(self, event): 00795 """!Button 'Cancel' pressed""" 00796 self.Close()