def _widgets(self): if self.etype == 'raster': self.resolution = TextCtrl(self.panel, validator=FloatValidator()) self.resampling = wx.Choice(self.panel, size=(200, -1), choices=[ 'nearest', 'bilinear', 'bicubic', 'lanczos', 'bilinear_f', 'bicubic_f', 'lanczos_f' ]) else: self.vsplit = TextCtrl(self.panel, validator=IntegerValidator()) self.vsplit.SetValue('10000') # # buttons # self.btn_close = Button(parent=self.panel, id=wx.ID_CLOSE) self.SetEscapeId(self.btn_close.GetId()) # run self.btn_run = Button(parent=self.panel, id=wx.ID_OK, label=_("Reproject")) if self.etype == 'raster': self.btn_run.SetToolTip(_("Reproject raster")) elif self.etype == 'vector': self.btn_run.SetToolTip(_("Reproject vector")) self.btn_run.SetDefault() self.btn_run.Bind(wx.EVT_BUTTON, self.OnReproject)
def __init__(self, parent, shape, title, id=wx.ID_ANY, style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, **kwargs): self.parent = parent self.shape = shape wx.Dialog.__init__( self, parent, id, title=title, style=style, **kwargs) self.panel = wx.Panel(parent=self, id=wx.ID_ANY) self.condBox = StaticBox(parent=self.panel, id=wx.ID_ANY, label=" %s " % _("Condition")) self.condText = TextCtrl(parent=self.panel, id=wx.ID_ANY, value=shape.GetLabel()) self.itemList = ItemCheckListCtrl(parent=self.panel, columns=[_("Label"), _("Command")], shape=shape, frame=parent) self.itemList.Populate(self.parent.GetModel().GetItems()) self.btnCancel = Button(parent=self.panel, id=wx.ID_CANCEL) self.btnOk = Button(parent=self.panel, id=wx.ID_OK) self.btnOk.SetDefault()
def __init__(self, parent, conf, giface=None, id=wx.ID_ANY, title=_("Modify the configuration file"), style=wx.DEFAULT_FRAME_STYLE | wx.RESIZE_BORDER, **kwargs): # VARIABLES self.parent = parent self.rlipath = retRLiPath() self.confile = conf self.pathfile = os.path.join(self.rlipath, conf) wx.Frame.__init__(self, parent=parent, id=id, title=title, **kwargs) self.SetIcon(wx.Icon(os.path.join(globalvar.ICONDIR, 'grass.ico'), wx.BITMAP_TYPE_ICO)) self.panel = wx.Panel(parent=self, id=wx.ID_ANY) self.confilesBox = StaticBox( parent=self.panel, id=wx.ID_ANY, label=_( "View and modify the " "configuration file '{name}'".format( name=self.confile))) self.textCtrl = TextCtrl(parent=self.panel, id=wx.ID_ANY, style=wx.TE_MULTILINE, size=(-1, 75)) self.textCtrl.Bind(wx.EVT_TEXT, self.OnFileText) f = open(self.pathfile) self.textCtrl.SetValue(''.join(f.readlines())) f.close() # BUTTONS #definition self.btn_close = Button(parent=self, id=wx.ID_EXIT) self.btn_ok = Button(parent=self, id=wx.ID_SAVE) self.btn_close.Bind(wx.EVT_BUTTON, self.OnClose) self.btn_ok.Bind(wx.EVT_BUTTON, self.OnOk) self._layout() self.enc = locale.getdefaultlocale()[1]
def MakeAdvConnPane(self, pane): """Create advanced connection settings pane""" self.usernameText = StaticText(parent=pane, id=wx.ID_ANY, label=_("Username:"******"Password:")) self.password = TextCtrl(parent=pane, id=wx.ID_ANY, style=wx.TE_PASSWORD) # pane layout adv_conn_sizer = wx.BoxSizer(wx.VERTICAL) usernameSizer = wx.BoxSizer(wx.HORIZONTAL) usernameSizer.Add(self.usernameText, flag=wx.ALIGN_CENTER_VERTICAL, border=5) usernameSizer.Add(self.username, proportion=1, flag=wx.EXPAND, border=5) adv_conn_sizer.Add(usernameSizer, flag=wx.ALL | wx.EXPAND, border=5) passwSizer = wx.BoxSizer(wx.HORIZONTAL) passwSizer.Add(self.passwText, flag=wx.ALIGN_CENTER_VERTICAL, border=5) passwSizer.Add(self.password, proportion=1, flag=wx.EXPAND, border=5) adv_conn_sizer.Add(passwSizer, flag=wx.ALL | wx.EXPAND, border=5) pane.SetSizer(adv_conn_sizer) adv_conn_sizer.Fit(pane) pane.SetSizer(adv_conn_sizer) adv_conn_sizer.Fit(pane)
def __layout(self): """Do layout""" sizer = wx.BoxSizer(wx.VERTICAL) dataSizer = wx.BoxSizer(wx.VERTICAL) dataSizer.Add( StaticText( parent=self.panel, id=wx.ID_ANY, label=_("Enter name of signature file:"), ), proportion=0, flag=wx.ALL, border=3, ) self.fileNameCtrl = TextCtrl(parent=self.panel, id=wx.ID_ANY, size=(400, -1)) if self.fileName: self.fileNameCtrl.SetValue(self.fileName) dataSizer.Add( self.fileNameCtrl, proportion=0, flag=wx.ALL | wx.EXPAND, border=3 ) dataSizer.Add( StaticText( parent=self.panel, id=wx.ID_ANY, label=_("Signature file path:") ), proportion=0, flag=wx.ALL, border=3, ) self.pathPanel = scrolled.ScrolledPanel(self.panel, size=(-1, 40)) pathSizer = wx.BoxSizer() self.filePathText = StaticText( parent=self.pathPanel, id=wx.ID_ANY, label=self.baseFilePath ) pathSizer.Add( self.filePathText, proportion=1, flag=wx.ALL | wx.EXPAND, border=1 ) self.pathPanel.SetupScrolling(scroll_x=True, scroll_y=False) self.pathPanel.SetSizer(pathSizer) dataSizer.Add(self.pathPanel, proportion=0, flag=wx.ALL | wx.EXPAND, border=3) # buttons btnSizer = wx.StdDialogButtonSizer() btnSizer.AddButton(self.btnCancel) btnSizer.AddButton(self.btnOK) btnSizer.Realize() sizer.Add(dataSizer, proportion=1, flag=wx.EXPAND | wx.ALL, border=5) sizer.Add(btnSizer, proportion=0, flag=wx.EXPAND | wx.ALL, border=5) self.panel.SetSizer(sizer) sizer.Fit(self) self.SetMinSize(self.GetSize())
def __init__(self, mapframe, statusbar, position=0): SbItem.__init__(self, mapframe, statusbar, position) self.name = 'goto' self.label = _("Go to") self.widget = TextCtrl(parent=self.statusbar, id=wx.ID_ANY, value="", style=wx.TE_PROCESS_ENTER, size=(300, -1)) self.widget.Hide() self.widget.Bind(wx.EVT_TEXT_ENTER, self.OnGoTo)
def __init__(self, parent, old_name, title=("Change class name")): SimpleDialog.__init__(self, parent, title) self.name = TextCtrl(self.panel, id=wx.ID_ANY) self.name.SetValue(old_name) self.dataSizer.Add(self.name, proportion=0, flag=wx.EXPAND | wx.ALL, border=1) self.panel.SetSizer(self.sizer) self.name.SetMinSize((200, -1)) self.sizer.Fit(self)
class DataCatalogToolbar(BaseToolbar): """Main data catalog toolbar """ def __init__(self, parent): """Main toolbar constructor """ BaseToolbar.__init__(self, parent) self.InitToolbar(self._toolbarData()) self.filter = TextCtrl(parent=self) self.filter.SetSize((120, self.filter.GetBestSize()[1])) self.filter.Bind( wx.EVT_TEXT, lambda event: self.parent.Filter(self.filter.GetValue())) self.AddControl(StaticText(self, label=_("Search:"))) self.AddControl(self.filter) help = _( "Type to search database by map type or name. " "Use prefix 'r:', 'v:' and 'r3:'" "to show only raster, vector or 3D raster data, respectively. " "Use Python regular expressions to refine your search.") self.SetToolShortHelp(self.filter.GetId(), help) # realize the toolbar self.Realize() def _toolbarData(self): """Returns toolbar data (name, icon, handler)""" # BaseIcons are a set of often used icons. It is possible # to reuse icons in ./trunk/gui/icons/grass or add new ones there. return self._getToolbarData( (("reloadTree", icons["reloadTree"], self.parent.OnReloadTree), ("reloadMapset", icons["reloadMapset"], self.parent.OnReloadCurrentMapset), ("lock", icons['locked'], self.OnSetRestriction, wx.ITEM_CHECK), ("addGrassDB", icons['addGrassDB'], self.parent.OnAddGrassDB), ("addLocation", icons['addLocation'], self.parent.OnCreateLocation), ("downloadLocation", icons['downloadLocation'], self.parent.OnDownloadLocation), ("addMapset", icons['addMapset'], self.parent.OnCreateMapset))) def OnSetRestriction(self, event): if self.GetToolState(self.lock): self.SetToolNormalBitmap(self.lock, icons['unlocked'].GetBitmap()) self.SetToolShortHelp(self.lock, icons['unlocked'].GetLabel()) self.parent.SetRestriction(restrict=False) else: self.SetToolNormalBitmap(self.lock, icons['locked'].GetBitmap()) self.SetToolShortHelp(self.lock, icons['locked'].GetLabel()) self.parent.SetRestriction(restrict=True)
def _pageCitation(self): """Citation information""" try: # import only when needed import grass.script as gscript text = gscript.read_command('g.version', flags='x') except CalledModuleError as error: text = _("Unable to provide citation suggestion," " see GRASS GIS website instead." " The error was: {0}").format(error) # put text into a scrolling panel window = ScrolledPanel(self.aboutNotebook) stat_text = TextCtrl(window, id=wx.ID_ANY, value=text, style=wx.TE_MULTILINE | wx.TE_READONLY) window.SetAutoLayout(True) window.sizer = wx.BoxSizer(wx.VERTICAL) window.sizer.Add(stat_text, proportion=1, flag=wx.EXPAND | wx.ALL, border=3) window.SetSizer(window.sizer) window.Layout() window.SetupScrolling() return window
def _pageLicense(self): """Licence about""" licfile = os.path.join(os.getenv("GISBASE"), "GPL.TXT") if os.path.exists(licfile): licenceFile = open(licfile, 'r') license = ''.join(licenceFile.readlines()) licenceFile.close() else: license = _('%s file missing') % 'GPL.TXT' # put text into a scrolling panel licensewin = ScrolledPanel(self.aboutNotebook) licensetxt = TextCtrl(licensewin, id=wx.ID_ANY, value=license, style=wx.TE_MULTILINE | wx.TE_READONLY) licensewin.SetAutoLayout(True) licensewin.sizer = wx.BoxSizer(wx.VERTICAL) licensewin.sizer.Add(licensetxt, proportion=1, flag=wx.EXPAND | wx.ALL, border=3) licensewin.SetSizer(licensewin.sizer) licensewin.Layout() licensewin.SetupScrolling() return licensewin
def _pageCopyright(self): """Copyright information""" copyfile = os.path.join(os.getenv("GISBASE"), "COPYING") if os.path.exists(copyfile): copyrightFile = open(copyfile, 'r') copytext = copyrightFile.read() copyrightFile.close() else: copytext = _('%s file missing') % 'COPYING' # put text into a scrolling panel copyrightwin = ScrolledPanel(self.aboutNotebook) copyrighttxt = TextCtrl(copyrightwin, id=wx.ID_ANY, value=copytext, style=wx.TE_MULTILINE | wx.TE_READONLY) copyrightwin.SetAutoLayout(True) copyrightwin.sizer = wx.BoxSizer(wx.VERTICAL) copyrightwin.sizer.Add(copyrighttxt, proportion=1, flag=wx.EXPAND | wx.ALL, border=3) copyrightwin.SetSizer(copyrightwin.sizer) copyrightwin.Layout() copyrightwin.SetupScrolling() return copyrightwin
def __init__(self, parent, title, id=wx.ID_ANY, style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER): """Dialog for adding column into table """ wx.Dialog.__init__(self, parent, id, title, style=style) self.CenterOnParent() self.data = {} self.data['addColName'] = TextCtrl( parent=self, id=wx.ID_ANY, value='', size=( 150, -1), style=wx.TE_PROCESS_ENTER) self.data['addColType'] = wx.Choice(parent=self, id=wx.ID_ANY, choices=["integer", "double", "varchar", "date"]) # FIXME self.data['addColType'].SetSelection(0) self.data['addColType'].Bind(wx.EVT_CHOICE, self.OnTableChangeType) self.data['addColLength'] = SpinCtrl( parent=self, id=wx.ID_ANY, size=( 65, -1), initial=250, min=1, max=1e6) self.data['addColLength'].Enable(False) # buttons self.btnCancel = Button(self, wx.ID_CANCEL) self.btnOk = Button(self, wx.ID_OK) self.btnOk.SetDefault() self._layout()
def _pageCredit(self): """Credit about""" # credits authfile = os.path.join(os.getenv("GISBASE"), "AUTHORS") if os.path.exists(authfile): with codecs.open(authfile, encoding='utf-8', mode='r') as authorsFile: authors = ''.join(authorsFile.readlines()) else: authors = _('%s file missing') % 'AUTHORS' authorwin = ScrolledPanel(self.aboutNotebook) authortxt = TextCtrl(authorwin, id=wx.ID_ANY, value=authors, style=wx.TE_MULTILINE | wx.TE_READONLY) authorwin.SetAutoLayout(True) authorwin.SetupScrolling() authorwin.sizer = wx.BoxSizer(wx.VERTICAL) authorwin.sizer.Add(authortxt, proportion=1, flag=wx.EXPAND | wx.ALL, border=3) authorwin.SetSizer(authorwin.sizer) authorwin.Layout() return authorwin
def MakeTextCtrl(self, text="", size=(100, -1), style=0, parent=None, tooltip=None): """Generic text control""" if not parent: parent = self textCtrl = TextCtrl(parent=parent, id=wx.ID_ANY, value=text, size=size, style=style) if tooltip: textCtrl.SetToolTip(tooltip) return textCtrl
def __init__(self, parent): wx.Panel.__init__(self, parent=parent, id=wx.ID_ANY) self.label1 = StaticText(self, id=wx.ID_ANY) self.slider = wx.Slider(self, id=wx.ID_ANY, style=wx.SL_HORIZONTAL) self.indexField = TextCtrl(self, id=wx.ID_ANY, size=(40, -1), style=wx.TE_PROCESS_ENTER | wx.TE_RIGHT, validator=IntegerValidator()) self.callbackSliderChanging = None self.callbackSliderChanged = None self.callbackFrameIndexChanged = None self.framesCount = 0 self.enable = True self.slider.Bind(wx.EVT_SPIN, self.OnSliderChanging) self.slider.Bind(wx.EVT_SCROLL_THUMBRELEASE, self.OnSliderChanged) self.indexField.Bind(wx.EVT_TEXT_ENTER, self.OnFrameIndexChanged)
def __init__(self, parent): """Main toolbar constructor """ BaseToolbar.__init__(self, parent) self.InitToolbar(self._toolbarData()) self.filter = TextCtrl(parent=self) self.filter.SetSize((120, self.filter.GetBestSize()[1])) self.filter.Bind( wx.EVT_TEXT, lambda event: self.parent.Filter(self.filter.GetValue())) self.AddControl(StaticText(self, label=_("Search:"))) self.AddControl(self.filter) help = _( "Type to search database by map type or name. " "Use prefix 'r:', 'v:' and 'r3:'" "to show only raster, vector or 3D raster data, respectively. " "Use Python regular expressions to refine your search.") self.SetToolShortHelp(self.filter.GetId(), help) # realize the toolbar self.Realize()
class ModelItemDialog(wx.Dialog): """Abstract item properties dialog""" def __init__( self, parent, shape, title, id=wx.ID_ANY, style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, **kwargs, ): self.parent = parent self.shape = shape wx.Dialog.__init__(self, parent, id, title=title, style=style, **kwargs) self.panel = wx.Panel(parent=self, id=wx.ID_ANY) self.condBox = StaticBox(parent=self.panel, id=wx.ID_ANY, label=" %s " % _("Condition")) self.condText = TextCtrl(parent=self.panel, id=wx.ID_ANY, value=shape.GetLabel()) self.itemList = ItemCheckListCtrl( parent=self.panel, columns=[_("Label"), _("Command")], shape=shape, frame=parent, ) self.itemList.Populate(self.parent.GetModel().GetItems()) self.btnCancel = Button(parent=self.panel, id=wx.ID_CANCEL) self.btnOk = Button(parent=self.panel, id=wx.ID_OK) self.btnOk.SetDefault() def _layout(self): """Do layout (virtual method)""" pass def GetCondition(self): """Get loop condition""" return self.condText.GetValue()
def AddTool(self): snum = len(self.toolslines.keys()) num = snum + 1 # tool tool_cbox = wx.ComboBox( parent=self.ct_panel, id=1000 + num, size=(300, -1), choices=self.tool_desc_list, style=wx.CB_DROPDOWN | wx.CB_READONLY | wx.TE_PROCESS_ENTER, ) self.Bind(wx.EVT_COMBOBOX, self.OnSetTool, tool_cbox) # threshold txt_ctrl = TextCtrl( parent=self.ct_panel, id=2000 + num, value="0.00", size=(100, -1), style=wx.TE_NOHIDESEL, ) self.Bind(wx.EVT_TEXT, self.OnThreshValue, txt_ctrl) # select with tool number select = wx.CheckBox(parent=self.ct_panel, id=num, label=str(num) + ".") select.SetValue(False) self.Bind(wx.EVT_CHECKBOX, self.OnSelect, select) # start with row 1 and col 1 for nicer layout self.ct_sizer.Add(select, pos=(num, 1), flag=wx.ALIGN_CENTER | wx.RIGHT) self.ct_sizer.Add(tool_cbox, pos=(num, 2), flag=wx.ALIGN_CENTER | wx.RIGHT, border=5) self.ct_sizer.Add(txt_ctrl, pos=(num, 3), flag=wx.ALIGN_CENTER | wx.RIGHT, border=5) self.toolslines[num] = {"tool_desc": "", "tool": "", "thresh": "0.00"} self.ct_panel.Layout() self.ct_panel.SetupScrolling()
def __init__( self, parent, id=wx.ID_ANY, title=_("Model properties"), size=(350, 400), style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, ): wx.Dialog.__init__(self, parent, id, title, size=size, style=style) self.metaBox = StaticBox(parent=self, id=wx.ID_ANY, label=" %s " % _("Metadata")) self.cmdBox = StaticBox(parent=self, id=wx.ID_ANY, label=" %s " % _("Commands")) self.name = TextCtrl(parent=self, id=wx.ID_ANY, size=(300, 25)) self.desc = TextCtrl(parent=self, id=wx.ID_ANY, style=wx.TE_MULTILINE, size=(300, 50)) self.author = TextCtrl(parent=self, id=wx.ID_ANY, size=(300, 25)) # commands self.overwrite = wx.CheckBox( parent=self, id=wx.ID_ANY, label=_("Allow output files to overwrite existing files"), ) self.overwrite.SetValue( UserSettings.Get(group="cmd", key="overwrite", subkey="enabled")) # buttons self.btnOk = Button(self, wx.ID_OK) self.btnCancel = Button(self, wx.ID_CANCEL) self.btnOk.SetDefault() self.btnOk.SetToolTip(_("Apply properties")) self.btnOk.SetDefault() self.btnCancel.SetToolTip(_("Close dialog and ignore changes")) self.Bind(wx.EVT_CLOSE, self.OnCloseWindow) self._layout()
def MakeSettings3DPaneContent(self, pane): """Create 3D region settings pane""" border = wx.BoxSizer(wx.VERTICAL) gridSizer = wx.GridBagSizer(vgap=0, hgap=0) # inputs self.ttop = TextCtrl(parent=pane, id=wx.ID_ANY, value=str(self.top), size=(150, -1)) self.tbottom = TextCtrl( parent=pane, id=wx.ID_ANY, value=str( self.bottom), size=( 150, -1)) self.ttbres = TextCtrl( parent=pane, id=wx.ID_ANY, value=str( self.tbres), size=( 150, -1)) # self.tnsres3 = wx.TextCtrl(parent = pane, id = wx.ID_ANY, value = str(self.nsres3), # size = (150, -1)) # self.tewres3 = wx.TextCtrl(parent = pane, id = wx.ID_ANY, value = str(self.ewres3), # size = (150, -1)) # labels self.ldepth = StaticText( parent=pane, label=_("Depth: %d") % self.depth) self.lcells3 = StaticText( parent=pane, label=_("3D Cells: %d") % self.cells3) # top gridSizer.Add(StaticText(parent=pane, label=_("Top")), flag=wx.ALIGN_CENTER | wx.LEFT | wx.RIGHT | wx.TOP, border=5, pos=(0, 1)) gridSizer.Add(self.ttop, flag=wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, border=5, pos=(1, 1)) # bottom gridSizer.Add(StaticText(parent=pane, label=_("Bottom")), flag=wx.ALIGN_CENTER | wx.LEFT | wx.RIGHT | wx.TOP, border=5, pos=(0, 2)) gridSizer.Add(self.tbottom, flag=wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, border=5, pos=(1, 2)) # tbres gridSizer.Add( StaticText( parent=pane, label=_("T-B resolution")), flag=wx.ALIGN_CENTER | wx.LEFT | wx.RIGHT | wx.TOP, border=5, pos=( 0, 3)) gridSizer.Add(self.ttbres, flag=wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, border=5, pos=(1, 3)) # res # gridSizer.Add(item = wx.StaticText(parent = pane, label = _("3D N-S resolution")), # flag = wx.ALIGN_CENTER | # wx.LEFT | wx.RIGHT | wx.TOP, border = 5, # pos = (2, 1)) # gridSizer.Add(item = self.tnsres3, # flag = wx.ALIGN_CENTER_HORIZONTAL | # wx.ALL, border = 5, pos = (3, 1)) # gridSizer.Add(item = wx.StaticText(parent = pane, label = _("3D E-W resolution")), # flag = wx.ALIGN_CENTER | # wx.LEFT | wx.RIGHT | wx.TOP, border = 5, # pos = (2, 3)) # gridSizer.Add(item = self.tewres3, # flag = wx.ALIGN_CENTER_HORIZONTAL | # wx.ALL, border = 5, pos = (3, 3)) # rows/cols/cells gridSizer.Add(self.ldepth, flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER | wx.ALL, border=5, pos=(2, 1)) gridSizer.Add(self.lcells3, flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER | wx.ALL, border=5, pos=(2, 2)) border.Add(gridSizer, proportion=1, flag=wx.ALL | wx.ALIGN_CENTER | wx.EXPAND, border=5) pane.SetSizer(border) border.Fit(pane)
class ViewFrame(wx.Frame): def __init__(self, parent, conf, giface=None, id=wx.ID_ANY, title=_("Modify the configuration file"), style=wx.DEFAULT_FRAME_STYLE | wx.RESIZE_BORDER, **kwargs): # VARIABLES self.parent = parent self.rlipath = retRLiPath() self.confile = conf self.pathfile = os.path.join(self.rlipath, conf) wx.Frame.__init__(self, parent=parent, id=id, title=title, **kwargs) self.SetIcon(wx.Icon(os.path.join(globalvar.ICONDIR, 'grass.ico'), wx.BITMAP_TYPE_ICO)) self.panel = wx.Panel(parent=self, id=wx.ID_ANY) self.confilesBox = StaticBox( parent=self.panel, id=wx.ID_ANY, label=_( "View and modify the " "configuration file '{name}'".format( name=self.confile))) self.textCtrl = TextCtrl(parent=self.panel, id=wx.ID_ANY, style=wx.TE_MULTILINE, size=(-1, 75)) self.textCtrl.Bind(wx.EVT_TEXT, self.OnFileText) f = open(self.pathfile) self.textCtrl.SetValue(''.join(f.readlines())) f.close() # BUTTONS #definition self.btn_close = Button(parent=self, id=wx.ID_EXIT) self.btn_ok = Button(parent=self, id=wx.ID_SAVE) self.btn_close.Bind(wx.EVT_BUTTON, self.OnClose) self.btn_ok.Bind(wx.EVT_BUTTON, self.OnOk) self._layout() self.enc = locale.getdefaultlocale()[1] def _layout(self): """Set the layout""" panelsizer = wx.GridBagSizer(1, 1) mainsizer = wx.BoxSizer(wx.VERTICAL) # CONFILES confilesSizer = wx.StaticBoxSizer(self.confilesBox, wx.HORIZONTAL) confilesSizer.Add(self.textCtrl, proportion=1, flag=wx.EXPAND) # END CONFILES # BUTTONS buttonSizer = wx.BoxSizer(wx.HORIZONTAL) buttonSizer.Add(self.btn_ok, flag=wx.ALL, border=5) buttonSizer.Add(self.btn_close, flag=wx.ALL, border=5) # END BUTTONS # add listbox to staticbox panelsizer.Add(confilesSizer, pos=(0, 0), flag=wx.EXPAND, border=3) # add panel and buttons mainsizer.Add(self.panel, proportion=1, flag=wx.EXPAND, border=3) mainsizer.Add(buttonSizer, proportion=0, flag=wx.EXPAND, border=3) panelsizer.AddGrowableRow(0) panelsizer.AddGrowableCol(0) self.panel.SetAutoLayout(True) self.panel.SetSizerAndFit(panelsizer) self.SetSizer(mainsizer) self.Layout() def OnClose(self, event): """Close window""" self.Destroy() def OnOk(self, event): """Launches help""" dlg = wx.MessageDialog( parent=self.parent, message=_( "Are you sure that you want modify" " r.li configuration file {name}?" "\nYou could broke the configuration" " file...").format( name=self.confile), caption=_("WARNING"), style=wx.YES_NO | wx.YES_DEFAULT | wx.ICON_WARNING) if dlg.ShowModal() == wx.ID_YES: f = codecs.open(self.pathfile, encoding=self.enc, mode='w', errors='replace') f.write(self.text + os.linesep) f.close() dlg.Destroy() self.Destroy() def OnFileText(self, event): """File input interactively entered""" self.text = event.GetString()
def __init__(self, parent, title=_("Add GRASS command to the model"), style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, **kwargs): """Graphical modeler module search window :param parent: parent window :param id: window id :param title: window title :param kwargs: wx.Dialogs' arguments """ self.parent = parent wx.Dialog.__init__( self, parent=parent, id=wx.ID_ANY, title=title, **kwargs) self.SetName("ModelerDialog") self.SetIcon( wx.Icon( os.path.join( globalvar.ICONDIR, 'grass.ico'), wx.BITMAP_TYPE_ICO)) self._command = None self.panel = wx.Panel(parent=self, id=wx.ID_ANY) self.cmdBox = StaticBox(parent=self.panel, id=wx.ID_ANY, label=" %s " % _("Command")) self.labelBox = StaticBox(parent=self.panel, id=wx.ID_ANY, label=" %s " % _("Label and comment")) # menu data for search widget and prompt menuModel = LayerManagerMenuData() self.cmd_prompt = GPromptSTC( parent=self, menuModel=menuModel.GetModel()) self.cmd_prompt.promptRunCmd.connect(self.OnCommand) self.cmd_prompt.commandSelected.connect( lambda command: self.label.SetValue(command)) self.search = SearchModuleWidget(parent=self.panel, model=menuModel.GetModel(), showTip=True) self.search.moduleSelected.connect( lambda name: self.cmd_prompt.SetTextAndFocus(name + ' ')) wx.CallAfter(self.cmd_prompt.SetFocus) self.label = TextCtrl(parent=self.panel, id=wx.ID_ANY) self.comment = TextCtrl( parent=self.panel, id=wx.ID_ANY, style=wx.TE_MULTILINE) self.btnCancel = Button(self.panel, wx.ID_CANCEL) self.btnOk = Button(self.panel, wx.ID_OK) self.btnOk.SetDefault() self.Bind(wx.EVT_BUTTON, self.OnOk, self.btnOk) self.Bind(wx.EVT_BUTTON, self.OnCancel, self.btnCancel) self._layout() self.SetSize((500, -1))
class ModelSearchDialog(wx.Dialog): def __init__(self, parent, title=_("Add GRASS command to the model"), style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, **kwargs): """Graphical modeler module search window :param parent: parent window :param id: window id :param title: window title :param kwargs: wx.Dialogs' arguments """ self.parent = parent wx.Dialog.__init__( self, parent=parent, id=wx.ID_ANY, title=title, **kwargs) self.SetName("ModelerDialog") self.SetIcon( wx.Icon( os.path.join( globalvar.ICONDIR, 'grass.ico'), wx.BITMAP_TYPE_ICO)) self._command = None self.panel = wx.Panel(parent=self, id=wx.ID_ANY) self.cmdBox = StaticBox(parent=self.panel, id=wx.ID_ANY, label=" %s " % _("Command")) self.labelBox = StaticBox(parent=self.panel, id=wx.ID_ANY, label=" %s " % _("Label and comment")) # menu data for search widget and prompt menuModel = LayerManagerMenuData() self.cmd_prompt = GPromptSTC( parent=self, menuModel=menuModel.GetModel()) self.cmd_prompt.promptRunCmd.connect(self.OnCommand) self.cmd_prompt.commandSelected.connect( lambda command: self.label.SetValue(command)) self.search = SearchModuleWidget(parent=self.panel, model=menuModel.GetModel(), showTip=True) self.search.moduleSelected.connect( lambda name: self.cmd_prompt.SetTextAndFocus(name + ' ')) wx.CallAfter(self.cmd_prompt.SetFocus) self.label = TextCtrl(parent=self.panel, id=wx.ID_ANY) self.comment = TextCtrl( parent=self.panel, id=wx.ID_ANY, style=wx.TE_MULTILINE) self.btnCancel = Button(self.panel, wx.ID_CANCEL) self.btnOk = Button(self.panel, wx.ID_OK) self.btnOk.SetDefault() self.Bind(wx.EVT_BUTTON, self.OnOk, self.btnOk) self.Bind(wx.EVT_BUTTON, self.OnCancel, self.btnCancel) self._layout() self.SetSize((500, -1)) def _layout(self): cmdSizer = wx.StaticBoxSizer(self.cmdBox, wx.VERTICAL) cmdSizer.Add(self.cmd_prompt, proportion=1, flag=wx.EXPAND) labelSizer = wx.StaticBoxSizer(self.labelBox, wx.VERTICAL) gridSizer = wx.GridBagSizer(hgap=5, vgap=5) gridSizer.Add(StaticText(parent=self.panel, id=wx.ID_ANY, label=_("Label:")), flag=wx.ALIGN_CENTER_VERTICAL, pos=(0, 0)) gridSizer.Add(self.label, pos=(0, 1), flag=wx.EXPAND) gridSizer.Add(StaticText(parent=self.panel, id=wx.ID_ANY, label=_("Comment:")), flag=wx.ALIGN_CENTER_VERTICAL, pos=(1, 0)) gridSizer.Add(self.comment, pos=(1, 1), flag=wx.EXPAND) gridSizer.AddGrowableRow(1) gridSizer.AddGrowableCol(1) labelSizer.Add(gridSizer, proportion=1, flag=wx.EXPAND) btnSizer = wx.StdDialogButtonSizer() btnSizer.AddButton(self.btnCancel) btnSizer.AddButton(self.btnOk) btnSizer.Realize() mainSizer = wx.BoxSizer(wx.VERTICAL) mainSizer.Add(self.search, proportion=0, flag=wx.EXPAND | wx.ALL, border=3) mainSizer.Add(cmdSizer, proportion=1, flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, border=3) mainSizer.Add(labelSizer, proportion=1, flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, border=3) mainSizer.Add(btnSizer, proportion=0, flag=wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border=5) self.panel.SetSizer(mainSizer) mainSizer.Fit(self) self.Layout() def GetPanel(self): """Get dialog panel""" return self.panel def _getCmd(self): line = self.cmd_prompt.GetCurLine()[0].strip() if len(line) == 0: cmd = list() else: try: cmd = utils.split(str(line)) except UnicodeError: cmd = utils.split(EncodeString((line))) return cmd def GetCmd(self): """Get command""" return self._command def GetLabel(self): """Get label and comment""" return self.label.GetValue(), self.comment.GetValue() def ValidateCmd(self, cmd): if len(cmd) < 1: GError(parent=self, message=_("Command not defined.\n\n" "Unable to add new action to the model.")) return False if cmd[0] not in globalvar.grassCmd: GError( parent=self, message=_( "'%s' is not a GRASS module.\n\n" "Unable to add new action to the model.") % cmd[0]) return False return True def OnCommand(self, cmd): """Command in prompt confirmed""" if self.ValidateCmd(cmd): self._command = cmd self.EndModal(wx.ID_OK) def OnOk(self, event): """Button 'OK' pressed""" cmd = self._getCmd() if self.ValidateCmd(cmd): self._command = cmd self.EndModal(wx.ID_OK) def OnCancel(self, event): """Cancel pressed, close window""" self.Hide() def Reset(self): """Reset dialog""" self.search.Reset() self.label.SetValue('') self.comment.SetValue('') self.cmd_prompt.OnCmdErase(None) self.cmd_prompt.SetFocus()
class WSDialogBase(wx.Dialog): """Base class for web service dialogs.""" def __init__( self, parent, id=wx.ID_ANY, style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, **kwargs, ): wx.Dialog.__init__(self, parent, id, style=style, **kwargs) self.parent = parent # contains panel for every web service on server self.ws_panels = { "WMS_1.1.1": { "panel": None, "label": "WMS 1.1.1" }, "WMS_1.3.0": { "panel": None, "label": "WMS 1.3.0" }, "WMTS": { "panel": None, "label": "WMTS" }, "OnEarth": { "panel": None, "label": "OnEarth" }, } # TODO: should be in file self.default_servers = { "OSM-WMS-EUROPE": [ "http://watzmann-geog.urz.uni-heidelberg.de/cached/osm", "", "", ], "irs.gis-lab.info (OSM)": ["http://irs.gis-lab.info", "", ""], "NASA GIBS WMTS": [ "http://gibs.earthdata.nasa.gov/wmts/epsg4326/best/wmts.cgi", "", "", ], } # holds reference to web service panel which is showed self.active_ws_panel = None # buttons which are disabled when the dialog is not connected self.run_btns = [] # stores error messages for GError dialog showed when all web service # connections were unsuccessful self.error_msgs = "" self._createWidgets() self._doLayout() def _createWidgets(self): settingsFile = os.path.join(GetSettingsPath(), "wxWS") self.settsManager = WSManageSettingsWidget( parent=self, settingsFile=settingsFile, default_servers=self.default_servers) self.settingsBox = StaticBox(parent=self, id=wx.ID_ANY, label=_(" Server settings ")) self.serverText = StaticText(parent=self, id=wx.ID_ANY, label=_("Server:")) self.server = TextCtrl(parent=self, id=wx.ID_ANY) self.btn_connect = Button(parent=self, id=wx.ID_ANY, label=_("&Connect")) self.btn_connect.SetToolTip(_("Connect to the server")) if not self.server.GetValue(): self.btn_connect.Enable(False) self.infoCollapseLabelExp = _("Show advanced connection settings") self.infoCollapseLabelCol = _("Hide advanced connection settings") self.adv_conn = wx.CollapsiblePane( parent=self, label=self.infoCollapseLabelExp, style=wx.CP_DEFAULT_STYLE | wx.CP_NO_TLW_RESIZE | wx.EXPAND, ) self.MakeAdvConnPane(pane=self.adv_conn.GetPane()) self.adv_conn.Collapse(True) self.Bind(wx.EVT_COLLAPSIBLEPANE_CHANGED, self.OnAdvConnPaneChanged, self.adv_conn) self.reqDataPanel = wx.Panel(parent=self, id=wx.ID_ANY) self.layerNameBox = StaticBox(parent=self.reqDataPanel, id=wx.ID_ANY, label=_(" Layer Manager Settings ")) self.layerNameText = StaticText(parent=self.reqDataPanel, id=wx.ID_ANY, label=_("Output layer name:")) self.layerName = TextCtrl(parent=self.reqDataPanel, id=wx.ID_ANY) for ws in six.iterkeys(self.ws_panels): # set class WSPanel argument layerNameTxtCtrl self.ws_panels[ws]["panel"] = WSPanel(parent=self.reqDataPanel, web_service=ws) self.ws_panels[ws]["panel"].capParsed.connect( self.OnPanelCapParsed) self.ws_panels[ws]["panel"].layerSelected.connect( self.OnLayerSelected) # buttons self.btn_close = Button(parent=self, id=wx.ID_CLOSE) self.btn_close.SetToolTip(_("Close dialog")) # statusbar self.statusbar = wx.StatusBar(parent=self, id=wx.ID_ANY) # bindings self.btn_close.Bind(wx.EVT_BUTTON, self.OnClose) self.Bind(wx.EVT_CLOSE, self.OnClose) self.btn_connect.Bind(wx.EVT_BUTTON, self.OnConnect) self.server.Bind(wx.EVT_TEXT, self.OnServer) self.layerName.Bind(wx.EVT_TEXT, self.OnOutputLayerName) self.settsManager.settingsChanged.connect(self.OnSettingsChanged) self.settsManager.settingsSaving.connect(self.OnSettingsSaving) def OnLayerSelected(self, title): self.layerName.SetValue(title) def _doLayout(self): dialogSizer = wx.BoxSizer(wx.VERTICAL) dialogSizer.Add( self.settsManager, proportion=0, flag=wx.EXPAND | wx.TOP | wx.LEFT | wx.RIGHT, border=5, ) # connectin settings settingsSizer = wx.StaticBoxSizer(self.settingsBox, wx.VERTICAL) serverSizer = wx.FlexGridSizer(cols=3, vgap=5, hgap=5) serverSizer.Add(self.serverText, flag=wx.ALIGN_CENTER_VERTICAL) serverSizer.AddGrowableCol(1) serverSizer.Add(self.server, flag=wx.EXPAND | wx.ALL) serverSizer.Add(self.btn_connect) settingsSizer.Add(serverSizer, proportion=0, flag=wx.EXPAND | wx.LEFT | wx.RIGHT, border=5) settingsSizer.Add(self.adv_conn, flag=wx.ALL | wx.EXPAND, border=5) dialogSizer.Add( settingsSizer, proportion=0, flag=wx.EXPAND | wx.TOP | wx.LEFT | wx.RIGHT, border=5, ) # layer name, parsed capabilities reqDataSizer = wx.BoxSizer(wx.VERTICAL) layerNameSizer = wx.StaticBoxSizer(self.layerNameBox, wx.HORIZONTAL) layerNameSizer.Add(self.layerNameText, flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5) layerNameSizer.Add(self.layerName, flag=wx.EXPAND, proportion=1) reqDataSizer.Add(layerNameSizer, flag=wx.TOP | wx.LEFT | wx.RIGHT | wx.EXPAND, border=5) self.ch_ws_sizer = wx.BoxSizer(wx.VERTICAL) reqDataSizer.Add(self.ch_ws_sizer, proportion=0, flag=wx.TOP | wx.EXPAND, border=5) for ws in six.iterkeys(self.ws_panels): reqDataSizer.Add( self.ws_panels[ws]["panel"], proportion=1, flag=wx.TOP | wx.LEFT | wx.RIGHT | wx.EXPAND, border=5, ) self.ws_panels[ws]["panel"].Hide() dialogSizer.Add(self.reqDataPanel, proportion=1, flag=wx.EXPAND) self.reqDataPanel.SetSizer(reqDataSizer) self.reqDataPanel.Hide() # buttons self.btnsizer = wx.BoxSizer(orient=wx.HORIZONTAL) self.btnsizer.Add(self.btn_close, proportion=0, flag=wx.ALL | wx.ALIGN_CENTER, border=10) dialogSizer.Add(self.btnsizer, proportion=0, flag=wx.ALIGN_CENTER) # expand wxWidget wx.StatusBar statusbarSizer = wx.BoxSizer(wx.HORIZONTAL) statusbarSizer.Add(self.statusbar, proportion=1, flag=wx.EXPAND) dialogSizer.Add(statusbarSizer, proportion=0, flag=wx.EXPAND) self.SetSizer(dialogSizer) self.Layout() self.SetMinSize((550, -1)) self.SetMaxSize((-1, self.GetBestSize()[1])) self.Fit() def MakeAdvConnPane(self, pane): """Create advanced connection settings pane""" self.usernameText = StaticText(parent=pane, id=wx.ID_ANY, label=_("Username:"******"Password:"******"""Check if required data are filled before setting save is performed.""" server = self.server.GetValue().strip() if not server: GMessage( parent=self, message=_("No data source defined, settings are not saved."), ) return self.settsManager.SetDataToSave( (server, self.username.GetValue(), self.password.GetValue())) self.settsManager.SaveSettings(name) def OnSettingsChanged(self, data): """Update widgets according to chosen settings""" # data list: [server, username, password] if len(data) < 3: return self.server.SetValue(data[0]) self.username.SetValue(data[1]) self.password.SetValue(data[2]) if data[1] or data[2]: self.adv_conn.Expand() else: self.adv_conn.Collapse(True) # clear content of the wxWidget wx.TextCtrl (Output layer # name:), based on changing default server selection in the # wxWidget wx.Choice if len(self.layerName.GetValue()) > 0: self.layerName.Clear() def OnClose(self, event): """Close the dialog""" """Close dialog""" if not self.IsModal(): self.Destroy() event.Skip() def _getCapFiles(self): ws_cap_files = {} for v in six.itervalues(self.ws_panels): ws_cap_files[v["panel"].GetWebService()] = v["panel"].GetCapFile() return ws_cap_files def OnServer(self, event): """Server settings edited""" value = event.GetString() if value: self.btn_connect.Enable(True) else: self.btn_connect.Enable(False) # clear content of the wxWidget wx.TextCtrl (Output Layer # name:), based on changing content of the wxWidget # wx.TextCtrl (Server:) self.layerName.Clear() def OnOutputLayerName(self, event): """Update layer name to web service panel""" lname = event.GetString() for v in six.itervalues(self.ws_panels): v["panel"].SetOutputLayerName(lname.strip()) def OnConnect(self, event): """Connect to the server""" server = self.server.GetValue().strip() self.ch_ws_sizer.Clear(True) if self.active_ws_panel is not None: self.reqDataPanel.Hide() for btn in self.run_btns: btn.Enable(False) self.active_ws_panel = None self.Layout() self.Fit() self.statusbar.SetStatusText( _("Connecting to <%s>..." % self.server.GetValue().strip())) # number of panels already connected self.finished_panels_num = 0 for ws in six.iterkeys(self.ws_panels): self.ws_panels[ws]["panel"].ConnectToServer( url=server, username=self.username.GetValue(), password=self.password.GetValue(), ) self.ws_panels[ws]["panel"].Hide() def OnPanelCapParsed(self, error_msg): """Called when panel has downloaded and parsed capabilities file.""" # how many web service panels are finished self.finished_panels_num += 1 if error_msg: self.error_msgs += "\n" + error_msg # if all are finished, show panels, which succeeded in connection if self.finished_panels_num == len(self.ws_panels): self.UpdateDialogAfterConnection() # show error dialog only if connections to all web services were # unsuccessful if not self._getConnectedWS() and self.error_msgs: GError(self.error_msgs, parent=self) self.error_msgs = "" self.Layout() self.Fit() def _getConnectedWS(self): """ :return: list of found web services on server (identified as keys in self.ws_panels) """ conn_ws = [] for ws, data in six.iteritems(self.ws_panels): if data["panel"].IsConnected(): conn_ws.append(ws) return conn_ws def UpdateDialogAfterConnection(self): """Update dialog after all web service panels downloaded and parsed capabilities data.""" avail_ws = {} conn_ws = self._getConnectedWS() for ws in conn_ws: avail_ws[ws] = self.ws_panels[ws] self.web_service_sel = [] self.rb_choices = [] # at least one web service found on server if len(avail_ws) > 0: self.reqDataPanel.Show() self.rb_order = ["WMS_1.1.1", "WMS_1.3.0", "WMTS", "OnEarth"] for ws in self.rb_order: if ws in avail_ws: self.web_service_sel.append(ws) self.rb_choices.append(avail_ws[ws]["label"]) self.choose_ws_rb = wx.RadioBox( parent=self.reqDataPanel, id=wx.ID_ANY, label=_("Available web services"), pos=wx.DefaultPosition, choices=self.rb_choices, majorDimension=1, style=wx.RA_SPECIFY_ROWS, ) self.Bind(wx.EVT_RADIOBOX, self.OnChooseWs, self.choose_ws_rb) self.ch_ws_sizer.Add( self.choose_ws_rb, flag=wx.TOP | wx.LEFT | wx.RIGHT | wx.EXPAND, border=5, ) self._showWsPanel( self.web_service_sel[self.choose_ws_rb.GetSelection()]) self.statusbar.SetStatusText( _("Connected to <%s>" % self.server.GetValue().strip())) for btn in self.run_btns: btn.Enable(True) # no web service found on server else: self.statusbar.SetStatusText( _("Unable to connect to <%s>" % self.server.GetValue().strip())) for btn in self.run_btns: btn.Enable(False) self.reqDataPanel.Hide() self.active_ws_panel = None def OnChooseWs(self, event): """Show panel corresponding to selected web service.""" choosen_r = event.GetInt() self._showWsPanel(self.web_service_sel[choosen_r]) def _showWsPanel(self, ws): """Helper function""" if self.active_ws_panel is not None: self.active_ws_panel.Hide() self.active_ws_panel = self.ws_panels[ws]["panel"] if not self.active_ws_panel.IsShown(): self.active_ws_panel.Show() self.SetMaxSize((-1, -1)) self.active_ws_panel.GetContainingSizer().Layout() def OnAdvConnPaneChanged(self, event): """Collapse search module box""" if self.adv_conn.IsExpanded(): self.adv_conn.SetLabel(self.infoCollapseLabelCol) else: self.adv_conn.SetLabel(self.infoCollapseLabelExp) self.Layout() self.SetMaxSize((-1, self.GetBestSize()[1])) self.SendSizeEvent() self.Fit()
def _createWidgets(self): settingsFile = os.path.join(GetSettingsPath(), "wxWS") self.settsManager = WSManageSettingsWidget( parent=self, settingsFile=settingsFile, default_servers=self.default_servers) self.settingsBox = StaticBox(parent=self, id=wx.ID_ANY, label=_(" Server settings ")) self.serverText = StaticText(parent=self, id=wx.ID_ANY, label=_("Server:")) self.server = TextCtrl(parent=self, id=wx.ID_ANY) self.btn_connect = Button(parent=self, id=wx.ID_ANY, label=_("&Connect")) self.btn_connect.SetToolTip(_("Connect to the server")) if not self.server.GetValue(): self.btn_connect.Enable(False) self.infoCollapseLabelExp = _("Show advanced connection settings") self.infoCollapseLabelCol = _("Hide advanced connection settings") self.adv_conn = wx.CollapsiblePane( parent=self, label=self.infoCollapseLabelExp, style=wx.CP_DEFAULT_STYLE | wx.CP_NO_TLW_RESIZE | wx.EXPAND, ) self.MakeAdvConnPane(pane=self.adv_conn.GetPane()) self.adv_conn.Collapse(True) self.Bind(wx.EVT_COLLAPSIBLEPANE_CHANGED, self.OnAdvConnPaneChanged, self.adv_conn) self.reqDataPanel = wx.Panel(parent=self, id=wx.ID_ANY) self.layerNameBox = StaticBox(parent=self.reqDataPanel, id=wx.ID_ANY, label=_(" Layer Manager Settings ")) self.layerNameText = StaticText(parent=self.reqDataPanel, id=wx.ID_ANY, label=_("Output layer name:")) self.layerName = TextCtrl(parent=self.reqDataPanel, id=wx.ID_ANY) for ws in six.iterkeys(self.ws_panels): # set class WSPanel argument layerNameTxtCtrl self.ws_panels[ws]["panel"] = WSPanel(parent=self.reqDataPanel, web_service=ws) self.ws_panels[ws]["panel"].capParsed.connect( self.OnPanelCapParsed) self.ws_panels[ws]["panel"].layerSelected.connect( self.OnLayerSelected) # buttons self.btn_close = Button(parent=self, id=wx.ID_CLOSE) self.btn_close.SetToolTip(_("Close dialog")) # statusbar self.statusbar = wx.StatusBar(parent=self, id=wx.ID_ANY) # bindings self.btn_close.Bind(wx.EVT_BUTTON, self.OnClose) self.Bind(wx.EVT_CLOSE, self.OnClose) self.btn_connect.Bind(wx.EVT_BUTTON, self.OnConnect) self.server.Bind(wx.EVT_TEXT, self.OnServer) self.layerName.Bind(wx.EVT_TEXT, self.OnOutputLayerName) self.settsManager.settingsChanged.connect(self.OnSettingsChanged) self.settsManager.settingsSaving.connect(self.OnSettingsSaving)
def __init__( self, parent, data, pointNo, itemCap="Point No.", id=wx.ID_ANY, title=_("Edit point"), style=wx.DEFAULT_DIALOG_STYLE): """Dialog for editing item cells in list""" wx.Dialog.__init__(self, parent, id, title=_(title), style=style) self.parent = parent panel = Panel(parent=self) sizer = wx.BoxSizer(wx.VERTICAL) box = StaticBox(parent=panel, id=wx.ID_ANY, label=" %s %s " % (_(itemCap), str(pointNo + 1))) boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL) # source coordinates gridSizer = wx.GridBagSizer(vgap=5, hgap=5) self.fields = [] self.data = deepcopy(data) col = 0 row = 0 iField = 0 for cell in self.data: # Select if type(cell[2]).__name__ == "list": self.fields.append(ComboBox(parent=panel, id=wx.ID_ANY, choices=cell[2], style=wx.CB_READONLY, size=(110, -1))) # Text field else: if cell[2] == float: validator = FloatValidator() elif cell[2] == int: validator = IntegerValidator() else: validator = None if validator: self.fields.append( TextCtrl( parent=panel, id=wx.ID_ANY, validator=validator, size=(150, -1))) else: self.fields.append(TextCtrl(parent=panel, id=wx.ID_ANY, size=(150, -1))) value = cell[1] if not isinstance(cell[1], basestring): value = str(cell[1]) self.fields[iField].SetValue(value) label = StaticText( parent=panel, id=wx.ID_ANY, label=_( parent.GetColumn( cell[0]).GetText()) + ":") # name of column) gridSizer.Add(label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(row, col)) col += 1 gridSizer.Add(self.fields[iField], pos=(row, col)) if col % 3 == 0: col = 0 row += 1 else: col += 1 iField += 1 boxSizer.Add(gridSizer, proportion=1, flag=wx.EXPAND | wx.ALL, border=5) sizer.Add(boxSizer, proportion=1, flag=wx.EXPAND | wx.ALL, border=5) # # buttons # self.btnCancel = Button(panel, wx.ID_CANCEL) self.btnOk = Button(panel, wx.ID_OK) self.btnOk.SetDefault() btnSizer = wx.StdDialogButtonSizer() btnSizer.AddButton(self.btnCancel) btnSizer.AddButton(self.btnOk) btnSizer.Realize() sizer.Add(btnSizer, proportion=0, flag=wx.ALIGN_RIGHT | wx.ALL, border=5) panel.SetSizer(sizer) sizer.Fit(self)
class RegionDef(BaseClass, wx.Dialog): """Page for setting default region extents and resolution """ def __init__(self, parent, id=wx.ID_ANY, size=(800, 600), title=_( "Set default region extent and resolution"), location=None): wx.Dialog.__init__(self, parent, id, title, size=size) panel = wx.Panel(self, id=wx.ID_ANY) self.SetIcon( wx.Icon( os.path.join( globalvar.ICONDIR, 'grass.ico'), wx.BITMAP_TYPE_ICO)) self.parent = parent self.location = location # # default values # # 2D self.north = 1.0 self.south = 0.0 self.east = 1.0 self.west = 0.0 self.nsres = 1.0 self.ewres = 1.0 # 3D self.top = 1.0 self.bottom = 0.0 # self.nsres3 = 1.0 # self.ewres3 = 1.0 self.tbres = 1.0 # # inputs # # 2D self.tnorth = self.MakeTextCtrl( text=str( self.north), size=( 150, -1), parent=panel) self.tsouth = self.MakeTextCtrl( str(self.south), size=(150, -1), parent=panel) self.twest = self.MakeTextCtrl( str(self.west), size=(150, -1), parent=panel) self.teast = self.MakeTextCtrl( str(self.east), size=(150, -1), parent=panel) self.tnsres = self.MakeTextCtrl( str(self.nsres), size=(150, -1), parent=panel) self.tewres = self.MakeTextCtrl( str(self.ewres), size=(150, -1), parent=panel) # # labels # self.lrows = self.MakeLabel(parent=panel) self.lcols = self.MakeLabel(parent=panel) self.lcells = self.MakeLabel(parent=panel) # # buttons # self.bset = self.MakeButton( text=_("&Set region"), id=wx.ID_OK, parent=panel) self.bcancel = Button(panel, id=wx.ID_CANCEL) self.bset.SetDefault() # # image # self.img = wx.Image(os.path.join(globalvar.IMGDIR, "qgis_world.png"), wx.BITMAP_TYPE_PNG).ConvertToBitmap() # # set current working environment to PERMANENT mapset # in selected location in order to set default region (WIND) # envval = {} ret = RunCommand('g.gisenv', read=True) if ret: for line in ret.splitlines(): key, val = line.split('=') envval[key] = val self.currlocation = envval['LOCATION_NAME'].strip("';") self.currmapset = envval['MAPSET'].strip("';") if self.currlocation != self.location or self.currmapset != 'PERMANENT': RunCommand('g.gisenv', set='LOCATION_NAME=%s' % self.location) RunCommand('g.gisenv', set='MAPSET=PERMANENT') else: dlg = wx.MessageBox( parent=self, message=_('Invalid location selected.'), caption=_("Error"), style=wx.ID_OK | wx.ICON_ERROR) return # # get current region settings # region = {} ret = RunCommand('g.region', read=True, flags='gp3') if ret: for line in ret.splitlines(): key, val = line.split('=') region[key] = float(val) else: dlg = wx.MessageBox( parent=self, message=_("Invalid region"), caption=_("Error"), style=wx.ID_OK | wx.ICON_ERROR) dlg.ShowModal() dlg.Destroy() return # # update values # 2D self.north = float(region['n']) self.south = float(region['s']) self.east = float(region['e']) self.west = float(region['w']) self.nsres = float(region['nsres']) self.ewres = float(region['ewres']) self.rows = int(region['rows']) self.cols = int(region['cols']) self.cells = int(region['cells']) # 3D self.top = float(region['t']) self.bottom = float(region['b']) # self.nsres3 = float(region['nsres3']) # self.ewres3 = float(region['ewres3']) self.tbres = float(region['tbres']) self.depth = int(region['depths']) self.cells3 = int(region['cells3']) # # 3D box collapsable # self.infoCollapseLabelExp = _("Click here to show 3D settings") self.infoCollapseLabelCol = _("Click here to hide 3D settings") self.settings3D = wx.CollapsiblePane(parent=panel, label=self.infoCollapseLabelExp, style=wx.CP_DEFAULT_STYLE | wx.CP_NO_TLW_RESIZE | wx.EXPAND) self.MakeSettings3DPaneContent(self.settings3D.GetPane()) self.settings3D.Collapse(False) # FIXME self.Bind( wx.EVT_COLLAPSIBLEPANE_CHANGED, self.OnSettings3DPaneChanged, self.settings3D) # # set current region settings # self.tnorth.SetValue(str(self.north)) self.tsouth.SetValue(str(self.south)) self.twest.SetValue(str(self.west)) self.teast.SetValue(str(self.east)) self.tnsres.SetValue(str(self.nsres)) self.tewres.SetValue(str(self.ewres)) self.ttop.SetValue(str(self.top)) self.tbottom.SetValue(str(self.bottom)) # self.tnsres3.SetValue(str(self.nsres3)) # self.tewres3.SetValue(str(self.ewres3)) self.ttbres.SetValue(str(self.tbres)) self.lrows.SetLabel(_("Rows: %d") % self.rows) self.lcols.SetLabel(_("Cols: %d") % self.cols) self.lcells.SetLabel(_("Cells: %d") % self.cells) # # bindings # self.Bind(wx.EVT_BUTTON, self.OnSetButton, self.bset) self.Bind(wx.EVT_BUTTON, self.OnCancel, self.bcancel) self.tnorth.Bind(wx.EVT_TEXT, self.OnValue) self.tsouth.Bind(wx.EVT_TEXT, self.OnValue) self.teast.Bind(wx.EVT_TEXT, self.OnValue) self.twest.Bind(wx.EVT_TEXT, self.OnValue) self.tnsres.Bind(wx.EVT_TEXT, self.OnValue) self.tewres.Bind(wx.EVT_TEXT, self.OnValue) self.ttop.Bind(wx.EVT_TEXT, self.OnValue) self.tbottom.Bind(wx.EVT_TEXT, self.OnValue) # self.tnsres3.Bind(wx.EVT_TEXT, self.OnValue) # self.tewres3.Bind(wx.EVT_TEXT, self.OnValue) self.ttbres.Bind(wx.EVT_TEXT, self.OnValue) self.__DoLayout(panel) self.SetMinSize(self.GetBestSize()) self.minWindowSize = self.GetMinSize() wx.CallAfter(self.settings3D.Collapse, True) def MakeSettings3DPaneContent(self, pane): """Create 3D region settings pane""" border = wx.BoxSizer(wx.VERTICAL) gridSizer = wx.GridBagSizer(vgap=0, hgap=0) # inputs self.ttop = TextCtrl(parent=pane, id=wx.ID_ANY, value=str(self.top), size=(150, -1)) self.tbottom = TextCtrl( parent=pane, id=wx.ID_ANY, value=str( self.bottom), size=( 150, -1)) self.ttbres = TextCtrl( parent=pane, id=wx.ID_ANY, value=str( self.tbres), size=( 150, -1)) # self.tnsres3 = wx.TextCtrl(parent = pane, id = wx.ID_ANY, value = str(self.nsres3), # size = (150, -1)) # self.tewres3 = wx.TextCtrl(parent = pane, id = wx.ID_ANY, value = str(self.ewres3), # size = (150, -1)) # labels self.ldepth = StaticText( parent=pane, label=_("Depth: %d") % self.depth) self.lcells3 = StaticText( parent=pane, label=_("3D Cells: %d") % self.cells3) # top gridSizer.Add(StaticText(parent=pane, label=_("Top")), flag=wx.ALIGN_CENTER | wx.LEFT | wx.RIGHT | wx.TOP, border=5, pos=(0, 1)) gridSizer.Add(self.ttop, flag=wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, border=5, pos=(1, 1)) # bottom gridSizer.Add(StaticText(parent=pane, label=_("Bottom")), flag=wx.ALIGN_CENTER | wx.LEFT | wx.RIGHT | wx.TOP, border=5, pos=(0, 2)) gridSizer.Add(self.tbottom, flag=wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, border=5, pos=(1, 2)) # tbres gridSizer.Add( StaticText( parent=pane, label=_("T-B resolution")), flag=wx.ALIGN_CENTER | wx.LEFT | wx.RIGHT | wx.TOP, border=5, pos=( 0, 3)) gridSizer.Add(self.ttbres, flag=wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, border=5, pos=(1, 3)) # res # gridSizer.Add(item = wx.StaticText(parent = pane, label = _("3D N-S resolution")), # flag = wx.ALIGN_CENTER | # wx.LEFT | wx.RIGHT | wx.TOP, border = 5, # pos = (2, 1)) # gridSizer.Add(item = self.tnsres3, # flag = wx.ALIGN_CENTER_HORIZONTAL | # wx.ALL, border = 5, pos = (3, 1)) # gridSizer.Add(item = wx.StaticText(parent = pane, label = _("3D E-W resolution")), # flag = wx.ALIGN_CENTER | # wx.LEFT | wx.RIGHT | wx.TOP, border = 5, # pos = (2, 3)) # gridSizer.Add(item = self.tewres3, # flag = wx.ALIGN_CENTER_HORIZONTAL | # wx.ALL, border = 5, pos = (3, 3)) # rows/cols/cells gridSizer.Add(self.ldepth, flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER | wx.ALL, border=5, pos=(2, 1)) gridSizer.Add(self.lcells3, flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER | wx.ALL, border=5, pos=(2, 2)) border.Add(gridSizer, proportion=1, flag=wx.ALL | wx.ALIGN_CENTER | wx.EXPAND, border=5) pane.SetSizer(border) border.Fit(pane) def OnSettings3DPaneChanged(self, event): """Collapse 3D settings box""" if self.settings3D.IsExpanded(): self.settings3D.SetLabel(self.infoCollapseLabelCol) self.Layout() self.SetSize(self.GetBestSize()) self.SetMinSize(self.GetSize()) else: self.settings3D.SetLabel(self.infoCollapseLabelExp) self.Layout() self.SetSize(self.minWindowSize) self.SetMinSize(self.minWindowSize) self.SendSizeEvent() def __DoLayout(self, panel): """Window layout""" frameSizer = wx.BoxSizer(wx.VERTICAL) gridSizer = wx.GridBagSizer(vgap=0, hgap=0) settings3DSizer = wx.BoxSizer(wx.VERTICAL) buttonSizer = wx.BoxSizer(wx.HORIZONTAL) # north gridSizer.Add(self.MakeLabel(text=_("North"), parent=panel), flag=wx.ALIGN_BOTTOM | wx.ALIGN_CENTER_HORIZONTAL | wx.TOP | wx.LEFT | wx.RIGHT, border=5, pos=(0, 2)) gridSizer.Add(self.tnorth, flag=wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5, pos=(1, 2)) # west gridSizer.Add(self.MakeLabel(text=_("West"), parent=panel), flag=wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.TOP | wx.BOTTOM, border=5, pos=(2, 0)) gridSizer.Add(self.twest, flag=wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5, pos=(2, 1)) gridSizer.Add( wx.StaticBitmap( panel, wx.ID_ANY, self.img, (-1, -1), (self.img.GetWidth(), self.img.GetHeight())), flag=wx.ALIGN_CENTER | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5, pos=(2, 2)) # east gridSizer.Add(self.teast, flag=wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5, pos=(2, 3)) gridSizer.Add(self.MakeLabel(text=_("East"), parent=panel), flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.RIGHT | wx.TOP | wx.BOTTOM, border=5, pos=(2, 4)) # south gridSizer.Add(self.tsouth, flag=wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5, pos=(3, 2)) gridSizer.Add(self.MakeLabel(text=_("South"), parent=panel), flag=wx.ALIGN_TOP | wx.ALIGN_CENTER_HORIZONTAL | wx.LEFT | wx.RIGHT | wx.BOTTOM, border=5, pos=(4, 2)) # ns-res gridSizer.Add(self.MakeLabel(text=_("N-S resolution"), parent=panel), flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER | wx.TOP | wx.LEFT | wx.RIGHT, border=5, pos=(5, 1)) gridSizer.Add(self.tnsres, flag=wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5, pos=(6, 1)) # ew-res gridSizer.Add(self.MakeLabel(text=_("E-W resolution"), parent=panel), flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER | wx.TOP | wx.LEFT | wx.RIGHT, border=5, pos=(5, 3)) gridSizer.Add(self.tewres, flag=wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5, pos=(6, 3)) # rows/cols/cells gridSizer.Add(self.lrows, flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER | wx.ALL, border=5, pos=(7, 1)) gridSizer.Add(self.lcells, flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER | wx.ALL, border=5, pos=(7, 2)) gridSizer.Add(self.lcols, flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER | wx.ALL, border=5, pos=(7, 3)) # 3D settings3DSizer.Add(self.settings3D, flag=wx.ALL, border=5) # buttons buttonSizer.Add(self.bcancel, proportion=1, flag=wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=10) buttonSizer.Add(self.bset, proportion=1, flag=wx.ALIGN_CENTER | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=10) frameSizer.Add(gridSizer, proportion=1, flag=wx.ALL | wx.ALIGN_CENTER, border=5) frameSizer.Add(settings3DSizer, proportion=0, flag=wx.ALL | wx.ALIGN_CENTER, border=5) frameSizer.Add(buttonSizer, proportion=0, flag=wx.ALL | wx.ALIGN_RIGHT, border=5) self.SetAutoLayout(True) panel.SetSizer(frameSizer) frameSizer.Fit(panel) self.Layout() def OnValue(self, event): """Set given value""" try: if event.GetId() == self.tnorth.GetId(): self.north = float(event.GetString()) elif event.GetId() == self.tsouth.GetId(): self.south = float(event.GetString()) elif event.GetId() == self.teast.GetId(): self.east = float(event.GetString()) elif event.GetId() == self.twest.GetId(): self.west = float(event.GetString()) elif event.GetId() == self.tnsres.GetId(): self.nsres = float(event.GetString()) elif event.GetId() == self.tewres.GetId(): self.ewres = float(event.GetString()) elif event.GetId() == self.ttop.GetId(): self.top = float(event.GetString()) elif event.GetId() == self.tbottom.GetId(): self.bottom = float(event.GetString()) # elif event.GetId() == self.tnsres3.GetId(): # self.nsres3 = float(event.GetString()) # elif event.GetId() == self.tewres3.GetId(): # self.ewres3 = float(event.GetString()) elif event.GetId() == self.ttbres.GetId(): self.tbres = float(event.GetString()) self.__UpdateInfo() except ValueError as e: if len(event.GetString()) > 0 and event.GetString() != '-': dlg = wx.MessageBox(parent=self, message=_("Invalid value: %s") % e, caption=_("Error"), style=wx.OK | wx.ICON_ERROR) # reset values self.tnorth.SetValue(str(self.north)) self.tsouth.SetValue(str(self.south)) self.teast.SetValue(str(self.east)) self.twest.SetValue(str(self.west)) self.tnsres.SetValue(str(self.nsres)) self.tewres.SetValue(str(self.ewres)) self.ttop.SetValue(str(self.top)) self.tbottom.SetValue(str(self.bottom)) self.ttbres.SetValue(str(self.tbres)) # self.tnsres3.SetValue(str(self.nsres3)) # self.tewres3.SetValue(str(self.ewres3)) event.Skip() def __UpdateInfo(self): """Update number of rows/cols/cells""" try: rows = int((self.north - self.south) / self.nsres) cols = int((self.east - self.west) / self.ewres) except ZeroDivisionError: return self.rows = rows self.cols = cols self.cells = self.rows * self.cols try: depth = int((self.top - self.bottom) / self.tbres) except ZeroDivisionError: return self.depth = depth self.cells3 = self.rows * self.cols * self.depth # 2D self.lrows.SetLabel(_("Rows: %d") % self.rows) self.lcols.SetLabel(_("Cols: %d") % self.cols) self.lcells.SetLabel(_("Cells: %d") % self.cells) # 3D self.ldepth.SetLabel(_("Depth: %d" % self.depth)) self.lcells3.SetLabel(_("3D Cells: %d" % self.cells3)) def OnSetButton(self, event=None): """Set default region""" ret = RunCommand('g.region', flags='sa', n=self.north, s=self.south, e=self.east, w=self.west, nsres=self.nsres, ewres=self.ewres, t=self.top, b=self.bottom, tbres=self.tbres) if ret == 0: self.Destroy() def OnCancel(self, event): self.Destroy()
class CatalogReprojectionDialog(wx.Dialog): def __init__(self, parent, giface, inputGisdbase, inputLocation, inputMapset, inputLayer, inputEnv, outputGisdbase, outputLocation, outputMapset, outputLayer, etype, outputEnv, callback, id=wx.ID_ANY, title=_("Reprojection"), style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER): self.parent = parent self._giface = giface wx.Dialog.__init__(self, parent, id, title, style=style, name="ReprojectionDialog") self.panel = wx.Panel(parent=self) self.iGisdbase = inputGisdbase self.iLocation = inputLocation self.iMapset = inputMapset self.iLayer = inputLayer self.iEnv = inputEnv self.oGisdbase = outputGisdbase self.oLocation = outputLocation self.oMapset = outputMapset self.oLayer = outputLayer self.etype = etype self.oEnv = outputEnv self.callback = callback self._widgets() self._doLayout() if self.etype == 'raster': self._estimateResampling() self._estimateResolution() def _widgets(self): if self.etype == 'raster': self.resolution = TextCtrl(self.panel, validator=FloatValidator()) self.resampling = wx.Choice(self.panel, size=(200, -1), choices=[ 'nearest', 'bilinear', 'bicubic', 'lanczos', 'bilinear_f', 'bicubic_f', 'lanczos_f' ]) else: self.vsplit = TextCtrl(self.panel, validator=IntegerValidator()) self.vsplit.SetValue('10000') # # buttons # self.btn_close = Button(parent=self.panel, id=wx.ID_CLOSE) self.SetEscapeId(self.btn_close.GetId()) # run self.btn_run = Button(parent=self.panel, id=wx.ID_OK, label=_("Reproject")) if self.etype == 'raster': self.btn_run.SetToolTip(_("Reproject raster")) elif self.etype == 'vector': self.btn_run.SetToolTip(_("Reproject vector")) self.btn_run.SetDefault() self.btn_run.Bind(wx.EVT_BUTTON, self.OnReproject) def _doLayout(self): """Do layout""" dialogSizer = wx.BoxSizer(wx.VERTICAL) optionsSizer = wx.GridBagSizer(5, 5) label = _("Map layer <{ml}> needs to be reprojected.\n" "Please review and modify reprojection parameters:").format( ml=self.iLayer) dialogSizer.Add(StaticText(self.panel, label=label), flag=wx.ALL | wx.EXPAND, border=10) if self.etype == 'raster': optionsSizer.Add(StaticText(self.panel, label=_("Estimated resolution:")), pos=(0, 0), flag=wx.EXPAND | wx.ALIGN_CENTER_VERTICAL) optionsSizer.Add(self.resolution, pos=(0, 1), flag=wx.EXPAND) optionsSizer.Add(StaticText(self.panel, label=_("Resampling method:")), pos=(1, 0), flag=wx.EXPAND | wx.ALIGN_CENTER_VERTICAL) optionsSizer.Add(self.resampling, pos=(1, 1), flag=wx.EXPAND) else: optionsSizer.Add(StaticText(self.panel, label=_("Maximum segment length:")), pos=(1, 0), flag=wx.EXPAND | wx.ALIGN_CENTER_VERTICAL) optionsSizer.Add(self.vsplit, pos=(1, 1), flag=wx.EXPAND) optionsSizer.AddGrowableCol(1) dialogSizer.Add(optionsSizer, proportion=1, flag=wx.ALL | wx.EXPAND, border=10) helptext = StaticText( self.panel, label="For more reprojection options," " please see {module}".format( module='r.proj' if self.etype == 'raster' else 'v.proj')) dialogSizer.Add(helptext, proportion=0, flag=wx.ALL | wx.EXPAND, border=10) # # buttons # btnStdSizer = wx.StdDialogButtonSizer() btnStdSizer.AddButton(self.btn_run) btnStdSizer.AddButton(self.btn_close) btnStdSizer.Realize() dialogSizer.Add(btnStdSizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5) self.panel.SetSizer(dialogSizer) dialogSizer.Fit(self.panel) self.Layout() self.SetSize(self.GetBestSize()) def _estimateResolution(self): output = RunCommand('r.proj', flags='g', quiet=False, read=True, input=self.iLayer, dbase=self.iGisdbase, location=self.iLocation, mapset=self.iMapset, env=self.oEnv).strip() params = parse_key_val(output, vsep=' ') output = RunCommand('g.region', flags='ug', quiet=False, read=True, env=self.oEnv, parse=lambda x: parse_key_val(x, val_type=float), **params) cell_ns = (output['n'] - output['s']) / output['rows'] cell_ew = (output['e'] - output['w']) / output['cols'] estimate = (cell_ew + cell_ns) / 2. self.resolution.SetValue(str(estimate)) self.params = params def _estimateResampling(self): output = RunCommand('r.info', flags='g', quiet=False, read=True, map=self.iLayer, env=self.iEnv, parse=parse_key_val) if output['datatype'] == 'CELL': self.resampling.SetStringSelection('nearest') else: self.resampling.SetStringSelection('bilinear') def OnReproject(self, event): cmd = [] if self.etype == 'raster': cmd.append('r.proj') cmd.append('dbase=' + self.iGisdbase) cmd.append('location=' + self.iLocation) cmd.append('mapset=' + self.iMapset) cmd.append('input=' + self.iLayer) cmd.append('output=' + self.oLayer) cmd.append('method=' + self.resampling.GetStringSelection()) self.oEnv['GRASS_REGION'] = region_env( n=self.params['n'], s=self.params['s'], e=self.params['e'], w=self.params['w'], flags='a', res=float(self.resolution.GetValue()), env=self.oEnv) else: cmd.append('v.proj') cmd.append('dbase=' + self.iGisdbase) cmd.append('location=' + self.iLocation) cmd.append('mapset=' + self.iMapset) cmd.append('input=' + self.iLayer) cmd.append('output=' + self.oLayer) cmd.append('smax=' + self.vsplit.GetValue()) self._giface.RunCmd(cmd, env=self.oEnv, compReg=False, addLayer=False, onDone=self._onDone, userData=None, notification=Notification.MAKE_VISIBLE) event.Skip() def _onDone(self, event): self.callback()
def __init__(self, parent=None, id=wx.ID_ANY, style=wx.DEFAULT_FRAME_STYLE): # # GRASS variables # self.gisbase = os.getenv("GISBASE") self.grassrc = sgui.read_gisrc() self.gisdbase = self.GetRCValue("GISDBASE") # # list of locations/mapsets # self.listOfLocations = [] self.listOfMapsets = [] self.listOfMapsetsSelectable = [] wx.Frame.__init__(self, parent=parent, id=id, style=style) self.locale = wx.Locale(language=wx.LANGUAGE_DEFAULT) # scroll panel was used here but not properly and is probably not need # as long as it is not high too much self.panel = wx.Panel(parent=self, id=wx.ID_ANY) # i18N # # graphical elements # # image try: if os.getenv('ISISROOT'): name = os.path.join(globalvar.GUIDIR, "images", "startup_banner_isis.png") else: name = os.path.join(globalvar.GUIDIR, "images", "startup_banner.png") self.hbitmap = wx.StaticBitmap( self.panel, wx.ID_ANY, wx.Bitmap(name=name, type=wx.BITMAP_TYPE_PNG)) except: self.hbitmap = wx.StaticBitmap( self.panel, wx.ID_ANY, BitmapFromImage(wx.EmptyImage(530, 150))) # labels # crashes when LOCATION doesn't exist # get version & revision grassVersion, grassRevisionStr = sgui.GetVersion() self.gisdbase_box = StaticBox( parent=self.panel, id=wx.ID_ANY, label=" %s " % _("1. Select GRASS GIS database directory")) self.location_box = StaticBox(parent=self.panel, id=wx.ID_ANY, label=" %s " % _("2. Select GRASS Location")) self.mapset_box = StaticBox(parent=self.panel, id=wx.ID_ANY, label=" %s " % _("3. Select GRASS Mapset")) self.lmessage = StaticText(parent=self.panel) # It is not clear if all wx versions supports color, so try-except. # The color itself may not be correct for all platforms/system settings # but in http://xoomer.virgilio.it/infinity77/wxPython/Widgets/wx.SystemSettings.html # there is no 'warning' color. try: self.lmessage.SetForegroundColour(wx.Colour(255, 0, 0)) except AttributeError: pass self.gisdbase_panel = wx.Panel(parent=self.panel) self.location_panel = wx.Panel(parent=self.panel) self.mapset_panel = wx.Panel(parent=self.panel) self.ldbase = StaticText( parent=self.gisdbase_panel, id=wx.ID_ANY, label=_("GRASS GIS database directory contains Locations.")) self.llocation = StaticWrapText( parent=self.location_panel, id=wx.ID_ANY, label=_("All data in one Location is in the same " " coordinate reference system (projection)." " One Location can be one project." " Location contains Mapsets."), style=wx.ALIGN_LEFT) self.lmapset = StaticWrapText( parent=self.mapset_panel, id=wx.ID_ANY, label=_("Mapset contains GIS data related" " to one project, task within one project," " subregion or user."), style=wx.ALIGN_LEFT) try: for label in [self.ldbase, self.llocation, self.lmapset]: label.SetForegroundColour( wx.SystemSettings.GetColour(wx.SYS_COLOUR_GRAYTEXT)) except AttributeError: # for explanation of try-except see above pass # buttons self.bstart = Button(parent=self.panel, id=wx.ID_ANY, label=_("Start &GRASS session")) self.bstart.SetDefault() self.bexit = Button(parent=self.panel, id=wx.ID_EXIT) self.bstart.SetMinSize((180, self.bexit.GetSize()[1])) self.bhelp = Button(parent=self.panel, id=wx.ID_HELP) self.bbrowse = Button(parent=self.gisdbase_panel, id=wx.ID_ANY, label=_("&Browse")) self.bmapset = Button( parent=self.mapset_panel, id=wx.ID_ANY, # GTC New mapset label=_("&New")) self.bmapset.SetToolTip(_("Create a new Mapset in selected Location")) self.bwizard = Button( parent=self.location_panel, id=wx.ID_ANY, # GTC New location label=_("N&ew")) self.bwizard.SetToolTip( _("Create a new location using location wizard." " After location is created successfully," " GRASS session is started.")) self.rename_location_button = Button( parent=self.location_panel, id=wx.ID_ANY, # GTC Rename location label=_("Ren&ame")) self.rename_location_button.SetToolTip(_("Rename selected location")) self.delete_location_button = Button( parent=self.location_panel, id=wx.ID_ANY, # GTC Delete location label=_("De&lete")) self.delete_location_button.SetToolTip(_("Delete selected location")) self.download_location_button = Button(parent=self.location_panel, id=wx.ID_ANY, label=_("Do&wnload")) self.download_location_button.SetToolTip(_("Download sample location")) self.rename_mapset_button = Button( parent=self.mapset_panel, id=wx.ID_ANY, # GTC Rename mapset label=_("&Rename")) self.rename_mapset_button.SetToolTip(_("Rename selected mapset")) self.delete_mapset_button = Button( parent=self.mapset_panel, id=wx.ID_ANY, # GTC Delete mapset label=_("&Delete")) self.delete_mapset_button.SetToolTip(_("Delete selected mapset")) # textinputs self.tgisdbase = TextCtrl(parent=self.gisdbase_panel, id=wx.ID_ANY, value="", size=(300, -1), style=wx.TE_PROCESS_ENTER) # Locations self.lblocations = GListBox(parent=self.location_panel, id=wx.ID_ANY, size=(180, 200), choices=self.listOfLocations) self.lblocations.SetColumnWidth(0, 180) # TODO: sort; but keep PERMANENT on top of list # Mapsets self.lbmapsets = GListBox(parent=self.mapset_panel, id=wx.ID_ANY, size=(180, 200), choices=self.listOfMapsets) self.lbmapsets.SetColumnWidth(0, 180) # layout & properties, first do layout so everything is created self._do_layout() self._set_properties(grassVersion, grassRevisionStr) # events self.bbrowse.Bind(wx.EVT_BUTTON, self.OnBrowse) self.bstart.Bind(wx.EVT_BUTTON, self.OnStart) self.bexit.Bind(wx.EVT_BUTTON, self.OnExit) self.bhelp.Bind(wx.EVT_BUTTON, self.OnHelp) self.bmapset.Bind(wx.EVT_BUTTON, self.OnCreateMapset) self.bwizard.Bind(wx.EVT_BUTTON, self.OnWizard) self.rename_location_button.Bind(wx.EVT_BUTTON, self.RenameLocation) self.delete_location_button.Bind(wx.EVT_BUTTON, self.DeleteLocation) self.download_location_button.Bind(wx.EVT_BUTTON, self.DownloadLocation) self.rename_mapset_button.Bind(wx.EVT_BUTTON, self.RenameMapset) self.delete_mapset_button.Bind(wx.EVT_BUTTON, self.DeleteMapset) self.lblocations.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnSelectLocation) self.lbmapsets.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnSelectMapset) self.lbmapsets.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnStart) self.tgisdbase.Bind(wx.EVT_TEXT_ENTER, self.OnSetDatabase) self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
class IClassSignatureFileDialog(wx.Dialog): def __init__(self, parent, group, subgroup, file=None, title=_("Save signature file"), id=wx.ID_ANY, style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, **kwargs): """Dialog for saving signature file :param parent: window :param group: group name :param file: signature file name :param title: window title """ wx.Dialog.__init__(self, parent, id, title, style=style, **kwargs) self.fileName = file env = grass.gisenv() # inconsistent group and subgroup name # path: # grassdata/nc_spm_08/landsat/group/test_group/subgroup/test_group/sig/sigFile self.baseFilePath = os.path.join(env['GISDBASE'], env['LOCATION_NAME'], env['MAPSET'], 'group', group, 'subgroup', subgroup, 'sig') self.panel = wx.Panel(parent=self, id=wx.ID_ANY) self.btnCancel = Button(parent=self.panel, id=wx.ID_CANCEL) self.btnOK = Button(parent=self.panel, id=wx.ID_OK) self.btnOK.SetDefault() self.btnOK.Enable(False) self.__layout() self.fileNameCtrl.Bind(wx.EVT_TEXT, self.OnTextChanged) self.OnTextChanged(None) def OnTextChanged(self, event): """Name for signature file given""" file = self.fileNameCtrl.GetValue() if len(file) > 0: self.btnOK.Enable(True) else: self.btnOK.Enable(False) path = os.path.join(self.baseFilePath, file) self.filePathText.SetLabel(path) bestSize = self.pathPanel.GetBestVirtualSize() self.pathPanel.SetVirtualSize(bestSize) self.pathPanel.Scroll(*bestSize) def __layout(self): """Do layout""" sizer = wx.BoxSizer(wx.VERTICAL) dataSizer = wx.BoxSizer(wx.VERTICAL) dataSizer.Add(StaticText(parent=self.panel, id=wx.ID_ANY, label=_("Enter name of signature file:")), proportion=0, flag=wx.ALL, border=3) self.fileNameCtrl = TextCtrl(parent=self.panel, id=wx.ID_ANY, size=(400, -1)) if self.fileName: self.fileNameCtrl.SetValue(self.fileName) dataSizer.Add(self.fileNameCtrl, proportion=0, flag=wx.ALL | wx.EXPAND, border=3) dataSizer.Add(StaticText(parent=self.panel, id=wx.ID_ANY, label=_("Signature file path:")), proportion=0, flag=wx.ALL, border=3) self.pathPanel = scrolled.ScrolledPanel(self.panel, size=(-1, 40)) pathSizer = wx.BoxSizer() self.filePathText = StaticText(parent=self.pathPanel, id=wx.ID_ANY, label=self.baseFilePath) pathSizer.Add(self.filePathText, proportion=1, flag=wx.ALL | wx.EXPAND, border=1) self.pathPanel.SetupScrolling(scroll_x=True, scroll_y=False) self.pathPanel.SetSizer(pathSizer) dataSizer.Add(self.pathPanel, proportion=0, flag=wx.ALL | wx.EXPAND, border=3) # buttons btnSizer = wx.StdDialogButtonSizer() btnSizer.AddButton(self.btnCancel) btnSizer.AddButton(self.btnOK) btnSizer.Realize() sizer.Add(dataSizer, proportion=1, flag=wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border=5) sizer.Add(btnSizer, proportion=0, flag=wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border=5) self.panel.SetSizer(sizer) sizer.Fit(self) self.SetMinSize(self.GetSize()) def GetFileName(self, fullPath=False): """Returns signature file name :param fullPath: return full path of sig. file """ if fullPath: return os.path.join(self.baseFilePath, self.fileNameCtrl.GetValue()) return self.fileNameCtrl.GetValue()