Пример #1
0
    def test_check_sensible_menu_items(self):
        col = SongListColumn("title")

        menu = self.songlist._menu(col)
        submenus = [item.get_submenu() for item in menu.get_children()]
        names = {
            item.get_label()
            for child in submenus
            if child and not isinstance(child, Gtk.SeparatorMenuItem)
            for item in child.get_children()
        }
        assert {"Title", "Genre", "Comment", "Artist"} < names
Пример #2
0
    def _menu(self, column: SongListColumn) -> Gtk.Menu:
        menu = Gtk.Menu()

        def selection_done_cb(menu):
            menu.destroy()

        menu.connect('selection-done', selection_done_cb)

        current_set = set(SongList.headers)

        def tag_title(tag: str):
            if "<" in tag:
                return util.pattern(tag)
            return util.tag(tag)
        current = [(tag_title(c), c) for c in SongList.headers]

        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)

        for header in current:
            add_header_toggle(menu, header, True)

        sep = SeparatorMenuItem()
        sep.show()
        menu.append(sep)

        trackinfo = """title genre comment ~title~version ~#track
            ~#playcount ~#skipcount ~rating ~#length ~playlists
            bpm initialkey""".split()
        peopleinfo = """artist ~people performer arranger author composer
            conductor lyricist originalartist""".split()
        albuminfo = """album ~album~discsubtitle labelid ~#disc ~#discs
            ~#tracks albumartist""".split()
        dateinfo = """date originaldate recordingdate ~year ~originalyear
            ~#laststarted ~#lastplayed ~#added ~#mtime""".split()
        fileinfo = """~format ~#bitdepth ~#bitrate ~#filesize
            ~filename ~basename ~dirname ~uri ~codec ~encoding ~#channels
            ~#samplerate""".split()
        copyinfo = """copyright organization location isrc
            contact website""".split()
        all_headers: List[str] = sum(
            [trackinfo, peopleinfo, albuminfo, dateinfo, fileinfo, copyinfo],
            [])

        for name, group in [
            (_("All _Headers"), all_headers),
            (_("_Track Headers"), trackinfo),
            (_("_Album Headers"), albuminfo),
            (_("_People Headers"), peopleinfo),
            (_("_Date Headers"), dateinfo),
            (_("_File Headers"), fileinfo),
            (_("_Production Headers"), copyinfo),
        ]:
            item = Gtk.MenuItem(label=name, use_underline=True)
            item.show()
            menu.append(item)
            submenu = Gtk.Menu()
            item.set_submenu(submenu)
            for header in sorted(zip(map(util.tag, group), group)):
                add_header_toggle(submenu, header, header[1] in current_set)

        sep = SeparatorMenuItem()
        sep.show()
        menu.append(sep)

        custom = Gtk.MenuItem(
            label=_(u"_Customize Headers…"), use_underline=True)
        custom.show()
        custom.connect('activate', self.__add_custom_column)
        menu.append(custom)

        item = Gtk.CheckMenuItem(label=_("_Expand Column"), use_underline=True)
        item.set_active(column.get_expand())
        item.set_sensitive(column.get_resizable())

        def set_expand_cb(item, column):
            do_expand = item.get_active()
            if not do_expand:
                # in case we unexpand, get the current width and set it
                # so the column doesn't give up all its space
                # to the left over expanded columns
                column.set_fixed_width(column.get_width())
            else:
                # in case we expand this seems to trigger a re-distribution
                # between all expanded columns
                column.set_fixed_width(-1)
            column.set_expand(do_expand)
            self.columns_autosize()

        sep = SeparatorMenuItem()
        sep.show()
        menu.append(sep)

        item.connect('activate', set_expand_cb, column)
        item.show()
        menu.append(item)

        return menu