Skip to content

Commit

Permalink
Don't squash config that was saved in another thread.
Browse files Browse the repository at this point in the history
...by reloading from disk before updating.
  • Loading branch information
cjwelborn committed Jan 24, 2019
1 parent 3f507f9 commit 2709450
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 12 deletions.
6 changes: 4 additions & 2 deletions lib/gui/about.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def __init__(self, *args, **kwargs):

# Initialize this window.
self.title('{} - About'.format(NAME))
self.geometry(self.config_gui.get('geometry_about', '442x240'))
self.geometry(self.config_gui.get('geometry_about', '442x246'))
# About window should stay above the main window.
self.attributes('-topmost', 1)
# Make the main frame expand.
Expand Down Expand Up @@ -254,7 +254,9 @@ def destroy(self):
debug('Saving gui-about config...')
self.config_gui['geometry_about'] = self.geometry()
config_save(self.config_gui)
debug('Closing about window (geometry={!r}).'.format(self.geometry()))
debug('Closing about window (geometry={!r}).'.format(
self.config_gui['geometry_about']
))
self.attributes('-topmost', 0)
self.withdraw()
super().destroy()
Expand Down
4 changes: 4 additions & 0 deletions lib/gui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,10 @@ def destroy(self):
self.config_gui['geometry'] = self.geometry()
self.config_gui['theme'] = self.theme
self.config_gui['auto_exit'] = self.var_auto_exit.get()
# Report, Unarchive, and About have saved their geometry already.
self.config_gui.pop('geometry_report')
self.config_gui.pop('geometry_about')
self.config_gui.pop('geometry_unarchive')
config_save(self.config_gui)
debug('Saving runtime info...')

Expand Down
4 changes: 3 additions & 1 deletion lib/gui/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,9 @@ def destroy(self):
config_save(self.config_gui)
# Remove topmost, and hide this report, in case any callbacks want
# to show a dialog.
debug('Closing report window (geometry={!r}).'.format(self.geometry()))
debug('Closing report window (geometry={!r}).'.format(
self.config_gui['geometry_report'],
))
self.attributes('-topmost', 0)
self.withdraw()
self.update()
Expand Down
16 changes: 7 additions & 9 deletions lib/gui/unarchive.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ def __init__(self, *args, **kwargs):
self.title('{} - Unarchive'.format(NAME))
self.geometry(self.config_gui.get('geometry_unarchive', '731x163'))

self.style = ttk.Style()
print(self.style.theme_use())
# Hotkey info.
hotkeys = {
'unarchive': {
Expand Down Expand Up @@ -79,26 +77,26 @@ def __init__(self, *args, **kwargs):
padding='2 2 2 2',
)
self.frm_top.pack(
fill=tk.X,
fill=tk.BOTH,
side=tk.TOP,
expand=False,
expand=True,
)
# # Build files frame
self.frm_files = ttk.Frame(
self.frm_top,
padding='2 2 2 2',
)
self.frm_files.pack(
fill=tk.X,
fill=tk.BOTH,
side=tk.LEFT,
expand=True,
)
self.tree_files = ttk.Treeview(
self.frm_files,
selectmode='browse',
selectmode='extended',
height=3,
)
self.tree_files.pack(side=tk.LEFT, fill=tk.X, expand=True)
self.tree_files.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
self.tree_files.configure(columns=('file', ), show='headings')
self.tree_files.heading(
'file',
Expand All @@ -118,7 +116,7 @@ def __init__(self, *args, **kwargs):
# Main commands frame.
self.frm_cmds = ttk.Frame(
self.frm_main,
padding='2 20 2 2',
padding='2 4 2 2',
)
self.frm_cmds.pack(
fill=tk.X,
Expand Down Expand Up @@ -280,7 +278,7 @@ def destroy(self):
self.config_gui['geometry_unarchive'] = self.geometry()
config_save(self.config_gui)
debug('Closing unarchive window (geometry={!r}).'.format(
self.geometry()
self.config_gui['geometry_unarchive']
))
self.withdraw()
super().destroy()
Expand Down
16 changes: 16 additions & 0 deletions lib/util/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,23 @@ def config_increment(**kwargs):
return config_save()


def config_load():
""" Reload config from disk. """
try:
c = JSONSettings.from_file(CONFIGFILE)
debug('Config reloaded from: {}'.format(CONFIGFILE))
except FileNotFoundError:
c = JSONSettings()
c.filename = CONFIGFILE
debug('No config to reload: {}'.format(CONFIGFILE))
return c


def config_save(d=None):
global config
# Reload config from disk, because other threads may have changed it.
config = config_load()

if d:
config.update(d)
# debug_obj(dict(config.items()), msg='Saving config:')
Expand Down

0 comments on commit 2709450

Please sign in to comment.