Exemple #1
0
    def __init__(self, app):
        Gtk.ApplicationWindow.__init__(
            self,
            title="Naglfar (libmunin demo application)",
            application=app
        )
        self.set_default_size(1400, 900)

        # application icon:
        script_path = os.path.dirname(os.path.abspath(__file__))
        pixbuf_path = os.path.join(script_path, 'logo.png')
        pixbuf = GdkPixbuf.Pixbuf.new_from_file(pixbuf_path)
        self.set_icon(pixbuf)

        self._volume_slider = BarSlider()
        self._volume_slider.set_size_request(60, 25)
        self._volume_slider.connect(
            'percent-change', self._on_volume_click_event
        )

        self._progress_bar = ProgressSlider()
        self._progress_bar.set_size_request(200, 15)
        self._progress_bar.connect(
            'percent-change',
            self._on_percent_change
        )

        self._headerbar = Gtk.HeaderBar()
        self._headerbar.set_show_close_button(True)
        self._headerbar.pack_start(PlaybuttonBox())
        self._headerbar.pack_start(align_widget(self._progress_bar))
        self._headerbar.pack_end(align_widget(self._volume_slider))
        self._headerbar.pack_end(ModebuttonBox())

        app_box = Gtk.VBox()
        app_box.pack_start(INFO_BAR, False, False, 0)
        app_box.pack_start(NoteBookContent(), True, True, 0)
        app_box.pack_start(self._headerbar, False, False, 0)
        self.add(app_box)

        GLib.timeout_add(500, self._timeout_callback)
        g.client.signal_add('client-event', self._on_client_event)
Exemple #2
0
class MainWindow(Gtk.ApplicationWindow):
    def __init__(self, app):
        Gtk.ApplicationWindow.__init__(
            self,
            title="Naglfar (libmunin demo application)",
            application=app
        )
        self.set_default_size(1400, 900)

        # application icon:
        script_path = os.path.dirname(os.path.abspath(__file__))
        pixbuf_path = os.path.join(script_path, 'logo.png')
        pixbuf = GdkPixbuf.Pixbuf.new_from_file(pixbuf_path)
        self.set_icon(pixbuf)

        self._volume_slider = BarSlider()
        self._volume_slider.set_size_request(60, 25)
        self._volume_slider.connect(
            'percent-change', self._on_volume_click_event
        )

        self._progress_bar = ProgressSlider()
        self._progress_bar.set_size_request(200, 15)
        self._progress_bar.connect(
            'percent-change',
            self._on_percent_change
        )

        self._headerbar = Gtk.HeaderBar()
        self._headerbar.set_show_close_button(True)
        self._headerbar.pack_start(PlaybuttonBox())
        self._headerbar.pack_start(align_widget(self._progress_bar))
        self._headerbar.pack_end(align_widget(self._volume_slider))
        self._headerbar.pack_end(ModebuttonBox())

        app_box = Gtk.VBox()
        app_box.pack_start(INFO_BAR, False, False, 0)
        app_box.pack_start(NoteBookContent(), True, True, 0)
        app_box.pack_start(self._headerbar, False, False, 0)
        self.add(app_box)

        GLib.timeout_add(500, self._timeout_callback)
        g.client.signal_add('client-event', self._on_client_event)

    def _on_client_event(self, client, event):
        if event & Idle.MIXER:
            with client.lock_status() as status:
                if status is not None:
                    self._volume_slider.percent = status.volume / 100

        if event & Idle.PLAYER:
            with client.lock_currentsong() as song:
                if song is not None:
                    self.set_title('Naglfar (Playing: {} - {})'.format(
                        GLib.markup_escape_text(
                            song.artist or song.album_artist
                        ),
                        song.title
                    ))
                    self._headerbar.set_title('{title}'.format(
                        title=song.title
                    ))
                    self._headerbar.set_subtitle('{album} - {artist}'.format(
                        album=song.album,
                        artist=song.artist or song.album_artist
                    ))
                else:
                    self._headerbar.set_title('Ready to play!')
                    self._headerbar.set_subtitle(
                        'Just add something to the playlist.'
                    )

    def _on_volume_click_event(self, bar):
        with g.client.lock_status() as status:
            if status is not None:
                status.volume = bar.percent * 100

    # User clicked in the Slider
    def _on_percent_change(self, slider):
        g.client.player_seek_relative(slider.percent)

    def _timeout_callback(self):
        self._progress_bar.percent = g.heartbeat.percent
        return True