This repository has been archived by the owner on Nov 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #101 from ZELLMECHANIK-DRESDEN/develop
Version 0.6.5
- Loading branch information
Showing
12 changed files
with
320 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
appdirs | ||
chaco>=4.1.0 | ||
cffi>=0.8.2 | ||
dclab>=0.1.0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#!/usr/bin/python | ||
# -*- coding: utf-8 -*- | ||
""" ShapeOut - autosaving of sessions | ||
""" | ||
from __future__ import division, print_function | ||
|
||
import appdirs | ||
import os | ||
import time | ||
import wx | ||
import wx.lib.delayedresult as delayedresult | ||
|
||
from . import session | ||
|
||
cache_dir = appdirs.user_cache_dir(appname="ShapeOut") | ||
autosave_file = os.path.join(cache_dir, "autosave.zmso") | ||
|
||
|
||
def mkdir_p(adir): | ||
"""Recursively create a directory""" | ||
adir = os.path.abspath(adir) | ||
while not os.path.exists(adir): | ||
try: | ||
os.mkdir(adir) | ||
except: | ||
mkdir_p(os.path.dirname(adir)) | ||
|
||
|
||
def _autosave_consumer(delayedresult, parent): | ||
parent.StatusBar.SetStatusText("Autosaving...") | ||
tempname = autosave_file+".tmp" | ||
mkdir_p(cache_dir) | ||
try: | ||
session.save_session(tempname, parent.analysis) | ||
except: | ||
parent.StatusBar.SetStatusText("Autosaving failed!") | ||
if os.path.exists(tempname): | ||
os.remove(tempname) | ||
else: | ||
if os.path.exists(autosave_file): | ||
os.remove(autosave_file) | ||
os.rename(tempname, autosave_file) | ||
parent.StatusBar.SetStatusText("") | ||
autosave_run(parent) | ||
|
||
|
||
def _autosave_worker(parent, interval): | ||
"""Runs in the background and performs autosaving""" | ||
time.sleep(interval) | ||
|
||
|
||
def autosave_run(parent, interval=60): | ||
"""Runs in the background and performs autosaving""" | ||
delayedresult.startWorker(_autosave_consumer, | ||
_autosave_worker, | ||
wargs=(parent, interval,), | ||
cargs=(parent,)) | ||
|
||
|
||
def check_recover(parent): | ||
"""Check for a recovery file and ask if user wants to restore | ||
Returns True if a session was restored. False otherwise. | ||
""" | ||
if os.path.exists(autosave_file): | ||
message="Autosaved session found. Restore?" | ||
dlg = wx.MessageDialog(parent, | ||
caption=_("Missing tdms files for session"), | ||
message=message, | ||
style=wx.YES|wx.NO, | ||
) | ||
mod = dlg.ShowModal() | ||
dlg.Destroy() | ||
if mod == wx.ID_YES: | ||
session.open_session(autosave_file, parent) | ||
return True | ||
return False |
Oops, something went wrong.