ab7eb54dc73b3ad65e5c06e0a4fa2b838242b984
Stefan Schuermans initial PyGtk window

Stefan Schuermans authored 10 years ago

1) #! /usr/bin/env python
2) 
3) import os
4) from gi.repository import Gtk
5) 
Stefan Schuermans reading playlist

Stefan Schuermans authored 10 years ago

6) import playlist
Stefan Schuermans show current position as h:...

Stefan Schuermans authored 10 years ago

7) import time_fmt
8) 
Stefan Schuermans initial PyGtk window

Stefan Schuermans authored 10 years ago

9) scriptdir = os.path.dirname(os.path.abspath(__file__))
10) 
11) class SyncGui:
12)   def __init__(self):
13)     self.builder = Gtk.Builder()
14)     self.builder.add_from_file(scriptdir + "/sync_gui.glade")
15)     self.position = self.builder.get_object("Position")
Stefan Schuermans show current position as h:...

Stefan Schuermans authored 10 years ago

16)     self.positionScale = self.builder.get_object("PositionScale")
17)     self.positionAt = self.builder.get_object("PositionAt")
18)     self.positionRemaining = self.builder.get_object("PositionRemaining")
Stefan Schuermans initial PyGtk window

Stefan Schuermans authored 10 years ago

19)     self.btnPause = self.builder.get_object("Pause")
20)     self.btnPlay = self.builder.get_object("Play")
21)     self.status = self.builder.get_object("Status")
22)     handlers = {
Stefan Schuermans show current position as h:...

Stefan Schuermans authored 10 years ago

23)       "onDestroy":     self.onDestroy,
24)       "onNewPosition": self.onNewPosition,
25)       "onPrevious":    self.onPrevious,
26)       "onBackward":    self.onBackward,
27)       "onStop":        self.onStop,
28)       "onPause":       self.onPause,
29)       "onPlay":        self.onPlay,
30)       "onForward":     self.onForward,
31)       "onNext":        self.onNext,
Stefan Schuermans initial PyGtk window

Stefan Schuermans authored 10 years ago

32)     }
33)     self.builder.connect_signals(handlers)
Stefan Schuermans reading playlist

Stefan Schuermans authored 10 years ago

34)     self.playlist = playlist.Playlist()
35)     self.playlist.read("playlist.txt")
Stefan Schuermans initial PyGtk window

Stefan Schuermans authored 10 years ago

36)     self.status.push(0, "TODO...")
Stefan Schuermans show current position as h:...

Stefan Schuermans authored 10 years ago

37)     self.showCurrentPosition()
38) 
39)   def showPosition(self, sec):
40)     if sec < 0:
41)       sec = 0
42)     if sec > self.position.get_upper():
43)       sec = self.position.get_upper()
44)     posAt = time_fmt.sec2str(sec)
45)     posRemaining = time_fmt.sec2str(self.position.get_upper() - sec)
46)     self.positionAt.set_text(posAt)
47)     self.positionRemaining.set_text(posRemaining)
48) 
49)   def showCurrentPosition(self):
50)     sec = self.positionScale.get_value()
51)     self.showPosition(sec)
Stefan Schuermans initial PyGtk window

Stefan Schuermans authored 10 years ago

52) 
53)   def onDestroy(self, widget):
54)     Gtk.main_quit()
55) 
Stefan Schuermans show current position as h:...

Stefan Schuermans authored 10 years ago

56)   def onNewPosition(self, widget, scroll, value):
57)     print("new position " + str(value));
58)     self.showPosition(value)
59)