Ejemplo n.º 1
0
    def __init__(self):
        MenuItem.__init__(self, _('Label'))  # noqa: F821

        self.sub_menu = Menu()
        self.set_submenu(self.sub_menu)
        self.items = []

        # attach..
        self.sub_menu.connect('show', self.on_show, None)
Ejemplo n.º 2
0
 def add_header_toggle(menu: Gtk.Menu, pair: Tuple[str, str], active: bool,
                       column: SongListColumn = column):
     header, tag = pair
     item = Gtk.CheckMenuItem(label=header)
     item.tag = tag
     item.set_active(active)
     item.connect('activate', self.__toggle_header_item, column)
     item.show()
     item.set_tooltip_text(tag)
     menu.append(item)
Ejemplo n.º 3
0
 def create_tab_pos_menuitem(self):
     """Returns a menu to select which side of the notebook the tabs should be shown"""
     tab_pos_menu = Menu()
     tab_pos_menuitem = MenuItem.new_with_label(_('Position'))
     group = []
     for pos in ('top', 'right', 'bottom', 'left'):
         menuitem = RadioMenuItem.new_with_mnemonic(group, _(pos.capitalize()))
         group = menuitem.get_group()
         menuitem.connect('toggled', self._on_tabs_pos_toggled, pos)
         menuitem.set_active(pos == self.notebook.get_tab_pos().value_nick)
         tab_pos_menu.append(menuitem)
     tab_pos_menuitem.set_submenu(tab_pos_menu)
     return tab_pos_menuitem
Ejemplo n.º 4
0
    def __init__(self, menu: Gtk.Menu, error: GrammalecteError,
                 process: CorrectionProcess) -> None:
        """
        Create the menu options.

        :param menu: The menu to populate.
        :param error: The error related to the menu.
        :param process: The correction process.
        """
        menu_item = Gtk.SeparatorMenuItem()
        menu_item.show()
        menu.prepend(menu_item)
        menu_item = Gtk.ImageMenuItem(Gtk.STOCK_SPELL_CHECK)
        menu_item.set_label(_("Suggestions"))
        menu_item.set_submenu(self.build_suggestion_menu(error, process))
        menu_item.show_all()
        menu.prepend(menu_item)
Ejemplo n.º 5
0
class LabelMenu(MenuItem):
    def __init__(self):
        MenuItem.__init__(self, _('Label'))  # noqa: F821

        self.sub_menu = Menu()
        self.set_submenu(self.sub_menu)
        self.items = []

        # attach..
        self.sub_menu.connect('show', self.on_show, None)

    def get_torrent_ids(self):
        return component.get('TorrentView').get_selected_torrents()

    def on_show(self, widget=None, data=None):
        log.debug('label-on-show')
        client.label.get_labels().addCallback(self.cb_labels)

    def cb_labels(self, labels):
        for child in self.sub_menu.get_children():
            self.sub_menu.remove(child)
        for label in [NO_LABEL] + list(labels):
            if label == NO_LABEL:
                item = MenuItem(_(NO_LABEL))  # noqa: F821
            else:
                item = MenuItem(label.replace('_', '__'))
            item.connect('activate', self.on_select_label, label)
            self.sub_menu.append(item)
        self.show_all()

    def on_select_label(self, widget=None, label_id=None):
        log.debug('select label:%s,%s', label_id, self.get_torrent_ids())
        for torrent_id in self.get_torrent_ids():
            client.label.set_torrent(torrent_id, label_id)
Ejemplo n.º 6
0
    def add_suggestions(self, topmenu: Gtk.Menu, error: GrammalecteError,
                        process: CorrectionProcess) -> None:
        """
        Add the actions to the suggestion menu.

        :param topmenu: The top suggestion menu.
        :param error: The error with suggestions.
        :param process: The correction process.
        """
        # Suggestions per groups of 6 items max
        suggestions = error.suggestions
        if len(suggestions) == 0:
            menu_item = Gtk.MenuItem(_("(no suggestions)"))
            menu_item.set_sensitive(False)
            menu_item.show_all()
            topmenu.append(menu_item)
        else:
            menu = topmenu
            count = 0
            for suggestion in suggestions:
                if count == 6:
                    menu_item = Gtk.SeparatorMenuItem()
                    menu_item.show()
                    menu.append(menu_item)
                    menu_item = Gtk.MenuItem(_("More"))
                    menu_item.show_all()
                    menu.append(menu_item)
                    menu = Gtk.Menu()
                    menu_item.set_submenu(menu)
                    count = 0
                menu_item = Gtk.MenuItem(suggestion)
                menu_item.show_all()
                menu.append(menu_item)
                menu_item.connect("activate", self.on_menu_replace, error,
                                  suggestion, process)
                count += 1
