Example #1
0
    def __init__(self, parent, giface=None):
        wx.Frame.__init__(self, parent=parent,
                          title=_('GRASS GIS Data Catalog'))
        self.SetName("DataCatalog")
        self.SetIcon(
            wx.Icon(
                os.path.join(
                    ICONDIR,
                    'grass.ico'),
                wx.BITMAP_TYPE_ICO))

        self._giface = giface
        self.panel = wx.Panel(self)

        self.toolbar = DataCatalogToolbar(parent=self)
        # workaround for http://trac.wxwidgets.org/ticket/13888
        if sys.platform != 'darwin':
            self.SetToolBar(self.toolbar)

        # tree
        self.tree = DataCatalogTree(parent=self.panel, giface=self._giface)
        self.tree.InitTreeItems()
        self.tree.ExpandCurrentMapset()
        self.tree.changeMapset.connect(lambda mapset:
                                       self.ChangeLocationMapset(location=None,
                                                                 mapset=mapset))
        self.tree.changeLocation.connect(lambda mapset, location:
                                         self.ChangeLocationMapset(location=location,
                                                                   mapset=mapset))

        # buttons
        self.btnClose = Button(parent=self.panel, id=wx.ID_CLOSE)
        self.btnClose.SetToolTip(_("Close GRASS GIS Data Catalog"))
        self.btnClose.SetDefault()

        # events
        self.btnClose.Bind(wx.EVT_BUTTON, self.OnCloseWindow)
        self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)

        self._layout()
Example #2
0
    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()
Example #3
0
    def __init__(
        self,
        parent,
        title=_("Select raster maps"),
        first=None,
        second=None,
        firstLayerList=None,
        secondLayerList=None,
    ):

        wx.Dialog.__init__(
            self,
            parent=parent,
            title=title,
            style=wx.RESIZE_BORDER | wx.DEFAULT_DIALOG_STYLE,
        )

        if firstLayerList is None:
            self._firstLayerList = LayerList()
        else:
            self._firstLayerList = copy.deepcopy(firstLayerList)
        if secondLayerList is None:
            self._secondLayerList = LayerList()
        else:
            self._secondLayerList = copy.deepcopy(secondLayerList)

        self._firstPanel = self._createSimplePanel()
        self._secondPanel = self._createAdvancedPanel()

        self.btnSwitch = Button(self)
        self.btnCancel = Button(self, id=wx.ID_CANCEL)
        self.btnApply = Button(self, id=wx.ID_APPLY)
        self.btnOK = Button(self, id=wx.ID_OK)
        self.btnOK.SetDefault()

        self.btnSwitch.Bind(wx.EVT_BUTTON, self.OnSwitchMode)
        self.btnApply.Bind(wx.EVT_BUTTON, lambda evt: self._apply())
        self.btnOK.Bind(wx.EVT_BUTTON, lambda evt: self._ok())
        self.btnCancel.Bind(wx.EVT_BUTTON, lambda evt: self.Close())
        self.Bind(wx.EVT_CLOSE, lambda evt: self.Hide())

        self.applyChanges = Signal("SwipeMapDialog.applyChanges")

        if first:
            self._firstRaster.SetValue(first)
        if second:
            self._secondRaster.SetValue(second)

        self._layout()
Example #4
0
    def __init__(self, parent, giface=None):
        wx.Frame.__init__(self,
                          parent=parent,
                          title=_('GRASS GIS Data Catalog'))
        self.SetName("DataCatalog")
        self.SetIcon(
            wx.Icon(os.path.join(ICONDIR, 'grass.ico'), wx.BITMAP_TYPE_ICO))

        self._giface = giface
        self.panel = wx.Panel(self)
        self.catalogpanel = DataCatalog(self.panel, giface=giface)

        # buttons
        self.btnClose = Button(parent=self.panel, id=wx.ID_CLOSE)
        self.btnClose.SetToolTip(_("Close GRASS GIS Data Catalog"))
        self.btnClose.SetDefault()

        # events
        self.btnClose.Bind(wx.EVT_BUTTON, lambda evt: self.Close())

        self._layout()
        self.catalogpanel.LoadItems()
Example #5
0
class DataCatalogFrame(wx.Frame):
    """Frame for testing purposes only."""
    def __init__(self, parent, giface=None):
        wx.Frame.__init__(self,
                          parent=parent,
                          title=_('GRASS GIS Data Catalog'))
        self.SetName("DataCatalog")
        self.SetIcon(
            wx.Icon(os.path.join(ICONDIR, 'grass.ico'), wx.BITMAP_TYPE_ICO))

        self._giface = giface
        self.panel = wx.Panel(self)
        self.catalogpanel = DataCatalog(self.panel, giface=giface)

        # buttons
        self.btnClose = Button(parent=self.panel, id=wx.ID_CLOSE)
        self.btnClose.SetToolTip(_("Close GRASS GIS Data Catalog"))
        self.btnClose.SetDefault()

        # events
        self.btnClose.Bind(wx.EVT_BUTTON, lambda evt: self.Close())

        self._layout()
        self.catalogpanel.LoadItems()

    def _layout(self):
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.catalogpanel, proportion=1, flag=wx.EXPAND)

        btnSizer = wx.BoxSizer(wx.HORIZONTAL)
        btnSizer.AddStretchSpacer()
        btnSizer.Add(self.btnClose)

        sizer.Add(btnSizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)

        self.panel.SetSizer(sizer)
        sizer.Fit(self.panel)

        self.SetMinSize((450, 500))
Example #6
0
    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)
Example #7
0
    def __init__(self, parent, id=wx.ID_ANY, ogr=False,
                 style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, *kwargs):
        """Dialog for setting output format for rasters/vectors

        .. todo::
            Split into GdalOutputDialog and OgrOutputDialog

        :param parent: parent window
        :param id: window id
        :param ogr: True for OGR (vector) otherwise GDAL (raster)
        :param style: window style
        :param *kwargs: other wx.Dialog's arguments
        """
        self.parent = parent  # GMFrame
        self.ogr = ogr
        wx.Dialog.__init__(self, parent, id=id, style=style, *kwargs)
        if self.ogr:
            self.SetTitle(_("Define output format for vector data"))
        else:
            self.SetTitle(_("Define output format for raster data"))

        self.panel = wx.Panel(parent=self, id=wx.ID_ANY)

        # buttons
        self.btnCancel = Button(parent=self.panel, id=wx.ID_CANCEL)
        self.btnCancel.SetToolTip(_("Close dialog"))
        self.btnOk = Button(parent=self.panel, id=wx.ID_OK)
        self.btnOk.SetToolTip(_("Set external format and close dialog"))
        self.btnOk.SetDefault()

        self.dsnInput = GdalSelect(parent=self, panel=self.panel,
                                   ogr=ogr,
                                   exclude=['file', 'protocol'], dest=True)
        self.dsnInput.AttachSettings()

        self.Bind(wx.EVT_BUTTON, self.OnCancel, self.btnCancel)
        self.Bind(wx.EVT_BUTTON, self.OnOK, self.btnOk)

        self._layout()
