def _load_labels(self, labels):

    if labels:
      labels = sorted(labels, key=lambda x: (Label.get_parent(x[0]), x[1]))

    items = {}
    for id, name in labels:
      item = gtk.MenuItem(name)
      handler = item.connect("activate", self.on_select_label, id)
      items[id] = (item, handler)

      parent_id = Label.get_parent(id)
      parent = items.get(parent_id)
      if parent:
        if parent[MENU_ITEM].get_submenu() is None:
          parent[MENU_ITEM].handler_disconnect(parent[HANDLER])
          parent[MENU_ITEM].set_submenu(gtk.Menu())

          # Create subitem for selecting items with submenus
          parent_item = gtk.MenuItem(parent[MENU_ITEM].get_label())
          parent_item.connect("activate", self.on_select_label, parent_id)
          parent[MENU_ITEM].get_submenu().append(parent_item)
          parent[MENU_ITEM].get_submenu().append(gtk.SeparatorMenuItem())

        parent[MENU_ITEM].get_submenu().append(item)
      else:
        self.submenu.append(item)
Exemplo n.º 2
0
    def hide_unavailable(widget):

      selected_item.hide()
      parent_item.hide()

      id = self.get_selected_torrent_label()
      if id:
        if getattr(selected_item, "handler", None):
          selected_item.disconnect(selected_item.handler)

        handler = selected_item.connect("activate", on_select_label, id)
        selected_item.handler = handler
        selected_item.show()

      elif self.label_sidebar.page_selected():
        id = self.label_sidebar.get_selected_label()

      if id:
        parent = get_parent(id)
        if parent and parent not in RESERVED_IDS:
          if getattr(parent_item, "handler", None):
            parent_item.disconnect(parent_item.handler)

          handler = parent_item.connect("activate", on_select_label, parent)
          parent_item.handler = handler
          parent_item.show()
Exemplo n.º 3
0
  def update_counts(self, counts):

    self.sorted_store.set_sort_column_id(-1, gtk.SORT_ASCENDING)
    self.label_tree.freeze_child_notify()

    self._remove_invalid_labels(counts)

    for id in sorted(counts):
      if id == NULL_PARENT: continue

      row = self.row_map.get(id)
      if row:
        self.store.set_value(row, 1, counts[id]["name"])
        self.store.set_value(row, 2, counts[id]["count"])
      else:
        if id in RESERVED_IDS:
          parent_id = NULL_PARENT
        else:
          parent_id = Label.get_parent(id)

        if parent_id in self.row_map:
          parent = self.row_map.get(parent_id)
          data = [id, counts[id]["name"], counts[id]["count"]]
          row = self.store.append(parent, data)
          self.row_map[id] = row
        else:
          log.debug("[%s] Label counts contained orphan: %s",
              PLUGIN_NAME, id)

    self.label_tree.thaw_child_notify()
    self.sorted_store.set_sort_column_id(1, gtk.SORT_ASCENDING)