diff options
author | Matthias Baumgartner <dev@igsor.net> | 2023-02-08 21:29:58 +0100 |
---|---|---|
committer | Matthias Baumgartner <dev@igsor.net> | 2023-02-08 21:29:58 +0100 |
commit | bf98c062ece242a5fc56de0f1adbc12f0588809a (patch) | |
tree | 417f4fe5af06bfeb028e96c809bb23bf58bb4e29 /tagit/windows | |
parent | 547124605a9f86469a547fcaf38dc18ae57b707f (diff) | |
parent | f39d577421bc2e4b041b5d22e788f4615ef78d77 (diff) | |
download | tagit-bf98c062ece242a5fc56de0f1adbc12f0588809a.tar.gz tagit-bf98c062ece242a5fc56de0f1adbc12f0588809a.tar.bz2 tagit-bf98c062ece242a5fc56de0f1adbc12f0588809a.zip |
Merge branch 'mb/port/desktop' into develop
Diffstat (limited to 'tagit/windows')
-rw-r--r-- | tagit/windows/__init__.py | 10 | ||||
-rw-r--r-- | tagit/windows/desktop.kv | 136 | ||||
-rw-r--r-- | tagit/windows/desktop.py | 162 |
3 files changed, 308 insertions, 0 deletions
diff --git a/tagit/windows/__init__.py b/tagit/windows/__init__.py new file mode 100644 index 0000000..c3ec3c0 --- /dev/null +++ b/tagit/windows/__init__.py @@ -0,0 +1,10 @@ +""" + +Part of the tagit module. +A copy of the license is provided with the project. +Author: Matthias Baumgartner, 2022 +""" +# inner-module imports +from .desktop import MainWindow + +## EOF ## diff --git a/tagit/windows/desktop.kv b/tagit/windows/desktop.kv new file mode 100644 index 0000000..cbc5c48 --- /dev/null +++ b/tagit/windows/desktop.kv @@ -0,0 +1,136 @@ +#:import TileDecorationBorder tagit.tiles.decoration.TileDecorationBorder +#:import TileDecorationFilledRectangle tagit.tiles.decoration.TileDecorationFilledRectangle + +# DEBUG: Draw borders around all widgets +#<Widget>: +# canvas.after: +# Line: +# rectangle: self.x+1,self.y+1,self.width-1,self.height-1 +# dash_offset: 5 +# dash_length: 3 + +<MainWindow>: + # main content + # required by most tiles and actions + browser: browser + filter: filter + status: status + # required by actions.planes + planes: planes + # required by Menu + context: context + + Carousel: + id: planes + loop: True + scroll_timeout: 0 # disables switching by touch event + # plane references + dashboard: dashboard + browsing: browsing + codash: codash + + # planes + + TileDock: # static dashboard plane + id: dashboard + root: root + # plane config + size_hint: 1, 1 + visible: planes.current_slide == self + # dock config + name: 'dashboard' + decoration: TileDecorationBorder + cols: 3 + rows: 2 + # self.size won't be updated correctly + tile_width: self.width / self.cols + tile_height: self.height / self.rows + + BoxLayout: # browsing plane + id: browsing + orientation: 'horizontal' + visible: planes.current_slide == self + + ButtonDock: # one column of buttons on the left + root: root + orientation: 'tb-lr' + # one column of buttons + width: 30 + 2*10 + name: 'sidebar_left' + spacing: 10 + padding: 10 + size_hint: None, 1 + button_height: 30 + button_show: 'image', + + BoxLayout: # main content + orientation: 'vertical' + size_hint: 1, 1 + + BoxLayout: + orientation: 'horizontal' + size_hint: 1, 1 + current: 0 + + BoxLayout: + orientation: 'vertical' + size_hint: 1, 1 + + Filter: + id: filter + root: root + size_hint: 1, None + height: 30 + + Browser: + id: browser + root: root + size_hint: 1, 0.96 + + Status: + id: status + root: root + size_hint: 1, None + height: 30 + + TileDock: # context info to the right + root: root + visible: planes.current_slide == self.parent + name: 'sidebar_right' + decoration: TileDecorationFilledRectangle + cols: 1 + rows: 3 + # self.height won't be updated correctly + #tile_height: self.size[1] / 4 + width: 180 + size_hint: None, 1 + + TileDock: # contextual dashboard + id: codash + root: root + # plane config + size_hint: 1, 1 + visible: planes.current_slide == self + # dock config + name: 'codash' + decoration: TileDecorationBorder + cols: 4 + rows: 2 + # self.size won't be update correctly + tile_width: self.width / 4 + tile_height: self.height / 2 + + Context: # context menu + id: context + root: root + cancel_handler_widget: root + bounding_box_widget: root + name: 'context' + + KeybindDock: + # key-only actions + root: root + size_hint: None, None + size: 0, 0 + +## EOF ## diff --git a/tagit/windows/desktop.py b/tagit/windows/desktop.py new file mode 100644 index 0000000..42b279e --- /dev/null +++ b/tagit/windows/desktop.py @@ -0,0 +1,162 @@ +"""Main container of the tagit UI. + +Part of the tagit module. +A copy of the license is provided with the project. +Author: Matthias Baumgartner, 2022 + +""" +# standard imports +import logging +import os +import typing + +# kivy imports +from kivy.clock import Clock +from kivy.lang import Builder +from kivy.uix.floatlayout import FloatLayout +import kivy.properties as kp + +# import Image and Loader to overwrite their caches later on +from kivy.loader import Loader +from kivy.cache import Cache + +# tagit imports +from tagit import actions, config, dialogues +from tagit.widgets.browser import Browser +from tagit.widgets.context import Context +from tagit.widgets.dock import TileDock, ButtonDock, KeybindDock +from tagit.widgets.filter import Filter +from tagit.widgets.keyboard import Keyboard +from tagit.widgets.session import Session +from tagit.widgets.status import Status + +# exports +__all__: typing.Sequence[str] = ( + 'KIVY_IMAGE_CACHE_SIZE', + 'KIVY_IMAGE_CACHE_TIMEOUT', + 'MainWindow', + ) + + +## code ## + +logger = logging.getLogger(__name__) + +# load kv +Builder.load_file(os.path.join(os.path.dirname(__file__), 'desktop.kv')) + +# classes +class MainWindow(FloatLayout): + """A self-contained user interface for desktop usage. + See `tagit.apps.gui` for an example of how to invoke it. + """ + + keys = kp.ObjectProperty(None) + + # unnecessary but nicely explicit + browser = kp.ObjectProperty(None) + filter = kp.ObjectProperty(None) + keytriggers = kp.ObjectProperty(None) + + # FIXME: log actions and and replay them + action_log = kp.ListProperty() + + def __init__ (self, cfg, stor, log, **kwargs): + # initialize the session + self._session = Session(cfg, stor, log) + # initialize key-only actions + self.keys = Keyboard() + + # initialize the cache + cache_size = max(0, cfg('ui', 'standalone', 'browser', 'cache_size')) + cache_size = cache_size if cache_size > 0 else None + cache_timeout = max(0, cfg('ui', 'standalone', 'browser', 'cache_timeout')) + cache_timeout = cache_timeout if cache_timeout > 0 else None + Cache.register('kv.loader', limit=cache_size, timeout=cache_timeout) + + # initialize the widget + super(MainWindow, self).__init__(**kwargs) + + # bind pre-close checks + from kivy.core.window import Window + Window.bind(on_request_close=self.on_request_close) + + + ## properties + + @property + def session(self): + return self._session + + def trigger(self, action, *args, **kwargs): + """Trigger an action once.""" + actions.ActionBuilder().get(action).single_shot(self, *args, **kwargs) + + + ## startup and shutdown + + def on_startup(self): + # switch to starting plane - if it's the dashboard no action is needed + if self.session.cfg('ui', 'standalone', 'plane') == 'browsing': + self.trigger('ShowBrowsing') + + # show welcome message + if self.session.cfg('session', 'first_start'): # FIXME: mb/port: move to starting app + self.display_welcome() + + # run script + for args in self.session.cfg('session', 'script'): + if isinstance(args, str): + cmd, args = args, [] + else: + cmd = args.pop(0) + Clock.schedule_once( + lambda dt, cmd=cmd, args=args: self.trigger(cmd, *args), + self.session.cfg('session', 'script_delay')) + + # FIXME: mb/port: debugging only + #return + #Clock.schedule_once(lambda dt: self.trigger('Search'), 0) + #Clock.schedule_once(lambda dt: self.trigger('ZoomOut'), 0) + #Clock.schedule_once(lambda dt: self.trigger('ZoomOut'), 0) + #from kivy.app import App + #App.get_running_app().stop() + + def on_request_close(self, *args): + with open('.action_history', 'a') as ofile: + for itm in self.action_log: + ofile.write(f'{itm}\n') + #App.get_running_app().stop() # FIXME: mb/port: from CloseSessionAndExit + return False + + def display_welcome(self): + """Display a welcome dialogue on the first start.""" + message = """ +[size=20sp]Welcome to [b]tagit[/b]![/size] + +Since you see this message, it's time to configure tagit. It's a good idea to get familiar with the configuration. Hit F1 or the config button to see all relevant settings. There, you can also get rid of this message. If you desire more flexibility, you can edit the config file directly. Check out the project homepage for more details. +""" # FIXME! + dialogues.Message(text=message, align='left').open() + + +## config ## + +config.declare(('session', 'first_start'), config.Bool(), True, + __name__, 'First start', 'Show the welcome message typically shown when tagit is started the first time.') + +config.declare(('session', 'script'), config.List(config.Any()), [], + __name__, 'start script', 'Actions to run after startup. Intended for testing.') + +config.declare(('session', 'script_delay'), config.Unsigned(), 0, + __name__, 'script delay', 'Start script execution delay in seconds.') + +config.declare(('ui', 'standalone', 'plane'), config.Enum('browsing', 'dashboard'), 'dashboard', + __name__, 'Initial plane', 'Start with the dashboard or browsing plane.') + +config.declare(('ui', 'standalone', 'browser', 'cache_size'), config.Unsigned(), 1000, + __name__, 'Cache size', 'Number of preview images that are held in the cache. Should be high or zero if memory is not an issue. Set to a small value to preserve memory, but should be at least the most common page size. It is advised to set a value in accordance with `ui.standalone.browser.cache_items`. If zero, no limit applies.') + +config.declare(('ui', 'standalone', 'browser', 'cache_timeout'), config.Unsigned(), 0, + __name__, 'Cache timeout', 'Number of seconds until cached items are discarded. Should be high or zero if memory is not an issue. Set it to a small value to preserve memory when browsing through many images. If zero, no limit applies. Specify in seconds.') + +## EOF ## |