Example #8
0
    def _doLayout(self, modeChoices):
        """Do dialog layout"""

        SQLBuilder._doLayout(self, modeChoices)

        self.text_sql.SetValue("SELECT * FROM %s" % self.tablename)
        self.text_sql.SetToolTip(
            _("Example: %s") %
            "SELECT * FROM roadsmajor WHERE MULTILANE = 'no' OR OBJECTID < 10")

        self.btn_verify = Button(parent=self.panel,
                                 id=wx.ID_ANY,
                                 label=_("Verify"))
        self.btn_verify.SetToolTip(_("Verify SQL statement"))

        self.buttonsizer.Insert(1, self.btn_verify)

        self.text_sql.Bind(wx.EVT_TEXT, self.OnText)
        self.btn_verify.Bind(wx.EVT_BUTTON, self.OnVerify)

        self.text_sql.SetInsertionPoint(self.text_sql.GetLastPosition())
        self.statusbar.SetStatusText(_("SQL statement not verified"), 0)
Example #9
0
    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()
Example #10
0
    def __init__(self,
                 parent,
                 giface,
                 id=wx.ID_ANY,
                 simpleEditorHandler=None,
                 **kwargs):
        self.parent = parent
        self.giface = giface

        wx.Panel.__init__(self, parent=parent, id=id, **kwargs)

        self.intro = _("Welcome to wxGUI Interactive Python Shell %s") % VERSION + "\n\n" + \
            _("Type %s for more GRASS scripting related information.") % "\"help(grass)\"" + "\n" + \
            _("Type %s to add raster or vector to the layer tree.") % "\"AddLayer()\"" + "\n\n"
        self.shell = PyShell(parent=self,
                             id=wx.ID_ANY,
                             introText=self.intro,
                             locals={
                                 'grass': grass,
                                 'AddLayer': self.AddLayer
                             })

        sys.displayhook = self._displayhook

        self.btnClear = Button(self, wx.ID_CLEAR)
        self.btnClear.Bind(wx.EVT_BUTTON, self.OnClear)
        self.btnClear.SetToolTip(_("Delete all text from the shell"))

        self.simpleEditorHandler = simpleEditorHandler
        if simpleEditorHandler:
            self.btnSimpleEditor = Button(self,
                                          id=wx.ID_ANY,
                                          label=_("Simple &editor"))
            self.btnSimpleEditor.Bind(wx.EVT_BUTTON, simpleEditorHandler)
            self.btnSimpleEditor.SetToolTip(
                _("Open a simple Python code editor"))

        self._layout()
Example #11
0
 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]
Example #12
0
    def __init__(self, parent, giface, id=wx.ID_ANY, simpleEditorHandler=None, **kwargs):
        self.parent = parent
        self.giface = giface

        wx.Panel.__init__(self, parent=parent, id=id, **kwargs)

        self.intro = _("Welcome to wxGUI Interactive Python Shell %s") % VERSION + "\n\n" + \
            _("Type %s for more GRASS scripting related information.") % "\"help(gs)\"" + "\n" + \
            _("Type %s to add raster or vector to the layer tree.") % "\"AddLayer()\"" + "\n\n"

        shellargs = dict(
            parent=self,
            id=wx.ID_ANY,
            introText=self.intro,
            locals={"gs": grass, "AddLayer": self.AddLayer},
        )
        # useStockId (available since wxPython 4.0.2) should be False on macOS
        if sys.platform == "darwin" and CheckWxVersion([4, 0, 2]):
            shellargs["useStockId"] = False
        self.shell = PyShell(**shellargs)
        if IsDark():
            SetDarkMode(self.shell)

        sys.displayhook = self._displayhook

        self.btnClear = ClearButton(self)
        self.btnClear.Bind(wx.EVT_BUTTON, self.OnClear)
        self.btnClear.SetToolTip(_("Delete all text from the shell"))

        self.simpleEditorHandler = simpleEditorHandler
        if simpleEditorHandler:
            self.btnSimpleEditor = Button(
                self, id=wx.ID_ANY, label=_("Simple &editor"))
            self.btnSimpleEditor.Bind(wx.EVT_BUTTON, simpleEditorHandler)
            self.btnSimpleEditor.SetToolTip(
                _("Open a simple Python code editor"))

        self._layout()
Example #13
0
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()
Example #14
0
    def __init__(self, parent, shape, id=wx.ID_ANY,
                 title=_("Relation properties"),
                 style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, **kwargs):
        self.parent = parent
        self.shape = shape

        options = self._getOptions()
        if not options:
            self.valid = False
            return

        self.valid = True
        wx.Dialog.__init__(self, parent, id, title, style=style, **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.fromBox = StaticBox(parent=self.panel, id=wx.ID_ANY,
                                 label=" %s " % _("From"))
        self.toBox = StaticBox(parent=self.panel, id=wx.ID_ANY,
                               label=" %s " % _("To"))

        self.option = wx.ComboBox(parent=self.panel, id=wx.ID_ANY,
                                  style=wx.CB_READONLY,
                                  choices=options)
        self.option.Bind(wx.EVT_COMBOBOX, self.OnOption)

        self.btnCancel = Button(self.panel, wx.ID_CANCEL)
        self.btnOk = Button(self.panel, wx.ID_OK)
        self.btnOk.Enable(False)

        self._layout()
Example #15
0
    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)
Example #16
0
    def __init__(self, parent, handlerObj, giface, model, id=wx.ID_ANY,
                 **kwargs):
        self.parent = parent
        self._handlerObj = handlerObj
        self._giface = giface

        self.showNotification = Signal('SearchModuleWindow.showNotification')
        wx.Panel.__init__(self, parent=parent, id=id, **kwargs)

        # tree
        self._tree = CTreeView(model=model, parent=self)
        self._tree.SetToolTip(
            _("Double-click or Ctrl-Enter to run selected module"))

