Stefan Schuermans commited on 2013-11-23 16:07:45
Showing 3 changed files, with 66 additions and 64 deletions.
... | ... |
@@ -1,6 +1,7 @@ |
1 | 1 |
#! /usr/bin/env python |
2 | 2 |
|
3 | 3 |
import re |
4 |
+import pango |
|
4 | 5 |
|
5 | 6 |
import time_fmt |
6 | 7 |
|
... | ... |
@@ -40,11 +41,11 @@ class Playlist: |
40 | 41 |
self.entries.append({"type": "normal", |
41 | 42 |
"name": name, |
42 | 43 |
"duration": duration}) |
43 |
- print("entry normal %s %f" % (self.entries[-1]["name"], |
|
44 |
- self.entries[-1]["duration"])) |
|
44 |
+ #print("DEBUG playlist entry normal %s %f" % |
|
45 |
+ # (self.entries[-1]["name"], self.entries[-1]["duration"])) |
|
45 | 46 |
else: |
46 | 47 |
self.entries.append({"type": "stop"}) |
47 |
- print("entry stop") |
|
48 |
+ #print("DEBUG playlist entry stop") |
|
48 | 49 |
f.close() |
49 | 50 |
|
50 | 51 |
def update(self, store): |
... | ... |
@@ -59,6 +60,6 @@ class Playlist: |
59 | 60 |
else: |
60 | 61 |
name = "" |
61 | 62 |
duration = "STOP" |
62 |
- store.append([idx, name, duration]) |
|
63 |
+ store.append([idx, pango.WEIGHT_NORMAL, name, duration]) |
|
63 | 64 |
idx = idx + 1 |
64 | 65 |
|
... | ... |
@@ -24,10 +24,35 @@ |
24 | 24 |
<property name="visible">True</property> |
25 | 25 |
<property name="can_focus">True</property> |
26 | 26 |
<property name="model">PlaylistStore</property> |
27 |
- <signal name="cursor-changed" handler="onPlaylistClick" swapped="no"/> |
|
28 | 27 |
<signal name="row-activated" handler="onPlaylistDblClick" swapped="no"/> |
29 | 28 |
<child internal-child="selection"> |
30 |
- <object class="GtkTreeSelection" id="treeview-selection2"/> |
|
29 |
+ <object class="GtkTreeSelection" id="PlaylistViewSelection"/> |
|
30 |
+ </child> |
|
31 |
+ <child> |
|
32 |
+ <object class="GtkTreeViewColumn" id="PlaylistColumnName"> |
|
33 |
+ <property name="title" translatable="yes">Name</property> |
|
34 |
+ <property name="sort_order">descending</property> |
|
35 |
+ <child> |
|
36 |
+ <object class="GtkCellRendererText" id="PlaylistCellRendererTextName"/> |
|
37 |
+ <attributes> |
|
38 |
+ <attribute name="text">2</attribute> |
|
39 |
+ <attribute name="weight">1</attribute> |
|
40 |
+ </attributes> |
|
41 |
+ </child> |
|
42 |
+ </object> |
|
43 |
+ </child> |
|
44 |
+ <child> |
|
45 |
+ <object class="GtkTreeViewColumn" id="PlaylistColumnDuration"> |
|
46 |
+ <property name="title" translatable="yes">Duration</property> |
|
47 |
+ <child> |
|
48 |
+ <object class="GtkCellRendererText" id="PlaylistCellRendererTextDuration"/> |
|
49 |
+ <attributes> |
|
50 |
+ <attribute name="text">3</attribute> |
|
51 |
+ <attribute name="weight">1</attribute> |
|
52 |
+ <attribute name="foreground-rgba">0</attribute> |
|
53 |
+ </attributes> |
|
54 |
+ </child> |
|
55 |
+ </object> |
|
31 | 56 |
</child> |
32 | 57 |
</object> |
33 | 58 |
</child> |
... | ... |
@@ -285,28 +310,13 @@ |
285 | 310 |
<columns> |
286 | 311 |
<!-- column-name EntryIdx --> |
287 | 312 |
<column type="guint"/> |
313 |
+ <!-- column-name FontWeight --> |
|
314 |
+ <column type="gint"/> |
|
288 | 315 |
<!-- column-name Name --> |
289 | 316 |
<column type="gchararray"/> |
290 |
- <!-- column-name Dauer --> |
|
317 |
+ <!-- column-name Duration --> |
|
291 | 318 |
<column type="gchararray"/> |
292 | 319 |
</columns> |
293 |
- <data> |
|
294 |
- <row> |
|
295 |
- <col id="0">0</col> |
|
296 |
- <col id="1" translatable="yes">Erster Akt</col> |
|
297 |
- <col id="2" translatable="yes">1:00:00</col> |
|
298 |
- </row> |
|
299 |
- <row> |
|
300 |
- <col id="0">1</col> |
|
301 |
- <col id="1" translatable="yes">Zweiter Akt</col> |
|
302 |
- <col id="2" translatable="yes">23:42</col> |
|
303 |
- </row> |
|
304 |
- <row> |
|
305 |
- <col id="0">2</col> |
|
306 |
- <col id="1" translatable="yes">Weltuntergang</col> |
|
307 |
- <col id="2" translatable="yes">0.5</col> |
|
308 |
- </row> |
|
309 |
- </data> |
|
310 | 320 |
</object> |
311 | 321 |
<object class="GtkAdjustment" id="Position"> |
312 | 322 |
<property name="upper">100</property> |
... | ... |
@@ -3,6 +3,7 @@ |
3 | 3 |
import os |
4 | 4 |
from gi.repository import Gtk |
5 | 5 |
import gobject |
6 |
+import pango |
|
6 | 7 |
import time |
7 | 8 |
|
8 | 9 |
import playlist |
... | ... |
@@ -25,10 +26,8 @@ class SyncGui: |
25 | 26 |
self.widBtnPause = self.builder.get_object("Pause") |
26 | 27 |
self.widBtnPlay = self.builder.get_object("Play") |
27 | 28 |
self.widStatus = self.builder.get_object("Status") |
28 |
- self.configPlaylistColumns() |
|
29 | 29 |
handlers = { |
30 | 30 |
"onDestroy": self.onDestroy, |
31 |
- "onPlaylistClick": self.onPlaylistClick, |
|
32 | 31 |
"onPlaylistDblClick": self.onPlaylistDblClick, |
33 | 32 |
"onNewPosition": self.onNewPosition, |
34 | 33 |
"onPrevious": self.onPrevious, |
... | ... |
@@ -50,20 +49,9 @@ class SyncGui: |
50 | 49 |
self.stPosition = 0 # at begin of current entry |
51 | 50 |
self.stPlaying = False # not playing |
52 | 51 |
gobject.timeout_add(10, self.onTimer10ms) |
53 |
- self.updateDuration() |
|
52 |
+ self.updateEntry() |
|
54 | 53 |
self.updateButtonVisibility() |
55 | 54 |
|
56 |
- def configPlaylistColumns(self): |
|
57 |
- """configure the columns of the playlist widget at program start""" |
|
58 |
- i = 1 # first column is index (not shown) |
|
59 |
- for title in ["Name", "Dauer"]: |
|
60 |
- column = Gtk.TreeViewColumn(title) |
|
61 |
- self.widPlaylistView.append_column(column) |
|
62 |
- cell = Gtk.CellRendererText() |
|
63 |
- column.pack_start(cell, False) |
|
64 |
- column.add_attribute(cell, "text", i) |
|
65 |
- i = i + 1 |
|
66 |
- |
|
67 | 55 |
def showPosition(self): |
68 | 56 |
"""update the position texts next to the position slider""" |
69 | 57 |
# format current time and remaining time |
... | ... |
@@ -104,6 +92,24 @@ class SyncGui: |
104 | 92 |
# update position of slider |
105 | 93 |
self.updatePosition() |
106 | 94 |
|
95 |
+ def updateEntry(self): |
|
96 |
+ """update current entry of playlist and duration, position, ...""" |
|
97 |
+ # sanity check for entry index |
|
98 |
+ if self.stEntryIdx < -1 or self.stEntryIdx >= len(self.playlist.entries): |
|
99 |
+ self.stEntryIdx = -1 |
|
100 |
+ # make current entry bold, all others non-bold |
|
101 |
+ def update(model, path, it, user_data): |
|
102 |
+ (idx,) = model.get(it, 0) |
|
103 |
+ if idx == self.stEntryIdx: |
|
104 |
+ weight = pango.WEIGHT_BOLD |
|
105 |
+ else: |
|
106 |
+ weight = pango.WEIGHT_NORMAL |
|
107 |
+ print("DEBUG sync_gui idx=%d weight=%d" % (idx, weight)) |
|
108 |
+ model.set(it, 1, weight) |
|
109 |
+ self.widPlaylistStore.foreach(update, None) |
|
110 |
+ # update duration, position, ... |
|
111 |
+ self.updateDuration() |
|
112 |
+ |
|
107 | 113 |
def updateButtonVisibility(self): |
108 | 114 |
"""update the visibility of the buttons based on if playing or not""" |
109 | 115 |
self.widBtnPause.set_visible(self.stPlaying) |
... | ... |
@@ -113,21 +119,6 @@ class SyncGui: |
113 | 119 |
"""window will be destroyed""" |
114 | 120 |
Gtk.main_quit() |
115 | 121 |
|
116 |
- def onPlaylistClick(self, widget): |
|
117 |
- """playlist entry has been clicked or selected""" |
|
118 |
- # get index of selected entry |
|
119 |
- idx = -1 |
|
120 |
- sel = self.widPlaylistView.get_selection() |
|
121 |
- if sel is not None: |
|
122 |
- (model, it) = sel.get_selected() |
|
123 |
- if it is not None: |
|
124 |
- (idx, ) = model.get(it, 0) |
|
125 |
- print("DEBUG: playlist click idx=%d" % (idx)) |
|
126 |
- # update playlist entry |
|
127 |
- self.stEntryIdx = idx |
|
128 |
- # update duration |
|
129 |
- self.updateDuration() |
|
130 |
- |
|
131 | 122 |
def onPlaylistDblClick(self, widget, row, col): |
132 | 123 |
"""playlist entry has been double-clicked""" |
133 | 124 |
# get index of selected entry |
... | ... |
@@ -137,17 +128,17 @@ class SyncGui: |
137 | 128 |
(model, it) = sel.get_selected() |
138 | 129 |
if it is not None: |
139 | 130 |
(idx,) = model.get(it, 0) |
140 |
- print("DEBUG: playlist double-click idx=%d" % (idx)) |
|
131 |
+ print("DEBUG sync_gui playlist double-click idx=%d" % (idx)) |
|
141 | 132 |
# update playlist entry |
142 | 133 |
self.stEntryIdx = idx |
143 |
- # update duration |
|
144 |
- self.updateDuration() |
|
134 |
+ # update entry |
|
135 |
+ self.updateEntry() |
|
145 | 136 |
# start playing |
146 | 137 |
# TODO |
147 | 138 |
|
148 | 139 |
def onNewPosition(self, widget, scroll, value): |
149 | 140 |
"""slider has been moved to a new position""" |
150 |
- print("DEBUG: new position " + str(value)); |
|
141 |
+ print("DEBUG sync_gui new position " + str(value)); |
|
151 | 142 |
# clamp position to valid range |
152 | 143 |
if value < 0: |
153 | 144 |
value = 0 |
... | ... |
@@ -160,15 +151,15 @@ class SyncGui: |
160 | 151 |
|
161 | 152 |
def onPrevious(self, widget): |
162 | 153 |
"""previous button as been pressed""" |
163 |
- print("DEBUG: previous") |
|
154 |
+ print("DEBUG sync_gui previous") |
|
164 | 155 |
|
165 | 156 |
def onBackward(self, widget): |
166 | 157 |
"""backward button has been pressed""" |
167 |
- print("DEBUG: backward") |
|
158 |
+ print("DEBUG sync_gui backward") |
|
168 | 159 |
|
169 | 160 |
def onStop(self, widget): |
170 | 161 |
"""stop button has been pressed""" |
171 |
- print("DEBUG: stop") |
|
162 |
+ print("DEBUG sync_gui stop") |
|
172 | 163 |
self.stPlaying = False |
173 | 164 |
self.stPosition = 0 # stop goes back to begin |
174 | 165 |
self.updatePosition() |
... | ... |
@@ -176,24 +167,24 @@ class SyncGui: |
176 | 167 |
|
177 | 168 |
def onPause(self, widget): |
178 | 169 |
"""pause button has been pressed""" |
179 |
- print("DEBUG: pause") |
|
170 |
+ print("DEBUG sync_gui pause") |
|
180 | 171 |
self.stPlaying = False |
181 | 172 |
self.updateButtonVisibility() |
182 | 173 |
|
183 | 174 |
def onPlay(self, widget): |
184 | 175 |
"""play button has been pressed""" |
185 |
- print("DEBUG: play") |
|
176 |
+ print("DEBUG sync_gui play") |
|
186 | 177 |
self.stPlaying = True |
187 | 178 |
self.updatePosition() |
188 | 179 |
self.updateButtonVisibility() |
189 | 180 |
|
190 | 181 |
def onForward(self, widget): |
191 | 182 |
"""forward button has been pressed""" |
192 |
- print("DEBUG: forward") |
|
183 |
+ print("DEBUG sync_gui forward") |
|
193 | 184 |
|
194 | 185 |
def onNext(self, widget): |
195 | 186 |
"""next button has been pressed""" |
196 |
- print("DEBUG: next") |
|
187 |
+ print("DEBUG sync_gui next") |
|
197 | 188 |
|
198 | 189 |
def onTimer10ms(self): |
199 | 190 |
"""timer callback, every 10ms""" |
200 | 191 |