Skip to content

Commit

Permalink
renew list of saved sessions with every autosave so that times are mo…
Browse files Browse the repository at this point in the history
…re accurate
  • Loading branch information
newville committed Apr 15, 2024
1 parent b896591 commit ae6ed79
Showing 1 changed file with 25 additions and 16 deletions.
41 changes: 25 additions & 16 deletions larch/wxxas/xasgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,21 +516,9 @@ def createMenus(self):
{'fileroot': 'autosave'})
froot= conf['fileroot']

recent_menu = wx.Menu()
for tstamp, fname in self.controller.get_recentfiles():
MenuItem(self, recent_menu,
"%s [%s ago]" % (fname, time_ago(tstamp)),
f"file saved {isotime(tstamp)}",
partial(self.onLoadSession, path=fname))

recent_menu.AppendSeparator()
for tstamp, fname in self.controller.recent_autosave_sessions():
MenuItem(self, recent_menu,
"%s [%s ago]" % (fname, time_ago(tstamp)),
f"file saved {isotime(tstamp)}",
partial(self.onLoadSession, path=fname))

fmenu.Append(-1, 'Recent Session Files', recent_menu)
self.recent_menu = wx.Menu()
self.get_recent_session_menu()
fmenu.Append(-1, 'Recent Session Files', self.recent_menu)


MenuItem(self, fmenu, "&Auto-Save Larch Session",
Expand Down Expand Up @@ -1643,17 +1631,39 @@ def install_group(self, groupname, filename=None, source=None, journal=None,
process=process, plot=plot)

##
def get_recent_session_menu(self):
""" get recent sessions files for Menu list"""
for menu_item in self.recent_menu.MenuItems:
self.recent_menu.Remove(menu_item)

for tstamp, fname in self.controller.get_recentfiles():
message = f"{fname} [{time_ago(tstamp)} ago]"
MenuItem(self, self.recent_menu, message,
f"file saved {isotime(tstamp)}",
partial(self.onLoadSession, path=fname))

self.recent_menu.AppendSeparator()
for tstamp, fname in self.controller.recent_autosave_sessions():
message = f"{fname} [{time_ago(tstamp)} ago]"
if abs(tstamp) < 5.0:
message = f"{fname} [most recent]"
MenuItem(self, self.recent_menu, message,
f"file saved {isotime(tstamp)}",
partial(self.onLoadSession, path=fname))

def onAutoSaveTimer(self, event=None):
"""autosave session periodically, using autosave_config settings
and avoiding saving sessions while program is inactive.
"""
conf = self.controller.get_config('autosave', {})
savetime = conf.get('savetime', 600)
symtab = self.larch.symtable

if (time.time() > self.last_autosave + savetime and
symtab._sys.last_eval_time > (self.last_autosave+60) and
len(symtab._xasgroups) > 0):
self.autosave_session()
self.get_recent_session_menu()

def autosave_session(self, event=None):
"""autosave session now"""
Expand All @@ -1664,7 +1674,6 @@ def autosave_session(self, event=None):
self.last_save_message = ("Session last saved", f"'{savefile}'", f"{stime}")
self.write_message(f"Session saved to '{savefile}' at {stime}")


## float-spin / pin timer events
def onPinTimer(self, event=None):
if 'start' not in self.cursor_dat:
Expand Down

0 comments on commit ae6ed79

Please sign in to comment.