tweaks to saving config keys (save keys without default, pylint, etc.)
This commit is contained in:
parent
48bab7bed1
commit
5929f2066e
@ -327,33 +327,29 @@ class ConfigManager:
|
||||
filename = self.filename
|
||||
if filename:
|
||||
try:
|
||||
head = os.path.split( filename )[0]
|
||||
os.makedirs( head )
|
||||
head = os.path.split(filename)[0]
|
||||
os.makedirs(head)
|
||||
except OSError as exp:
|
||||
if exp.errno != errno.EEXIST:
|
||||
raise
|
||||
try:
|
||||
with open(filename, "w", encoding="utf-8") as key_file:
|
||||
key_file.write(";; Gramps key file\n")
|
||||
key_file.write((";; Automatically created at %s" %
|
||||
time.strftime("%Y/%m/%d %H:%M:%S")) + "\n\n")
|
||||
sections = sorted(self.data)
|
||||
for section in sections:
|
||||
key_file.write(("[%s]\n") % section)
|
||||
keys = sorted(self.data[section])
|
||||
for key in keys:
|
||||
key_file.write(";; Automatically created at %s" %
|
||||
time.strftime("%Y/%m/%d %H:%M:%S") + "\n\n")
|
||||
for section in sorted(self.data):
|
||||
key_file.write("[%s]\n" % section)
|
||||
for key in sorted(self.data[section]):
|
||||
value = self.data[section][key]
|
||||
# If it has a default:
|
||||
default = "" # might be a third-party setting
|
||||
if self.has_default("%s.%s" % (section, key)):
|
||||
if value == self.get_default("%s.%s" % (section, key)):
|
||||
if value == self.get_default("%s.%s"
|
||||
% (section, key)):
|
||||
default = ";;"
|
||||
else:
|
||||
default = ""
|
||||
if isinstance(value, int):
|
||||
value = int(value)
|
||||
key_file.write(("%s%s=%s\n")% (default,
|
||||
key,
|
||||
repr(value)))
|
||||
if isinstance(value, int):
|
||||
value = int(value) # TODO why is this needed?
|
||||
key_file.write("%s%s=%s\n" % (default, key,
|
||||
repr(value)))
|
||||
key_file.write("\n")
|
||||
# else, no filename given; nothing to save so do nothing quietly
|
||||
except IOError as err:
|
||||
|
@ -545,8 +545,8 @@ class ManagedWindow:
|
||||
|
||||
Takes care of closing children and removing itself from menu.
|
||||
"""
|
||||
self._save_position(save_config=False) # the next line will save it
|
||||
self._save_size()
|
||||
self._save_position()
|
||||
self.clean_up()
|
||||
self.uistate.gwm.close_track(self.track)
|
||||
self.opened = False
|
||||
@ -596,16 +596,19 @@ class ManagedWindow:
|
||||
vert_position = config.get(self.vert_position_key)
|
||||
self.window.move(horiz_position, vert_position)
|
||||
|
||||
def _save_position(self):
|
||||
def _save_position(self, save_config=True):
|
||||
"""
|
||||
Save the window's position to the config file
|
||||
|
||||
(You can set save_config False if a _save_size() will instantly follow)
|
||||
"""
|
||||
# self.horiz_position_key is set in the subclass (or in setup_configs)
|
||||
if self.horiz_position_key is not None:
|
||||
(horiz_position, vert_position) = self.window.get_position()
|
||||
config.set(self.horiz_position_key, horiz_position)
|
||||
config.set(self.vert_position_key, vert_position)
|
||||
config.save()
|
||||
if save_config:
|
||||
config.save()
|
||||
|
||||
def setup_configs(self, config_base,
|
||||
default_width, default_height,
|
||||
|
Loading…
Reference in New Issue
Block a user