diff src/browser/sat_browser/list_manager.py @ 740:b6510fd9ae15

browser_side: implements tags UI
author souliane <souliane@mailoo.org>
date Thu, 19 Nov 2015 16:43:18 +0100
parents 4545d48dee60
children c3cb68227cca
line wrap: on
line diff
--- a/src/browser/sat_browser/list_manager.py	Thu Nov 19 16:42:39 2015 +0100
+++ b/src/browser/sat_browser/list_manager.py	Thu Nov 19 16:43:18 2015 +0100
@@ -473,3 +473,40 @@
         self.popup_menu = base_panel.PopupMenuPanel(entries, callback=callback)
         for key in self.lists:  # register click sender for already existing lists
             self.popup_menu.registerClickSender(self.lists[key]["button"])
+
+
+class TagsPanel(base_panel.ToggleStackPanel):
+    """A toggle panel to set the tags"""
+
+    TAGS = _("Tags")
+    
+    STYLE = {"main": "tagsPanel-main",
+             "tags": "tagsPanel-tags"}
+
+    def __init__(self, suggested_tags, tags):
+        """
+        
+        @param suggested_tags (list[unicode]): list of all suggested tags
+        @param tags (list[unicode]): already assigned tags
+        """
+        base_panel.ToggleStackPanel.__init__(self, Width="100%")
+        self.addStyleName(self.STYLE["main"])
+        self.tags = ListPanel(quick_list_manager.QuickTagList(suggested_tags), tags)
+        self.tags.addStyleName(self.STYLE["tags"])
+        self.tags.ACCEPT_NEW_ENTRY = True
+        self.add(self.tags, self.TAGS)
+        self.addStackChangeListener(self)
+
+    def onStackChanged(self, sender, index, visible=None):
+        if visible is None:
+            visible = sender.getWidget(index).getVisible()
+        text = ", ".join(self.getTags())
+        suffix = "" if (visible or not text) else (": %s" % text)
+        sender.setStackText(index, self.TAGS + suffix)
+
+    def getTags(self):
+        return self.tags.getItems()
+
+    def setTags(self, items):
+        self.tags.resetItems(items)
+