예제 #1
0
    def __init__(self, queue_only=False):
        BasePlaylistWidget.__init__(self, queue_only=queue_only)

        self._menu = SimplePopupMenu()
        self._menu.simple_add(
            'Recommend from this song',
            self._on_menu_recommend,
            stock_id='gtk-add'
        )
        self._menu.simple_add(
            'Clear & Recommend from this song',
            self._on_menu_recommend_clear,
            stock_id='gtk-go-down'
        )
        self._menu.simple_add(
            'Recommend from attribute search',
            self._on_menu_recommend_attrs,
            stock_id='gtk-color-picker'
        )
        self._menu.simple_add(
            'Recommend from heuristic',
            self._on_menu_recommend_heuristic,
            stock_id='gtk-about'
        )
        self._menu.simple_add(
            'Recommend from random',
            self._on_menu_recommend_random,
            stock_id='gtk-dialog-error'
        )
        self.set_menu(self._menu)
예제 #2
0
    def _create_menu(self):
        # Note that the visual appearance is already similar to the final menu.
        # :-)

        is_playing = False
        with g.client.lock_status() as status:
            if status.state == Status.Playing:
                is_playing = True

        self._menu = SimplePopupMenu()
        self._menu.simple_add(
            'Show Window',
            callback=lambda *_: g.gtk_app.activate(),
            stock_id='gtk-execute'
        )
        self._menu.simple_add(
            'Preferences',
            callback=lambda *_: g.gtk_sidebar.switch_to('Settings'),
            stock_id='gtk-preferences'
        )
        # ------------------------------
        self._menu.simple_add_separator()
        self._menu.simple_add(
            'Play' if is_playing else 'Pause',
            callback=lambda *_: g.client.player_pause(),
            stock_id='gtk-media-play' if is_playing else 'gtk-media-pause'
        )
        self._menu.simple_add(
            'Previous',
            callback=lambda *_: g.client.player_previous(),
            stock_id='gtk-media-previous'
        )
        self._menu.simple_add(
            'Next',
            callback=lambda *_: g.client.player_next(),
            stock_id='gtk-media-next'
        )
        self._menu.simple_add(
            'Stop',
            callback=lambda *_: g.client.player_stop(),
            stock_id='gtk-media-stop'
        )
        # ------------------------------
        self._menu.simple_add_separator()
        self._menu.simple_add(
            'Quit',
            callback=lambda *_: g.gtk_app.quit(),
            stock_id='gtk-quit'
        )
예제 #3
0
class TrayIconController:
    def __init__(self):
        self._icon = TrayIcon()
        g.client.signal_add(
            'client-event', self._on_client_event, mask=Idle.PLAYER
        )
        self._icon.connect('scroll-event', self._on_default_scroll_event)
        self._icon.connect('size-changed', self._on_size_changed)
        self._icon.connect('popup-menu', self._on_popup)

        self._create_menu()

    #############
    #  Signals  #
    #############

    def _on_client_event(self, client, event):
        with client.lock_status() as status:
            hue, symbol = STATES[status.state]
            self._icon.symbol = symbol
            self._icon.hue = hue

    def _on_default_scroll_event(self, icon, event):
        if event.direction == Gdk.ScrollDirection.UP:
            sign = +1
        elif event.direction == Gdk.ScrollDirection.DOWN:
            sign = -1
        else:
            sign = 0

        with g.client.lock_status() as status:
            status.volume += sign * 5

    def _on_size_changed(self, tray, new_size):
        self._icon._redraw()

    def _on_popup(self, icon, button, time):
        self._menu.popup(None, None, None, None, button, time)

    def _create_menu(self):
        # Note that the visual appearance is already similar to the final menu.
        # :-)

        is_playing = False
        with g.client.lock_status() as status:
            if status.state == Status.Playing:
                is_playing = True

        self._menu = SimplePopupMenu()
        self._menu.simple_add(
            'Show Window',
            callback=lambda *_: g.gtk_app.activate(),
            stock_id='gtk-execute'
        )
        self._menu.simple_add(
            'Preferences',
            callback=lambda *_: g.gtk_sidebar.switch_to('Settings'),
            stock_id='gtk-preferences'
        )
        # ------------------------------
        self._menu.simple_add_separator()
        self._menu.simple_add(
            'Play' if is_playing else 'Pause',
            callback=lambda *_: g.client.player_pause(),
            stock_id='gtk-media-play' if is_playing else 'gtk-media-pause'
        )
        self._menu.simple_add(
            'Previous',
            callback=lambda *_: g.client.player_previous(),
            stock_id='gtk-media-previous'
        )
        self._menu.simple_add(
            'Next',
            callback=lambda *_: g.client.player_next(),
            stock_id='gtk-media-next'
        )
        self._menu.simple_add(
            'Stop',
            callback=lambda *_: g.client.player_stop(),
            stock_id='gtk-media-stop'
        )
        # ------------------------------
        self._menu.simple_add_separator()
        self._menu.simple_add(
            'Quit',
            callback=lambda *_: g.gtk_app.quit(),
            stock_id='gtk-quit'
        )
