# HG changeset patch # User fabien # Date 1075656062 18000 # Node ID c51b96c1690e625a1db759bd5103c9774396f44d # Parent 2bd676cc3f22dd6befb8c05e9a8c2cc936d93444 [svn] Add play selected song. diff -r 2bd676cc3f22 -r c51b96c1690e immsview --- a/immsview Sun Feb 01 11:22:40 2004 -0500 +++ b/immsview Sun Feb 01 12:21:02 2004 -0500 @@ -1,6 +1,6 @@ #!/usr/bin/python -_immsview_version = "$Id: immsview 1686 2004-02-01 16:22:40Z fabien $" +_immsview_version = "$Id: immsview 1687 2004-02-01 17:21:02Z fabien $" # Copyright (C) 2004 by Fabien Ninoles @@ -32,7 +32,6 @@ # - Columns ordering (should pass to GTK probably for this). # - Rating edition # * XMMS: -# - selecting a song # - getting current playlist # - editing playlist # * File support: @@ -77,6 +76,24 @@ s += "%d\"" % (secs) return s +class XMMSControl: + def __getattr__(self, name): + return xmms.control.__dict__[name] + def get_current_file(self): + return self.get_playlist_file( + self.get_playlist_pos()) + def find_in_playlist(self, filename): + for idx in range(self.get_playlist_length()): + if filename == self.get_playlist_file(idx): + return idx + return -1 + def play_file(self, filename): + idx = self.find_in_playlist(filename) + print idx + if idx == -1: + self.enqueue_and_play((filename,)) + else: + self.set_playlist_pos(idx) class IMMSDb: def __init__(self): @@ -123,10 +140,10 @@ return results class IMMSView(Tkinter.Frame): - def __init__(self, master = None): + def __init__(self, xmms, db, master = None): Tkinter.Frame.__init__(self, master) - self.db = IMMSDb() - self.xmms = xmms.control + self.db = db + self.xmms = xmms self.create_widgets() def create_widgets(self): lf = Tkinter.Frame(self) @@ -142,6 +159,7 @@ xsb['command'] = self.lb.xview self.lb['yscrollcommand'] = ysb.set self.lb['xscrollcommand'] = xsb.set + self.lb.bind("", self.play_selection) self.refresh() @@ -157,13 +175,17 @@ apply(self.lb.insert, [0]+ l) self.select_current() def select_current(self): - fn = self.xmms.get_playlist_file( - self.xmms.get_playlist_pos()) + fn = self.xmms.get_current_file() tune = filter(lambda x: x['path'] == fn, self.tunes) if len(tune): idx = self.tunes.index(tune[0]) self.lb.see(idx) self.lb.select_set(idx) + def play_selection(self, event): + sel = self.lb.curselection() + if len(sel) > 0: + fn = self.tunes[int(sel[0])]['path'] + self.xmms.play_file(fn) class IMMSToolbar(Tkinter.Frame): def __init__(self, master = None): @@ -191,7 +213,7 @@ root = Tkinter.Tk() root.wm_title(_("IMMSview")) -iview = IMMSView(root) +iview = IMMSView(XMMSControl(), IMMSDb(), root) iview.pack(side = Tkinter.BOTTOM, expand = 1, fill = Tkinter.BOTH) toolbar = IMMSToolbar() toolbar.refresh_command = iview.refresh