Only write to gui.json once during shutdown

This commit is contained in:
Kovid Goyal 2012-07-26 00:20:12 +05:30
parent 382248eff1
commit cf06ad7e67
2 changed files with 13 additions and 3 deletions

View File

@ -702,9 +702,10 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, EmailMixin, # {{{
self.read_layout_settings()
def write_settings(self):
config.set('main_window_geometry', self.saveGeometry())
dynamic.set('sort_history', self.library_view.model().sort_history)
self.save_layout_state()
with gprefs: # Only write to gprefs once
config.set('main_window_geometry', self.saveGeometry())
dynamic.set('sort_history', self.library_view.model().sort_history)
self.save_layout_state()
def quit(self, checked=True, restart=False, debug_on_restart=False,
confirm_quit=True):

View File

@ -240,6 +240,7 @@ class XMLConfig(dict):
def __init__(self, rel_path_to_cf_file):
dict.__init__(self)
self.no_commit = False
self.defaults = {}
self.file_path = os.path.join(config_dir,
*(rel_path_to_cf_file.split('/')))
@ -304,6 +305,7 @@ class XMLConfig(dict):
self.commit()
def commit(self):
if self.no_commit: return
if hasattr(self, 'file_path') and self.file_path:
dpath = os.path.dirname(self.file_path)
if not os.path.exists(dpath):
@ -314,6 +316,13 @@ class XMLConfig(dict):
f.truncate()
f.write(raw)
def __enter__(self):
self.no_commit = True
def __exit__(self, *args):
self.no_commit = False
self.commit()
def to_json(obj):
if isinstance(obj, bytearray):
return {'__class__': 'bytearray',