841836320d38668407e84fc4a6bf64a6defed6f3
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 show current position as h:...

Stefan Schuermans authored 10 years ago

6) import time_fmt
7) 
Stefan Schuermans initial PyGtk window

Stefan Schuermans authored 10 years ago

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

Stefan Schuermans authored 10 years ago

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

Stefan Schuermans authored 10 years ago

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

Stefan Schuermans authored 10 years ago

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

Stefan Schuermans authored 10 years ago

31)     }
32)     self.builder.connect_signals(handlers)
33)     self.status.push(0, "TODO...")
Stefan Schuermans show current position as h:...

Stefan Schuermans authored 10 years ago

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

Stefan Schuermans authored 10 years ago

49) 
50)   def onDestroy(self, widget):
51)     Gtk.main_quit()
52) 
Stefan Schuermans show current position as h:...

Stefan Schuermans authored 10 years ago

53)   def onNewPosition(self, widget, scroll, value):
54)     print("new position " + str(value));
55)     self.showPosition(value)
56)