Thread: [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...
[truncated message content] |