#        self._dataBox = wx.StaticBox(parent = self, id = wx.ID_ANY,
#                                     label = " %s " % _("Module tree"))

        # search widget
        self._search = SearchModuleWidget(parent=self,
                                          model=model,
                                          showChoice=False)
        self._search.showSearchResult.connect(
            lambda result: self._tree.Select(result))
        self._search.showNotification.connect(self.showNotification)

        self._helpText = StaticText(
            parent=self, id=wx.ID_ANY,
            label="Press Enter for next match, Ctrl+Enter to run command")
        self._helpText.SetForegroundColour(
            wx.SystemSettings.GetColour(
                wx.SYS_COLOUR_GRAYTEXT))

        # buttons
        self._btnRun = Button(self, id=wx.ID_OK, label=_("&Run"))
        self._btnRun.SetToolTip(_("Run selected module from the tree"))
        self._btnHelp = Button(self, id=wx.ID_ANY, label=_("H&elp"))
        self._btnHelp.SetToolTip(
            _("Show manual for selected module from the tree"))
        self._btnAdvancedSearch = Button(self, id=wx.ID_ANY,
                                         label=_("Adva&nced search..."))
        self._btnAdvancedSearch.SetToolTip(
            _("Do advanced search using %s module") % 'g.search.module')

        # bindings
        self._btnRun.Bind(wx.EVT_BUTTON, lambda evt: self.Run())
        self._btnHelp.Bind(wx.EVT_BUTTON, lambda evt: self.Help())
        self._btnAdvancedSearch.Bind(wx.EVT_BUTTON,
                                     lambda evt: self.AdvancedSearch())
        self.Bind(wx.EVT_KEY_UP, self.OnKeyUp)

        self._tree.selectionChanged.connect(self.OnItemSelected)
        self._tree.itemActivated.connect(lambda node: self.Run(node))

        self._layout()

        self._search.SetFocus()
Example #17
0
    def _createWidgets(self):

        self.labels = {}
        self.params = {}

        self.band_1_label = StaticText(parent=self,
                                       id=wx.ID_ANY,
                                       label=_("x axis:"))

        self.band_1_ch = wx.ComboBox(
            parent=self,
            id=wx.ID_ANY,
            choices=self.bands,
            style=wx.CB_READONLY,
            size=(350, 30),
        )

        self.band_2_label = StaticText(parent=self,
                                       id=wx.ID_ANY,
                                       label=_("y axis:"))

        self.band_2_ch = wx.ComboBox(
            parent=self,
            id=wx.ID_ANY,
            choices=self.bands,
            style=wx.CB_READONLY,
            size=(350, 30),
        )

        self.scattsBox = wx.ListBox(
            parent=self,
            id=wx.ID_ANY,
            size=(-1, 150),
            style=wx.LB_MULTIPLE | wx.LB_NEEDED_SB,
        )

        # buttons
        self.btn_add = Button(parent=self, id=wx.ID_ADD)
        self.btn_remove = Button(parent=self, id=wx.ID_REMOVE)

        self.btn_close = Button(parent=self, id=wx.ID_CANCEL)
        self.btn_ok = Button(parent=self, id=wx.ID_OK)

        self._layout()
Example #18
0
    def __init__(self,
                 parent,
                 handlerObj,
                 giface,
                 model,
                 id=wx.ID_ANY,
                 **kwargs):
        self.parent = parent
        self._handlerObj = handlerObj
        self._giface = giface
        self._model = model

        self.showNotification = Signal("SearchModuleWindow.showNotification")
        wx.Panel.__init__(self, parent=parent, id=id, **kwargs)

        # search widget
        self._search = SearchCtrl(self)
        self._search.SetDescriptiveText(_("Search"))
        self._search.ShowCancelButton(True)
        self._btnAdvancedSearch = Button(self,
                                         id=wx.ID_ANY,
                                         label=_("Adva&nced search..."))
        self._btnAdvancedSearch.SetToolTip(
            _("Do advanced search using %s module") % "g.search.module")
        # tree
        self._tree = CTreeView(model=model, parent=self)
        self._tree.SetToolTip(_("Double-click to run selected module"))

        # buttons
        self._btnRun = Button(self, id=wx.ID_OK, label=_("&Run..."))
        self._btnRun.SetToolTip(_("Run selected module from the tree"))
        self._btnHelp = Button(self, id=wx.ID_ANY, label=_("H&elp"))
        self._btnHelp.SetToolTip(
            _("Show manual for selected module from the tree"))

        # bindings
        self._search.Bind(wx.EVT_TEXT,
                          lambda evt: self.Filter(evt.GetString()))
        self._search.Bind(wx.EVT_SEARCHCTRL_CANCEL_BTN,
                          lambda evt: self.Filter(""))
        self._btnRun.Bind(wx.EVT_BUTTON, lambda evt: self.Run())
        self._btnHelp.Bind(wx.EVT_BUTTON, lambda evt: self.Help())
        self._btnAdvancedSearch.Bind(wx.EVT_BUTTON,
                                     lambda evt: self.AdvancedSearch())

        self._tree.selectionChanged.connect(self.OnItemSelected)
        self._tree.itemActivated.connect(lambda node: self.Run(node))

        self._layout()

        self._search.SetFocus()
Example #19
0
class WSManageSettingsWidget(ManageSettingsWidget):
    def __init__(self, parent, settingsFile, default_servers):

        ManageSettingsWidget.__init__(self, parent, settingsFile)
        self.default_servers = default_servers

    def _layout(self):

        self.btnAddDefaultServers = Button(
            parent=self, id=wx.ID_ANY, label=_("Add default")
        )
        self.btnAddDefaultServers.Bind(wx.EVT_BUTTON, self.OnAddDefaultServers)

        ManageSettingsWidget._layout(self)
        self.settingsSizer.Add(self.btnAddDefaultServers, flag=wx.RIGHT, border=5)

    def OnAddDefaultServers(self, event):

        setts = self.GetSettings()
        self.servers_to_add = {}
        for k, v in six.iteritems(self.default_servers):
            if k not in six.iterkeys(setts):
                self.servers_to_add[k] = v
            elif v != setts[k]:
                GMessage(
                    parent=self,
                    message=_(
                        "User defined server with same name "
                        "as default server <%s> already exists.\n"
                        "Keeping user defined server"
                    )
                    % (k),
                )

        if self.servers_to_add:
            self.AddSettings(self.servers_to_add)
