diff options
Diffstat (limited to 'tagit/actions')
-rw-r--r-- | tagit/actions/__init__.py | 8 | ||||
-rw-r--r-- | tagit/actions/session.kv | 7 | ||||
-rw-r--r-- | tagit/actions/session.py | 56 |
3 files changed, 65 insertions, 6 deletions
diff --git a/tagit/actions/__init__.py b/tagit/actions/__init__.py index 7144e44..fa2bed0 100644 --- a/tagit/actions/__init__.py +++ b/tagit/actions/__init__.py @@ -18,7 +18,7 @@ from . import misc #from . import objects from . import planes from . import search -#from . import session +from . import session from . import tagging # exports @@ -104,11 +104,7 @@ class ActionBuilder(BuilderBase): #'SortKey': search.SortKey, 'SortOrder': search.SortOrder, ## session - #'LoadSession': session.LoadSession, - #'CreateSession': session.CreateSession, - #'CreateTempSession': session.CreateTempSession, - #'ReloadSession': session.ReloadSession, - #'CloseSessionAndExit': session.CloseSessionAndExit, + 'LoadSession': session.LoadSession, } ## EOF ## diff --git a/tagit/actions/session.kv b/tagit/actions/session.kv new file mode 100644 index 0000000..21807b2 --- /dev/null +++ b/tagit/actions/session.kv @@ -0,0 +1,7 @@ +#:import resource_find kivy.resources.resource_find + +<LoadSession>: + source: resource_find('atlas://session/open') + tooltip: 'Load a session' + +## EOF ## diff --git a/tagit/actions/session.py b/tagit/actions/session.py new file mode 100644 index 0000000..3c5ad39 --- /dev/null +++ b/tagit/actions/session.py @@ -0,0 +1,56 @@ +""" + +Part of the tagit module. +A copy of the license is provided with the project. +Author: Matthias Baumgartner, 2022 +""" +# standard imports +import os + +# kivy imports +from kivy.lang import Builder +import kivy.properties as kp + +# tagit imports +from tagit import config, dialogues +from tagit.config.loader import load_settings + +# inner-module imports +from .action import Action + +# exports +__all__ = [] + + +## code ## + +# load kv +Builder.load_file(os.path.join(os.path.dirname(__file__), 'session.kv')) + +# classes +class LoadSession(Action): + """Load a session from a project file.""" + text = kp.StringProperty('Load') + + def apply(self): + """Open a file load dialogue to select a session file.""" + dlg = dialogues.FilePicker(title='Select a session file to load') + dlg.bind(on_ok=self.load_from_path) + dlg.open() + + def load_from_path(self, wx): + """Load a session from *path*.""" + with self.root.session as session: + try: + if not os.path.exists(wx.path) or not os.path.isfile(wx.path): + raise FileNotFoundError(wx.path) + + # load config from path + cfg = load_settings(wx.path, verbose=self.cfg('session', 'verbose')) + session.load(cfg) + + except Exception as e: + dialogues.Error(text=f'The file cannot be loaded ({e})').open() + + +## EOF ## |