[Ap-python-commits] python/aptk playlist.py,1.2,1.3
Status: Beta
Brought to you by:
sjah
|
From: <sj...@us...> - 2002-07-19 07:34:09
|
Update of /cvsroot/ap-python/python/aptk
In directory usw-pr-cvs1:/tmp/cvs-serv30199
Modified Files:
playlist.py
Log Message:
New properties theme for playlist widget.
Index: playlist.py
===================================================================
RCS file: /cvsroot/ap-python/python/aptk/playlist.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** playlist.py 18 Jul 2002 09:16:46 -0000 1.2
--- playlist.py 19 Jul 2002 07:34:03 -0000 1.3
***************
*** 24,50 ****
__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)
--- 24,68 ----
__license__ = "GNU"
! import gtk, GDK
###########################################################################
class SmartList (gtk.GtkCList):
! def __init__ (self, columns):
"""Initializer."""
# Remember
! self.columns = columns
# Call base class init-er
! gtk.GtkCList.__init__ (self, len (columns), columns)
!
! def set_titles (self, titles):
! """Set titles from dict."""
!
! for column in self.columns:
! if titles.has_key (column):
! value = titles [column]
!
! if type (value) is type (''):
! # This is a text label
!
! gtk.GtkCList.set_column_title (self, self.columns.index (column), value)
! else:
! # This is an xpm filename
!
! window = self.get_window ()
!
! if window is None:
! self.realize ()
! window = self.get_window ()
!
! pixmap = gtk.GtkPixmap (self, value [0])
! gtk.GtkCList.set_column_widget (self, self.columns.index (column), pixmap)
! pixmap.show ()
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)
***************
*** 53,86 ****
"""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])
! def set_pixmap (self, r, title_name, pixmap, mask = None):
"""Set pixmap."""
! gtk.GtkCList.set_pixmap (self, r, self.titles.index (title_name), pixmap, mask)
! def set_text (self, r, title_name, text):
"""Set text."""
! gtk.GtkCList.set_text (self, r, self.titles.index (title_name), text)
###############################################################################
class PlaylistWindow (gtk.GtkWindow):
! def __init__ (self, pl, mark_xpmfile):
"""Initializer."""
# Remember
self.pl = pl
--- 71,144 ----
"""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)
###############################################################################
+ default_properties = {
+ 'columns' : ['current', 'playtime', 'track', 'title', 'album', 'artist', 'year', 'genre'],
+ 'title for playtime' : 'Playtime',
+ 'title for track' : 'Track',
+ 'title for title' : 'Title',
+ 'title for current' : ' ',
+ 'title for album' : 'Album',
+ 'title for artist' : 'Artist',
+ 'title for year' : 'Year',
+ 'title for genre' : 'Genre',
+ 'mark for current' : '*'
+ }
+
class PlaylistWindow (gtk.GtkWindow):
! def __init__ (self, pl, prop):
"""Initializer."""
+ # Helper function
+ def prop_value (key, prop=prop):
+ if prop.has_key (key): return prop [key]
+ else: return default_properties [key]
+
# Remember
self.pl = pl
***************
*** 92,125 ****
# Vbox
self.vbox = gtk.GtkVBox ()
- self.vbox.show ()
self.add (self.vbox)
# Scrolled window for list
self.scrolled = gtk.GtkScrolledWindow ()
self.scrolled.show ()
self.scrolled.set_policy (1, 0)
- self.vbox.add (self.scrolled)
# Create list
! self.list = SmartList (["current", "playtime", "track", "title", "album", "artist", "year", "genre"],
! {"current" : " ",
! "playtime" : "Time",
! "track" : "Track",
! "title" : "Title",
! "album" : "Album",
! "artist" : "Artist",
! "year" : "Year",
! "genre" : "Genre"})
self.list.show ()
self.list.column_titles_passive ()
- self.scrolled.add (self.list)
# Create pixmap to mark the current song
! self.realize ()
! self.np_pixmap, self.np_mask = gtk.create_pixmap_from_xpm (self, None, mark_xpmfile)
# Register new playlist interface
pl.register (self)
def cb_insert (self, items, pos):
"""Called by alsaplayer when new items arrived."""
--- 150,187 ----
# Vbox
self.vbox = gtk.GtkVBox ()
self.add (self.vbox)
+ self.vbox.show ()
# 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_value ('columns'))
! self.scrolled.add (self.list)
!
! self.list.set_titles ({"current" : prop ['title for current'],
! "playtime" : prop ['title for playtime'],
! "track" : prop ['title for track'],
! "title" : prop ['title for title'],
! "album" : prop ['title for album'],
! "artist" : prop ['title for artist'],
! "year" : prop ['title for year'],
! "genre" : prop ['title for genre']})
!
self.list.show ()
self.list.column_titles_passive ()
# Create pixmap to mark the current song
! self.current_mark = prop_value ('mark for current')
# 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."""
***************
*** 154,158 ****
if self.current != pos - 1:
# Blank previous mark
- print self.current
if self.current is not None:
self.list.set_text (self.current, 'current', '')
--- 216,219 ----
***************
*** 160,164 ****
# Mark row
self.current = pos - 1
! self.list.set_pixmap (self.current, 'current', self.np_pixmap, self.np_mask)
gtk.threads_leave ()
--- 221,233 ----
# 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 ()
|