Exemple #1
0
 def __init__(self, element, mapset, env, **kwargs):
     TextEntryDialog.__init__(self, **kwargs)
     self._element = element
     self._mapset = mapset
     self._env = env
     id_OK = self.GetAffirmativeId()
     self.Bind(wx.EVT_BUTTON, self.OnOK, self.FindWindowById(id_OK))
Exemple #2
0
 def __init__(self, element, mapset, env, **kwargs):
     TextEntryDialog.__init__(self, **kwargs)
     self._element = element
     self._mapset = mapset
     self._env = env
     id_OK = self.GetAffirmativeId()
     self.Bind(wx.EVT_BUTTON, self.OnOK, self.FindWindowById(id_OK))
Exemple #3
0
    def OnWizard(self, event):
        """Location wizard started"""
        from location_wizard.wizard import LocationWizard

        gWizard = LocationWizard(parent=self,
                                 grassdatabase=self.tgisdbase.GetValue())
        if gWizard.location is not None:
            self.tgisdbase.SetValue(gWizard.grassdatabase)
            self.OnSetDatabase(None)
            self.UpdateMapsets(os.path.join(self.gisdbase, gWizard.location))
            self.lblocations.SetSelection(
                self.listOfLocations.index(gWizard.location))
            self.lbmapsets.SetSelection(0)
            self.SetLocation(self.gisdbase, gWizard.location, "PERMANENT")
            if gWizard.georeffile:
                message = _(
                    "Do you want to import <%(name)s> to the newly created location?"
                ) % {
                    "name": gWizard.georeffile
                }
                dlg = wx.MessageDialog(
                    parent=self,
                    message=message,
                    caption=_("Import data?"),
                    style=wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION,
                )
                dlg.CenterOnParent()
                if dlg.ShowModal() == wx.ID_YES:
                    self.ImportFile(gWizard.georeffile)
                dlg.Destroy()
            if gWizard.default_region:
                defineRegion = RegionDef(self, location=gWizard.location)
                defineRegion.CenterOnParent()
                defineRegion.ShowModal()
                defineRegion.Destroy()

            if gWizard.user_mapset:
                dlg = TextEntryDialog(
                    parent=self,
                    message=_("New mapset:"),
                    caption=_("Create new mapset"),
                    defaultValue=self._getDefaultMapsetName(),
                    validator=GenericValidator(grass.legal_name,
                                               self._nameValidationFailed),
                    style=wx.OK | wx.CANCEL | wx.HELP,
                )
                help = dlg.FindWindowById(wx.ID_HELP)
                help.Bind(wx.EVT_BUTTON, self.OnHelp)
                if dlg.ShowModal() == wx.ID_OK:
                    mapsetName = dlg.GetValue()
                    self.CreateNewMapset(mapsetName)
Exemple #4
0
 def OnCreateMapset(self, event):
     """Create new mapset"""
     dlg = TextEntryDialog(parent=self,
                           message=_('Enter name for new mapset:'),
                           caption=_('Create new mapset'),
                           defaultValue=self._getDefaultMapsetName(),
                           validator=GenericValidator(
                               grass.legal_name,
                               self._nameValidationFailed))
     if dlg.ShowModal() == wx.ID_OK:
         mapset = dlg.GetValue()
         return self.CreateNewMapset(mapset=mapset)
     else:
         return False
Exemple #5
0
    def __init__(self, parent=None, default=None, message=None, caption=None,
                 database=None):
        self.database = database

        validator = GenericValidator(self._isLocationNameValid,
                                     self._showLocationNameInvalidReason)

        TextEntryDialog.__init__(
            self, parent=parent,
            message=message,
            caption=caption,
            defaultValue=default,
            validator=validator,
        )
Exemple #6
0
    def __init__(self,
                 parent=None,
                 default=None,
                 message=None,
                 caption=None,
                 database=None):
        self.database = database

        # list of tuples consisting of conditions and callbacks
        checks = [(gs.legal_name, self._nameValidationFailed),
                  (self._checkLocationNotExists, self._locationAlreadyExists)]
        validator = GenericMultiValidator(checks)

        TextEntryDialog.__init__(
            self,
            parent=parent,
            message=message,
            caption=caption,
            defaultValue=default,
            validator=validator,
        )
