|
@@ -24,28 +24,28 @@ import os
|
|
|
import sys
|
|
|
import copy
|
|
|
import platform
|
|
|
-import codecs
|
|
|
-import getpass
|
|
|
|
|
|
# i18n is taken care of in the grass library code.
|
|
|
# So we need to import it before any of the GUI code.
|
|
|
-from grass.script import core as grass
|
|
|
|
|
|
from core import globalvar
|
|
|
import wx
|
|
|
import wx.lib.mixins.listctrl as listmix
|
|
|
|
|
|
-from core.gcmd import GMessage, GError, DecodeString, RunCommand
|
|
|
+from core.gcmd import GMessage, GError, RunCommand
|
|
|
from core.utils import GetListOfLocations, GetListOfMapsets
|
|
|
from startup.utils import (
|
|
|
get_lockfile_if_present, get_possible_database_path,
|
|
|
- create_database_directory, create_mapset, get_default_mapset_name)
|
|
|
-import startup.utils as sutils
|
|
|
-from startup.guiutils import SetSessionMapset, NewMapsetDialog
|
|
|
+ create_database_directory)
|
|
|
+from startup.guiutils import (SetSessionMapset,
|
|
|
+ create_mapset_interactively,
|
|
|
+ rename_mapset_interactively,
|
|
|
+ rename_location_interactively,
|
|
|
+ delete_mapset_interactively,
|
|
|
+ delete_location_interactively)
|
|
|
import startup.guiutils as sgui
|
|
|
from location_wizard.dialogs import RegionDef
|
|
|
-from gui_core.dialogs import TextEntryDialog
|
|
|
-from gui_core.widgets import GenericValidator, StaticWrapText
|
|
|
+from gui_core.widgets import StaticWrapText
|
|
|
from gui_core.wrap import Button, ListCtrl, StaticText, StaticBox, \
|
|
|
TextCtrl, BitmapFromImage
|
|
|
|
|
@@ -233,11 +233,11 @@ class GRASSStartup(wx.Frame):
|
|
|
self.bmapset.Bind(wx.EVT_BUTTON, self.OnCreateMapset)
|
|
|
self.bwizard.Bind(wx.EVT_BUTTON, self.OnWizard)
|
|
|
|
|
|
- self.rename_location_button.Bind(wx.EVT_BUTTON, self.RenameLocation)
|
|
|
- self.delete_location_button.Bind(wx.EVT_BUTTON, self.DeleteLocation)
|
|
|
- self.download_location_button.Bind(wx.EVT_BUTTON, self.DownloadLocation)
|
|
|
- self.rename_mapset_button.Bind(wx.EVT_BUTTON, self.RenameMapset)
|
|
|
- self.delete_mapset_button.Bind(wx.EVT_BUTTON, self.DeleteMapset)
|
|
|
+ self.rename_location_button.Bind(wx.EVT_BUTTON, self.OnRenameLocation)
|
|
|
+ self.delete_location_button.Bind(wx.EVT_BUTTON, self.OnDeleteLocation)
|
|
|
+ self.download_location_button.Bind(wx.EVT_BUTTON, self.OnDownloadLocation)
|
|
|
+ self.rename_mapset_button.Bind(wx.EVT_BUTTON, self.OnRenameMapset)
|
|
|
+ self.delete_mapset_button.Bind(wx.EVT_BUTTON, self.OnDeleteMapset)
|
|
|
|
|
|
self.lblocations.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnSelectLocation)
|
|
|
self.lbmapsets.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnSelectMapset)
|
|
@@ -606,165 +606,74 @@ class GRASSStartup(wx.Frame):
|
|
|
'name': filePath},
|
|
|
parent=self)
|
|
|
|
|
|
+
|
|
|
# the event can be refactored out by using lambda in bind
|
|
|
- def RenameMapset(self, event):
|
|
|
+ def OnRenameMapset(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:
|
|
|
- sutils.rename_mapset(self.gisdbase, location,
|
|
|
- mapset, newmapset)
|
|
|
- self.OnSelectLocation(None)
|
|
|
- self.lbmapsets.SetSelection(
|
|
|
+ try:
|
|
|
+ newmapset = rename_mapset_interactively(self, self.gisdbase,
|
|
|
+ location, mapset)
|
|
|
+ if 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()
|
|
|
+ except Exception as e:
|
|
|
+ GError(parent=self,
|
|
|
+ message=_("Unable to rename mapset: %s") % e,
|
|
|
+ showTraceback=False)
|
|
|
|
|
|
- def RenameLocation(self, event):
|
|
|
+ def OnRenameLocation(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:
|
|
|
- sutils.rename_location(self.gisdbase,
|
|
|
- location, newlocation)
|
|
|
- self.UpdateLocations(self.gisdbase)
|
|
|
- self.lblocations.SetSelection(
|
|
|
+ try:
|
|
|
+ newlocation = rename_location_interactively(self, self.gisdbase,
|
|
|
+ location)
|
|
|
+ if 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()
|
|
|
+ self.UpdateMapsets(newlocation)
|
|
|
+ except Exception as e:
|
|
|
+ GError(parent=self,
|
|
|
+ message=_("Unable to rename location: %s") % e,
|
|
|
+ showTraceback=False)
|
|
|
|
|
|
- def DeleteMapset(self, event):
|
|
|
- """Delete selected mapset
|
|
|
+ def OnDeleteMapset(self, event):
|
|
|
+ """
|
|
|
+ Delete 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 deleted.'))
|
|
|
- return
|
|
|
-
|
|
|
- dlg = wx.MessageDialog(
|
|
|
- parent=self,
|
|
|
- message=_(
|
|
|
- "Do you want to continue with deleting mapset <%(mapset)s> "
|
|
|
- "from location <%(location)s>?\n\n"
|
|
|
- "ALL MAPS included in this mapset will be "
|
|
|
- "PERMANENTLY DELETED!") %
|
|
|
- {'mapset': mapset, 'location': location},
|
|
|
- caption=_("Delete selected mapset"),
|
|
|
- style=wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
|
|
|
-
|
|
|
- if dlg.ShowModal() == wx.ID_YES:
|
|
|
- try:
|
|
|
- sutils.delete_mapset(self.gisdbase, location, mapset)
|
|
|
- self.OnSelectLocation(None)
|
|
|
- self.lbmapsets.SetSelection(0)
|
|
|
- except:
|
|
|
- wx.MessageBox(message=_('Unable to delete mapset'))
|
|
|
-
|
|
|
- dlg.Destroy()
|
|
|
+ try:
|
|
|
+ delete_mapset_interactively(self, self.gisdbase, location, mapset)
|
|
|
+ self.OnSelectLocation(None)
|
|
|
+ self.lbmapsets.SetSelection(0)
|
|
|
+ except Exception as e:
|
|
|
+ GError(parent=self,
|
|
|
+ message=_("Unable to delete mapset: %s") % e,
|
|
|
+ showTraceback=False)
|
|
|
|
|
|
- def DeleteLocation(self, event):
|
|
|
+ def OnDeleteLocation(self, event):
|
|
|
"""
|
|
|
Delete selected location
|
|
|
"""
|
|
|
-
|
|
|
location = self.listOfLocations[self.lblocations.GetSelection()]
|
|
|
+ try:
|
|
|
+ delete_location_interactively(self, self.gisdbase, location)
|
|
|
+ self.UpdateLocations(self.gisdbase)
|
|
|
+ self.lblocations.SetSelection(0)
|
|
|
+ self.OnSelectLocation(None)
|
|
|
+ self.lbmapsets.SetSelection(0)
|
|
|
+ except Exception as e:
|
|
|
+ GError(parent=self,
|
|
|
+ message=_("Unable to delete location: %s") % e,
|
|
|
+ showTraceback=False)
|
|
|
|
|
|
- dlg = wx.MessageDialog(
|
|
|
- parent=self,
|
|
|
- message=_(
|
|
|
- "Do you want to continue with deleting "
|
|
|
- "location <%s>?\n\n"
|
|
|
- "ALL MAPS included in this location will be "
|
|
|
- "PERMANENTLY DELETED!") %
|
|
|
- (location),
|
|
|
- caption=_("Delete selected location"),
|
|
|
- style=wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
|
|
|
-
|
|
|
- if dlg.ShowModal() == wx.ID_YES:
|
|
|
- try:
|
|
|
- sutils.delete_location(self.gisdbase, location)
|
|
|
- self.UpdateLocations(self.gisdbase)
|
|
|
- self.lblocations.SetSelection(0)
|
|
|
- self.OnSelectLocation(None)
|
|
|
- self.lbmapsets.SetSelection(0)
|
|
|
- except:
|
|
|
- wx.MessageBox(message=_('Unable to delete location'))
|
|
|
-
|
|
|
- dlg.Destroy()
|
|
|
-
|
|
|
- def DownloadLocation(self, event):
|
|
|
+ def OnDownloadLocation(self, event):
|
|
|
"""Download location online"""
|
|
|
from startup.locdownload import LocationDownloadDialog
|
|
|
|
|
@@ -946,29 +855,16 @@ class GRASSStartup(wx.Frame):
|
|
|
"""Create new mapset"""
|
|
|
gisdbase = self.tgisdbase.GetValue()
|
|
|
location = self.listOfLocations[self.lblocations.GetSelection()]
|
|
|
-
|
|
|
- dlg = NewMapsetDialog(
|
|
|
- parent=self,
|
|
|
- default=get_default_mapset_name(),
|
|
|
- database=gisdbase,
|
|
|
- location=location
|
|
|
- )
|
|
|
- if dlg.ShowModal() == wx.ID_OK:
|
|
|
- mapset = dlg.GetValue()
|
|
|
- try:
|
|
|
- create_mapset(gisdbase, location, mapset)
|
|
|
+ try:
|
|
|
+ mapset = create_mapset_interactively(self, gisdbase, location)
|
|
|
+ if mapset:
|
|
|
self.OnSelectLocation(None)
|
|
|
self.lbmapsets.SetSelection(self.listOfMapsets.index(mapset))
|
|
|
self.bstart.SetFocus()
|
|
|
- return True
|
|
|
- except Exception as e:
|
|
|
- GError(parent=self,
|
|
|
- message=_("Unable to create new mapset: %s") % e,
|
|
|
- showTraceback=False)
|
|
|
- return False
|
|
|
- else:
|
|
|
- return False
|
|
|
-
|
|
|
+ except Exception as e:
|
|
|
+ GError(parent=self,
|
|
|
+ message=_("Unable to create new mapset: %s") % e,
|
|
|
+ showTraceback=False)
|
|
|
|
|
|
def OnStart(self, event):
|
|
|
"""'Start GRASS' button clicked"""
|
|
@@ -1042,15 +938,6 @@ class GRASSStartup(wx.Frame):
|
|
|
event.Skip()
|
|
|
sys.exit(self.exit_user_requested)
|
|
|
|
|
|
- def _nameValidationFailed(self, ctrl):
|
|
|
- message = _(
|
|
|
- "Name <%(name)s> is not a valid name for location or mapset. "
|
|
|
- "Please use only ASCII characters excluding %(chars)s "
|
|
|
- "and space.") % {
|
|
|
- 'name': ctrl.GetValue(),
|
|
|
- 'chars': '/"\'@,=*~'}
|
|
|
- GError(parent=self, message=message, caption=_("Invalid name"))
|
|
|
-
|
|
|
|
|
|
class GListBox(ListCtrl, listmix.ListCtrlAutoWidthMixin):
|
|
|
"""Use wx.ListCtrl instead of wx.ListBox, different style for
|