Ejemplo n.º 7
0
    def generate_menu(self):
        """Generates the checklist menu for all the tabs and attaches it"""
        menu = Menu()
        # Create 'All' menuitem and a separator
        menuitem = CheckMenuItem.new_with_mnemonic(self.translate_tabs['All'])
        menuitem.set_name('All')

        all_tabs = True
        for key in self.tabs:
            if not self.tabs[key].is_visible:
                all_tabs = False
                break
        menuitem.set_active(all_tabs)
        menuitem.connect('toggled', self._on_menuitem_toggled)

        menu.append(menuitem)

        menuitem = SeparatorMenuItem()
        menu.append(menuitem)

        # Create a list in order of tabs to create menu
        menuitem_list = []
        for tab_name in self.tabs:
            menuitem_list.append((self.tabs[tab_name].weight, tab_name))
        menuitem_list.sort()

        for pos, name in menuitem_list:
            menuitem = CheckMenuItem.new_with_mnemonic(
                self.translate_tabs[name])
            menuitem.set_name(name)
            menuitem.set_active(self.tabs[name].is_visible)
            menuitem.connect('toggled', self._on_menuitem_toggled)
            menu.append(menuitem)

        self.menu_tabs.set_submenu(menu)
        self.menu_tabs.show_all()
Ejemplo n.º 8
0
    def add_actions(self, suggestion_menu: Gtk.Menu, error: GrammalecteError,
                    config: GrammalecteConfig) -> None:
        """
        Add the actions to the suggestion menu.

        :param suggestion_menu: The suggestion menu.
        :param error: The error with suggestions.
        :param config: The configuration of the correction process.
        """
        # Separator
        menu_item = Gtk.SeparatorMenuItem()
        menu_item.show()
        suggestion_menu.append(menu_item)

        # Ignore rule
        menu_item = Gtk.MenuItem(_("Ignore rule"))
        menu_item.set_sensitive(error.rule)
        menu_item.show_all()
        suggestion_menu.append(menu_item)
        menu_item.connect("activate", self.on_menu_ign_rule, error.rule,
                          config)

        # Ignore error in the file
        menu_item = Gtk.MenuItem(_("Ignore error"))
        menu_item.show_all()
        suggestion_menu.append(menu_item)
        menu_item.connect("activate", self.on_menu_ign_error,
                          list(error.context), config)

        # Add error to dictionnary
        menu_item = Gtk.MenuItem(_("Add"))
        menu_item.set_sensitive(error.option == GrammalecteError.SPELL_OPTION)
        menu_item.show_all()
        suggestion_menu.append(menu_item)
        menu_item.connect("activate", self.on_menu_add, list(error.context),
                          config)

        # Separator
        menu_item = Gtk.SeparatorMenuItem()
        menu_item.show()
        suggestion_menu.append(menu_item)

        # Open browser to see the rule
        menu_item = Gtk.MenuItem(_("See the rule"))
        menu_item.set_sensitive(error.url)
        menu_item.show_all()
        suggestion_menu.append(menu_item)
        menu_item.connect("activate", self.on_menu_info, error.url)
Ejemplo n.º 9
0
def build_menu_radio_list(
    value_list,
    callback,
    pref_value=None,
    suffix=None,
    show_notset=False,
    notset_label='∞',
    notset_lessthan=0,
    show_other=False,
):
    """Build a menu with radio menu items from a list and connect them to the callback.

    Params:
    value_list [list]: List of values to build into a menu.
    callback (function): The function to call when menu item is clicked.
    pref_value (int): A preferred value to insert into value_list
    suffix (str): Append a suffix the the menu items in value_list.
    show_notset (bool): Show the unlimited menu item.
    notset_label (str): The text for the unlimited menu item.
    notset_lessthan (int): Activates the unlimited menu item if pref_value is less than this.
    show_other (bool): Show the `Other` menu item.

    The pref_value is what you would like to test for the default active radio item.

    Returns:
        Menu: The menu radio
    """
    menu = Menu()
    # Create menuitem to prevent unwanted toggled callback when creating menu.
    menuitem = RadioMenuItem()
    group = menuitem.get_group()

    if pref_value > -1 and pref_value not in value_list:
        value_list.pop()
        value_list.append(pref_value)

    for value in sorted(value_list):
        item_text = str(value)
        if suffix:
            item_text += ' ' + suffix
        menuitem = RadioMenuItem.new_with_label(group, item_text)
        if pref_value and value == pref_value:
            menuitem.set_active(True)
        if callback:
            menuitem.connect('toggled', callback)
        menu.append(menuitem)

    if show_notset:
        menuitem = RadioMenuItem.new_with_label(group, notset_label)
        menuitem.set_name('unlimited')
        if pref_value and pref_value < notset_lessthan:
            menuitem.set_active(True)
        menuitem.connect('toggled', callback)
        menu.append(menuitem)

    if show_other:
        menuitem = SeparatorMenuItem()
        menu.append(menuitem)
        menuitem = MenuItem.new_with_label(_('Other...'))
        menuitem.set_name('other')
        menuitem.connect('activate', callback)
        menu.append(menuitem)

    return menu