Exemple #7
0
 def __init__(self,
              parent=None,
              default=None,
              validation_failed_handler=None,
              help_hanlder=None):
     if help_hanlder:
         style = wx.OK | wx.CANCEL | wx.HELP
     else:
         style = wx.OK | wx.CANCEL
     if validation_failed_handler:
         validator = GenericValidator(gs.legal_name,
                                      validation_failed_handler)
     else:
         validator = None
     TextEntryDialog.__init__(self,
                              parent=parent,
                              message=_("Name for the new mapset:"),
                              caption=_("Create new mapset"),
                              defaultValue=default,
                              validator=validator,
                              style=style)
     if help_hanlder:
         help_button = self.FindWindowById(wx.ID_HELP)
         help_button.Bind(wx.EVT_BUTTON, help_hanlder)
Exemple #8
0
    def RenameMapset(self, event):
        """Rename selected mapset"""
        location = self.listOfLocations[self.lblocations.GetSelection()]
        mapset = self.listOfMapsets[self.lbmapsets.GetSelection()]
        if mapset == "PERMANENT":
            GMessage(
                parent=self,
                message=_(
                    "Mapset <PERMANENT> is required for valid GRASS location.\n\n"
                    "This mapset cannot be renamed."),
            )
            return

        dlg = TextEntryDialog(
            parent=self,
            message=_("Current name: %s\n\nEnter new name:") % mapset,
            caption=_("Rename selected mapset"),
            validator=GenericValidator(grass.legal_name,
                                       self._nameValidationFailed),
        )

        if dlg.ShowModal() == wx.ID_OK:
            newmapset = dlg.GetValue()
            if newmapset == mapset:
                dlg.Destroy()
                return

            if newmapset in self.listOfMapsets:
                wx.MessageBox(
                    parent=self,
                    caption=_("Message"),
                    message=_("Unable to rename mapset.\n\n"
                              "Mapset <%s> already exists in location.") %
                    newmapset,
                    style=wx.OK | wx.ICON_INFORMATION | wx.CENTRE,
                )
            else:
                try:
                    os.rename(
                        os.path.join(self.gisdbase, location, mapset),
                        os.path.join(self.gisdbase, location, newmapset),
                    )
                    self.OnSelectLocation(None)
                    self.lbmapsets.SetSelection(
                        self.listOfMapsets.index(newmapset))
                except Exception as e:
                    wx.MessageBox(
                        parent=self,
                        caption=_("Error"),
                        message=_("Unable to rename mapset.\n\n%s") % e,
                        style=wx.OK | wx.ICON_ERROR | wx.CENTRE,
                    )

        dlg.Destroy()
Exemple #9
0
    def _getUserEntry(self, message, title, value):
        """Dialog for simple text entry"""
        dlg = TextEntryDialog(self, message, title)
        dlg.SetValue(value)
        if dlg.ShowModal() == wx.ID_OK:
            name = dlg.GetValue()
        else:
            name = None
        dlg.Destroy()

        return name
Exemple #10
0
    def RenameLocation(self, event):
        """Rename selected location"""
        location = self.listOfLocations[self.lblocations.GetSelection()]

        dlg = TextEntryDialog(
            parent=self,
            message=_("Current name: %s\n\nEnter new name:") % location,
            caption=_("Rename selected location"),
            validator=GenericValidator(grass.legal_name,
                                       self._nameValidationFailed),
        )

        if dlg.ShowModal() == wx.ID_OK:
            newlocation = dlg.GetValue()
            if newlocation == location:
                dlg.Destroy()
                return

            if newlocation in self.listOfLocations:
                wx.MessageBox(
                    parent=self,
                    caption=_("Message"),
                    message=_(
                        "Unable to rename location.\n\n"
                        "Location <%s> already exists in GRASS database.") %
                    newlocation,
                    style=wx.OK | wx.ICON_INFORMATION | wx.CENTRE,
                )
            else:
                try:
                    os.rename(
                        os.path.join(self.gisdbase, location),
                        os.path.join(self.gisdbase, newlocation),
                    )
                    self.UpdateLocations(self.gisdbase)
                    self.lblocations.SetSelection(
                        self.listOfLocations.index(newlocation))
                    self.UpdateMapsets(newlocation)
                except Exception as e:
                    wx.MessageBox(
                        parent=self,
                        caption=_("Error"),
                        message=_("Unable to rename location.\n\n%s") % e,
                        style=wx.OK | wx.ICON_ERROR | wx.CENTRE,
                    )

        dlg.Destroy()