[svn] Add current and correct plot function. immsview
authorfabien
Sun, 01 Feb 2004 11:12:45 -0500
branchimmsview
changeset 3 d488fff3852f
parent 2 fc119540f904
child 4 2bd676cc3f22
[svn] Add current and correct plot function.
immsview
--- a/immsview	Sun Feb 01 10:59:04 2004 -0500
+++ b/immsview	Sun Feb 01 11:12:45 2004 -0500
@@ -1,9 +1,12 @@
 #!/usr/bin/python
 
-_immsview_version = "$Id: immsview 1684 2004-02-01 15:59:04Z fabien $"
+_immsview_version = "$Id: immsview 1685 2004-02-01 16:12:45Z fabien $"
 
 # Copyright (C) 2004 by Fabien Ninoles
 
+# IMMSView is aim to be a replacement to XMMS playlist editor
+# with better support for IMMS plugin.
+
 # IMMSView is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation; either version 2, or (at your option)
@@ -19,6 +22,9 @@
 # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 # Boston, MA 02111-1307, USA.
 
+# The aim of immsview is to become a better playlist editor than the
+# normal
+
 # TODO:
 # * IMMS:
 #   - Add Artist, Title, SID, etc.
@@ -141,24 +147,23 @@
                 
 	def refresh(self):
                 curtime = time.time()
-                filename = self.xmms.get_playlist_file(
-                        self.xmms.get_playlist_pos())
-		tunes = self.db.get_ratings_and_info()
+		self.tunes = self.db.get_ratings_and_info()
 		self.lb.delete(0,self.lb.size())
                 l = []
-                idx = -1
-                for tune in tunes:
-                        if idx < 0:
-                                if tune['path'] == filename:
-                                        idx = tunes.index(tune)
+                for tune in self.tunes:
                         l.append("%4d: %s [%s]" %
                                 (tune['rating'], tune['path'],
                                  strtime(curtime - tune['last'])))
                 apply(self.lb.insert, [0]+ l)
-                if idx < 0:
-                        idx = 0
-		self.lb.see(idx)
-                self.lb.select_set(idx)
+                self.select_current()
+        def select_current(self):
+                fn = self.xmms.get_playlist_file(
+                        self.xmms.get_playlist_pos())
+                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)
 
 class IMMSToolbar(Tkinter.Frame):
 	def __init__(self, master = None):
@@ -169,18 +174,26 @@
 		button = Tkinter.Button(self, text = _('Refresh'),
                                         command = self.do_refresh)
 		button.pack(side = Tkinter.LEFT)
-		button = Tkinter.Button(self, text = _('Plot'), command = self.plot)
+		button = Tkinter.Button(self, text = _('Plot'),
+                                        command = self.plot)
 		button.pack(side = Tkinter.LEFT)
-	def plot():
+                button = Tkinter.Button(self, text = _('Current'),
+                                        command = self.do_get_current)
+		button.pack(side = Tkinter.LEFT)
+	def plot(self):
 		os.system('exec immsplot &')
 	def do_refresh(self):
 		if (self.refresh_command):
 			self.refresh_command()
+        def do_get_current(self):
+                if (self.get_current):
+                        self.get_current()
 
 root = Tkinter.Tk()
 iview = IMMSView(root)
 iview.pack(side = Tkinter.BOTTOM, expand = 1, fill = Tkinter.BOTH)
 toolbar = IMMSToolbar()
 toolbar.refresh_command = iview.refresh
+toolbar.get_current = iview.select_current
 toolbar.pack(side = Tkinter.TOP, fill = Tkinter.X)
 root.mainloop()