def OnStart(self, event): """'Start GRASS' button clicked""" dbase = self.tgisdbase.GetValue() location = self.listOfLocations[self.lblocations.GetSelection()] mapset = self.listOfMapsets[self.lbmapsets.GetSelection()] lockfile = get_lockfile_if_present(dbase, location, mapset) if lockfile: dlg = wx.MessageDialog( parent=self, message=_( "GRASS is already running in selected mapset <%(mapset)s>\n" "(file %(lock)s found).\n\n" "Concurrent use not allowed.\n\n" "Do you want to try to remove .gislock (note that you " "need permission for this operation) and continue?") % { 'mapset': mapset, 'lock': lockfile }, caption=_("Lock file found"), style=wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION | wx.CENTRE) ret = dlg.ShowModal() dlg.Destroy() if ret == wx.ID_YES: dlg1 = wx.MessageDialog( parent=self, message= _("ARE YOU REALLY SURE?\n\n" "If you really are running another GRASS session doing this " "could corrupt your data. Have another look in the processor " "manager just to be sure..."), caption=_("Lock file found"), style=wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION | wx.CENTRE) ret = dlg1.ShowModal() dlg1.Destroy() if ret == wx.ID_YES: try: os.remove(lockfile) except IOError as e: GError( _("Unable to remove '%(lock)s'.\n\n" "Details: %(reason)s") % { 'lock': lockfile, 'reason': e }) else: return else: return self.SetLocation(dbase, location, mapset) self.ExitSuccessfully()
def OnSelectLocation(self, event): """Location selected""" if event: self.lblocations.SetSelection(event.GetIndex()) if self.lblocations.GetSelection() != wx.NOT_FOUND: self.UpdateMapsets( os.path.join( self.gisdbase, self.listOfLocations[self.lblocations.GetSelection()])) else: self.listOfMapsets = [] disabled = [] idx = 0 try: locationName = self.listOfLocations[ self.lblocations.GetSelection()] except IndexError: locationName = '' for mapset in self.listOfMapsets: if mapset not in self.listOfMapsetsSelectable or \ get_lockfile_if_present(self.gisdbase, locationName, mapset): disabled.append(idx) idx += 1 self.lbmapsets.Clear() self.lbmapsets.InsertItems(self.listOfMapsets, 0, disabled=disabled) if len(self.listOfMapsets) > 0: self.lbmapsets.SetSelection(0) if locationName: # enable start button when location and mapset is selected self.bstart.Enable() self.bstart.SetFocus() self.bmapset.Enable() # replacing disabled choice, perhaps just mapset needed self.rename_location_button.Enable() self.delete_location_button.Enable() self.rename_mapset_button.Enable() self.delete_mapset_button.Enable() else: self.lbmapsets.SetSelection(wx.NOT_FOUND) self.bstart.Enable(False) self.bmapset.Enable(False) # this all was originally a choice, perhaps just mapset needed self.rename_location_button.Enable(False) self.delete_location_button.Enable(False) self.rename_mapset_button.Enable(False) self.delete_mapset_button.Enable(False)
def UpdateMapsets(self, location): """Update list of mapsets""" self.FormerMapsetSelection = wx.NOT_FOUND # for non-selectable item self.listOfMapsetsSelectable = list() self.listOfMapsets = GetListOfMapsets(self.gisdbase, location) self.lbmapsets.Clear() # disable mapset with denied permission locationName = os.path.basename(location) ret = RunCommand('g.mapset', read=True, flags='l', location=locationName, gisdbase=self.gisdbase) if ret: for line in ret.splitlines(): self.listOfMapsetsSelectable += line.split(' ') else: self.SetLocation(self.gisdbase, locationName, "PERMANENT") # first run only self.listOfMapsetsSelectable = copy.copy(self.listOfMapsets) disabled = [] idx = 0 for mapset in self.listOfMapsets: if mapset not in self.listOfMapsetsSelectable or \ get_lockfile_if_present(self.gisdbase, locationName, mapset): disabled.append(idx) idx += 1 self.lbmapsets.InsertItems(self.listOfMapsets, 0, disabled=disabled) return self.listOfMapsets