show current position as h:mm:ss.ss
Stefan Schuermans

Stefan Schuermans commited on 2013-11-14 21:38:33
Showing 4 changed files, with 84 additions and 2 deletions.

... ...
@@ -0,0 +1,2 @@
1
+*.pyc
2
+.*.swp
... ...
@@ -36,6 +36,24 @@
36 36
             <property name="position">0</property>
37 37
           </packing>
38 38
         </child>
39
+        <child>
40
+          <object class="GtkBox" id="PositionBox">
41
+            <property name="visible">True</property>
42
+            <property name="can_focus">False</property>
43
+            <child>
44
+              <object class="GtkLabel" id="PositionAt">
45
+                <property name="visible">True</property>
46
+                <property name="can_focus">False</property>
47
+                <property name="margin_left">3</property>
48
+                <property name="margin_right">3</property>
49
+                <property name="label" translatable="yes">0:00:00.00</property>
50
+              </object>
51
+              <packing>
52
+                <property name="expand">False</property>
53
+                <property name="fill">True</property>
54
+                <property name="position">0</property>
55
+              </packing>
56
+            </child>
39 57
             <child>
40 58
               <object class="GtkScale" id="PositionScale">
41 59
                 <property name="visible">True</property>
... ...
@@ -45,9 +63,31 @@
45 63
                 <property name="adjustment">Position</property>
46 64
                 <property name="restrict_to_fill_level">False</property>
47 65
                 <property name="fill_level">100</property>
48
-            <property name="round_digits">2</property>
49 66
                 <property name="digits">2</property>
67
+                <property name="draw_value">False</property>
50 68
                 <property name="value_pos">bottom</property>
69
+                <signal name="change-value" handler="onNewPosition" swapped="no"/>
70
+              </object>
71
+              <packing>
72
+                <property name="expand">True</property>
73
+                <property name="fill">True</property>
74
+                <property name="position">1</property>
75
+              </packing>
76
+            </child>
77
+            <child>
78
+              <object class="GtkLabel" id="PositionRemaining">
79
+                <property name="visible">True</property>
80
+                <property name="can_focus">False</property>
81
+                <property name="margin_left">3</property>
82
+                <property name="margin_right">3</property>
83
+                <property name="label" translatable="yes">0:00:00.00</property>
84
+              </object>
85
+              <packing>
86
+                <property name="expand">False</property>
87
+                <property name="fill">True</property>
88
+                <property name="position">2</property>
89
+              </packing>
90
+            </child>
51 91
           </object>
52 92
           <packing>
53 93
             <property name="expand">False</property>
... ...
@@ -1,9 +1,10 @@
1 1
 #! /usr/bin/env python
2 2
 
3 3
 import os
4
-
5 4
 from gi.repository import Gtk
6 5
 
6
+import time_fmt
7
+
7 8
 scriptdir = os.path.dirname(os.path.abspath(__file__))
8 9
 
9 10
 class SyncGui:
... ...
@@ -11,11 +12,15 @@ class SyncGui:
11 12
     self.builder = Gtk.Builder()
12 13
     self.builder.add_from_file(scriptdir + "/sync_gui.glade")
13 14
     self.position = self.builder.get_object("Position")
15
+    self.positionScale = self.builder.get_object("PositionScale")
16
+    self.positionAt = self.builder.get_object("PositionAt")
17
+    self.positionRemaining = self.builder.get_object("PositionRemaining")
14 18
     self.btnPause = self.builder.get_object("Pause")
15 19
     self.btnPlay = self.builder.get_object("Play")
16 20
     self.status = self.builder.get_object("Status")
17 21
     handlers = {
18 22
       "onDestroy":     self.onDestroy,
23
+      "onNewPosition": self.onNewPosition,
19 24
       "onPrevious":    self.onPrevious,
20 25
       "onBackward":    self.onBackward,
21 26
       "onStop":        self.onStop,
... ...
@@ -26,10 +31,29 @@ class SyncGui:
26 31
     }
27 32
     self.builder.connect_signals(handlers)
28 33
     self.status.push(0, "TODO...")
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)
29 49
 
30 50
   def onDestroy(self, widget):
31 51
     Gtk.main_quit()
32 52
 
53
+  def onNewPosition(self, widget, scroll, value):
54
+    print("new position " + str(value));
55
+    self.showPosition(value)
56
+
33 57
   def onPrevious(self, widget):
34 58
     print("previous")
35 59
 
... ...
@@ -0,0 +1,16 @@
1
+#! /usr/bin/env python
2
+
3
+def sec2str(sec):
4
+  sign = ""
5
+  if sec < 0:
6
+    sign = "-";
7
+    sec = -sec;
8
+  sec1 = int(sec)
9
+  sec100 = round((sec - sec1) * 100)
10
+  minu = sec1 // 60
11
+  sec1 = sec1 % 60
12
+  hour = minu // 60
13
+  minu = minu % 60
14
+  return "%s%u:%02u:%02u.%02u" % (sign, hour, minu, sec1, sec100)
15
+
16
+
0 17