2
# Copyright 2001-2005 Free Software Foundation
4
# This file is part of GNU Enterprise.
6
# GNU Enterprise is free software; you can redistribute it
7
# and/or modify it under the terms of the GNU General Public
8
# License as published by the Free Software Foundation; either
9
# version 2, or (at your option) any later version.
11
# GNU Enterprise is distributed in the hope that it will be
12
# useful, but WITHOUT ANY WARRANTY; without even the implied
13
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14
# PURPOSE. See the GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public
17
# License along with program; see the file COPYING. If not,
18
# write to the Free Software Foundation, Inc., 59 Temple Place
19
# - Suite 330, Boston, MA 02111-1307, USA.
25
# Saves the state of designer between runs. Saves such data as
26
# window positions, size, visibility, etc.
30
import sys, os, ConfigParser
33
# TODO: Should this save into the Win32 registry if its available?????
34
# TODO: This is, after all, session-specific information and not
35
# TODO: user-settable configuration data.
37
if not globals().has_key('location'):
40
def init(configFilename="default.ini", homeConfigDir=".gnue"):
41
global location, config
42
if os.environ.has_key('HOME'):
44
os.makedirs(os.path.join(os.environ['HOME'], homeConfigDir))
47
location = os.path.join(os.environ['HOME'], homeConfigDir ,configFilename)
48
elif sys.platform[:3] in ('win','mac'):
49
location = os.path.join(os.path.abspath(os.path.dirname(sys.argv[0])),configFilename)
51
location = configFilename
54
config = ConfigParser.ConfigParser()
59
def registerInstance(instance):
60
instance._runtimes = []
63
def get(section, setting, default):
64
# Backwards compatability
68
return config.get(section, setting)
73
def getint(section, setting, default):
74
# Backwards compatability
78
return config.getint(section, setting)
83
# Save the runtime settings
85
def saveRuntimeSettings(instance):
86
from gnue.common.apps.GDebug import _DEBUG_LEVELS
89
fh = open(location,'w')
91
for h in instance._runtimes:
92
section, hash = h.saveRuntimeSettings()
94
if not config.has_section(section):
95
config.add_section(section)
96
for key in hash.keys():
97
config.set(section, key, "%s" % hash[key])
101
print o(u_("\nWarning: Unable to save session data to %s\n") %
103
if _DEBUG_LEVELS != [0]:
107
print o(u_("\nWarning: Unable to save session data to %s\n") % location)
108
if _DEBUG_LEVELS != [0]:
112
# Any object (class) that has settings it wants saved should
113
# register with this method. The object should define a
114
# getRuntimeSettings() method.
116
def registerRuntimeSettingHandler(instance, object):
117
instance._runtimes.append(object)