[Ap-python-commits] python/aptk info.py,1.7,1.8 playlist.py,1.5,1.6
Status: Beta
Brought to you by:
sjah
|
From: <sj...@us...> - 2002-07-22 16:26:34
|
Update of /cvsroot/ap-python/python/aptk
In directory usw-pr-cvs1:/tmp/cvs-serv9288/aptk
Modified Files:
info.py playlist.py
Log Message:
Rewrite playlist widget for gtk2.0
Index: info.py
===================================================================
RCS file: /cvsroot/ap-python/python/aptk/info.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** info.py 21 Jul 2002 18:15:43 -0000 1.7
--- info.py 22 Jul 2002 16:26:27 -0000 1.8
***************
*** 191,195 ****
# Defualt properties
__properties = aptk.misc.WidgetProperties ([
! ('*.tagsinfo.format', '%t - %a')
])
--- 191,195 ----
# Defualt properties
__properties = aptk.misc.WidgetProperties ([
! ('*.tagsinfo.format', '%a - %t')
])
Index: playlist.py
===================================================================
RCS file: /cvsroot/ap-python/python/aptk/playlist.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** playlist.py 21 Jul 2002 18:15:43 -0000 1.5
--- playlist.py 22 Jul 2002 16:26:27 -0000 1.6
***************
*** 24,215 ****
__license__ = "GNU"
! import gtk
!
! ###########################################################################
! class SmartList (gtk.CList):
! def __init__ (self, columns):
! """Initializer."""
! # Remember
! self.columns = columns
!
! # Call base class init-er
! gtk.GtkCList.__init__ (self, len (columns), columns)
! def append (self, values):
! """Append values. Where 'value' variable is a dict of titles and associated values."""
!
! translated = [values [column] for column in self.column]
! 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 [column] for column in self.columns]
!
! gtk.GtkCList.insert (self, row, translated)
!
! def set_column_width (self, column, width):
! """Set width for column."""
!
! gtk.GtkCList.set_column_width (self, self.columns.index (column), width)
! def set_widthes (self, widthes):
! """Set width for columns."""
! for column in self.columns:
! if widthes.has_key (column):
! self.set_column_width (self.columns.index (column), widthes [column])
! def set_pixmap (self, r, column, pixmap, mask = None):
! """Set pixmap."""
! gtk.GtkCList.set_pixmap (self, r, self.columns.index (column), pixmap, mask)
! def set_text (self, r, column, text):
! """Set text."""
! gtk.GtkCList.set_text (self, r, self.columns.index (column), text)
! def set_cell (self, r, column, value):
! """Set cell value. Could be text or a tuple where the first element is a filename with xpm data."""
! if type (value) is type (''):
! # This is a text label
!
! self.set_text (r, column, value)
! else:
! # This is an xpm filename
!
! window = self.get_window ()
! if window is None:
! self.realize ()
! window = self.get_window ()
! # Allocate pixmap
! p, m = gtk.create_pixmap_from_xpm (window, None, value [0])
!
! self.set_pixmap (r, column, p, m)
! ###############################################################################
class PlaylistWindow (gtk.Window):
! properties = {
! 'playlist.list.columns' : ['current', 'playtime', 'track', 'title',
! 'album', 'artist', 'year', 'genre'],
! 'playlist.playtime.label' : 'Playtime',
! 'playlist.track.label' : 'Track',
! 'playlist.title.label' : 'Title',
! 'playlist.current.label' : 'Current',
! 'playlist.album.label' : 'Album',
! 'playlist.artist.label' : 'Artist',
! 'playlist.year.label' : 'Year',
! 'playlist.genre.label' : 'Genre',
! 'playlist.filename.label' : 'Filename',
! 'playlist.comment.label' : 'Comment',
! 'playlist.npmark.label' : '*',
! 'playlist.playtime.xpmfile' : None,
! 'playlist.track.xpmfile' : None,
! 'playlist.title.xpmfile' : None,
! 'playlist.current.xpmfile' : None,
! 'playlist.album.xpmfile' : None,
! 'playlist.artist.xpmfile' : None,
! 'playlist.year.xpmfile' : None,
! 'playlist.genre.xpmfile' : None,
! 'playlist.filename.xpmfile' : None,
! 'playlist.comment.xpmfile' : None,
! 'playlist.npmark.xpmfile' : None
! }
!
! def __init__ (self, pl, prop = None, strip = ""):
"""Initializer."""
- # Create strip string for this class
- this_strip = (strip and strip + ".") + 'playlist'
-
# Remember
! self.pl = pl
! self.current = None
! # Init base class
! gtk.GtkWindow.__init__ (self)
!
! # Vbox
! self.vbox = gtk.GtkVBox ()
! self.add (self.vbox)
! self.vbox.show ()
!
! # LIST - - - - - - - - - -- - - - - - - - - - - - - - - - - - - -
! # Scrolled window for list
! self.scrolled = gtk.GtkScrolledWindow ()
! self.vbox.add (self.scrolled)
! self.scrolled.show ()
! self.scrolled.set_policy (1, 0)
!
! # Create list
! self.list = SmartList (prop, this_strip)
! self.scrolled.add (self.list)
!
! self.list.set_titles (prop, this_strip)
! self.list.show ()
! self.list.column_titles_passive ()
! # Create mark for the current song
! # - -- - - - - - - - - - - - - - - - - -- - - - - - - - - - - - -
! # Register new playlist interface
! pl.register (self)
! # Setup callbacks
! self.list.connect ("select_row", self.gtkcb_select_row)
def cb_insert (self, items, pos):
! """Called by alsaplayer when new items arrived."""
- gtk.threads_enter ()
- self.list.freeze ()
-
for item in items:
! values = {'current' : '',
! '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
-
- self.list.thaw ()
- gtk.threads_leave ()
-
- def cb_set_current (self, pos):
- """Called by alsaplayer when the playing song changed."""
! gtk.threads_enter ()
!
! if self.current != pos - 1:
! # Blank previous mark
! if self.current is not None:
! self.list.set_text (self.current, 'current', '')
!
! # Mark row
! self.current = pos - 1
! self.list.set_cell (self.current, 'current', self.current_mark)
! gtk.threads_leave ()
!
! def gtkcb_select_row (self, w, row, column, event):
! """Called by gtk, when the new row is selected."""
!
! if event.type == GDK._2BUTTON_PRESS:
! gtk.threads_leave ()
! self.pl.play (row + 1)
! gtk.threads_enter ()
--- 24,180 ----
__license__ = "GNU"
! import gtk, aptk, gobject, locale
! gdk = gtk.gdk
! # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
! class List (gtk.ScrolledWindow):
! __properties = aptk.misc.WidgetProperties ([
! ('*.list.columns', ('playtime', 'track', 'title', 'album',
! 'artist', 'year', 'genre')),
! ('*.list.playtime.label', 'Playtime'),
! ('*.list.year.label', 'Year'),
! ('*.list.track.label', 'Track'),
! ('*.list.title.label', 'Title'),
! ('*.list.album.label', 'Album'),
! ('*.list.artist.label', 'Artist'),
! ('*.list.genre.label', 'Genre'),
! ('*.list.comment.label', 'Comment'),
! ('*.list.filename.label', 'Filename'),
! ('*.list.*.file', None),
! ('*.list.*.alignment', 0.5),
! ('*.list.charset', None)
! ])
! __columns = ['year', 'track', 'title', 'album', 'artist',
! 'playtime', 'genre', 'filename', 'comment']
! __types = (gobject.TYPE_STRING,) * len (__columns)
! __COLUMN_YEAR = __columns.index ('year')
! __COLUMN_TRACK = __columns.index ('track')
! __COLUMN_TITLE = __columns.index ('title')
! __COLUMN_ALBUM = __columns.index ('album')
! __COLUMN_ARTIST = __columns.index ('artist')
! __COLUMN_PLAYTIME = __columns.index ('playtime')
! __COLUMN_GENRE = __columns.index ('genre')
! __COLUMN_FILENAME = __columns.index ('filename')
! __COLUMN_COMMENT = __columns.index ('comment')
!
! def __init__ (self, prop = None, prefix = ""):
! """Initializer."""
! # Create new properties whth our defaults added
! prop = prop and (prop + self.__properties) or self.__properties
! prefix += '.list'
! # Init base class
! gtk.ScrolledWindow.__init__ (self)
! self.set_policy (gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS)
! # Get properties
! columns = prop.get_value (prefix + ".columns")
! charset = prop.get_value (prefix + ".charset")
! if not charset:
! charset = locale.getlocale ()[1]
! self.__charset = charset
! # Create list model
! self.__store = gtk.ListStore (*self.__types)
! # Create tree view
! self.__treeview = gtk.TreeView (self.__store)
! self.add (self.__treeview)
! # Append columns
! for name in columns:
! # Create renderer
! renderer = gtk.CellRendererText ()
!
! # Create column
! label = prop.get_value ("%s.%s.label" % (prefix, name))
! file = prop.get_value ("%s.%s.file" % (prefix, name))
! alignment = prop.get_value ("%s.%s.alignment" % (prefix, name))
! if file:
! label = None
! column = gtk.TreeViewColumn (label, renderer, text = self.__columns.index (name))
! column.set_resizable (gtk.TRUE)
! column.set_alignment (alignment)
! if file:
! image = gtk.Image ()
! image.set_from_file (file)
! column.set_widget (image)
! image.show ()
! # Append column
! self.__treeview.append_column (column)
! # Show these widgets
! self.__treeview.show ()
! def insert (self, pos, title, album, artist, track, playtime,
! year, genre, comment, filename):
! """Insert new values into this list."""
!
! iter = self.__store.insert (pos)
! self.__store.set (iter,
! self.__COLUMN_TITLE, title.decode (self.__charset),
! self.__COLUMN_ALBUM, album.decode (self.__charset),
! self.__COLUMN_ARTIST, artist.decode (self.__charset),
! self.__COLUMN_TRACK, track.decode (self.__charset),
! self.__COLUMN_PLAYTIME, "%02u:%02u" % divmod (playtime, 60),
! self.__COLUMN_YEAR, year.decode (self.__charset),
! self.__COLUMN_GENRE, genre.decode (self.__charset),
! self.__COLUMN_COMMENT, comment.decode (self.__charset),
! self.__COLUMN_FILENAME, filename.decode (self.__charset))
!
! # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
class PlaylistWindow (gtk.Window):
! def __init__ (self, pl, prop = None, prefix = ""):
"""Initializer."""
# Remember
! self.__pl = pl
! # Create new properties whth our defaults added
! # prop = prop and (prop + self.__properties) or self.__properties
! prefix += '.playlist'
! # Init base class
! gtk.Window.__init__ (self)
! # Create and add list
! self.__list = List (prop, prefix)
! self.add (self.__list)
! self.__list.show ()
! # Register this object as the playlist notifier
! self.__pl.register (self)
! # Connect signals
! self.connect ("destroy", self.__gtkcb_destroy)
def cb_insert (self, items, pos):
! """Alsaplayer's callback."""
for item in items:
! self.__list.insert (pos,
! title = item.title,
! artist = item.artist,
! album = item.album,
! year = item.year,
! genre = item.genre,
! playtime = item.playtime,
! track = item.track,
! comment = item.comment,
! filename = item.filename)
pos += 1
! def __gtkcb_destroy (self, widget):
! """Called on the destroy."""
! gdk.threads_leave ()
! self.__pl.unregister (self)
! gdk.threads_enter ()
|