6e98624edccf0449b87c99c6cfc822585982f195
Stefan Schuermans initial PyGtk window

Stefan Schuermans authored 11 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 11 years ago

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

Stefan Schuermans authored 11 years ago

7) import time_fmt
8) 
Stefan Schuermans initial PyGtk window

Stefan Schuermans authored 11 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")
Stefan Schuermans show playlist in TreeView

Stefan Schuermans authored 10 years ago

15)     self.playlistView = self.builder.get_object("PlaylistView")
16)     self.playlistStore = self.builder.get_object("PlaylistStore")
Stefan Schuermans initial PyGtk window

Stefan Schuermans authored 11 years ago

17)     self.position = self.builder.get_object("Position")
Stefan Schuermans show current position as h:...

Stefan Schuermans authored 11 years ago

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

Stefan Schuermans authored 11 years ago

21)     self.btnPause = self.builder.get_object("Pause")
22)     self.btnPlay = self.builder.get_object("Play")
23)     self.status = self.builder.get_object("Status")
Stefan Schuermans show playlist in TreeView

Stefan Schuermans authored 10 years ago

24)     self.configPlaylistColumns()
Stefan Schuermans initial PyGtk window

Stefan Schuermans authored 11 years ago

25)     handlers = {
Stefan Schuermans show current position as h:...

Stefan Schuermans authored 11 years ago

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

Stefan Schuermans authored 11 years ago

35)     }
36)     self.builder.connect_signals(handlers)
Stefan Schuermans reading playlist

Stefan Schuermans authored 11 years ago

37)     self.playlist = playlist.Playlist()
38)     self.playlist.read("playlist.txt")
Stefan Schuermans show playlist in TreeView

Stefan Schuermans authored 10 years ago

39)     self.playlist.update(self.playlistStore)
Stefan Schuermans initial PyGtk window

Stefan Schuermans authored 11 years ago

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

Stefan Schuermans authored 11 years ago

41)     self.showCurrentPosition()
42) 
Stefan Schuermans show playlist in TreeView

Stefan Schuermans authored 10 years ago

43)   def configPlaylistColumns(self):
44)     i = 0
45)     for title in ["Name", "Dauer"]:
46)       column = Gtk.TreeViewColumn(title)
47)       self.playlistView.append_column(column)
48)       cell = Gtk.CellRendererText()
49)       column.pack_start(cell, False)
50)       column.add_attribute(cell, "text", i)
51)       i = i + 1
52) 
Stefan Schuermans show current position as h:...

Stefan Schuermans authored 11 years ago

53)   def showPosition(self, sec):
54)     if sec < 0:
55)       sec = 0
56)     if sec > self.position.get_upper():
57)       sec = self.position.get_upper()
58)     posAt = time_fmt.sec2str(sec)
59)     posRemaining = time_fmt.sec2str(self.position.get_upper() - sec)
60)     self.positionAt.set_text(posAt)
61)     self.positionRemaining.set_text(posRemaining)
62) 
63)   def showCurrentPosition(self):
64)     sec = self.positionScale.get_value()
65)     self.showPosition(sec)
Stefan Schuermans initial PyGtk window

Stefan Schuermans authored 11 years ago

66) 
67)   def onDestroy(self, widget):
68)     Gtk.main_quit()
69) 
Stefan Schuermans show current position as h:...

Stefan Schuermans authored 11 years ago

70)   def onNewPosition(self, widget, scroll, value):
71)     print("new position " + str(value));
72)     self.showPosition(value)
73)