Example #20
0
    def __init__(
            self, parent, id=wx.ID_ANY,
            title=_("Manage installed GRASS Addons extensions"),
            **kwargs):
        self.parent = parent

        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.extBox = StaticBox(
            parent=self.panel, id=wx.ID_ANY, label=" %s " %
            _("List of installed extensions"))

        self.extList = CheckListExtension(parent=self.panel)

        # buttons
        self.btnUninstall = Button(
            parent=self.panel,
            id=wx.ID_REMOVE,
            label=_("Uninstall"))
        self.btnUninstall.SetToolTip(
            _("Uninstall selected Addons extensions"))
        self.btnUpdate = Button(
            parent=self.panel,
            id=wx.ID_REFRESH,
            label=_("Reinstall"))
        self.btnUpdate.SetToolTip(
            _("Reinstall selected Addons extensions"))

        self.btnClose = Button(parent=self.panel, id=wx.ID_CLOSE)

        self.btnUninstall.Bind(wx.EVT_BUTTON, self.OnUninstall)
        self.btnUpdate.Bind(wx.EVT_BUTTON, self.OnUpdate)
        self.btnClose.Bind(wx.EVT_BUTTON, lambda evt: self.Close())

        self._layout()
Example #21
0
class AddScattPlotDialog(wx.Dialog):

    def __init__(self, parent, bands, check_bands_callback, id=wx.ID_ANY):
        wx.Dialog.__init__(self, parent, title=_("Add scatter plots"), id=id)

        self.bands = bands

        self.x_band = None
        self.y_band = None

        self.chb_callback = check_bands_callback

        self.added_bands_ids = []
        self.sel_bands_ids = []
        self._createWidgets()

    def _createWidgets(self):

        self.labels = {}
        self.params = {}

        self.band_1_label = StaticText(
            parent=self, id=wx.ID_ANY, label=_("x axis:"))

        self.band_1_ch = wx.ComboBox(parent=self, id=wx.ID_ANY,
                                     choices=self.bands,
                                     style=wx.CB_READONLY, size=(350, 30))

        self.band_2_label = StaticText(
            parent=self, id=wx.ID_ANY, label=_("y axis:"))

        self.band_2_ch = wx.ComboBox(parent=self, id=wx.ID_ANY,
                                     choices=self.bands,
                                     style=wx.CB_READONLY, size=(350, 30))

        self.scattsBox = wx.ListBox(parent=self, id=wx.ID_ANY, size=(-1, 150),
                                    style=wx.LB_MULTIPLE | wx.LB_NEEDED_SB)

        # buttons
        self.btn_add = Button(parent=self, id=wx.ID_ADD)
        self.btn_remove = Button(parent=self, id=wx.ID_REMOVE)

        self.btn_close = Button(parent=self, id=wx.ID_CANCEL)
        self.btn_ok = Button(parent=self, id=wx.ID_OK)

        self._layout()

    def _layout(self):

        border = wx.BoxSizer(wx.VERTICAL)
        dialogSizer = wx.BoxSizer(wx.VERTICAL)

        regionSizer = wx.BoxSizer(wx.HORIZONTAL)

        dialogSizer.Add(self._addSelectSizer(title=self.band_1_label,
                                             sel=self.band_1_ch))

        dialogSizer.Add(self._addSelectSizer(title=self.band_2_label,
                                             sel=self.band_2_ch))

        dialogSizer.Add(
            self.btn_add,
            proportion=0,
            flag=wx.TOP | wx.ALIGN_RIGHT,
            border=5)

        box = StaticBox(
            self, id=wx.ID_ANY, label=" %s " %
            _("Bands of scatter plots to be added (x y):"))
        sizer = wx.StaticBoxSizer(box, wx.VERTICAL)

        sizer.Add(
            self.scattsBox,
            proportion=1,
            flag=wx.EXPAND | wx.TOP,
            border=5)
        sizer.Add(
            self.btn_remove,
            proportion=0,
            flag=wx.TOP | wx.ALIGN_RIGHT,
            border=5)

        dialogSizer.Add(
            sizer,
            proportion=1,
            flag=wx.EXPAND | wx.TOP,
            border=5)

        # buttons
        self.btnsizer = wx.BoxSizer(orient=wx.HORIZONTAL)

        self.btnsizer.Add(self.btn_close, proportion=0,
                          flag=wx.RIGHT | wx.LEFT | wx.ALIGN_CENTER,
                          border=10)

        self.btnsizer.Add(self.btn_ok, proportion=0,
                          flag=wx.RIGHT | wx.LEFT | wx.ALIGN_CENTER,
                          border=10)

        dialogSizer.Add(self.btnsizer, proportion=0,
                        flag=wx.ALIGN_CENTER | wx.TOP, border=5)

        border.Add(dialogSizer, proportion=0,
                   flag=wx.LEFT | wx.RIGHT | wx.BOTTOM, border=10)

        self.SetSizer(border)
        self.Layout()
        self.Fit()

        # bindings
        self.btn_close.Bind(wx.EVT_BUTTON, self.OnClose)
        self.btn_ok.Bind(wx.EVT_BUTTON, self.OnOk)
        self.btn_add.Bind(wx.EVT_BUTTON, self.OnAdd)
        self.btn_remove.Bind(wx.EVT_BUTTON, self.OnRemoveLayer)

    def OnOk(self, event):

        if not self.GetBands():
            GMessage(parent=self, message=_("No scatter plots selected."))
            return

        event.Skip()

    def _addSelectSizer(self, title, sel):
        """Helper layout function.
        """
        selSizer = wx.BoxSizer(orient=wx.VERTICAL)

        selTitleSizer = wx.BoxSizer(wx.HORIZONTAL)
        selTitleSizer.Add(title, proportion=1,
                          flag=wx.TOP | wx.EXPAND, border=5)

        selSizer.Add(selTitleSizer, proportion=0,
                     flag=wx.EXPAND)

        selSizer.Add(sel, proportion=1,
                     flag=wx.EXPAND | wx.TOP | wx.ALIGN_CENTER_VERTICAL,
                     border=5)

        return selSizer

    def GetBands(self):
        """Get layers"""
        return self.sel_bands_ids

    def OnClose(self, event):
        """Close dialog
        """
        if not self.IsModal():
            self.Destroy()
        event.Skip()

    def OnRemoveLayer(self, event):
        """Remove layer from listbox"""
        while self.scattsBox.GetSelections():
            sel = self.scattsBox.GetSelections()[0]
            self.scattsBox.Delete(sel)
            self.sel_bands_ids.pop(sel)

    def OnAdd(self, event):
        """
        """
        b_x = self.band_1_ch.GetSelection()
        b_y = self.band_2_ch.GetSelection()

        if b_x < 0 or b_y < 0:
            GMessage(parent=self, message=_("Select both x and y bands."))
            return
        if b_y == b_x:
            GMessage(parent=self, message=_(
                "Selected bands must be different."))
            return

        if [b_x, b_y] in self.sel_bands_ids or [
                b_y, b_x] in self.sel_bands_ids:
            GMessage(
                parent=self, message=_(
                    "Scatter plot with same bands combination (regardless x y order) "
                    "has been already added into the list."))
            return

        if not self.chb_callback(b_x, b_y):
            return

        self.sel_bands_ids.append([b_x, b_y])

        b_x_str = self.band_1_ch.GetStringSelection()
        b_y_str = self.band_2_ch.GetStringSelection()

        text = b_x_str + " " + b_y_str

        self.scattsBox.Append(text)
        event.Skip()
