[GRASS-SVN] r30235 - grass/trunk/gui/wxpython/gui_modules
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Feb 18 10:26:31 EST 2008
Author: martinl
Date: 2008-02-18 10:26:31 -0500 (Mon, 18 Feb 2008)
New Revision: 30235
Modified:
grass/trunk/gui/wxpython/gui_modules/gselect.py
grass/trunk/gui/wxpython/gui_modules/preferences.py
grass/trunk/gui/wxpython/gui_modules/utils.py
grass/trunk/gui/wxpython/gui_modules/wxgui_utils.py
Log:
wxGUI: user can set up mapset search path (g.mapsets -p/-l)in Preferences dialog. This variable is used in GUI dialogs. Default value is 'p' (module search path).
Modified: grass/trunk/gui/wxpython/gui_modules/gselect.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/gselect.py 2008-02-18 15:23:05 UTC (rev 30234)
+++ grass/trunk/gui/wxpython/gui_modules/gselect.py 2008-02-18 15:26:31 UTC (rev 30235)
@@ -22,6 +22,7 @@
import wx.combo
import gcmd
+from preferences import globalSettings as UserSettings
class SelectDialog(wx.Dialog):
def __init__(self, parent, id=wx.ID_ANY, title='Select GIS element',
@@ -159,9 +160,7 @@
curr_mapset = gcmd.Command(cmdlist).ReadStdOutput()[0]
#mapsets in current location
- cmdlist = ['g.mapsets', '-p']
- mapsets = gcmd.Command(cmdlist).ReadStdOutput()[0].split(' ')
-
+ mapsets = UserSettings.Get('mapsetPath', internal=True)
# map element types to g.mlist types
elementdict = {'cell':'rast',
'raster':'rast',
Modified: grass/trunk/gui/wxpython/gui_modules/preferences.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/preferences.py 2008-02-18 15:23:05 UTC (rev 30234)
+++ grass/trunk/gui/wxpython/gui_modules/preferences.py 2008-02-18 15:26:31 UTC (rev 30235)
@@ -28,6 +28,7 @@
import gcmd
import grassenv
+import utils
class Settings:
"""Generic class where to store settings"""
@@ -39,6 +40,7 @@
self.defaultSettings = {
# general
'displayFont' : '',
+ 'mapsetPath' : 'p', # current mapset search path
# advanced
'settingsFile' : 'gisdbase', # gisdbase, location, mapset
'digitInterface' : 'vdigit', # vedit, vdigit
@@ -54,6 +56,19 @@
except:
gcmd.SettingsError('Reading settings failed.')
+ # internal settings (based on user settings)
+ self.internalSettings = {}
+ self.internalSettings["mapsetPath"] = self.GetMapsetPath()
+
+ def GetMapsetPath(self):
+ """Store mapset search path"""
+ all, access = utils.ListOfMapsets()
+
+ if self.Get('mapsetPath') == 'p':
+ return access
+ else:
+ return all
+
def ReadSettingsFile(self, settings=None):
"""Reads settings file (mapset, location, gisdbase)"""
if settings is None:
@@ -137,25 +152,35 @@
return filePath
- def Get(self, key):
+ def Get(self, key, internal=False):
"""Get value by key
@return value
@return None if key not found
"""
- if self.userSettings.has_key(key):
- return self.userSettings[key]
+ if internal is True:
+ settings = self.internalSettings
else:
- None
+ settings = self.userSettings
+
+ if settings.has_key(key):
+ return settings[key]
+
+ return None
- def Set(self, key, value):
+ def Set(self, key, value, internal=False):
"""Set value by key
Raise KeyError if key is not found
"""
- if self.userSettings.has_key(key):
- self.userSettings[key] = value
+ if internal is True:
+ settings = self.internalSettings
else:
+ settings = self.userSettings
+
+ if settings.has_key(key):
+ settings[key] = value
+ else:
raise KeyError
globalSettings = Settings()
@@ -238,6 +263,25 @@
wx.ALIGN_CENTER_VERTICAL,
pos=(1, 0), span=(1, 2))
+ #
+ # mapsets path
+ #
+ gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
+ label=_("Mapsets path:")),
+ flag=wx.ALIGN_LEFT |
+ wx.ALIGN_CENTER_VERTICAL,
+ pos=(2, 0))
+ self.mapsetPath = wx.Choice(parent=panel, id=wx.ID_ANY, size=(200, -1),
+ choices=['mapset search path', 'all available mapsets'])
+ if self.settings.Get('mapsetPath') == 'p':
+ self.mapsetPath.SetSelection(0)
+ else:
+ self.mapsetPath.SetSelection(1)
+ gridSizer.Add(item=self.mapsetPath,
+ flag=wx.ALIGN_RIGHT |
+ wx.ALIGN_CENTER_VERTICAL,
+ pos=(2, 1))
+
sizer.Add(item=gridSizer, proportion=1, flag=wx.ALL | wx.EXPAND, border=5)
border.Add(item=sizer, proportion=1, flag=wx.ALL | wx.EXPAND, border=3)
@@ -245,7 +289,8 @@
# bindings
fontButton.Bind(wx.EVT_BUTTON, self.OnSetFont)
-
+ self.mapsetPath.Bind(wx.EVT_CHOICE, self.OnChangeMapsetPath)
+
return panel
def __CreateAdvancedPage(self, notebook):
@@ -370,6 +415,16 @@
event.Skip()
+ def OnChangeMapsetPath(self, event):
+ """Mapset path changed"""
+ if event.GetSelection() == 0:
+ self.settings.Set('mapsetPath', 'p')
+ else:
+ self.settings.Set('mapsetPath', 'l')
+
+ # update internal settings
+ self.settings.Set("mapsetPath", self.settings.GetMapsetPath(), internal=True)
+
def OnSave(self, event):
"""Button 'Save' clicked"""
self.__UpdateSettings()
Modified: grass/trunk/gui/wxpython/gui_modules/utils.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/utils.py 2008-02-18 15:23:05 UTC (rev 30234)
+++ grass/trunk/gui/wxpython/gui_modules/utils.py 2008-02-18 15:26:31 UTC (rev 30235)
@@ -17,6 +17,13 @@
import os
import sys
+try:
+ import subprocess
+except:
+ compatPath = os.path.join(globalvar.ETCWXDIR, "compat")
+ sys.path.append(compatPath)
+ import subprocess
+
def GetTempfile(pref=None):
"""
Creates GRASS temporary file using defined prefix.
@@ -139,19 +146,29 @@
import gcmd
all_mapsets = []
accessible_mapsets = []
+
+ ### FIXME
+ # problem using Command here (see preferences.py)
+ # cmd = gcmd.Command(['g.mapsets', '-l'])
+ cmd = subprocess.Popen(['g.mapsets', '-l'],
+ stdout=subprocess.PIPE)
- cmd = gcmd.Command(['g.mapsets', '-l'])
-
try:
- for mset in cmd.ReadStdOutput()[0].split(' '):
- all_mapsets.append(mset.strip('%s' % os.linesep))
+ # for mset in cmd.ReadStdOutput()[0].split(' '):
+ for mset in cmd.stdout.readlines()[0].strip('%s' % os.linesep).split(' '):
+ if len(mset) > 0:
+ all_mapsets.append(mset)
except:
raise gcmd.CmdError('Unable to get list of available mapsets.')
-
- cmd = gcmd.Command(['g.mapsets', '-p'])
+
+ # cmd = gcmd.Command(['g.mapsets', '-p'])
+ cmd = subprocess.Popen(['g.mapsets', '-p'],
+ stdout=subprocess.PIPE)
try:
- for mset in cmd.ReadStdOutput()[0].split(' '):
- accessible_mapsets.append(mset.strip('\n'))
+ # for mset in cmd.ReadStdOutput()[0].split(' '):
+ for mset in cmd.stdout.readlines()[0].strip('%s' % os.linesep).split(' '):
+ if len(mset) > 0:
+ accessible_mapsets.append(mset)
except:
raise gcmd.CmdError('Unable to get list of accessible mapsets.')
Modified: grass/trunk/gui/wxpython/gui_modules/wxgui_utils.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/wxgui_utils.py 2008-02-18 15:23:05 UTC (rev 30234)
+++ grass/trunk/gui/wxpython/gui_modules/wxgui_utils.py 2008-02-18 15:26:31 UTC (rev 30235)
@@ -46,6 +46,7 @@
import utils
from debug import Debug as Debug
from icon import Icons as Icons
+from preferences import globalSettings as UserSettings
try:
import subprocess
except:
@@ -1483,9 +1484,10 @@
bodySizer.Add(item=wx.StaticText(parent=self, label=_("Mapset:")),
flag=wx.ALIGN_CENTER_VERTICAL,
pos=(1,0))
+
self.mapset = wx.ComboBox(parent=self, id=wx.ID_ANY,
style=wx.CB_SIMPLE | wx.CB_READONLY,
- choices=utils.ListOfMapsets()[0],
+ choices=UserSettings.Get('mapsetPath', internal=True),
size=(200,-1))
self.mapset.SetStringSelection(grassenv.GetGRASSVariable("MAPSET"))
bodySizer.Add(item=self.mapset,
More information about the grass-commit
mailing list