aboutsummaryrefslogtreecommitdiffstats
path: root/tagit/tiles/info.py
blob: 9555b3523536879f294f184cb2583709901d6737 (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
"""

Part of the tagit module.
A copy of the license is provided with the project.
Author: Matthias Baumgartner, 2022
"""
# standard imports
from collections import OrderedDict

# kivy imports
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

# exports
__all__ = ('Info', )


## code ##

# load kv
Builder.load_string('''
<Info>:
    title: 'Item info'
    tooltip: 'Key properties of the cursor item'
    # assuming 7 info items
    #default_size: None, 7*self.font_size + 6*5
    keywidth: min(75, self.width * 0.4)
''')


# classes
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:
            self.browser.unbind(cursor=self.update)
        # add new binding
        self.browser = browser
        if self.browser is not None:
            self.browser.bind(cursor=self.update)
            self.update()

    def __del__(self):
        if self.browser is not None:
            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:
            # invisible or no cursor, nothing to show
            self.tabledata = OrderedDict({})

        else:
            preds = cursor.get(
                ns.bsfs.Node().t_created,
                ns.bse.filesize,
                ns.bse.filename,
                (ns.bse.tag, ns.bst.label),
                )
            self.tabledata = OrderedDict({
                'Date'      : ttime.from_timestamp_utc(
                    preds.get(ns.bsfs.Node().t_created, ttime.timestamp_min)).strftime('%d.%m.%y %H:%M'),
                '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), [' ']))),
                })

## EOF ##