Example #22
0
    def __init__(
            self, parent, id, title, scatt_mgr, pos=wx.DefaultPosition,
            size=wx.DefaultSize, style=wx.DEFAULT_DIALOG_STYLE):
        """Settings dialog"""
        wx.Dialog.__init__(self, parent, id, title, pos, size, style)

        self.scatt_mgr = scatt_mgr

        maxValue = 1e8
        self.parent = parent
        self.settings = {}

        settsLabels = {}

        self.settings["show_ellips"] = wx.CheckBox(
            parent=self, id=wx.ID_ANY, label=_('Show confidence ellipses'))
        show_ellips = UserSettings.Get(
            group='scatt', key="ellipses", subkey="show_ellips")
        self.settings["show_ellips"].SetValue(show_ellips)

        self.colorsSetts = {
            "sel_pol": [
                "selection", _("Selection polygon color:")], "sel_pol_vertex": [
                "selection", _("Color of selection polygon vertex:")], "sel_area": [
                "selection", _("Selected area color:")]}

        for settKey, sett in six.iteritems(self.colorsSetts):
            settsLabels[settKey] = StaticText(
                parent=self, id=wx.ID_ANY, label=sett[1])
            col = UserSettings.Get(group='scatt', key=sett[0], subkey=settKey)
            self.settings[settKey] = csel.ColourSelect(
                parent=self, id=wx.ID_ANY, colour=wx.Colour(
                    col[0], col[1], col[2], 255))

        self.sizeSetts = {
            "snap_tresh": ["selection", _("Snapping threshold in pixels:")],
            "sel_area_opacty": ["selection", _("Selected area opacity:")]
        }

        for settKey, sett in six.iteritems(self.sizeSetts):
            settsLabels[settKey] = StaticText(
                parent=self, id=wx.ID_ANY, label=sett[1])
            self.settings[settKey] = SpinCtrl(
                parent=self, id=wx.ID_ANY, min=0, max=100)
            size = int(
                UserSettings.Get(
                    group='scatt',
                    key=sett[0],
                    subkey=settKey))
            self.settings[settKey].SetValue(size)

        # buttons
        self.btnSave = Button(self, wx.ID_SAVE)
        self.btnApply = Button(self, wx.ID_APPLY)
        self.btnClose = Button(self, wx.ID_CLOSE)
        self.btnApply.SetDefault()

        # bindings
        self.btnApply.Bind(wx.EVT_BUTTON, self.OnApply)
        self.btnApply.SetToolTip(
            _("Apply changes for the current session"))
        self.btnSave.Bind(wx.EVT_BUTTON, self.OnSave)
        self.btnSave.SetToolTip(
            _("Apply and save changes to user settings file (default for next sessions)"))
        self.btnClose.Bind(wx.EVT_BUTTON, self.OnClose)
        self.btnClose.SetToolTip(_("Close dialog"))

        # Layout

        # Analysis result style layout
        self.SetMinSize(self.GetBestSize())

        sizer = wx.BoxSizer(wx.VERTICAL)

        sel_pol_box = StaticBox(parent=self, id=wx.ID_ANY,
                                label=" %s " % _("Selection style:"))
        selPolBoxSizer = wx.StaticBoxSizer(sel_pol_box, wx.VERTICAL)

        gridSizer = wx.GridBagSizer(vgap=1, hgap=1)

        row = 0
        setts = dict()
        setts.update(self.colorsSetts)
        setts.update(self.sizeSetts)

        settsOrder = ["sel_pol", "sel_pol_vertex", "sel_area",
                      "sel_area_opacty", "snap_tresh"]
        for settKey in settsOrder:
            sett = setts[settKey]
            gridSizer.Add(
                settsLabels[settKey],
                flag=wx.ALIGN_CENTER_VERTICAL,
                pos=(
                    row,
                    0))
            gridSizer.Add(self.settings[settKey],
                          flag=wx.ALIGN_RIGHT | wx.ALL, border=5,
                          pos=(row, 1))
            row += 1

        gridSizer.AddGrowableCol(1)
        selPolBoxSizer.Add(gridSizer, flag=wx.EXPAND)

        ell_box = StaticBox(parent=self, id=wx.ID_ANY,
                            label=" %s " % _("Ellipses settings:"))
        ellPolBoxSizer = wx.StaticBoxSizer(ell_box, wx.VERTICAL)
        gridSizer = wx.GridBagSizer(vgap=1, hgap=1)

        sett = setts[settKey]

        row = 0
        gridSizer.Add(self.settings["show_ellips"],
                      flag=wx.ALIGN_CENTER_VERTICAL,
                      pos=(row, 0))

        gridSizer.AddGrowableCol(0)
        ellPolBoxSizer.Add(gridSizer, flag=wx.EXPAND)

        btnSizer = wx.BoxSizer(wx.HORIZONTAL)
        btnSizer.Add(self.btnApply, flag=wx.LEFT | wx.RIGHT, border=5)
        btnSizer.Add(self.btnSave, flag=wx.LEFT | wx.RIGHT, border=5)
        btnSizer.Add(self.btnClose, flag=wx.LEFT | wx.RIGHT, border=5)

        sizer.Add(selPolBoxSizer, flag=wx.EXPAND | wx.ALL, border=5)
        sizer.Add(ellPolBoxSizer, flag=wx.EXPAND | wx.ALL, border=5)
        sizer.Add(
            btnSizer,
            flag=wx.EXPAND | wx.ALL,
            border=5,
            proportion=0)

        self.SetSizer(sizer)
        sizer.Fit(self)
