コード例 #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 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()
コード例 #3
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