예제 #4
0
 def _create_menu(self):
     menu = SimplePopupMenu()
     menu.simple_add('Clear', self._on_menu_clear, stock_id='gtk-clear')
     self.set_menu(menu)
예제 #5
0
    def __init__(self):
        Gtk.MenuButton.__init__(self)
        self.set_margin_top(6)
        self.set_margin_bottom(4)
        self.set_margin_left(10)
        self.set_margin_right(4)

        menu = SimplePopupMenu()
        menu.simple_add('Connect', 'gtk-connect')
        menu.simple_add_separator()
        menu.simple_add_checkbox('One')
        menu.simple_add_checkbox('Two')
        menu.simple_add_checkbox('Three')
        menu.simple_add_separator()
        menu.simple_add('Quit', 'gtk-quit')

        self.set_halign(Gtk.Align.CENTER)
        self.set_direction(Gtk.ArrowType.DOWN)
        self.set_popup(menu)
        self.set_image(
            Gtk.Image.new_from_icon_name('emblem-system-symbolic', Gtk.IconSize.MENU)
        )
예제 #6
0
class DatabasePlaylistWidget(BasePlaylistWidget):
    def __init__(self, queue_only=False):
        BasePlaylistWidget.__init__(self, queue_only=queue_only)

        self._menu = SimplePopupMenu()
        self._menu.simple_add(
            'Recommend from this song',
            self._on_menu_recommend,
            stock_id='gtk-add'
        )
        self._menu.simple_add(
            'Clear & Recommend from this song',
            self._on_menu_recommend_clear,
            stock_id='gtk-go-down'
        )
        self._menu.simple_add(
            'Recommend from attribute search',
            self._on_menu_recommend_attrs,
            stock_id='gtk-color-picker'
        )
        self._menu.simple_add(
            'Recommend from heuristic',
            self._on_menu_recommend_heuristic,
            stock_id='gtk-about'
        )
        self._menu.simple_add(
            'Recommend from random',
            self._on_menu_recommend_random,
            stock_id='gtk-dialog-error'
        )
        self.set_menu(self._menu)

    def _on_menu_recommend_clear(self, menu_item):
        g.client.queue_clear()
        self._on_menu_recommend(menu_item)

    def _on_menu_recommend(self, menu_item):
        model, rows = self.get_selected_rows()
        for row in rows:
            # row[-1] is the uri of the song.
            munin_id = SESSION.mapping[:row[-1]]
            process_recommendation(
                itertools.chain(
                    [SESSION[munin_id]],
                    SESSION.recommend_from_seed(
                        munin_id, SESSION.data.recom_count
                    )
                )
            )

    def _on_menu_recommend_random(self, menu_item):
        model, rows = self.get_selected_rows()
        for row in rows:
            munin_id = SESSION.mapping[:row[-1]]
            process_recommendation(
                itertools.chain(
                    [SESSION[munin_id]],
                    random_iterator()
                )
            )

    def _on_menu_recommend_attrs(self, menu_item):
        if SESSION.data.attribute_search_query is None:
            INFO_BAR.message(
                'Please fill some attributes in the top right entry!',
                Gtk.MessageType.ERROR
            )
            return

        process_recommendation(
            SESSION.recommend_from_attributes(
                SESSION.data.attribute_search_query, SESSION.data.recom_count
            )
        )

    def _on_menu_recommend_heuristic(self, menu_item):
        process_recommendation(
            SESSION.recommend_from_heuristic(SESSION.data.recom_count)
        )

    def do_row_activated(self, row):
        queue_id, uri = row[-2], row[-1]
        if queue_id > 0:
            g.client.player_play(queue_id=queue_id)
        else:
            g.client.queue_add(uri)