blob: 3c5ad39c9afec5f992092af9e1d0c81a7443a912 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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 ##
|