Esempio n. 1
0
class MainWindowController():
    def __init__(self):
        self.store = Gtk.TreeStore(str)
        self.store.append(None, ["foobar"])
        self.store.append(None, ["barfoo"])

        self.ui = MainWindow(self.store)
        self.ui.connect("delete-event", Gtk.main_quit)


    def show(self):
        self.ui.show_all()
Esempio n. 2
0
class MainWindowController():
    def __init__(self, app, library):
        self.app = app
        self.library = library

        self.player = None

        self.ui = MainWindow(app, library.playlists)
        self.context_id = self.ui.statusbar.get_context_id("mainwindow")

        self.ui.set_tree_selection_callback(self.on_tree_selection_changed)
        self.ui.set_ppbutton_callback(self.on_playpause_button)

    def on_tree_selection_changed(self, selection):
        model, treeiter = selection.get_selected()
        if treeiter is not None and model[treeiter][0] is not None:
            vc = PlaylistViewController(model[treeiter][0])
            vc.set_click_listener(self.on_track_clicked)
            self.ui.setright(vc.ui)

    def status_msg(self, message):
        self.ui.statusbar.push(self.context_id, message)

    def fetch_albumart_thread(self, url):
        response = urllib2.urlopen(url)
        input_stream = Gio.MemoryInputStream.new_from_data(response.read(), None)
        pixbuf = GdkPixbuf.Pixbuf.new_from_stream(input_stream, None)
        if pixbuf is not None:
            self.ui.set_albumart(pixbuf.scale_simple(32, 32, GdkPixbuf.InterpType.BILINEAR))


    def on_track_clicked(self, track):
        self.ui.set_trackinfo(track.title, track.artist)
        self.player.playsong(track.id)

        if track.albumarturl is not None:
            thread = threading.Thread(target=self.fetch_albumart_thread, args=[track.albumarturl])
            thread.start()

    def show(self):
        self.ui.show_all()

    def setplayer(self, player):
        self.player = player
        player.add_messagelistener(self.on_playerstate)
        player.statusbar_func = self.status_msg

    def on_playerstate(self, state, param):
        if state == "playing":
            self.ui.set_ppbutton_play(True)
        elif state == "paused":
            self.ui.set_ppbutton_play(False)

    def on_playpause_button(self, widget):
        if self.player is not None:
            if self.player.isplaying():
                print("Pausing")
                self.player.pause()
            else:
                print("Playing")
                self.player.play()