[Ap-python-commits] python/aptk playlist.py,1.6,1.7
Status: Beta
Brought to you by:
sjah
|
From: <sj...@us...> - 2002-07-24 07:04:53
|
Update of /cvsroot/ap-python/python/aptk
In directory usw-pr-cvs1:/tmp/cvs-serv12226/aptk
Modified Files:
playlist.py
Log Message:
Make columns reoraderable. Change selection mode to SELECTION_MULTIPLE. Add song changing by
double clicking on the situated row. Show currently playing song with a mark in the CURRENT column.
Index: playlist.py
===================================================================
RCS file: /cvsroot/ap-python/python/aptk/playlist.py,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** playlist.py 22 Jul 2002 16:26:27 -0000 1.6
--- playlist.py 24 Jul 2002 07:04:48 -0000 1.7
***************
*** 1,3 ****
! # playlist.py
# Copyright (C) 2002 Evgeny Chukreev <co...@ec...>
#
--- 1,3 ----
! # playlist.py - APTK Playlist Widgets
# Copyright (C) 2002 Evgeny Chukreev <co...@ec...>
#
***************
*** 30,34 ****
class List (gtk.ScrolledWindow):
__properties = aptk.misc.WidgetProperties ([
! ('*.list.columns', ('playtime', 'track', 'title', 'album',
'artist', 'year', 'genre')),
('*.list.playtime.label', 'Playtime'),
--- 30,34 ----
class List (gtk.ScrolledWindow):
__properties = aptk.misc.WidgetProperties ([
! ('*.list.columns', ('current', 'playtime', 'track', 'title', 'album',
'artist', 'year', 'genre')),
('*.list.playtime.label', 'Playtime'),
***************
*** 41,44 ****
--- 41,46 ----
('*.list.comment.label', 'Comment'),
('*.list.filename.label', 'Filename'),
+ ('*.list.current.label', ''),
+ ('*.list.mark.label', '-->'),
('*.list.*.file', None),
('*.list.*.alignment', 0.5),
***************
*** 46,54 ****
])
__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')
--- 48,61 ----
])
+ # Names of the first columns
__columns = ['year', 'track', 'title', 'album', 'artist',
'playtime', 'genre', 'filename', 'comment']
! # Types of the first columns
! __types = (gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING,
! gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING,
! gobject.TYPE_STRING)
+ # Numbers for columns
__COLUMN_YEAR = __columns.index ('year')
__COLUMN_TRACK = __columns.index ('track')
***************
*** 60,64 ****
__COLUMN_FILENAME = __columns.index ('filename')
__COLUMN_COMMENT = __columns.index ('comment')
!
def __init__ (self, prop = None, prefix = ""):
"""Initializer."""
--- 67,76 ----
__COLUMN_FILENAME = __columns.index ('filename')
__COLUMN_COMMENT = __columns.index ('comment')
! __COLUMN_CURRENT = len (__columns)
!
! # Blank pixbuf
! __blank_pixbuf = gdk.Pixbuf (gdk.COLORSPACE_RGB, 1, 8, 1, 1)
! __blank_pixbuf.fill (0)
!
def __init__ (self, prop = None, prefix = ""):
"""Initializer."""
***************
*** 79,84 ****
self.__charset = charset
# Create list model
! self.__store = gtk.ListStore (*self.__types)
# Create tree view
--- 91,107 ----
self.__charset = charset
+ # Get mark property
+ mark_file = prop.get_value (prefix + ".mark.file")
+ if mark_file:
+ self.__mark_pixbuf = gdk.pixbuf_new_from_file (mark_file)
+ current_column_type = gobject.TYPE_OBJECT
+ else:
+ self.__mark_pixbuf = None
+ self.__mark_label = prop.get_value (prefix + ".mark.label")
+ current_column_type = gobject.TYPE_STRING
+ self.__marked_path = None
+
# Create list model
! self.__store = gtk.ListStore (*(self.__types + (current_column_type,)))
# Create tree view
***************
*** 86,106 ****
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 ()
--- 109,151 ----
self.add (self.__treeview)
+ # Setup selection type
+ selection = self.__treeview.get_selection ()
+ selection.set_mode (gtk.SELECTION_MULTIPLE)
+
# Append columns
! for name in columns:
# Create renderer
! if name == "current":
! if mark_file:
! renderer = gtk.CellRendererPixbuf ()
! column_properties = {
! 'pixbuf' : self.__COLUMN_CURRENT
! }
! else:
! renderer = gtk.CellRendererText ()
! column_properties = {
! 'text' : self.__COLUMN_CURRENT
! }
! else:
! renderer = gtk.CellRendererText ()
! column_properties = {
! 'text' : self.__columns.index (name)
! }
! # Settings
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))
!
! # Create column
if file:
label = None
! column = gtk.TreeViewColumn (label, renderer, **column_properties)
column.set_resizable (gtk.TRUE)
column.set_alignment (alignment)
+ column.set_reorderable (gtk.TRUE)
+ # Set image title if file is specified
if file:
image = gtk.Image ()
***************
*** 131,134 ****
--- 176,201 ----
self.__COLUMN_FILENAME, filename.decode (self.__charset))
+ def get_treeview (self):
+ """Return list TreeView object."""
+
+ return self.__treeview
+
+ def mark_row (self, row):
+ """Mark row by its number."""
+
+ # Blank old marked row
+ if self.__marked_path:
+ iter = self.__store.get_iter (self.__marked_path)
+ value = self.__mark_pixbuf and self.__blank_pixbuf or ''
+ self.__store.set (iter, self.__COLUMN_CURRENT, value)
+
+ # Create value to mark new row
+ value = self.__mark_pixbuf or self.__mark_label
+
+ # Set
+ self.__marked_path = (row, )
+ iter = self.__store.get_iter (self.__marked_path)
+ self.__store.set (iter, self.__COLUMN_CURRENT, value)
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
class PlaylistWindow (gtk.Window):
***************
*** 156,159 ****
--- 223,227 ----
# Connect signals
self.connect ("destroy", self.__gtkcb_destroy)
+ self.__list.get_treeview ().connect ("row-activated", self.__gtkcb_list_row_activated)
def cb_insert (self, items, pos):
***************
*** 172,175 ****
--- 240,255 ----
filename = item.filename)
pos += 1
+
+ def cb_set_current (self, row):
+ """Alsaplayer's callback."""
+
+ self.__list.mark_row (row-1)
+
+ def __gtkcb_list_row_activated (self, tree, path, column):
+ """Handler for a row activated signal."""
+
+ gdk.threads_leave ()
+ self.__pl.play (path [0] + 1)
+ gdk.threads_enter ()
def __gtkcb_destroy (self, widget):
|