"""
Part of the tagit module.
A copy of the license is provided with the project.
Author: Matthias Baumgartner, 2016
"""
# IMPORTS
from kivy.uix.label import Label
import operator
# INNER-MODULE IMPORTS
from sidebox import VSidebox
from ...controller.sidebox import CSidebox_Tags_Browser
from ...basics import union
from ..basics import colorize, fontize
# EXPORTS
__all__ = ('VSidebox_Tags_Browser', )
# LOAD KV
# CLASSES
[docs]class VSidebox_Tags_Browser(Label, VSidebox):
"""Show tags if images displayed. Highlight tags of selected images and the cursor."""
def __init__(self, *args, **kwargs):
super(VSidebox_Tags_Browser, self).__init__(*args, **kwargs)
self.markup = True
def on_widget_change(self, instance, widget):
self.controller = widget.get_controller(CSidebox_Tags_Browser, wx=self)
def update(self, displayed, selected, cursor, hist):
tags = sorted(union(displayed, selected, cursor))
prefix = [fontize(colorize(unichr(0x2b1b) + ' ', t in hist and hist[t] or '#000000'), 'Unifont') for t in tags]
idx_c = [tags.index(t) for t in cursor]
idx_s = [tags.index(t) for t in selected]
for i in idx_c: # Cursor
#tags[i] += ' #' # Added char
tags[i] = "[b]" + tags[i] + "[/b]" # Bold
tags[i] = "[i]" + tags[i] + "[/i]" # Italic
for i in idx_s: # Selection
#tags[i] += ' *' # Added char
tags[i] = "[color=#415bCD]" + tags[i] + "[/color]" # Blue color
#tags[i] = "[i]" + tags[i] + "[/i]" # Italic
# Apply prefix and display
tags = map(operator.add, prefix, tags)
self.text = '\n'.join(tags)
## EOF ##