예제 #1
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()
예제 #2
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
예제 #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)
예제 #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
예제 #5
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()