Example #23
0
class ExportCategoryRaster(wx.Dialog):

    def __init__(self, parent, title, rasterName=None, id=wx.ID_ANY,
                 style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER,
                 **kwargs):
        """Dialog for export of category raster.

        :param parent: window
        :param str rasterName name of vector layer for export
        :param title: window title
        """
        wx.Dialog.__init__(self, parent, id, title, style=style, **kwargs)

        self.rasterName = rasterName
        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.btnOK.Bind(wx.EVT_BUTTON, self.OnOK)

        self.__layout()

        self.vectorNameCtrl.Bind(wx.EVT_TEXT, self.OnTextChanged)
        self.OnTextChanged(None)
        wx.CallAfter(self.vectorNameCtrl.SetFocus)

    def OnTextChanged(self, event):
        """Name of new vector map given.

        Enable/diable OK button.
        """
        file = self.vectorNameCtrl.GetValue()
        if len(file) > 0:
            self.btnOK.Enable(True)
        else:
            self.btnOK.Enable(False)

    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 new vector map:")),
            proportion=0,
            flag=wx.ALL,
            border=3)
        self.vectorNameCtrl = Select(parent=self.panel, type='raster',
                                     mapsets=[grass.gisenv()['MAPSET']],
                                     size=globalvar.DIALOG_GSELECT_SIZE)
        if self.rasterName:
            self.vectorNameCtrl.SetValue(self.rasterName)
        dataSizer.Add(self.vectorNameCtrl,
                      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 GetRasterName(self):
        """Returns vector name"""
        return self.vectorNameCtrl.GetValue()

    def OnOK(self, event):
        """Checks if map exists and can be overwritten."""
        overwrite = UserSettings.Get(
            group='cmd', key='overwrite', subkey='enabled')
        rast_name = self.GetRasterName()
        res = grass.find_file(rast_name, element='cell')
        if res['fullname'] and overwrite is False:
            qdlg = wx.MessageDialog(
                parent=self, message=_(
                    "Raster map <%s> already exists."
                    " Do you want to overwrite it?" %
                    rast_name), caption=_(
                    "Raster <%s> exists" %
                    rast_name), style=wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION | wx.CENTRE)
            if qdlg.ShowModal() == wx.ID_YES:
                event.Skip()
            qdlg.Destroy()
        else:
            event.Skip()
Example #24
0
class PyShellWindow(wx.Panel):
    """Python Shell Window"""

    def __init__(self, parent, giface, id=wx.ID_ANY, simpleEditorHandler=None, **kwargs):
        self.parent = parent
        self.giface = giface

        wx.Panel.__init__(self, parent=parent, id=id, **kwargs)

        self.intro = _("Welcome to wxGUI Interactive Python Shell %s") % VERSION + "\n\n" + \
            _("Type %s for more GRASS scripting related information.") % "\"help(gs)\"" + "\n" + \
            _("Type %s to add raster or vector to the layer tree.") % "\"AddLayer()\"" + "\n\n"
        self.shell = PyShell(parent=self, id=wx.ID_ANY,
                             introText=self.intro,
                             locals={'gs': grass,
                                     'AddLayer': self.AddLayer})

        sys.displayhook = self._displayhook

        self.btnClear = Button(self, wx.ID_CLEAR)
        self.btnClear.Bind(wx.EVT_BUTTON, self.OnClear)
        self.btnClear.SetToolTip(_("Delete all text from the shell"))

        self.simpleEditorHandler = simpleEditorHandler
        if simpleEditorHandler:
            self.btnSimpleEditor = Button(
                self, id=wx.ID_ANY, label=_("Simple &editor"))
            self.btnSimpleEditor.Bind(wx.EVT_BUTTON, simpleEditorHandler)
            self.btnSimpleEditor.SetToolTip(
                _("Open a simple Python code editor"))

        self._layout()

    def _displayhook(self, value):
        print(value)  # do not modify __builtin__._

    def _layout(self):
        sizer = wx.BoxSizer(wx.VERTICAL)

        sizer.Add(self.shell, proportion=1,
                  flag=wx.EXPAND)

        btnSizer = wx.BoxSizer(wx.HORIZONTAL)
        if self.simpleEditorHandler:
            btnSizer.Add(self.btnSimpleEditor, proportion=0,
                         flag=wx.EXPAND | wx.LEFT | wx.RIGHT, border=5)
        btnSizer.AddStretchSpacer()
        btnSizer.Add(self.btnClear, proportion=0,
                     flag=wx.EXPAND, border=5)
        sizer.Add(btnSizer, proportion=0,
                  flag=wx.ALL | wx.EXPAND, border=5)

        sizer.Fit(self)
        sizer.SetSizeHints(self)

        self.SetSizer(sizer)

        self.Fit()
        self.SetAutoLayout(True)
        self.Layout()

    def AddLayer(self, name, ltype='auto'):
        """Add selected map to the layer tree

        :param name: name of raster/vector map to be added
        :param type: map type ('raster', 'vector', 'auto' for autodetection)
        """
        fname = None
        if ltype == 'raster' or ltype != 'vector':
            # check for raster
            fname = grass.find_file(name, element='cell')['fullname']
            if fname:
                ltype = 'raster'
                lcmd = 'd.rast'

        if not fname and (ltype == 'vector' or ltype != 'raster'):
            # if not found check for vector
            fname = grass.find_file(name, element='vector')['fullname']
            if fname:
                ltype = 'vector'
                lcmd = 'd.vect'

        if not fname:
            return _("Raster or vector map <%s> not found") % (name)

        self.giface.GetLayerTree().AddLayer(ltype=ltype,
                                            lname=fname,
                                            lchecked=True,
                                            lcmd=[lcmd, 'map=%s' % fname])
        if ltype == 'raster':
            return _('Raster map <%s> added') % fname

        return _('Vector map <%s> added') % fname

    def OnClear(self, event):
        """Delete all text from the shell
        """
        self.shell.clear()
        self.shell.showIntro(self.intro)
        self.shell.prompt()
Example #25
0
    def __init__(self, parent, transforms,
                 title=_("Select datum transformation"),
                 pos=wx.DefaultPosition, size=wx.DefaultSize,
                 style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER):

        wx.Dialog.__init__(self, parent, wx.ID_ANY, title, pos, size, style)

        global transformlist
        self.CentreOnParent()

        # default transform number
        self.transnum = 0

        panel = scrolled.ScrolledPanel(self, wx.ID_ANY)
        sizer = wx.BoxSizer(wx.VERTICAL)

        #
        # set panel sizer
        #
        panel.SetSizer(sizer)
        panel.SetupScrolling()

        #
        # dialog body
        #
        bodyBox = StaticBox(
            parent=panel, id=wx.ID_ANY, label=" %s " %
            _("Select from list of datum transformations"))
        bodySizer = wx.StaticBoxSizer(bodyBox)

        # add no transform option
        transforms = '---\n\n0\nDo not apply any datum transformations\n\n' + transforms

        transformlist = transforms.split('---')
        tlistlen = len(transformlist)

        # calculate size for transform list
        height = 0
        width = 0
        for line in transforms.splitlines():
            w, h = self.GetTextExtent(line)
            height += h
            width = max(width, w)

        height = height + 5
        if height > 400:
            height = 400
        width = width + 5
        if width > 400:
            width = 400

        #
        # VListBox for displaying and selecting transformations
        #
        self.translist = TransList(
            panel, id=-1, size=(width, height),
            style=wx.SUNKEN_BORDER)
        self.translist.SetItemCount(tlistlen)
        self.translist.SetSelection(2)
        self.translist.SetFocus()

        self.Bind(wx.EVT_LISTBOX, self.ClickTrans, self.translist)

        bodySizer.Add(
            self.translist,
            proportion=1,
            flag=wx.ALIGN_CENTER | wx.ALL | wx.EXPAND)

        #
        # buttons
        #
        btnsizer = wx.StdDialogButtonSizer()

        btn = Button(parent=panel, id=wx.ID_OK)
        btn.SetDefault()
        btnsizer.AddButton(btn)

        btn = Button(parent=panel, id=wx.ID_CANCEL)
        btnsizer.AddButton(btn)
        btnsizer.Realize()

        sizer.Add(bodySizer, proportion=1,
                  flag=wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border=5)

        sizer.Add(btnsizer, proportion=0,
                  flag=wx.ALL | wx.ALIGN_RIGHT, border=5)

        sizer.Fit(panel)

        self.SetSize(self.GetBestSize())
        self.Layout()
Example #26
0
    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)
