4 @brief Default GUI settings
11 from core.settings import UserSettings
14 (C) 2007-2011 by the GRASS Development Team
15 This program is free software under the GNU General Public License
16 (>=v2). Read the file COPYING that comes with GRASS for details.
18 @author Martin Landa <landa.martin gmail.com>
19 @author Luca Delucchi <lucadeluge gmail.com> (language choice)
28 from core
import globalvar
30 from core.utils import GetSettingsPath, PathJoin
33 """!Generic class where to store settings"""
49 print >> sys.stderr, e.value
54 def _generateLocale(self):
60 self.
locs = os.listdir(os.path.join(os.environ[
'GISBASE'],
'locale'))
61 self.locs.append(
'en')
64 self.locs.insert(0,
'system')
67 self.
locs = [
'system']
71 def _defaultSettings(self):
72 """!Define default settings
75 projFile =
PathJoin(os.environ[
"GRASS_PROJSHARE"],
'epsg')
87 'dim' :
'0,0,%d,%d,%d,0,%d,%d' % \
88 (globalvar.GM_WINDOW_SIZE[0],
89 globalvar.GM_WINDOW_SIZE[1],
90 globalvar.GM_WINDOW_SIZE[0],
91 globalvar.MAP_WINDOW_SIZE[0],
92 globalvar.MAP_WINDOW_SIZE[1])
106 'changeOpacityLevel' : {
110 'askOnRemoveLayer' : {
122 'copySelectedTextToClipboard' : {
131 'type' :
'Courier New',
135 'elementListExpand' : {
141 'gSelectPopupHeight' : {
162 'encoding':
'ISO-8859-1',
183 'color' : (255, 255, 255, 255),
188 'scrollDirection' : {
191 'nvizDepthBuffer' : {
202 'projFile' : projFile,
214 'color' : (255, 255, 0, 255),
241 'selection' :
'grassenv'
247 'rasterColorTable' : {
249 'selection' :
'rainbow',
275 'interactiveInput' : {
287 'color' : (255, 0, 0, 255)
291 'color' : (0, 86, 45, 255)
295 'color' : (255, 255, 0, 255)
299 'color' : (255, 72, 0, 255)
303 'color' : (0, 0, 0, 255)
307 'color' : (0, 0, 0, 255)
311 'color' : (126, 126, 126, 255)
315 'color' : (0, 255, 0, 255)
319 'color' : (255, 135, 0, 255)
323 'color' : (0, 0, 255, 255)
327 'color' : (165, 42, 42, 255)
331 'color' : (156, 62, 206, 255)
335 'color' : (255, 0, 0, 255)
339 'color' : (0, 86, 45, 255)
343 'color' : (255, 20, 147, 255)
347 'color' : (217, 255, 217, 255)
351 'color' : (255, 0, 0, 255)
357 'units' :
'screen pixels'
362 'units' :
'screen pixels'
390 'than-selection' : 0,
394 'than-selection' : 0,
414 'units' :
'screen pixels'
433 'pcolor' : (0, 0, 255, 255),
443 'color' : (0, 0, 0, 255),
444 'fill' :
'transparent',
447 'legend' : _(
'Segment break'),
450 'color' : (200, 200, 200, 255),
471 'highestonly' :
True,
475 'color' : (0, 0, 255, 255),
476 'hcolor' : (255, 0, 0, 255),
477 'scolor' : (0, 255, 0, 255),
478 'ucolor' : (255, 165, 0, 255),
503 'color' : (255, 255, 255, 255),
514 'prefix' : _(
"animation")
523 'value' : (100, 100, 100, 255),
526 'wire-color' : (136, 136, 136, 255),
540 'color' : (100, 100, 100, 255),
549 'color' : (0, 0, 255, 255),
558 'color' : (0, 0, 255, 255),
565 'value' : (100, 100, 100, 255),
617 'color' : (255, 255, 255, 255),
622 'color' : (128, 128, 128, 255),
633 'color': (211, 211, 211, 255),
637 'valid' : (180, 234, 154, 255),
638 'invalid' : (255, 255, 255, 255),
639 'running' : (255, 0, 0, 255),
652 'raster' : (215, 215, 248, 255),
653 'raster3d' : (215, 248, 215, 255),
654 'vector' : (248, 215, 215, 255),
663 'valid' : (234, 226, 154, 255),
681 if sys.platform ==
'darwin':
684 def _internalSettings(self):
685 """!Define internal settings (based on user settings)
688 for group
in self.userSettings.keys():
695 (_(
"Collapse all except PERMANENT and current"),
696 _(
"Collapse all except PERMANENT"),
697 _(
"Collapse all except current"),
702 self.
internalSettings[
'atm'][
'leftDbClick'][
'choices'] = (_(
'Edit selected record'),
703 _(
'Display selected'))
713 (_(
"Classic (labels only)"),
714 _(
"Combined (labels and module names)"),
715 _(
"Professional (module names only)"))
722 self.
internalSettings[
'display'][
'mouseWheelZoom'][
'choices'] = (_(
'Zoom and recenter'),
723 _(
'Zoom to mouse cursor'),
725 self.
internalSettings[
'display'][
'scrollDirection'][
'choices'] = (_(
'Scroll forward to zoom in'),
726 _(
'Scroll back to zoom in'))
750 for decor
in (
'arrow',
'scalebar'):
770 """!Reads settings file (mapset, location, gisdbase)"""
777 font = self.
Get(group =
'display', key =
'font', subkey =
'type')
778 enc = self.
Get(group =
'display', key =
'font', subkey =
'encoding')
780 os.environ[
"GRASS_FONT"] = font
782 os.environ[
"GRASS_ENCODING"] = enc
784 def _readFile(self, filename, settings = None):
785 """!Read settings from file to dict
787 @param filename settings file path
788 @param settings dict where to store settings (None for self.userSettings)
793 if not os.path.exists(filename):
795 filename = os.path.join(os.path.expanduser(
"~"),
'.grasswx6')
796 if not os.path.exists(filename):
800 fd = open(filename,
"r")
802 sys.stderr.write(_(
"Unable to read settings file <%s>\n") % filename)
807 for line
in fd.readlines():
808 line = line.rstrip(
'%s' % os.linesep)
809 group, key = line.split(self.
sep)[0:2]
810 kv = line.split(self.
sep)[2:]
818 subkey = [subkeyMaster, kv[idx]]
823 self.
Append(settings, group, key, subkey, value)
825 except ValueError, e:
826 print >> sys.stderr, _(
"Error: Reading settings from file <%(file)s> failed.\n"
827 "\t\tDetails: %(detail)s\n"
828 "\t\tLine: '%(line)s'\n") % {
'file' : filename,
836 """!Save settings to the file"""
841 if not os.path.exists(dirPath):
845 GError(_(
'Unable to create settings directory'))
850 for group
in settings.keys():
851 for key
in settings[group].keys():
852 subkeys = settings[group][key].keys()
853 file.write(
'%s%s%s%s' % (group, self.
sep, key, self.
sep))
854 for idx
in range(len(subkeys)):
855 value = settings[group][key][subkeys[idx]]
856 if type(value) == types.DictType:
858 file.write(
'%s%s%s%s%s' % (os.linesep, group, self.
sep, key, self.
sep))
859 file.write(
'%s%s' % (subkeys[idx], self.
sep))
860 kvalues = settings[group][key][subkeys[idx]].keys()
861 srange =
range(len(kvalues))
863 svalue = self.
_parseValue(settings[group][key][subkeys[idx]][kvalues[sidx]])
864 file.write(
'%s%s%s' % (kvalues[sidx], self.
sep,
866 if sidx < len(kvalues) - 1:
867 file.write(
'%s' % self.
sep)
870 type(settings[group][key][subkeys[idx - 1]]) == types.DictType:
871 file.write(
'%s%s%s%s%s' % (os.linesep, group, self.
sep, key, self.
sep))
872 value = self.
_parseValue(settings[group][key][subkeys[idx]])
873 file.write(
'%s%s%s' % (subkeys[idx], self.
sep, value))
874 if idx < len(subkeys) - 1
and \
875 type(settings[group][key][subkeys[idx + 1]]) != types.DictType:
876 file.write(
'%s' % self.
sep)
877 file.write(os.linesep)
880 except StandardError, e:
881 raise GException(_(
'Writing settings to file <%(file)s> failed.'
882 '\n\nDetails: %(detail)s') % {
'file' : self.
filePath,
887 def _parseValue(self, value, read = False):
888 """!Parse value to be store in settings file"""
892 elif value ==
'False':
894 elif value ==
'None':
898 value = tuple(map(int, value.split(
':')))
911 value = str(value[0]) +
':' +\
912 str(value[1]) +
':' + \
917 def Get(self, group, key = None, subkey = None, internal = False):
918 """!Get value by key/subkey
920 Raise KeyError if key is not found
922 @param group settings group
923 @param key (value, None)
924 @param subkey (value, list or None)
925 @param internal use internal settings instead
937 return settings[group]
939 return settings[group][key]
941 if type(subkey) ==
type(tuple())
or \
943 return settings[group][key][subkey[0]][subkey[1]]
945 return settings[group][key][subkey]
948 print >> sys.stderr,
"Settings: unable to get value '%s:%s:%s'\n" % \
951 def Set(self, group, value, key = None, subkey = None, internal = False):
952 """!Set value of key/subkey
954 Raise KeyError if group/key is not found
956 @param group settings group
957 @param key key (value, None)
958 @param subkey subkey (value, list or None)
960 @param internal use internal settings instead
970 settings[group] = value
972 settings[group][key] = value
974 if type(subkey) ==
type(tuple())
or \
976 settings[group][key][subkey[0]][subkey[1]] = value
978 settings[group][key][subkey] = value
980 raise GException(
"%s '%s:%s:%s'" % (_(
"Unable to set "), group, key, subkey))
982 def Append(self, dict, group, key, subkey, value):
983 """!Set value of key/subkey
985 Create group/key/subkey if not exists
987 @param dict settings dictionary to use
988 @param group settings group
990 @param subkey subkey (value or list)
993 if group
not in dict:
996 if key
not in dict[group]:
997 dict[group][key] = {}
999 if type(subkey) == types.ListType:
1001 if subkey[0]
not in dict[group][key]:
1002 dict[group][key][subkey[0]] = {}
1004 dict[group][key][subkey[0]][subkey[1]] = value
1006 print >> sys.stderr, _(
"Unable to parse settings '%s'") % value + \
1007 ' (' + group +
':' + key +
':' + subkey[0] +
':' + subkey[1] +
')'
1010 dict[group][key][subkey] = value
1012 print >> sys.stderr, _(
"Unable to parse settings '%s'") % value + \
1013 ' (' + group +
':' + key +
':' + subkey +
')'
1016 """!Get default user settings"""
1020 """!Reset to default settings
1022 @key key in settings dict (None for all keys)
def Set
Set value of key/subkey.
def ReadSettingsFile
Reads settings file (mapset, location, gisdbase)
def Get
Get value by key/subkey.
def PathJoin(args)
Check path created by os.path.join.
def _defaultSettings(self)
Define default settings.
def _parseValue
Parse value to be store in settings file.
def Reset
Reset to default settings.
def _readFile
Read settings from file to dict.
def GetSettingsPath()
Get full path to the settings directory.
def _generateLocale(self)
Generate locales.
def Append(self, dict, group, key, subkey, value)
Set value of key/subkey.
Generic class where to store settings.
Misc utilities for wxGUI.
def SaveToFile
Save settings to the file.
def GetDefaultSettings(self)
Get default user settings.
def _internalSettings(self)
Define internal settings (based on user settings)