csndsugui
index
/home/victor/csndsugui/csndsugui.py

# sugar-aware GUI classes
# with boxes, sliders, spinbuttons, buttons, etc
#
# (c) Victor Lazzarini, 2006-08
#   
#    This library is free software; you can redistribute it
#    and/or modify it under the terms of the GNU Lesser General Public
#    License as published by the Free Software Foundation; either
#    version 2.1 of the License, or (at your option) any later version.
#
#    csndsugui is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Lesser General Public License for more details.
#
#    You should have received a copy of the GNU Lesser General Public
#    License along with csndsugui; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
#    02111-1307 USA
#
#    As a special exception, if other files instantiate templates or
#    use macros or inline functions from this file, this file does not
#    by itself cause the resulting executable or library to be covered
#    by the GNU Lesser General Public License. This exception does not
#    however invalidate any other reasons why the library or executable
#    file might be covered by the GNU Lesser General Public License.
#
#
#  version 0.1.2  18/03/08

 
Modules
       
sugar.activity.activity
csnd
gtk
locale
math
os
pygtk
sugar
sys
time

 
Classes
       
BasicGUI
CsoundGUI

 
class BasicGUI
    Basic GUI with boxes, sliders, spins, buttons etc
using pygtk/sugar, from which GUI classes
can be derived for Csound use.
 
  Methods defined here:
__init__(self, act, colour=(-1, -1, -1), vert=True, toolbox=None)
Constructor
act:  activity object
colour: bg colour RGB tuple (R,G, B)
vert: True for vertical topmost arrangement, horiz. otherwise
toolbox: activity toolbox object, if None (default) a
   standard toolbox will be supplied
box(self, vert=True, parent=None, padding=5)
creates a box 
vert: True, creates a vertical box; horiz.
 otherwise
parent: parent box, None if this is a toplevel box
padding: box padding
returns the widget instance
buttcallback(self, widget, data=None)
button(self, box, title='', label='')
Creates a button (on/off)
box: parent box
title: if given, the button name,
  which will also be the bus channel
  name. Otherwise a default name is
  given, BN, where N is button number
  in order of creation.
label: if given, an alternative button name,
  which will be displayed instead of title
returns the widget instance
buttonbank(self, items, box)
Creates a button bank 
items: number of sliders
box: parent box.
cbbutton(self, box, callback, title='')
Creates a callbackbutton
box: parent box
callback: click callback
title: if given, the button name
returns the widget instance
channels_reinit(self)
resets channel to current widget values
delete_event(self, widget, event, data=None)
destroy_chooser(self, widget)
fbuttcallback(self, widget, data=None)
# internal callback
filecallback(self, widget)
filechooser(self, box, title, label='')
Creates a filechooser button
title: button name, also file bus channel name
box: parent box
label: if given, alternative name, for display purposes only
  otherwise button will display its title.