Example #27
0
    def __init__(self, parent, data=None):
        wx.Dialog.__init__(self,
                           parent,
                           id=wx.ID_ANY,
                           title=_("Query results"),
                           size=(420, 400),
                           style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER)
        # send query output to console
        self.redirectOutput = Signal('QueryDialog.redirectOutput')

        self.data = data

        self.panel = wx.Panel(self, id=wx.ID_ANY)
        self.mainSizer = wx.BoxSizer(wx.VERTICAL)

        helpText = StaticText(
            self.panel,
            wx.ID_ANY,
            label=_("Right click to copy selected values to clipboard."))
        helpText.SetForegroundColour(
            wx.SystemSettings.GetColour(wx.SYS_COLOUR_GRAYTEXT))
        self.mainSizer.Add(helpText, proportion=0, flag=wx.ALL, border=5)

        self._colNames = [_("Feature"), _("Value")]
        self._model = QueryTreeBuilder(self.data, column=self._colNames[1])
        self.tree = TreeListView(model=self._model,
                                 parent=self.panel,
                                 columns=self._colNames,
                                 style=wx.TR_DEFAULT_STYLE | wx.TR_HIDE_ROOT
                                 | wx.TR_FULL_ROW_HIGHLIGHT | wx.TR_MULTIPLE)

        self.tree.SetColumnWidth(0, 220)
        self.tree.SetColumnWidth(1, 1000)
        self.tree.ExpandAll(self._model.root)
        self.tree.RefreshItems()
        self.tree.contextMenu.connect(self.ShowContextMenu)
        self.mainSizer.Add(self.tree,
                           proportion=1,
                           flag=wx.EXPAND | wx.ALL,
                           border=5)

        close = Button(self.panel, id=wx.ID_CLOSE)
        close.Bind(wx.EVT_BUTTON, lambda event: self.Close())
        copy = Button(self.panel,
                      id=wx.ID_ANY,
                      label=_("Copy all to clipboard"))
        copy.Bind(wx.EVT_BUTTON, self.Copy)
        self.Bind(wx.EVT_CLOSE, self.OnClose)
        self.redirect = wx.CheckBox(self.panel, label=_("Redirect to console"))
        self.redirect.SetValue(False)
        self.redirect.Bind(wx.EVT_CHECKBOX,
                           lambda evt: self._onRedirect(evt.IsChecked()))

        hbox = wx.BoxSizer(wx.HORIZONTAL)
        hbox.Add(self.redirect,
                 proportion=0,
                 flag=wx.EXPAND | wx.RIGHT,
                 border=5)
        hbox.AddStretchSpacer(1)
        hbox.Add(copy, proportion=0, flag=wx.EXPAND | wx.RIGHT, border=5)
        hbox.Add(close, proportion=0, flag=wx.EXPAND | wx.ALL, border=0)

        self.mainSizer.Add(hbox,
                           proportion=0,
                           flag=wx.EXPAND | wx.ALL,
                           border=5)
        self.panel.SetSizer(self.mainSizer)
        self.mainSizer.Fit(self.panel)
        # for Windows
        self.SendSizeEvent()
Example #28
0
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()
Example #29
0
    def __init__(
            self, parent, giface=None, id=wx.ID_ANY,
            title=_("GRASS"
                    " GIS Setup for r.li modules"),
            style=wx.DEFAULT_FRAME_STYLE | wx.RESIZE_BORDER, **kwargs):
        # VARIABLES
        self.parent = parent
#        self.cmd = "r.li.setup"
        self.rlipath = retRLiPath()
        self.listfiles = self.ListFiles()
        # END VARIABLES
        # init of frame
        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)
        # box for select configuration file
        self.confilesBox = StaticBox(
            parent=self.panel, id=wx.ID_ANY,
            label=_('Available sampling area configuration files'))
        self.listfileBox = wx.ListBox(parent=self.panel, id=wx.ID_ANY,
                                      choices=self.listfiles)

        # BUTTONS      #definition
        self.btn_close = Button(parent=self, id=wx.ID_CLOSE)
        self.btn_help = Button(parent=self, id=wx.ID_HELP)
        self.btn_remove = Button(parent=self, id=wx.ID_ANY,
                                    label=_("Remove"))
        self.btn_remove.SetToolTip(_('Remove a configuration file'))
        self.btn_new = Button(parent=self, id=wx.ID_ANY,
                                 label=_("Create"))
        self.btn_new.SetToolTip(_('Create a new configuration file'))
        self.btn_rename = Button(parent=self, id=wx.ID_ANY,
                                    label=_("Rename"))
        self.btn_rename.SetToolTip(_('Rename a configuration file'))
        self.btn_view = Button(parent=self, id=wx.ID_ANY,
                                  label=_("View/Edit"))
        self.btn_view.SetToolTip(_('View and edit a configuration file'))
        # set action for button
        self.btn_close.Bind(wx.EVT_BUTTON, self.OnClose)
        self.btn_help.Bind(wx.EVT_BUTTON, self.OnHelp)
        self.btn_remove.Bind(wx.EVT_BUTTON, self.OnRemove)
        self.btn_new.Bind(wx.EVT_BUTTON, self.OnNew)
        self.btn_rename.Bind(wx.EVT_BUTTON, self.OnRename)
        self.btn_view.Bind(wx.EVT_BUTTON, self.OnView)
        self._layout()
        # END BUTTONS
        # SIZE FRAME
        self.SetMinSize(self.GetBestSize())
        # Please check this because without this the size it is not the min
        self.SetClientSize(self.GetBestSize())
