[Ap-python-commits] python/aptk Makefile.am,1.3,1.4 control.py,1.5,1.6 info.py,1.6,1.7 misc.py,1.2,1
Status: Beta
Brought to you by:
sjah
Update of /cvsroot/ap-python/python/aptk
In directory usw-pr-cvs1:/tmp/cvs-serv26166/aptk
Modified Files:
Makefile.am control.py info.py misc.py pan.py playlist.py
position.py speed.py volume.py
Log Message:
Rewrite APTK to use it with PyGTK2!
Index: Makefile.am
===================================================================
RCS file: /cvsroot/ap-python/python/aptk/Makefile.am,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** Makefile.am 16 Jul 2002 17:08:45 -0000 1.3
--- Makefile.am 21 Jul 2002 18:15:43 -0000 1.4
***************
*** 4,8 ****
if ENABLE_APTK
aptk_DATA = $(EXTRA_DIST) control.pyc info.pyc __init__.pyc misc.pyc\
! pan.pyc position.pyc speed.pyc volume.pyc playlist.py
aptkdir = @PY_MOD_DIR@/aptk
endif
--- 4,8 ----
if ENABLE_APTK
aptk_DATA = $(EXTRA_DIST) control.pyc info.pyc __init__.pyc misc.pyc\
! pan.pyc position.pyc speed.pyc volume.pyc playlist.pyc
aptkdir = @PY_MOD_DIR@/aptk
endif
Index: control.py
===================================================================
RCS file: /cvsroot/ap-python/python/aptk/control.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** control.py 19 Jul 2002 18:04:13 -0000 1.5
--- control.py 21 Jul 2002 18:15:43 -0000 1.6
***************
*** 30,140 ****
import aptk.misc, alsaplayer, gtk
! # - - - - - - - - - - - - - - - Buttons - - - - - - - - -
class PlayButton (aptk.misc.Button):
"""Start playback.
"""
! def __init__ (self, pl, prop = None, strip = ""):
"""Initializer."""
! # Create strip string for this class
! this_strip = (strip and strip + ".") + 'play'
# Call base contructor
! aptk.misc.Button.__init__ (self, prop, this_strip)
! self.connect ("clicked", self.__cb_clicked)
self.__pl = pl
! def __cb_clicked (self, w):
! gtk.threads_leave ()
! self.__pl.play (self._pl.get_current ())
! gtk.threads_enter ()
class NextButton (aptk.misc.Button):
"""Move to next song.
"""
!
! def __init__ (self, pl, prop = None, strip = ""):
"""Initializer."""
! # Create strip string for this class
! this_strip = (strip and strip + ".") + 'next'
# Call base contructor
! aptk.misc.Button.__init__ (self, prop, this_strip)
! self.connect ("clicked", self.__cb_clicked)
self.__pl = pl
! def __cb_clicked (self, w):
! gtk.threads_leave ()
self.__pl.next ()
! gtk.threads_enter ()
class PrevButton (aptk.misc.Button):
"""Move to previous song.
"""
! def __init__ (self, pl, prop = None, strip = ""):
"""Initializer."""
! # Create strip string for this class
! this_strip = (strip and strip + ".") + 'prev'
# Call base contructor
! aptk.misc.Button.__init__ (self, prop, this_strip)
! self.connect ("clicked", self.__cb_clicked)
self.__pl = pl
! def __cb_clicked (self, w):
! gtk.threads_leave ()
self.__pl.prev ()
! gtk.threads_enter ()
class StopButton (aptk.misc.Button):
"""Stop playback.
"""
!
! def __init__ (self, pl, prop = None, strip = ""):
"""Initializer."""
! # Create strip string for this class
! this_strip = (strip and strip + ".") + 'stop'
# Call base contructor
! aptk.misc.Button.__init__ (self, prop, this_strip)
! self.connect ("clicked", self.__cb_clicked)
self.__pl = pl
! def __cb_clicked (self, w):
! gtk.threads_leave ()
! self._pl.stop ()
! gtk.threads_enter ()
! # - - - - - - - - - - - - - - - Boxes - - - - - - - - - -
class _Box:
"""Internal."""
! def __init__ (self, pl, prop = None, strip = ""):
"""Initializeer."""
! # Create strip string for this class
! this_strip = (strip and strip + ".") + 'control'
# Create buttons
! self.prev_button = PrevButton (pl, prop, this_strip)
self.add (self.prev_button)
! self.play_button = PlayButton (pl, prop, this_strip)
self.add (self.play_button)
! self.stop_button = StopButton (pl, prop, this_strip)
self.add (self.stop_button)
! self.next_button = NextButton (pl, prop, this_strip)
self.add (self.next_button)
--- 30,168 ----
import aptk.misc, alsaplayer, gtk
+ gdk = gtk.gdk
! # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
class PlayButton (aptk.misc.Button):
"""Start playback.
"""
! # Defualt properties
! __properties = aptk.misc.WidgetProperties ([
! ('*.play.button.label', 'Play')
! ])
!
! def __init__ (self, pl, prop = None, prefix = ""):
"""Initializer."""
! # Create new properties whth our defaults added
! prop = prop and (prop + self.__properties) or self.__properties
! prefix += ".play"
# Call base contructor
! aptk.misc.Button.__init__ (self, prop, prefix)
! self.connect ("clicked", self.__gtkcb_clicked)
self.__pl = pl
! def __gtkcb_clicked (self, w):
! gdk.threads_leave ()
! self.__pl.play (self.__pl.get_current ())
! gdk.threads_enter ()
+ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
class NextButton (aptk.misc.Button):
"""Move to next song.
"""
!
! # Defualt properties
! __properties = aptk.misc.WidgetProperties ([
! ('*.next.button.label', 'Next')
! ])
!
! def __init__ (self, pl, prop = None, prefix = ""):
"""Initializer."""
! # Create new properties whth our defaults added
! prop = prop and (prop + self.__properties) or self.__properties
! prefix += '.next'
# Call base contructor
! aptk.misc.Button.__init__ (self, prop, prefix)
! self.connect ("clicked", self.__gtkcb_clicked)
self.__pl = pl
! def __gtkcb_clicked (self, w):
! gdk.threads_leave ()
self.__pl.next ()
! gdk.threads_enter ()
+ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
class PrevButton (aptk.misc.Button):
"""Move to previous song.
"""
! # Defualt properties
! __properties = aptk.misc.WidgetProperties ([
! ('*.prev.button.label', 'Prev')
! ])
!
! def __init__ (self, pl, prop = None, prefix = ""):
"""Initializer."""
! # Create new properties whth our defaults added
! prop = prop and (prop + self.__properties) or self.__properties
! prefix += '.prev'
# Call base contructor
! aptk.misc.Button.__init__ (self, prop, prefix)
! self.connect ("clicked", self.__gtkcb_clicked)
self.__pl = pl
! def __gtkcb_clicked (self, w):
! gdk.threads_leave ()
self.__pl.prev ()
! gdk.threads_enter ()
+ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
class StopButton (aptk.misc.Button):
"""Stop playback.
"""
!
! # Defualt properties
! __properties = aptk.misc.WidgetProperties ([
! ('*.stop.button.label', 'Stop')
! ])
!
! def __init__ (self, pl, prop = None, prefix = ""):
"""Initializer."""
! # Create new properties whth our defaults added
! prop = prop and (prop + self.__properties) or self.__properties
! prefix += ".stop"
# Call base contructor
! aptk.misc.Button.__init__ (self, prop, prefix)
! self.connect ("clicked", self.__gtkcb_clicked)
self.__pl = pl
! def __gtkcb_clicked (self, w):
! gdk.threads_leave ()
! self.__pl.stop ()
! gdk.threads_enter ()
! # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
class _Box:
"""Internal."""
! def __init__ (self, pl, prop = None, prefix = ""):
"""Initializeer."""
! # Create new properties whth our defaults added
! prefix += ".control"
# Create buttons
! self.prev_button = PrevButton (pl, prop, prefix)
self.add (self.prev_button)
! self.play_button = PlayButton (pl, prop, prefix)
self.add (self.play_button)
! self.stop_button = StopButton (pl, prop, prefix)
self.add (self.stop_button)
! self.next_button = NextButton (pl, prop, prefix)
self.add (self.next_button)
***************
*** 145,149 ****
self.next_button.show ()
! class HBox (gtk.GtkHBox, _Box):
"""Horizontal box of all control buttons.
This widget provided to create typical control panel.
--- 173,178 ----
self.next_button.show ()
! # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
! class HBox (gtk.HBox, _Box):
"""Horizontal box of all control buttons.
This widget provided to create typical control panel.
***************
*** 151,175 ****
"""
! def __init__ (self, pl, prop = None, strip = ""):
"""Initialize the HBox.
"""
! gtk.GtkHBox.__init__ (self)
! _Box.__init__ (self, pl, prop, strip)
! class VBox (gtk.GtkVBox, _Box):
"""Vertical box of all control buttons.
This widget provided to create typical control panel.
"""
! def __init__ (self, pl, prop = None, strip = ""):
"""Initialize the VBox.
"""
! gtk.GtkVBox.__init__ (self)
_Box.__init__ (self, pl, prop, relief = relief)
!
! # - - - - - - - - - - - - Final (High level) Widgets
HControl = HBox
VControl = VBox
--- 180,204 ----
"""
! def __init__ (self, pl, prop = None, prefix = ""):
"""Initialize the HBox.
"""
! gtk.HBox.__init__ (self)
! _Box.__init__ (self, pl, prop, prefix)
! # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
! class VBox (gtk.VBox, _Box):
"""Vertical box of all control buttons.
This widget provided to create typical control panel.
"""
! def __init__ (self, pl, prop = None, prefix = ""):
"""Initialize the VBox.
"""
! gtk.VBox.__init__ (self)
_Box.__init__ (self, pl, prop, relief = relief)
! # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
HControl = HBox
VControl = VBox
Index: info.py
===================================================================
RCS file: /cvsroot/ap-python/python/aptk/info.py,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** info.py 19 Jul 2002 18:04:13 -0000 1.6
--- info.py 21 Jul 2002 18:15:43 -0000 1.7
***************
*** 26,59 ****
__license__ = "GNU"
! import aptk.misc, alsaplayer, gtk, GTK
! class StreamTypeLabel (gtk.GtkLabel):
! def __init__ (self, cp):
! gtk.GtkLabel.__init__ (self, "")
! self.__cp = cp
# Start timeout which will update label
! self.__timeout = gtk.timeout_add (200, self.__cb_timeout)
! def __cb_timeout (self):
s = self.__cp.get_stream_info ().stream_type
! gtk.threads_enter ()
self.set_text (s)
! gtk.threads_leave ()
return 1
! class TimeLabel (gtk.GtkLabel):
! def __init__ (self, cp, position = None):
! gtk.GtkLabel.__init__ (self, "")
! self.__cp = cp
self.__dragging = 0
! # Start timeout which will update label
! self.__timeout = gtk.timeout_add (500, self.__cb_timeout)
# Show scale position when it is in use
--- 26,77 ----
__license__ = "GNU"
! import aptk.misc, alsaplayer, gtk
! gdk = gtk.gdk
! # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
! class StreamTypeLabel (gtk.Label):
! def __init__ (self, pl):
! """Initializer."""
!
! # Init base class
! gtk.Label.__init__ (self, "")
! # Remember for use in the timeout callback
! self.__cp = pl.get_coreplayer ()
# Start timeout which will update label
! self.__timeout = gtk.timeout_add (200, self.__gtkcb_timeout)
! def __gtkcb_timeout (self):
! """Callback for gtk timeout. Use to update label."""
!
! # Get current stream type
s = self.__cp.get_stream_info ().stream_type
! # Update label
! gdk.threads_enter ()
self.set_text (s)
! gdk.threads_leave ()
return 1
! # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
! class TimeLabel (gtk.Label):
! def __init__ (self, pl, position = None):
! """Initializer."""
!
! # Init base class
! gtk.Label.__init__ (self, "")
! # Remember for use in callback
! self.__cp = pl.get_coreplayer ()
self.__dragging = 0
! # Register this instance as the notifier for coreplayer
! self.__cp.register_notifier (self)
!
! # Register gtk signals
! self.connect ("destroy", self.__gtkcb_destroy)
# Show scale position when it is in use
***************
*** 61,71 ****
self.__adj = position.get_adjustment ()
! position.connect ("button_press_event", self.__press_event)
! position.connect ("button_release_event", self.__release_event)
! position.connect ("motion_notify_event", self.__motion_event)
- def __cb_timeout (self):
# Don't show current time if user is dargging position scale
! if self.__dragging: return 1
status = self.__cp.get_stream_info ().status
--- 79,91 ----
self.__adj = position.get_adjustment ()
! position.connect ("button_press_event", self.__gtkcb_press_event)
! position.connect ("button_release_event", self.__gtkcb_release_event)
! position.connect ("motion_notify_event", self.__gtkcb_motion_event)
!
! def cb_position_notify (self, pos=0):
! """Callback handler for position changed alsaplayer signal."""
# Don't show current time if user is dargging position scale
! if self.__dragging: return
status = self.__cp.get_stream_info ().status
***************
*** 73,79 ****
if status:
# Show status
! gtk.threads_enter ()
self.set_text (status)
! gtk.threads_leave ()
else:
# Show time
--- 93,99 ----
if status:
# Show status
! gdk.threads_enter ()
self.set_text (status)
! gdk.threads_leave ()
else:
# Show time
***************
*** 87,106 ****
t_m, t_s = divmod (total, 60)
! gtk.threads_enter ()
self.set_text ("%02u:%02u/%02u:%02u" % (m, s, t_m, t_s))
! gtk.threads_leave ()
!
! return 1
! def __press_event (self, widget, event):
"""Button press event handler."""
self.__dragging = 1
! self.__motion_event (None, None)
! def __motion_event (self, widget, event):
"""Motion notify event handler."""
! gtk.threads_leave ()
played = self.__cp.get_current_time (self.__adj.value) / 100
--- 107,125 ----
t_m, t_s = divmod (total, 60)
! gdk.threads_enter ()
self.set_text ("%02u:%02u/%02u:%02u" % (m, s, t_m, t_s))
! gdk.threads_leave ()
! def __gtkcb_press_event (self, widget, event):
"""Button press event handler."""
self.__dragging = 1
! self.__gtkcb_motion_event (None, None)
! def __gtkcb_motion_event (self, widget, event):
"""Motion notify event handler."""
! # Calculate time based on a position adjustment value
! gdk.threads_leave ()
played = self.__cp.get_current_time (self.__adj.value) / 100
***************
*** 111,139 ****
t_m, t_s = divmod (total, 60)
! gtk.threads_enter ()
self.set_text ("%02u:%02u/%02u:%02u" % (m, s, t_m, t_s))
! def __release_event (self, widget, event):
"""Button release event handler."""
self.__dragging = 0
! gtk.threads_leave ()
! self.__cb_timeout ()
! gtk.threads_enter ()
! class FullStatusHBox (gtk.GtkHBox):
! def __init__ (self, cp, position = None):
! gtk.GtkHBox.__init__ (self)
! self.stream_type_label = StreamTypeLabel (cp)
! self.time_label = TimeLabel (cp, position)
! self.stream_type_label.set_justify (GTK.JUSTIFY_LEFT)
! self.time_label.set_justify (GTK.JUSTIFY_RIGHT)
! self.pack_start (self.stream_type_label, expand=GTK.FALSE)
! self.pack_end (self.time_label, expand=GTK.FALSE, fill=GTK.TRUE)
# Show these widgets
--- 130,172 ----
t_m, t_s = divmod (total, 60)
! gdk.threads_enter ()
+ # Update label
self.set_text ("%02u:%02u/%02u:%02u" % (m, s, t_m, t_s))
! def __gtkcb_release_event (self, widget, event):
"""Button release event handler."""
self.__dragging = 0
! # Dragging is done, so we should show now playing position
! gdk.threads_leave ()
! self.cb_position_notify ()
! gdk.threads_enter ()
! def __gtkcb_destroy (self, widget):
! """Callback handler for a destroy signal."""
!
! gdk.threads_leave ()
! self.__cp.unregister_notifier (self)
! gdk.threads_enter ()
! # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
! class FullStatusHBox (gtk.HBox):
! def __init__ (self, pl, position = None):
! """Initializer."""
! # Init base class
! gtk.HBox.__init__ (self)
! # Create Widgets
! self.stream_type_label = StreamTypeLabel (pl)
! self.time_label = TimeLabel (pl, position)
!
! self.stream_type_label.set_justify (gtk.JUSTIFY_LEFT)
! self.time_label.set_justify (gtk.JUSTIFY_RIGHT)
!
! self.pack_start (self.stream_type_label, expand = gtk.FALSE)
! self.pack_end (self.time_label, expand = gtk.FALSE, fill = gtk.TRUE)
# Show these widgets
***************
*** 141,152 ****
self.time_label.show ()
! #############################################################################
!
! class TagsLabel (gtk.GtkLabel):
! properties = {
! "format" : "%a - %t (%y - %l)"
! }
!
! ch = {
't' : 'si.title',
'a' : 'si.artist',
--- 174,181 ----
self.time_label.show ()
! # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
! class TagsLabel (gtk.Label):
! # List of format tags
! __ch = {
't' : 'si.title',
'a' : 'si.artist',
***************
*** 159,181 ****
'u' : 'si.status'
}
! def __init__ (self, cp, prop = None, strip = ""):
! """Create instance label which will show tags info accordance with format string.
"""
! # Create strip string for this class
! this_strip = (strip and strip + ".") + 'tagslabel'
! # Get properties
! format = aptk.misc.get_property (self.properties, prop, 'format', this_strip)
! gtk.GtkLabel.__init__ (self, "")
! self.connect ("destroy", self.__on_destroy)
# Remember
! self.__cp = cp
# Parse and create list of members which will compose values tuple
- fmt = format [:]
i = 0;
attrs = []
--- 188,218 ----
'u' : 'si.status'
}
+
+ # Defualt properties
+ __properties = aptk.misc.WidgetProperties ([
+ ('*.tagsinfo.format', '%t - %a')
+ ])
! def __init__ (self, pl, prop = None, prefix = ""):
! """Create label object which will show tags info accordance with format string.
"""
! # Init base class
! gtk.Label.__init__ (self, "")
! # Create new properties whth our defaults added
! prop = prop and (prop + self.__properties) or self.__properties
! prefix += ".tagsinfo"
! # Get values
! fmt = prop.get_value (prefix + ".format")
!
! # Connect gtk signals
! self.connect ("destroy", self.__gtkcb_destroy)
# Remember
! self.__cp = pl.get_coreplayer ()
# Parse and create list of members which will compose values tuple
i = 0;
attrs = []
***************
*** 184,189 ****
if i == -1: break
! if self.ch.has_key (fmt [i+1]):
! attrs.append (self.ch [fmt [i+1]])
fmt = fmt [:i+1] + 's' + fmt [i+2:]
--- 221,226 ----
if i == -1: break
! if self.__ch.has_key (fmt [i+1]):
! attrs.append (self.__ch [fmt [i+1]])
fmt = fmt [:i+1] + 's' + fmt [i+2:]
***************
*** 194,201 ****
# Register callback to update label
! cp.register_notifier (self)
self.cb_start_notify (None)
def cb_start_notify (self, thread=1):
# Prepare locals for dynamic code
si = self.__cp.get_stream_info ()
--- 231,240 ----
# Register callback to update label
! self.__cp.register_notifier (self)
self.cb_start_notify (None)
def cb_start_notify (self, thread=1):
+ """Callback handler. It called when the song playback started."""
+
# Prepare locals for dynamic code
si = self.__cp.get_stream_info ()
***************
*** 208,219 ****
# Set right value
! if thread: gtk.threads_enter ()
self.set_text (s)
! if thread: gtk.threads_leave ()
! def __on_destroy (self, widget):
! """Called on the destroy."""
! gtk.threads_leave ()
self.__cp.unregister_notifier (self)
! gtk.threads_enter ()
--- 247,258 ----
# Set right value
! if thread: gdk.threads_enter ()
self.set_text (s)
! if thread: gdk.threads_leave ()
! def __gtkcb_destroy (self, widget):
! """Callback for a destroy signal."""
! gdk.threads_leave ()
self.__cp.unregister_notifier (self)
! gdk.threads_enter ()
Index: misc.py
===================================================================
RCS file: /cvsroot/ap-python/python/aptk/misc.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** misc.py 19 Jul 2002 18:04:13 -0000 1.2
--- misc.py 21 Jul 2002 18:15:43 -0000 1.3
***************
*** 24,80 ****
__license__ = "GNU"
! import gtk
! ######################################################################
! # Work with properties
! def get_property (default_prop, prop, key, strip = ""):
! fullkey = (strip and strip + ".") + key
! if prop and prop.has_key (fullkey): return prop [fullkey]
! else: return default_prop [key]
! ######################################################################
! # Button
! class Button (gtk.GtkButton):
! properties = {
! "relief" : None,
! "label" : None,
! "xpmfile" : None
! }
! def __init__ (self, prop = None, strip = ""):
"""Create button."""
! # Create strip string for this class
! this_strip = (strip and strip + ".") + 'button'
!
# Get properties
! label = get_property (self.properties, prop, 'label', this_strip)
! xpmfile = get_property (self.properties, prop, 'xpmfile', this_strip)
! relief = get_property (self.properties, prop, 'relief', this_strip)
!
! # Remember this. We will load xpm file after a parent will be set
! self.__xpmfile = xpmfile
! self.__pixmap = None
# Create button
! gtk.GtkButton.__init__ (self, label)
if relief is not None:
self.set_relief (relief)
! # Connect signals
! self.connect ("parent_set", self.__gtkcb_parent_set)
!
! def __gtkcb_parent_set (self, w, old_parent):
! """Calling by gtk if a parent is setted up."""
!
! # We have no picture to add or a picture already added
! if self.__pixmap or self.__xpmfile is None: return
!
! # Create Pixmap
! self.__pixmap = gtk.GtkPixmap (self, self.__xpmfile)
! self.add (self.__pixmap)
! self.__pixmap.show ()
--- 24,118 ----
__license__ = "GNU"
! import gtk, re
! # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
! class WidgetProperties (object):
! def __init__ (self, list = []):
! """Initializer."""
!
! self.__list = []
! # Add values from a given list
! for key, value in list:
! self.add_property (key, value)
!
! def add_property (self, key, value):
! """Add property."""
!
! key = self.__compile_key (key)
! self.__list.append ((key, value))
!
! def __compile_key (self, key):
! """Translate key into compiled regexp."""
! # Allow only * in regexps
! key = key.replace ("*", "MiU2hLo4SpI5GN999UeSED")
! key = re.escape (key)
! key = "^" + key.replace ("MiU2hLo4SpI5GN999UeSED", ".*") + "$"
! return re.compile (key)
! def has_key (self, key):
! """Return 1 if key is present."""
!
! for pattern, value in self.__list:
! if pattern.match (key): return 1
!
! return 0
!
! def get_value (self, key):
! """Return value by key."""
!
! for pattern, value in self.__list:
! if pattern.match (key): return value
!
! raise AttributeError, "key is not found"
!
! def __add__ (self, other):
! """Add another WidgetProperties object."""
!
! if type (other) is not type (self):
! raise TypeError, "you could add only WidgetProperties object"
!
! new = WidgetProperties ()
! new.__list = self.__list + other.__list
!
! return new
!
! # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
! class Button (gtk.Button):
! # Defualt properties
! __properties = WidgetProperties ([
! ('*.button.relief', None),
! ('*.button.label', ''),
! ('*.button.file', None),
! ])
! def __init__ (self, prop = None, prefix = ""):
"""Create button."""
! # Create new properties whth our defaults added
! prop = prop and (prop + self.__properties) or self.__properties
! prefix += '.button'
!
# Get properties
! file = prop.get_value (prefix + ".file")
! label = prop.get_value (prefix + ".label")
! relief = prop.get_value (prefix + ".relief")
# Create button
! if not file:
! gtk.Button.__init__ (self, label)
! else:
! gtk.Button.__init__ (self)
+ # Set relief
if relief is not None:
self.set_relief (relief)
! # Add image
! if file:
! image = gtk.Image ()
! image.set_from_file (file)
! self.add (image)
! image.show ()
Index: pan.py
===================================================================
RCS file: /cvsroot/ap-python/python/aptk/pan.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** pan.py 19 Jul 2002 18:04:13 -0000 1.4
--- pan.py 21 Jul 2002 18:15:43 -0000 1.5
***************
*** 24,54 ****
__license__ = "GNU"
! import aptk.misc, alsaplayer, gtk, GTK
!
! # - - - - - - - - Scale --------------------------------------------------
class _Scale:
! def __init__ (self, cp):
! adj = gtk.GtkAdjustment (value=cp.get_pan(), lower=-100, upper=100)
! adj.connect ("value_changed", self.__cb_pan_changed)
! self.connect ("destroy", self.__on_destroy)
! self.set_adjustment (adj)
self.set_draw_value (0)
! self.__cp = cp
self.__adj = adj
self.__cp_locked = 0
# Register callback to update scale by external changes
! cp.register_notifier (self)
! def __cb_pan_changed (self, w):
"""Gtk callback handler for scale changes."""
if not self.__cp_locked:
! gtk.threads_leave ()
self.__cp.set_pan (w.value);
! gtk.threads_enter ()
def cb_pan_changed (self, pan):
--- 24,65 ----
__license__ = "GNU"
+ import aptk.misc, alsaplayer, gtk
+ gdk = gtk.gdk
! # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
class _Scale:
! def __init__ (self, pl):
! """Initializer."""
!
! # Remember for future use
! self.__cp = pl.get_coreplayer ()
!
! # Create adjustment
! adj = gtk.Adjustment (value = self.__cp.get_pan (),
! lower = -100,
! upper = 100)
+ self.set_adjustment (adj)
self.set_draw_value (0)
! # Remember for future use
self.__adj = adj
self.__cp_locked = 0
# Register callback to update scale by external changes
! self.__cp.register_notifier (self)
! # Connect gtk signals
! adj.connect ("value_changed", self.__gtkcb_pan_changed)
! self.connect ("destroy", self.__gtkcb_destroy)
!
!
! def __gtkcb_pan_changed (self, w):
"""Gtk callback handler for scale changes."""
if not self.__cp_locked:
! gdk.threads_leave ()
self.__cp.set_pan (w.value);
! gdk.threads_enter ()
def cb_pan_changed (self, pan):
***************
*** 57,121 ****
self.__cp_locked = 1
! gtk.threads_enter ()
self.__adj.set_value (pan)
! gtk.threads_leave ()
self.__cp_locked = 0
! def __on_destroy (self, widget):
"""Called on the destroy."""
! gtk.threads_leave ()
self.__cp.unregister_notifier (self)
! gtk.threads_enter ()
!
! class HScale (gtk.GtkHScale, _Scale):
! def __init__ (self, cp):
! gtk.GtkHScale.__init__ (self)
! _Scale.__init__ (self, cp)
! class VScale (gtk.GtkVScale, _Scale):
! def __init__ (self, cp):
! gtk.GtkVScale.__init__ (self)
! _Scale.__init__ (self, cp)
! # - - - - - - - - - Button ---------------------------------------------------
class Button (aptk.misc.Button):
! def __init__ (self, cp, value, prop = None, strip = ""):
"""Intitializer."""
# Call base class initializer
! aptk.misc.Button.__init__ (self, prop, strip)
# Connect signals
! self.connect ("clicked", self.__cb_clicked)
# Remember
self.__value = value
! self.__cp = cp
!
! def __cb_clicked (self, w):
! gtk.threads_leave ()
self.__cp.set_pan (self.__value)
! gtk.threads_enter ()
! # - - - - - - - - - - - - - - - Boxes - - - - - - - - - -
class _Box:
! def __init__ (self, cp, prop = None, strip = ""):
"""Inititalizer."""
! # Create strip string for this class
! this_strip = (strip and strip + ".") + 'pan'
# Create buttons
! self.left_button = Button (cp, -100, prop, this_strip + ".left")
self.add (self.left_button)
! self.center_button = Button (cp, 0, prop, this_strip + ".center")
self.add (self.center_button)
! self.right_button = Button (cp, 100, prop, this_strip + ".right")
self.add (self.right_button)
--- 68,140 ----
self.__cp_locked = 1
! gdk.threads_enter ()
self.__adj.set_value (pan)
! gdk.threads_leave ()
self.__cp_locked = 0
! def __gtkcb_destroy (self, widget):
"""Called on the destroy."""
! gdk.threads_leave ()
self.__cp.unregister_notifier (self)
! gdk.threads_enter ()
+ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+ class HScale (gtk.HScale, _Scale):
+ def __init__ (self, pl):
+ gtk.HScale.__init__ (self)
+ _Scale.__init__ (self, pl)
! # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
! class VScale (gtk.VScale, _Scale):
! def __init__ (self, pl):
! gtk.VScale.__init__ (self)
! _Scale.__init__ (self, pl)
! # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
class Button (aptk.misc.Button):
! def __init__ (self, pl, value, prop = None, prefix = ""):
"""Intitializer."""
# Call base class initializer
! aptk.misc.Button.__init__ (self, prop, prefix)
# Connect signals
! self.connect ("clicked", self.__gtkcb_clicked)
# Remember
self.__value = value
! self.__cp = pl.get_coreplayer ()
! def __gtkcb_clicked (self, w):
! gdk.threads_leave ()
self.__cp.set_pan (self.__value)
! gdk.threads_enter ()
! # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
class _Box:
! # Defualt properties
! __properties = aptk.misc.WidgetProperties ([
! ('*.pan.left.button.label', 'Left'),
! ('*.pan.center.button.label', 'Center'),
! ('*.pan.right.button.label', 'Right')
! ])
!
! def __init__ (self, pl, prop = None, prefix = ""):
"""Inititalizer."""
! # Create new properties whth our defaults added
! prop = prop and (prop + self.__properties) or self.__properties
! prefix += ".pan"
# Create buttons
! self.left_button = Button (pl, -100, prop, prefix + ".left")
self.add (self.left_button)
! self.center_button = Button (pl, 0, prop, prefix + ".center")
self.add (self.center_button)
! self.right_button = Button (pl, 100, prop, prefix + ".right")
self.add (self.right_button)
***************
*** 125,148 ****
self.right_button.show ()
! class HBox (gtk.GtkHBox, _Box):
! def __init__ (self, cp, prop = None, strip = ""):
! gtk.GtkHBox.__init__ (self)
! _Box.__init__ (self, cp, prop, strip)
!
! class VBox (gtk.GtkVBox, _Box):
! def __init__ (self, cp, prop = None, strip = ""):
! gtk.GtkVBox.__init__ (self)
! _Box.__init__ (self, cp, prop, strip)
! # - - - - - - - - - - - - - Final Widgets
! class HPan (gtk.GtkHBox):
! def __init__ (self, cp, prop = None, strip = ""):
! gtk.GtkHBox.__init__ (self)
! box = HBox (cp, prop, strip)
! scale = HScale (cp)
! self.pack_start (box, expand = GTK.FALSE)
self.add (scale)
--- 144,168 ----
self.right_button.show ()
! # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
! class HBox (gtk.HBox, _Box):
! def __init__ (self, pl, prop = None, prefix = ""):
! gtk.HBox.__init__ (self)
! _Box.__init__ (self, pl, prop, prefix)
! # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
! class VBox (gtk.VBox, _Box):
! def __init__ (self, pl, prop = None, prefix = ""):
! gtk.VBox.__init__ (self)
! _Box.__init__ (self, pl, prop, prefix)
! # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
! class HPan (gtk.HBox):
! def __init__ (self, pl, prop = None, prefix = ""):
! gtk.HBox.__init__ (self)
! box = HBox (pl, prop, prefix)
! scale = HScale (pl)
! self.pack_start (box, expand = gtk.FALSE)
self.add (scale)
***************
*** 150,161 ****
scale.show ()
! class VPan (gtk.GtkVBox):
! def __init__ (self, cp, prop = None, strip = ""):
! gtk.GtkVBox.__init__ (self)
! box = VBox (cp, prop, strip)
! scale = VScale (cp)
! self.pack_start (box, expand = GTK.FALSE)
self.add (scale)
--- 170,182 ----
scale.show ()
! # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
! class VPan (gtk.VBox):
! def __init__ (self, pl, prop = None, prefix = ""):
! gtk.VBox.__init__ (self)
! box = VBox (pl, prop, prefix)
! scale = VScale (pl)
! self.pack_start (box, expand = gtk.FALSE)
self.add (scale)
Index: playlist.py
===================================================================
RCS file: /cvsroot/ap-python/python/aptk/playlist.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** playlist.py 19 Jul 2002 18:04:13 -0000 1.4
--- playlist.py 21 Jul 2002 18:15:43 -0000 1.5
***************
*** 24,31 ****
__license__ = "GNU"
! import gtk, GDK
###########################################################################
! class SmartList (gtk.GtkCList):
def __init__ (self, columns):
"""Initializer."""
--- 24,31 ----
__license__ = "GNU"
! import gtk
###########################################################################
! class SmartList (gtk.CList):
def __init__ (self, columns):
"""Initializer."""
***************
*** 37,64 ****
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."""
--- 37,40 ----
***************
*** 119,145 ****
###############################################################################
! class PlaylistWindow (gtk.GtkWindow):
properties = {
! 'playlist.columns' : ['current', 'playtime', 'track', 'title',
'album', 'artist', 'year', 'genre'],
! 'playlist.title.playtime' : ("playtime.xpm",),
! 'playlist.title.track' : ("track.xpm",),
! 'playlist.title.title' : 'Title',
! 'playlist.title.current' : ' ',
! 'playlist.title.album' : 'Album',
! 'playlist.title.artist' : 'Artist',
! 'playlist.title.year' : 'Year',
! 'playlist.title.genre' : 'Genre',
! 'playlist.current.mark' : ("current_play.xpm",)
! }
! def __init__ (self, pl, prop):
"""Initializer."""
! # Helper function. Get value from given properties or even from default
! def prop_value (key, prop=prop):
! if prop.has_key (key): return prop [key]
! else: return default_properties [key]
!
# Remember
self.pl = pl
--- 95,132 ----
###############################################################################
! 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
***************
*** 162,176 ****
# 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 ()
--- 149,156 ----
# Create list
! self.list = SmartList (prop, this_strip)
self.scrolled.add (self.list)
! self.list.set_titles (prop, this_strip)
self.list.show ()
***************
*** 178,184 ****
# Create mark for the current song
- self.current_mark = prop_value ('mark for current')
-
- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --
# - -- - - - - - - - - - - - - - - - - -- - - - - - - - - - - - -
--- 158,161 ----
Index: position.py
===================================================================
RCS file: /cvsroot/ap-python/python/aptk/position.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** position.py 6 Jul 2002 16:08:10 -0000 1.3
--- position.py 21 Jul 2002 18:15:43 -0000 1.4
***************
*** 24,38 ****
__license__ = "GNU"
! import alsaplayer, gtk, aptk.misc, GTK
! # - - - - - - - - Scale --------------------------------------------------
class _Scale:
! def __init__ (self, cp):
# Initialize adjustment
! adj = gtk.GtkAdjustment ()
self.set_adjustment (adj)
# Remember
! self.__cp = cp
self.__adj = adj
self.__dragging = 0
--- 24,41 ----
__license__ = "GNU"
! import alsaplayer, gtk, aptk.misc
! gdk = gtk.gdk
! # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
class _Scale:
! def __init__ (self, pl):
! """Initializer."""
!
# Initialize adjustment
! adj = gtk.Adjustment ()
self.set_adjustment (adj)
# Remember
! self.__cp = pl.get_coreplayer ()
self.__adj = adj
self.__dragging = 0
***************
*** 42,88 ****
# Signals
! cp.register_notifier (self)
! self.connect ("button_press_event", self.__press_event)
! self.connect ("button_release_event", self.__release_event)
! self.connect ("motion_notify_event", self.__motion_event)
! self.connect ("destroy", self.__on_destroy)
! def cb_position_notify (self, pos):
! """Callback handler for the position changes."""
! if self.__cp.can_seek ():
! gtk.threads_enter ()
! self.set_sensitive (GTK.TRUE)
! gtk.threads_leave ()
! if self.__dragging:
! value = self.__adj.value
! else:
! value = pos
# FIXME:
# Hack derived from Andy's gtk_interface.cpp. Why 34 is here? ;)
! gtk.threads_enter ()
! self.__adj.set_all (value = value,
! lower = 0,
! upper = self.__cp.get_frames () - 34,
! step_increment = 1,
! page_increment = 0,
! page_size = 0)
! gtk.threads_leave ()
! else:
! gtk.threads_enter ()
! self.set_sensitive (GTK.FALSE)
! self.__adj.set_all (value = 0,
! lower = 0,
! upper = 0,
! step_increment = 0,
! page_increment = 0,
! page_size = 0)
! gtk.threads_leave ()
! return 1
!
! def __press_event (self, widget, event):
"""Button press event handler."""
--- 45,83 ----
# Signals
! self.__cp.register_notifier (self)
! self.connect ("button_press_event", self.__gtkcb_press_event)
! self.connect ("button_release_event", self.__gtkcb_release_event)
! self.connect ("motion_notify_event", self.__gtkcb_motion_event)
! self.connect ("destroy", self.__gtkcb_destroy)
!
! # Update upper
! self.cb_start_notify (None)
!
! def cb_start_notify (self, thread = 1):
! """Callback handler for a song start event. This signal emits by AlsaPlayer."""
! can_seek = self.__cp.can_seek ()
!
! if thread: gdk.threads_enter ()
! self.__adj.upper = float (self.__cp.get_frames () - 34)
! self.set_sensitive (can_seek)
!
! if thread: gdk.threads_leave ()
!
! def cb_position_notify (self, pos):
! """Callback handler for the position changes. This signal emits by AlsaPlayer."""
!
! if self.__dragging: return
+ if self.__cp.can_seek ():
# FIXME:
# Hack derived from Andy's gtk_interface.cpp. Why 34 is here? ;)
! gdk.threads_enter ()
! self.__adj.set_value (pos)
! gdk.threads_leave ()
! def __gtkcb_press_event (self, widget, event):
"""Button press event handler."""
***************
*** 90,123 ****
self.__motion = 0
! def __motion_event (self, widget, event):
"""Motion notify event handler."""
self.__motion = 1
! def __release_event (self, widget, event):
"""Button release event handler."""
if self.__motion:
! gtk.threads_leave ()
self.__cp.seek (self.__adj.value)
! gtk.threads_enter ()
self.__dragging = 0
! def __on_destroy (self, widget):
"""Called on the destroy."""
! gtk.threads_leave ()
self.__cp.unregister_notifier (self)
! gtk.threads_enter ()
! class HScale (gtk.GtkHScale, _Scale):
def __init__ (self, cp):
! gtk.GtkHScale.__init__ (self)
_Scale.__init__ (self, cp)
!
! class VScale (gtk.GtkVScale, _Scale):
def __init__ (self, cp):
! gtk.GtkVScale.__init__ (self)
_Scale.__init__ (self, cp)
--- 85,119 ----
self.__motion = 0
! def __gtkcb_motion_event (self, widget, event):
"""Motion notify event handler."""
self.__motion = 1
! def __gtkcb_release_event (self, widget, event):
"""Button release event handler."""
if self.__motion:
! gdk.threads_leave ()
self.__cp.seek (self.__adj.value)
! gdk.threads_enter ()
self.__dragging = 0
! def __gtkcb_destroy (self, widget):
"""Called on the destroy."""
! gdk.threads_leave ()
self.__cp.unregister_notifier (self)
! gdk.threads_enter ()
! # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
! class HScale (gtk.HScale, _Scale):
def __init__ (self, cp):
! gtk.HScale.__init__ (self)
_Scale.__init__ (self, cp)
! # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
! class VScale (gtk.VScale, _Scale):
def __init__ (self, cp):
! gtk.VScale.__init__ (self)
_Scale.__init__ (self, cp)
Index: speed.py
===================================================================
RCS file: /cvsroot/ap-python/python/aptk/speed.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** speed.py 19 Jul 2002 18:04:13 -0000 1.4
--- speed.py 21 Jul 2002 18:15:43 -0000 1.5
***************
*** 24,53 ****
__license__ = "GNU"
! import alsaplayer, gtk, aptk.misc, GTK
! # - - - - - - - - Scale --------------------------------------------------
class _Scale:
! def __init__ (self, cp):
! adj = gtk.GtkAdjustment (value=cp.get_speed()*100, lower=-333, upper=333)
! adj.connect ("value_changed", self.__cb_speed_changed)
! self.connect ("destroy", self.__on_destroy)
self.set_adjustment (adj)
-
self.set_draw_value (0)
! self.__cp = cp
self.__adj = adj
self.__cp_locked = 0
# Register callback to update scale by external pan changes
! cp.register_notifier (self)
! def __cb_speed_changed (self, w):
"""Gtk callback handler for scale changes."""
if not self.__cp_locked:
! gtk.threads_leave ()
self.__cp.set_speed (w.value/100)
! gtk.threads_enter ()
def cb_speed_changed (self, speed):
--- 24,64 ----
__license__ = "GNU"
! import alsaplayer, gtk, aptk.misc
! gdk = gtk.gdk
! # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
class _Scale:
! def __init__ (self, pl):
! """Initializer."""
!
! # Remeber for future use
! self.__cp = pl.get_coreplayer ()
!
! # Create adjustmnet
! adj = gtk.Adjustment (value = self.__cp.get_speed () * 100,
! lower = -333,
! upper = 333)
!
self.set_adjustment (adj)
self.set_draw_value (0)
! # Remember for future use
self.__adj = adj
self.__cp_locked = 0
# Register callback to update scale by external pan changes
! self.__cp.register_notifier (self)
! # Connect signals
! adj.connect ("value_changed", self.__gtkcb_speed_changed)
! self.connect ("destroy", self.__gtkcb_destroy)
!
! def __gtkcb_speed_changed (self, w):
"""Gtk callback handler for scale changes."""
if not self.__cp_locked:
! gdk.threads_leave ()
self.__cp.set_speed (w.value/100)
! gdk.threads_enter ()
def cb_speed_changed (self, speed):
***************
*** 56,120 ****
self.__cp_locked = 1
! gtk.threads_enter ()
self.__adj.set_value (speed*100)
! gtk.threads_leave ()
self.__cp_locked = 0
! def __on_destroy (self, widget):
"""Called on the destroy."""
! gtk.threads_leave ()
self.__cp.unregister_notifier (self)
! gtk.threads_enter ()
! class HScale (gtk.GtkHScale, _Scale):
def __init__ (self, cp):
! gtk.GtkHScale.__init__ (self)
_Scale.__init__ (self, cp)
!
! class VScale (gtk.GtkVScale, _Scale):
def __init__ (self, cp):
! gtk.GtkVScale.__init__ (self)
_Scale.__init__ (self, cp)
!
! # - - - - - - - - - Button ---------------------------------------------------
class Button (aptk.misc.Button):
! def __init__ (self, cp, value, prop = None, strip = ""):
"""Intitializer."""
# Call base class initializer
! aptk.misc.Button.__init__ (self, prop, strip)
# Connect signals
! self.connect ("clicked", self.__cb_clicked)
# Remember
self.__value = value
! self.__cp = cp
! def __cb_clicked (self, w):
! gtk.threads_leave ()
self.__cp.set_speed (self.__value)
! gtk.threads_enter ()
! # - - - - - - - - - - - - - - - Boxes - - - - - - - - - -
class _Box:
! def __init__ (self, cp, prop = None, strip = ""):
"""Inititalizer."""
! # Create strip string for this class
! this_strip = (strip and strip + ".") + 'speed'
!
# Create buttons
! self.backward_button = Button (cp, -1, prop, this_strip + ".backward")
self.add (self.backward_button)
! self.pause_button = Button (cp, 0, prop, this_strip + ".pause")
self.add (self.pause_button)
! self.forward_button = Button (cp, 1, prop, this_strip + ".forward")
self.add (self.forward_button)
--- 67,139 ----
self.__cp_locked = 1
! gdk.threads_enter ()
self.__adj.set_value (speed*100)
! gdk.threads_leave ()
self.__cp_locked = 0
! def __gtkcb_destroy (self, widget):
"""Called on the destroy."""
! gdk.threads_leave ()
self.__cp.unregister_notifier (self)
! gdk.threads_enter ()
! # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
! class HScale (gtk.HScale, _Scale):
def __init__ (self, cp):
! gtk.HScale.__init__ (self)
_Scale.__init__ (self, cp)
! # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
! class VScale (gtk.VScale, _Scale):
def __init__ (self, cp):
! gtk.VScale.__init__ (self)
_Scale.__init__ (self, cp)
! # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
class Button (aptk.misc.Button):
! def __init__ (self, pl, value, prop = None, prefix = ""):
"""Intitializer."""
# Call base class initializer
! aptk.misc.Button.__init__ (self, prop, prefix)
# Connect signals
! self.connect ("clicked", self.__gtkcb_clicked)
# Remember
self.__value = value
! self.__cp = pl.get_coreplayer ()
! def __gtkcb_clicked (self, w):
! gdk.threads_leave ()
self.__cp.set_speed (self.__value)
! gdk.threads_enter ()
! # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
class _Box:
! # Defualt properties
! __properties = aptk.misc.WidgetProperties ([
! ('*.speed.pause.button.label', '||'),
! ('*.speed.backward.button.label', 'Rw'),
! ('*.speed.forward.button.label', 'Fw')
! ])
!
! def __init__ (self, pl, prop = None, prefix = ""):
"""Inititalizer."""
! # Create new properties whth our defaults added
! prop = prop and (prop + self.__properties) or self.__properties
! prefix += ".speed"
!
# Create buttons
! self.backward_button = Button (pl, -1, prop, prefix + ".backward")
self.add (self.backward_button)
! self.pause_button = Button (pl, 0, prop, prefix + ".pause")
self.add (self.pause_button)
! self.forward_button = Button (pl, 1, prop, prefix + ".forward")
self.add (self.forward_button)
***************
*** 124,147 ****
self.forward_button.show ()
! class HBox (gtk.GtkHBox, _Box):
! def __init__ (self, cp, prop = None, strip = ""):
! gtk.GtkHBox.__init__ (self)
! _Box.__init__ (self, cp, prop, strip)
!
! class VBox (gtk.GtkVBox, _Box):
! def __init__ (self, cp, prop = None, strip = ""):
! gtk.GtkVBox.__init__ (self)
! _Box.__init__ (self, cp, prop, strip)
! # - - - - - - - - - - - - - Final Widgets - - - - - - - - - - - - - - -
! class HSpeed (gtk.GtkHBox):
! def __init__ (self, cp, prop = None, strip = ""):
! gtk.GtkHBox.__init__ (self)
! box = HBox (cp, prop, strip)
! scale = HScale (cp)
! self.pack_start (box, expand = GTK.FALSE)
self.add (scale)
--- 143,167 ----
self.forward_button.show ()
! # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
! class HBox (gtk.HBox, _Box):
! def __init__ (self, pl, prop = None, prefix = ""):
! gtk.HBox.__init__ (self)
! _Box.__init__ (self, pl, prop, prefix)
! # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
! class VBox (gtk.VBox, _Box):
! def __init__ (self, pl, prop = None, prefix = ""):
! gtk.VBox.__init__ (self)
! _Box.__init__ (self, pl, prop, prefix)
! # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
! class HSpeed (gtk.HBox):
! def __init__ (self, pl, prop = None, prefix = ""):
! gtk.HBox.__init__ (self)
! box = HBox (pl, prop, prefix)
! scale = HScale (pl)
! self.pack_start (box, expand = gtk.FALSE)
self.add (scale)
***************
*** 149,160 ****
scale.show ()
! class VSpeed (gtk.GtkVBox):
! def __init__ (self, cp, prop = None, strip = ""):
! gtk.GtkVBox.__init__ (self)
! box = VBox (cp, prop, strip)
! scale = VScale (cp)
! self.pack_start (box, expand = GTK.FALSE)
self.add (scale)
--- 169,181 ----
scale.show ()
! # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
! class VSpeed (gtk.VBox):
! def __init__ (self, pl, prop = None, prefix = ""):
! gtk.VBox.__init__ (self)
! box = VBox (pl, prop, prefix)
! scale = VScale (pl)
! self.pack_start (box, expand = gtk.FALSE)
self.add (scale)
Index: volume.py
===================================================================
RCS file: /cvsroot/ap-python/python/aptk/volume.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** volume.py 6 Jul 2002 16:08:10 -0000 1.3
--- volume.py 21 Jul 2002 18:15:43 -0000 1.4
***************
*** 25,53 ****
import alsaplayer, gtk, aptk.misc
! # - - - - - - - - Scale --------------------------------------------------
class _Scale:
! def __init__ (self, cp):
! adj = gtk.GtkAdjustment (value=cp.get_volume(), lower=0.0, upper=100)
! adj.connect ("value_changed", self.__cb_volume_changed)
! self.connect ("destroy", self.__on_destroy)
! self.set_adjustment (adj)
self.set_draw_value (0)
! self.__cp = cp
self.__adj = adj
self.__cp_locked = 0
# Register callback to update scale by external changes
! cp.register_notifier (self)
! def __cb_volume_changed (self, w):
"""Gtk callback handler for scale changes."""
if not self.__cp_locked:
! gtk.threads_leave ()
self.__cp.set_volume (w.value);
! gtk.threads_enter ()
def cb_volume_changed (self, volume):
--- 25,64 ----
import alsaplayer, gtk, aptk.misc
+ gdk = gtk.gdk
! # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
class _Scale:
! def __init__ (self, pl):
! """Initializer."""
!
! # Remeber for future use
! self.__cp = pl.get_coreplayer ()
+ # Create adjustmnet
+ adj = gtk.Adjustment (value = self.__cp.get_volume (),
+ lower = 0.0,
+ upper = 100)
+
+ self.set_adjustment (adj)
self.set_draw_value (0)
! # Remember for future use
self.__adj = adj
self.__cp_locked = 0
# Register callback to update scale by external changes
! self.__cp.register_notifier (self)
! # Connect gtk signals
! adj.connect ("value_changed", self.__gtkcb_volume_changed)
! self.connect ("destroy", self.__gtkcb_destroy)
!
! def __gtkcb_volume_changed (self, w):
"""Gtk callback handler for scale changes."""
if not self.__cp_locked:
! gdk.threads_leave ()
self.__cp.set_volume (w.value);
! gdk.threads_enter ()
def cb_volume_changed (self, volume):
***************
*** 56,97 ****
self.__cp_locked = 1
! gtk.threads_enter ()
self.__adj.set_value (volume)
! gtk.threads_leave ()
self.__cp_locked = 0
! def __on_destroy (self, widget):
"""Called on the destroy."""
! gtk.threads_leave ()
self.__cp.unregister_notifier (self)
! gtk.threads_enter ()
!
! class HScale (gtk.GtkHScale, _Scale):
! def __init__ (self, cp):
! gtk.GtkHScale.__init__ (self)
! _Scale.__init__ (self, cp)
!
!
! class VScale (gtk.GtkVScale, _Scale):
! def __init__ (self, cp):
! gtk.GtkVScale.__init__ (self)
! _Scale.__init__ (self, cp)
! # - - - - - - - - - Button ---------------------------------------------------
! class Button (aptk.misc.Button):
! def __init__ (self, cp, value, **keys):
! aptk.misc.Button.__init__ (self, **keys)
! self.connect ("clicked", self.__cb_clicked)
! self.__value = value
! self.__cp = cp
! def __cb_clicked (self, w):
! gtk.threads_leave ()
! self.__cp.set_volume (self.__value)
! gtk.threads_enter ()
! # - - - - - - - - - - - - - Final Widgets - - - - - - - - - - - - - - -
HVolume = HScale
VVolume = VScale
--- 67,96 ----
self.__cp_locked = 1
! gdk.threads_enter ()
self.__adj.set_value (volume)
! gdk.threads_leave ()
self.__cp_locked = 0
! def __gtkcb_destroy (self, widget):
"""Called on the destroy."""
! gdk.threads_leave ()
self.__cp.unregister_notifier (self)
! gdk.threads_enter ()
! # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
! class HScale (gtk.HScale, _Scale):
! def __init__ (self, pl):
! gtk.HScale.__init__ (self)
! _Scale.__init__ (self, pl)
! # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
! class VScale (gtk.VScale, _Scale):
! def __init__ (self, pl):
! gtk.VScale.__init__ (self)
! _Scale.__init__ (self, pl)
! # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
HVolume = HScale
VVolume = VScale
|