#! /usr/bin/env python import os from gi.repository import Gtk import playlist import time_fmt scriptdir = os.path.dirname(os.path.abspath(__file__)) class SyncGui: def __init__(self): self.builder = Gtk.Builder() self.builder.add_from_file(scriptdir + "/sync_gui.glade") self.playlistView = self.builder.get_object("PlaylistView") self.playlistStore = self.builder.get_object("PlaylistStore") self.position = self.builder.get_object("Position") self.positionScale = self.builder.get_object("PositionScale") self.positionAt = self.builder.get_object("PositionAt") self.positionRemaining = self.builder.get_object("PositionRemaining") self.btnPause = self.builder.get_object("Pause") self.btnPlay = self.builder.get_object("Play") self.status = self.builder.get_object("Status") self.configPlaylistColumns() handlers = { "onDestroy": self.onDestroy, "onNewPosition": self.onNewPosition, "onPrevious": self.onPrevious, "onBackward": self.onBackward, "onStop": self.onStop, "onPause": self.onPause, "onPlay": self.onPlay, "onForward": self.onForward, "onNext": self.onNext, } self.builder.connect_signals(handlers) self.playlist = playlist.Playlist() self.playlist.read("playlist.txt") self.playlist.update(self.playlistStore) self.status.push(0, "TODO...") self.showCurrentPosition() def configPlaylistColumns(self): i = 0 for title in ["Name", "Dauer"]: column = Gtk.TreeViewColumn(title) self.playlistView.append_column(column) cell = Gtk.CellRendererText() column.pack_start(cell, False) column.add_attribute(cell, "text", i) i = i + 1 def showPosition(self, sec): if sec < 0: sec = 0 if sec > self.position.get_upper(): sec = self.position.get_upper() posAt = time_fmt.sec2str(sec) posRemaining = time_fmt.sec2str(self.position.get_upper() - sec) self.positionAt.set_text(posAt) self.positionRemaining.set_text(posRemaining) def showCurrentPosition(self): sec = self.positionScale.get_value() self.showPosition(sec) def onDestroy(self, widget): Gtk.main_quit() def onNewPosition(self, widget, scroll, value): print("new position " + str(value)); self.showPosition(value) def onPrevious(self, widget): print("previous") def onBackward(self, widget): print("backward") def onStop(self, widget): print("stop") self.btnPause.set_visible(False) self.btnPlay.set_visible(True) def onPause(self, widget): print("pause") self.btnPause.set_visible(False) self.btnPlay.set_visible(True) def onPlay(self, widget): print("play") self.btnPause.set_visible(True) self.btnPlay.set_visible(False) def onForward(self, widget): print("forward") def onNext(self, widget): print("next") if __name__ == "__main__": app = SyncGui() Gtk.main()