[Ap-python-commits] python/aptk playlist.py,NONE,1.1
Status: Beta
Brought to you by:
sjah
From: <sj...@us...> - 2002-07-16 17:10:29
|
Update of /cvsroot/ap-python/python/aptk In directory usw-pr-cvs1:/tmp/cvs-serv31240 Added Files: playlist.py Log Message: Add playlist module. --- NEW FILE: playlist.py --- # playlist.py # Copyright (C) 2002 Evgeny Chukreev <co...@ec...> # # This program 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 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # # $Id: playlist.py,v 1.1 2002/07/16 17:10:21 sjah Exp $ # __author__ = "Evgeny Chukreev <co...@ec...>" __date__ = "$Date: 2002/07/16 17:10:21 $" __version__ = "$Revision: 1.1 $" __license__ = "GNU" import gtk ########################################################################### class SmartList (gtk.GtkCList): def __init__ (self, titles, tr = None): """Initializer.""" # Remember self.titles = titles # Translate if needed if tr: translated = [tr.has_key (title) and tr [title] or title for title in titles] else: translated = titles # Call base class init-er gtk.GtkCList.__init__ (self, len (translated), translated) def append (self, values): """Append values. Where 'value' variable is a dict of titles and associated values.""" translated = [values [title] for title in self.titles] gtk.GtkCList.append (self, translated) def insert (self, row, values): """Insert values in row. Where 'value' variable is a dict of titles and associated values.""" translated = [values [title] for title in self.titles] gtk.GtkCList.insert (self, row, translated) def set_column_width (self, title, width): """Set width for column with this title.""" gtk.GtkCList.set_column_width (self, self.titles.index (title), width) def set_widthes (self, widthes): """Set width for columns.""" for title in self.titles: self.set_column_width (title, widthes [title]) ############################################################################### class PlaylistWindow (gtk.GtkWindow): def __init__ (self, pl): """Initializer.""" # Remember self.pl = pl # Init base class gtk.GtkWindow.__init__ (self) # Create list self.list = SmartList (["playtime", "track", "title", "album", "artist", "year", "genre"], {"playtime" : "Time", "track" : "Track", "title" : "Title", "album" : "Album", "artist" : "Artist", "year" : "Year", "genre" : "Genre"}) self.add (self.list) self.list.show () # Register new playlist interface pl.register (self) def cb_insert (self, items, pos): """Called by alsaplayer when new items arrived.""" gtk.threads_enter () for item in items: values = {'title' : item.title, 'filename' : item.filename, 'artist' : item.artist, 'album' : item.album, 'genre' : item.genre, 'comment' : item.comment, 'track' : item.track, 'year' : item.year, 'playtime' : "%02u:%02u" % divmod (item.playtime, 60)} self.list.insert (pos, values) pos += 1 gtk.threads_leave () |