diff options
author | Matthias Baumgartner <dev@igsor.net> | 2023-03-05 19:17:00 +0100 |
---|---|---|
committer | Matthias Baumgartner <dev@igsor.net> | 2023-03-05 19:17:00 +0100 |
commit | 5a325565f917c8b1d233d8e6373756c253400909 (patch) | |
tree | e6e0b475c7ab5c6a7ff4f0ea7ad1b08cecf05e68 /tagit/apps | |
parent | e1e77797454ac747b293f589d8f2e0243173a419 (diff) | |
parent | 98e567933723c59d1d97b3a85e649cfdce514676 (diff) | |
download | tagit-0.23.03.tar.gz tagit-0.23.03.tar.bz2 tagit-0.23.03.zip |
Merge branch 'develop'v0.23.03
Diffstat (limited to 'tagit/apps')
-rw-r--r-- | tagit/apps/__init__.py | 52 | ||||
-rw-r--r-- | tagit/apps/desktop.py | 98 |
2 files changed, 150 insertions, 0 deletions
diff --git a/tagit/apps/__init__.py b/tagit/apps/__init__.py new file mode 100644 index 0000000..84d0bf1 --- /dev/null +++ b/tagit/apps/__init__.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python3 +"""The tagit applications. + +Part of the tagit module. +A copy of the license is provided with the project. +Author: Matthias Baumgartner, 2022 +""" +# standard imports +import argparse +import typing + +# tagit imports +import tagit + +# inner-module imports +from .desktop import main as desktop + +# exports +__all__: typing.Sequence[str] = ( + 'desktop', + 'main', + ) + +# config +apps = { + 'desktop' : desktop, + } + + +## code ## + +def main(argv=None): + """The BSFS browser, focused on image tagging.""" + parser = argparse.ArgumentParser(description=main.__doc__, prog='tagit') + # version + parser.add_argument('--version', action='version', + version='%(prog)s {}.{}.{}'.format(*tuple(tagit.version_info))) # pylint: disable=C0209 + # application selection + parser.add_argument('app', choices=apps.keys(), nargs='?', default='desktop', + help='Select the application to run.') + # dangling args + parser.add_argument('rest', nargs=argparse.REMAINDER) + # parse + args = parser.parse_args() + # run application + apps[args.app](args.rest) + +if __name__ == '__main__': + import sys + main(sys.argv[1:]) + +## EOF ## diff --git a/tagit/apps/desktop.py b/tagit/apps/desktop.py new file mode 100644 index 0000000..149bf30 --- /dev/null +++ b/tagit/apps/desktop.py @@ -0,0 +1,98 @@ +""" + +Part of the tagit module. +A copy of the license is provided with the project. +Author: Matthias Baumgartner, 2022 +""" +# standard imports +import os +import typing + +# kivy imports +from kivy.app import App +from kivy.resources import resource_find +from kivy.uix.settings import SettingsWithSidebar + +# tagit imports +from tagit import config +from tagit.utils import bsfs, ns +from tagit.utils.bsfs import URI +from tagit.windows import desktop + +# exports +__all__: typing.Sequence[str] = ( + 'main', + ) + + +## code ## + +def load_data_hook(cfg, store): + """Data loading hook to circumvent non-persistent storage.""" + import pickle + import os + # fetch data_hook config flags + schema_path = os.path.expanduser(cfg('session', 'data_hook', 'schema')) + triples_path = os.path.expanduser(cfg('session', 'data_hook', 'triples')) + # load data if present + if os.path.exists(schema_path) and os.path.exists(triples_path): + with open(schema_path, 'rb') as ifile: + store._backend._schema = pickle.load(ifile) + with open(triples_path, 'rb') as ifile: + for triple in pickle.load(ifile): + store._backend._graph.add(triple) + return store + +config.declare(('session', 'data_hook', 'schema'), config.String(), '') +config.declare(('session', 'data_hook', 'triples'), config.String(), '') + + +class TagitApp(App): + """The tagit main application.""" + + def build(self): + # set settings panel style + self.settings_cls = SettingsWithSidebar + + # set title + self.title = 'tagit v0.23.03' + + # load config + from tagit.config.loader import load_settings, TAGITRC + cfg = load_settings(TAGITRC, 0) + + # open BSFS storage + store = load_data_hook(cfg, bsfs.Open(cfg('session', 'bsfs'))) # FIXME: mb/port: data hook + # check storage schema + with open(resource_find('required_schema.nt'), 'rt') as ifile: + required_schema = bsfs.schema.from_string(ifile.read()) + if not required_schema.consistent_with(store.schema): + raise Exception("The storage's schema is incompatible with tagit's requirements") + if not required_schema <= store.schema: + store.migrate(required_schema | store.schema) + + # create widget + return desktop.MainWindow(cfg, store, None) # FIXME: mb/port: expects log arguments + + def on_start(self): + # trigger startup operations + self.root.on_startup() + + +def main(argv): + """Start the tagit GUI. Opens a window to browse images.""" + # Run the GUI + app = TagitApp() + app.run() + +## config + +config.declare(('session', 'bsfs'), config.Any(), {}, + __name__, 'bsfs config', 'Configuration to connect to a BSFS storage.') + +## main ## + +if __name__ == '__main__': + main() + +## EOF ## |