diff --git a/bin/ascoltami b/bin/ascoltami --- a/bin/ascoltami +++ b/bin/ascoltami @@ -32,6 +32,8 @@ from twisted.web import xmlrpc, server import run_local from light9 import networking, showconfig, wavelength +from light9.namespaces import L9, MUS +from light9.uihelpers import toplevelat from pympd import Mpd @@ -131,9 +133,12 @@ class Player: if self.state.get() != stat.state: self.state.set(stat.state) - if self.state.get() != stat.state: - self.state.set(stat.state) - + if hasattr(stat, 'time_elapsed'): + elapsed = stat.time_elapsed + songnum = stat.song + total = stat.time_total + if self.mpd_is_lying and elapsed < 3: + self.mpd_is_lying = False # mpd lies about elapsed, song, and total during the last # .5sec of each song. so we coast through that part @@ -269,16 +274,13 @@ class GoButton: -def buildsonglist(root,songfiles,player): +def buildsonglist(root, graph, songs, player): songlist=tk.Frame(root,bd=2,relief='raised',bg='black') - prefixlen=len(os.path.commonprefix(songfiles)) - # include to the last os.sep- dont crop path elements in the middle - prefixlen=songfiles[0].rfind(os.sep)+1 - maxsfwidth=max([len(x[prefixlen:]) for x in songfiles]) + maxsfwidth=max([len(graph.label(song)) for song in songs]) - for i,sf in enumerate(songfiles): - b=tk.Button(songlist,text=sf[prefixlen:],width=maxsfwidth, + for i,song in enumerate(songs): + b=tk.Button(songlist,text=graph.label(song),width=maxsfwidth, anchor='w',pady=0,bd=0,relief='flat', font="arial 14 bold") b.bind("",lambda ev,b=b: @@ -299,7 +301,7 @@ def buildsonglist(root,songfiles,player) def color_buttons(x, y, z, song=song, b=b): name = player.filename_var.get() - if name == sf[prefixlen:]: + if name == graph.value(song, L9['showPath']): b['bg'] = 'grey50' else: b['bg'] = 'black' @@ -460,15 +462,20 @@ class ControlButtons(tk.Frame): ############################ -if len(songfiles)<1: - songfiles = [f for f in os.listdir(showconfig.musicDir()) - if f.endswith('wav')] - songfiles.sort() +def main(): + global graph + parser = OptionParser() + graph = showconfig.getGraph() (options, songfiles) = parser.parse_args() -songlist = buildsonglist(root,songfiles,player) -songlist.pack(fill='both',exp=1) + if len(songfiles)<1: + graph = showconfig.getGraph() + playList = graph.value(L9['show/dance2007'], L9['playList']) + songs = list(graph.items(playList)) + else: + raise NotImplementedError("don't know how to make rdf song nodes from cmdline song paths") + root=tk.Tk() root.wm_title("ascoltami") @@ -476,7 +483,8 @@ songlist.pack(fill='both',exp=1) root.config(bg="black") player=Player() - songlist = buildsonglist(root, songfiles, player) + songlist = buildsonglist(root, graph, songs, player) + songlist.pack(fill='both',exp=1) seeker = Seeker(root, player)