Example #30
0
class RLiSetupFrame(wx.Frame):

    def __init__(
            self, parent, giface=None, id=wx.ID_ANY,
            title=_("GRASS"
                    " GIS Setup for r.li modules"),
            style=wx.DEFAULT_FRAME_STYLE | wx.RESIZE_BORDER, **kwargs):
        # VARIABLES
        self.parent = parent
#        self.cmd = "r.li.setup"
        self.rlipath = retRLiPath()
        self.listfiles = self.ListFiles()
        # END VARIABLES
        # init of frame
        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)
        # box for select configuration file
        self.confilesBox = StaticBox(
            parent=self.panel, id=wx.ID_ANY,
            label=_('Available sampling area configuration files'))
        self.listfileBox = wx.ListBox(parent=self.panel, id=wx.ID_ANY,
                                      choices=self.listfiles)

        # BUTTONS      #definition
        self.btn_close = Button(parent=self, id=wx.ID_CLOSE)
        self.btn_help = Button(parent=self, id=wx.ID_HELP)
        self.btn_remove = Button(parent=self, id=wx.ID_ANY,
                                    label=_("Remove"))
        self.btn_remove.SetToolTip(_('Remove a configuration file'))
        self.btn_new = Button(parent=self, id=wx.ID_ANY,
                                 label=_("Create"))
        self.btn_new.SetToolTip(_('Create a new configuration file'))
        self.btn_rename = Button(parent=self, id=wx.ID_ANY,
                                    label=_("Rename"))
        self.btn_rename.SetToolTip(_('Rename a configuration file'))
        self.btn_view = Button(parent=self, id=wx.ID_ANY,
                                  label=_("View/Edit"))
        self.btn_view.SetToolTip(_('View and edit a configuration file'))
        # set action for button
        self.btn_close.Bind(wx.EVT_BUTTON, self.OnClose)
        self.btn_help.Bind(wx.EVT_BUTTON, self.OnHelp)
        self.btn_remove.Bind(wx.EVT_BUTTON, self.OnRemove)
        self.btn_new.Bind(wx.EVT_BUTTON, self.OnNew)
        self.btn_rename.Bind(wx.EVT_BUTTON, self.OnRename)
        self.btn_view.Bind(wx.EVT_BUTTON, self.OnView)
        self._layout()
        # END BUTTONS
        # SIZE FRAME
        self.SetMinSize(self.GetBestSize())
        # Please check this because without this the size it is not the min
        self.SetClientSize(self.GetBestSize())
        # END SIZE

    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.listfileBox, proportion=1,
                          flag=wx.EXPAND)
        # END CONFILES
        # BUTTONS
        buttonSizer = wx.BoxSizer(wx.HORIZONTAL)
        buttonSizer.Add(self.btn_new, flag=wx.ALL, border=5)
        buttonSizer.Add(self.btn_rename, flag=wx.ALL, border=5)
        buttonSizer.Add(self.btn_view, flag=wx.ALL, border=5)
        buttonSizer.Add(self.btn_remove, flag=wx.ALL, border=5)
        buttonSizer.Add(self.btn_help, 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 ListFiles(self):
        """Check the configuration files inside the path"""
        # list of configuration file
        listfiles = []
        # return all the configuration files in self.rlipath, check if there are
        # link or directory and doesn't add them
        for l in os.listdir(self.rlipath):
            if os.path.isfile(os.path.join(self.rlipath, l)):
                listfiles.append(l)
        return sorted(listfiles)

    def OnClose(self, event):
        """Close window"""
        self.Destroy()

    def OnHelp(self, event):
        """Launches help"""
        gcmd.RunCommand('g.manual', parent=self, entry='wxGUI.rlisetup')

    def OnRemove(self, event):
        """Remove configuration file from path and update the list"""
        confile = self.listfiles[self.listfileBox.GetSelections()[0]]
        dlg = wx.MessageDialog(
            parent=self.parent,
            message=_(
                "Do you want remove r.li "
                "configuration file <%s>?") %
            confile,
            caption=_("Remove new r.li configuration file?"),
            style=wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)

        if dlg.ShowModal() == wx.ID_YES:
            self.listfileBox.Delete(self.listfileBox.GetSelections()[0])
            try_remove(os.path.join(self.rlipath, confile))
            self.listfiles = self.ListFiles()
        dlg.Destroy()
        return

    def OnNew(self, event):
        """Remove configuration file from path and update the list"""
        RLIWizard(self)
        self.listfiles = self.ListFiles()
        self.listfileBox.Clear()
        self.listfileBox.Set(self.listfiles)

    def OnRename(self, event):
        """Rename an existing configuration file"""
        try:
            confile = self.listfiles[self.listfileBox.GetSelections()[0]]
        except:
            gcmd.GMessage(parent=self,
                          message=_("You have to select a configuration file"))
            return
        dlg = wx.TextEntryDialog(parent=self.parent,
                                 message=_('Set the new name for %s " \
                                           "configuration file') % confile,
                                 caption=_('Rename configuration file'))
        if dlg.ShowModal() == wx.ID_OK:
            res = dlg.GetValue()
            newname = "%s%s%s" % (self.rlipath, os.sep, res)
            os.rename(os.path.join(self.rlipath, confile), newname)
            self.listfiles = self.ListFiles()
            self.listfileBox.Clear()
            self.listfileBox.Set(self.listfiles)

    def OnView(self, event):
        """Show and edit a configuration file"""
        try:
            confile = self.listfiles[self.listfileBox.GetSelections()[0]]
        except:
            gcmd.GMessage(parent=self,
                          message=_("You have to select a configuration file"))
            return
        frame = ViewFrame(self, conf=confile)
        frame.Show()