diff options
author | Matthias Baumgartner <dev@igsor.net> | 2023-03-04 14:19:06 +0100 |
---|---|---|
committer | Matthias Baumgartner <dev@igsor.net> | 2023-03-04 14:19:06 +0100 |
commit | ceb95600c5d3cff789d466706bcdec7143c11bb3 (patch) | |
tree | f3d73d5c9e9cb74e5cb50fd3e8f2d03a5bb595d4 | |
parent | a4be2d7d5752ed68a5c0f5fa46a1058f17b9ca01 (diff) | |
download | tagit-ceb95600c5d3cff789d466706bcdec7143c11bb3.tar.gz tagit-ceb95600c5d3cff789d466706bcdec7143c11bb3.tar.bz2 tagit-ceb95600c5d3cff789d466706bcdec7143c11bb3.zip |
info tile refactoring
-rw-r--r-- | tagit/assets/themes/default/style.kv | 6 | ||||
-rw-r--r-- | tagit/tiles/decoration.kv | 4 | ||||
-rw-r--r-- | tagit/tiles/info.py | 20 | ||||
-rw-r--r-- | tagit/tiles/tile.kv | 26 | ||||
-rw-r--r-- | tagit/tiles/tile.py | 61 | ||||
-rw-r--r-- | tagit/windows/desktop.kv | 6 |
6 files changed, 68 insertions, 55 deletions
diff --git a/tagit/assets/themes/default/style.kv b/tagit/assets/themes/default/style.kv index a3f9cd1..5747fbd 100644 --- a/tagit/assets/themes/default/style.kv +++ b/tagit/assets/themes/default/style.kv @@ -140,6 +140,12 @@ # other elements +<TileTabularLine>: + spacing: 5 + +<TileTabularRow>: + spacing: 5 + <Action>: # decoration canvas.before: diff --git a/tagit/tiles/decoration.kv b/tagit/tiles/decoration.kv index d4b37a2..ae7e49d 100644 --- a/tagit/tiles/decoration.kv +++ b/tagit/tiles/decoration.kv @@ -62,11 +62,11 @@ text: root.client.title size: root.width, 20 size_hint: None, None - pos: 0, root.height - self.height - 5 + pos: 0, root.height - self.height - 3 RelativeLayout: id: cbox - pos: 5, 5 + pos: 5, 3 size: root.width-10, root.height-30 size_hint: None, None diff --git a/tagit/tiles/info.py b/tagit/tiles/info.py index 8edc9bb..9555b35 100644 --- a/tagit/tiles/info.py +++ b/tagit/tiles/info.py @@ -13,6 +13,7 @@ from kivy.lang import Builder # tagit imports from tagit.utils import ttime, ns, magnitude_fmt from tagit.widgets.browser import BrowserAwareMixin +from tagit.widgets.session import StorageAwareMixin # inner-module imports from .tile import TileTabular @@ -29,15 +30,19 @@ Builder.load_string(''' title: 'Item info' tooltip: 'Key properties of the cursor item' # assuming 7 info items - default_size: None, 7*self.font_size + 6*5 + #default_size: None, 7*self.font_size + 6*5 keywidth: min(75, self.width * 0.4) ''') # classes -class Info(TileTabular, BrowserAwareMixin): +class Info(TileTabular, BrowserAwareMixin, StorageAwareMixin): """Show essential attributes about the cursor.""" + def on_root(self, wx, root): + BrowserAwareMixin.on_root(self, wx, root) + StorageAwareMixin.on_root(self, wx, root) + def on_browser(self, sender, browser): # remove old binding if self.browser is not None: @@ -53,6 +58,9 @@ class Info(TileTabular, BrowserAwareMixin): self.browser.unbind(cursor=self.update) self.browser = None + def on_predicate_modified(self, *args): + self.update() + def update(self, *args): cursor = self.root.browser.cursor if not self.visible or cursor is None: @@ -69,15 +77,9 @@ class Info(TileTabular, BrowserAwareMixin): self.tabledata = OrderedDict({ 'Date' : ttime.from_timestamp_utc( preds.get(ns.bsfs.Node().t_created, ttime.timestamp_min)).strftime('%d.%m.%y %H:%M'), - #'Size' : f'{preds.get(ns.bse.width, "?")} x {preds.get(ns.bse.height, "?")}', - #'ISO' : preds.get(ns.bse.iso, '?'), 'Filesize' : magnitude_fmt(preds.get(ns.bse.filesize, 0)), 'Filename' : preds.get(ns.bse.filename, 'n/a'), - 'Tags' : ', '.join(sorted(preds.get((ns.bse.tag, ns.bst.label), []))), - #'Exposure' : f'1 / {preds.get(ns.bse.exposure, 0):0.2f}', - #'Aperture' : preds.get(ns.bse.aperture, '?'), - #'Fx' : preds.get(ns.bse.focal_length_35, '?'), - #'Flash' : 'Yes' if preds.get(ns.bse.flash, False) else 'No', + 'Tags' : ', '.join(sorted(preds.get((ns.bse.tag, ns.bst.label), [' ']))), }) ## EOF ## diff --git a/tagit/tiles/tile.kv b/tagit/tiles/tile.kv index 277b23d..fcd9821 100644 --- a/tagit/tiles/tile.kv +++ b/tagit/tiles/tile.kv @@ -7,16 +7,28 @@ <TileTabular>: # config font_size: sp(15) - spacer: 10 keywidth: 0.5 # table - grid: grid - GridLayout: - id: grid - cols: 2 - size: root.size - size_hint: None, None + rows: rows + TileTabularLine: + id: rows + orientation: 'tb-lr' + size_hint: 1, 1 + +<TileTabularLine@StackLayout>: + spacing: 10 + +<TileTabularRow>: + orientation: 'horizontal' + size_hint: 1, None + height: self.minimum_height + spacing: 10 + +<TileTabularCell>: + valign: 'top' + height: self.texture_size[1] + text_size: self.width, None <TileWithLabel>: text: '' diff --git a/tagit/tiles/tile.py b/tagit/tiles/tile.py index 7ea690a..981d45b 100644 --- a/tagit/tiles/tile.py +++ b/tagit/tiles/tile.py @@ -9,6 +9,7 @@ import os # kivy imports from kivy.lang import Builder +from kivy.uix.boxlayout import BoxLayout from kivy.uix.label import Label from kivy.uix.relativelayout import RelativeLayout import kivy.properties as kp @@ -38,51 +39,47 @@ class Tile(RelativeLayout): class TileWithLabel(Tile): pass +class TileTabularRow(BoxLayout): + pass + +class TileTabularCell(Label): + pass class TileTabular(Tile): tabledata = kp.ObjectProperty() - spacer = kp.NumericProperty(10) keywidth = kp.NumericProperty(0.5) - def on_size(self, wx, size): - if not self.visible or len(self.grid.children) == 0: - return - - height = self.height / (len(self.grid.children) / 2) - kwidth = self.width * self.keywidth if self.keywidth < 1 else self.keywidth - vwidth = self.width - kwidth - self.spacer - - # adjust size - for idx, child in enumerate(self.grid.children): - if idx % 2 == 1: # key - child.text_size = kwidth, height - child.width = kwidth - else: # label - child.text_size = vwidth, height - def on_tabledata(self, wx, data): # set items - self.grid.clear_widgets() - for key, value in data.items(): + self.rows.clear_widgets() + for t_key, t_value in data.items(): + # row + row = TileTabularRow() # left column (keys) - self.grid.add_widget(Label( - text=key, + key = TileTabularCell( + text=t_key, halign='right', - valign='top', font_size = self.font_size, - size_hint = (None, 1), - )) - + size_hint=(None, 1), + width=self.width * self.keywidth if self.keywidth < 1 else self.keywidth, + ) # right column (values) - self.grid.add_widget(Label( - text=str(value), + value = TileTabularCell( + text=str(t_value), halign='left', - valign='top', font_size = self.font_size, - )) - - # set sizes - self.on_size(self, self.size) + size_hint=(1, None), + ) + # adjust key's width and height dynamically. + # value's width and height are adjusted automatically + self.bind(width=lambda wx, width, key=key: setattr(key, 'width', + width * self.keywidth if self.keywidth < 1 else self.keywidth)) + key.bind(height=lambda wx, height, key=key: setattr(key, 'text_size', + (key.width, height))) + # add widgets + row.add_widget(key) + row.add_widget(value) + self.rows.add_widget(row) ## EOF ## diff --git a/tagit/windows/desktop.kv b/tagit/windows/desktop.kv index 8fde41a..d2ca0e7 100644 --- a/tagit/windows/desktop.kv +++ b/tagit/windows/desktop.kv @@ -74,11 +74,7 @@ cols: 1 rows: 1 width: 220 - size_hint: None, None - # self.height won't be updated correctly - #tile_height: self.size[1] / 4 - #height: sum(tile.client.default_size[1] for tile in self.children) - height: self.parent.height / 2 + size_hint: None, 0.5 pos_hint: {'center_y': 0.5} Widget: # spacer |