Tiles#

Tiles are containers to display information about the file system, or specific items therein. Their main purpose is to assist the user in navigating and tag their files. They can also display additional information about selected files, e.g., by showing metadata or placing geo-tagged files on a map.

Content update#

A Tile is responsible to update its content itself, whenever appropriate. The mixin classes tagit.widgets.browser.BrowserAwareMixin, tagit.widgets.session.SessionAwareMixin, and tagit.widgets.filter.FilterAwareMixin provide a series of events that trigger when the UI or storage state changes. A Tile can trigger its content update by binding to these events. In addition, a Tile’s visibility indicates if it is actually visible to the user. The visibility flag is controlled by the parent widget (mostly a tagit.widget.dock.TileDock) and the tile updates automatically if its visibility changes. Similar to actions, a tagit.tiles.Tile is automatically linked to the root window so that it can retrieve contextual information about the UI’s state, or to query the storage backed for additional file properties.

For example, the info tile updates when the browser state changes (e.g., the user moves the cursor), or when the storage content changes (e.g., the item information changes). In such an event, the tile fetches the current information from the storage and displays it as a table:

from collections import OrderedDict
from tagit.utils import ns, magnitude_fmt
from tagit.widgets.browser import BrowserAwareMixin
from tagit.widgets.session import StorageAwareMixin
from .tile import TileTabular

class Info(TileTabular, BrowserAwareMixin, StorageAwareMixin):
    """Show essential attributes about the cursor."""

    # bind to events so that the tile updates when the context changes
    def on_browser(self, sender, browser):
        ...
    def on_predicate_modified(self, *args):
        ...

    def update(self, *args):
        """Update the tile's content."""
        cursor = self.root.browser.cursor
        if not self.visible or cursor is None:
            # invisible or no cursor, nothing to show
            self.tabledata = OrderedDict({})
        else:
            # fetch information about the cursor from the storage
            data = cursor.get(
                ns.bse.filesize,
                ns.bse.filename,
                (ns.bse.tag, ns.bst.label),
                )
            # display the information as a two-column table
            self.tabledata = OrderedDict({
                'Filesize'  : magnitude_fmt(data.get(ns.bse.filesize, 0)),
                'Filename'  : data.get(ns.bse.filename, 'n/a'),
                'Tags'      : ', '.join(sorted(data.get((ns.bse.tag, ns.bst.label), [' ']))),
                })

Appearance#

Tiles can appear at any place in the UI and they could also be re-used in multiple locations. To enable this, they are typically located within a tagit.widgets.dock.TileDock which controls the tile’s appearance, position, and size.

The tile itself only has to define the appearance of its content. For example, for the info tile the following kivy language snippet suffices:

<Info>:
    title: 'Item info'
    keywidth: min(75, self.width * 0.4)