focus_back(self, widget, event)
focus_connect(self)
focus_disconnect(self)
focus_in(self, widget, event)
focus_out(self, widget, event)
framebox(self, name, vert=True, parent=None, colour=(0, 0, 0), padding=5)
Creates a frame box
name: text label
vert: vertical (True) box, else horiz.
parent: parent box, if None, this is a toplevel box
colour: RGB values in a tuple (R,G,B) 
padding: padding space
returns the box widget instance
get_button(self, name)
returns the button widget instance
name: button name
get_button_value(self, name)
returns the button value (0 or 1)
name: button name (which should also be the attached bus channel name)
get_slider(self, name)
returns the slider widget instance
name: slider name
get_slider_value(self, name)
returns the slider value
name: slider name (which should also be the attached bus channel name
get_toolbox(self)
Returns the Activity toolbox
hsliderbank(self, items, init, start, end, x, y, box)
Creates a horizontal slider bank 
items: number of sliders
init: initial value
start, end: start and end of slider range
x, y: x and y sizes of slider
box: parent box
mbuttcallback(self, widget, data=None)
mbutton(self, box, mess, title='')
Creates a mbutton (for sending a message)
box: parent box
title: if given, the button name, otherwise a default name is
 given, BN, where N is button number
 in order of creation.
mess: message to be sent when button is clicked
returns the widget instance
nofocus(self)
set_channel(self, name, val)
basic bus channel setting method,
should be overriden for full-functionality.
set_filechannel(self, chan, name)
basic filename channel setting method
should be overriden for full-functionality.
set_focus(self)
called whenever the focus changes
set_message(self, mess)
basic message setting method
should be overriden for full-functionality.
slidcallback(self, adj, widget)
slider(self, init, start, end, x, y, box, title='', vert=True, linear=True, dwid=100, label='')
Creates a slider
init: initial value
start, end: start and end of slider range
x, y: x and y sizes of slider
box: parent box
title: if given, the slider name,
 which will also be the bus channel
 name. Otherwise a default name is
 given, SN, where N is slider number
 in order of creation.
vert: vertical slider (True), else horiz.
linear: linear response (True), else exponential (zero or negative
 ranges are not allowed)
dwid:  display width in pixels
label: if given, the alternative slider name, for display only 
returns the widget instance
spin(self, init, start, end, step, page, box, accel=0, title='', label='')
Creates a spin button
init: initial value
start, end: start and end of slider range
step, page: small and large step sizes
box: parent box
accel: acceleration or 'climb rate' (0.0-1.0)
title: if given, the spin button name,
  which will also be the bus channel
  name. Otherwise a default name is
  given, SPN, where N is spin number
  in order of creation.
label: if given, the alternative name for the widget, for display only.
returns the widget instance
spincallback(self, adj, widget)
text(self, name, box=None, colour=(0, 0, 0))
Creates a static text label
name: text label
box: parent box, None if text is to be placed toplevel
colour: RGB values in a tuple (R,G,B)
returns the widget instance
vsliderbank(self, items, init, start, end, x, y, box)
Creates a vertical slider bank 
items: number of sliders
init: initial value
start, end: start and end of slider range
x, y: x and y sizes of slider
box: parent box

 
class CsoundGUI(BasicGUI)
    A class inheriting from BasicGUI containing a Csound instance and a performance 
thread instance.
 
  Methods defined here:
__init__(self, act, colour=(-1, -1, -1), vert=True)
constructor
act:  activity object
colour: bg colour RGB tuple (R,G, B)
vert: True for vertical topmost arrangement, horiz. otherwise.
close(self, event)
compile(self, name=None, args=[])
Compiles Csound code.
name: CSD filename if given
args: list of arguments (as strings)
returns 0 if successful , non-zero if not.
csd(self, name)
Sets the source CSD and compiles it.
name: CSD filename
returns zero if successful
pause(self)
Pauses a performance.
play(self)
Starts a performance.
recompile(self)
Recompiles the set CSD.
returns zero if successful
reset(self)
Resets Csound, ready for a new CSD
set_channel(self, name, val)
overrides the base method.
sets the bus channel value, called by the widget callbacks
channel names 'play', 'pause' and
'reset' are reserved for these respective uses
set_filechannel(self, chan, name)
overrides the base method, setting the channel string
set_focus(self)
overrides the base class method, resetting/recompiling Csound
set_message(self, mess)
overrides the base method, sends a score message

Methods inherited from BasicGUI:
box(self, vert=True, parent=None, padding=5)
creates a box 
vert: True, creates a vertical box; horiz.
 otherwise
parent: parent box, None if this is a toplevel box
padding: box padding
returns the widget instance
buttcallback(self, widget, data=None)
button(self, box, title='', label='')
Creates a button (on/off)
box: parent box
title: if given, the button name,
  which will also be the bus channel
  name. Otherwise a default name is
  given, BN, where N is button number
  in order of creation.
label: if given, an alternative button name,
  which will be displayed instead of title
returns the widget instance
buttonbank(self, items, box)
Creates a button bank 
items: number of sliders
box: parent box.
cbbutton(self, box, callback, title='')
Creates a callbackbutton
box: parent box
callback: click callback
title: if given, the button name
returns the widget instance
channels_reinit(self)
resets channel to current widget values
delete_event(self, widget, event, data=None)
destroy_chooser(self, widget)
fbuttcallback(self, widget, data=None)
# internal callback
filecallback(self, widget)
filechooser(self, box, title, label='')
Creates a filechooser button
title: button name, also file bus channel name
box: parent box
label: if given, alternative name, for display purposes only
  otherwise button will display its title.
focus_back(self, widget, event)
focus_connect(self)
focus_disconnect(self)
focus_in(self, widget, event)
focus_out(self, widget, event)
framebox(self, name, vert=True, parent=None, colour=(0, 0, 0), padding=5)
Creates a frame box
name: text label
vert: vertical (True) box, else horiz.
parent: parent box, if None, this is a toplevel box
colour: RGB values in a tuple (R,G,B) 
padding: padding space
returns the box widget instance
get_button(self, name)
returns the button widget instance
name: button name
get_button_value(self, name)
returns the button value (0 or 1)
name: button name (which should also be the attached bus channel name)
get_slider(self, name)
returns the slider widget instance
name: slider name
get_slider_value(self, name)
returns the slider value
name: slider name (which should also be the attached bus channel name
get_toolbox(self)
Returns the Activity toolbox
hsliderbank(self, items, init, start, end, x, y, box)
Creates a horizontal slider bank 
items: number of sliders
init: initial value
start, end: start and end of slider range
x, y: x and y sizes of slider
box: parent box
mbuttcallback(self, widget, data=None)
mbutton(self, box, mess, title='')
Creates a mbutton (for sending a message)
box: parent box
title: if given, the button name, otherwise a default name is
 given, BN, where N is button number
 in order of creation.
mess: message to be sent when button is clicked
returns the widget instance
nofocus(self)
slidcallback(self, adj, widget)
slider(self, init, start, end, x, y, box, title='', vert=True, linear=True, dwid=100, label='')
Creates a slider
init: initial value
start, end: start and end of slider range
x, y: x and y sizes of slider
box: parent box
title: if given, the slider name,
 which will also be the bus channel
 name. Otherwise a default name is
 given, SN, where N is slider number
 in order of creation.
vert: vertical slider (True), else horiz.
linear: linear response (True), else exponential (zero or negative
 ranges are not allowed)
dwid:  display width in pixels
label: if given, the alternative slider name, for display only 
returns the widget instance
spin(self, init, start, end, step, page, box, accel=0, title='', label='')
Creates a spin button
init: initial value
start, end: start and end of slider range
step, page: small and large step sizes
box: parent box
accel: acceleration or 'climb rate' (0.0-1.0)
title: if given, the spin button name,
  which will also be the bus channel
  name. Otherwise a default name is
  given, SPN, where N is spin number
  in order of creation.
label: if given, the alternative name for the widget, for display only.
returns the widget instance
spincallback(self, adj, widget)
text(self, name, box=None, colour=(0, 0, 0))
Creates a static text label
name: text label
box: parent box, None if text is to be placed toplevel
colour: RGB values in a tuple (R,G,B)
returns the widget instance
vsliderbank(self, items, init, start, end, x, y, box)
Creates a vertical slider bank 
items: number of sliders
init: initial value
start, end: start and end of slider range
x, y: x and y sizes of slider
box: parent box