|
Olivier,
Thanks so much; it works perfectly. With your
suggestions, I was even able to display 25 buttons in a single "for i in"
construction!
One last question:
Do you have any idea how to initialize a normal
gtk.Button to the "on" state, rather than the usual "off"?
My code is:
self.w.button(self.b6, "Filter", "Low-cut
Filter?") The idea is to have "Filter" initially send a value of 1 to Csound
rather than than 0, with the first switch being from "on" to "off."
Here's the code called from Victor Lazzarini's
csndsugui.py:
def 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""" self.butts =
self.butts + 1 if title ==
"": title = "B%d" %
self.butts if label == "": name =
title else: name =
label butt = gtk.Button(" %s " %
name)
self.scale_font(butt.child)
butt.modify_bg(gtk.STATE_PRELIGHT, gtk.gdk.Color(0x8000,0x8000,0x8000,
2)) box.pack_start(butt, False, False,
1)
self.buttons.append([butt,title,0])
butt.connect("clicked",
self.buttcallback)
butt.show() return butt
def buttcallback(self, widget,
data=None): for i in
self.buttons: if i[0] ==
widget: if i[2]:
i[2] =
0
i[0].modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(0x8000,0x8000,0x8000,
2))
i[0].modify_bg(gtk.STATE_PRELIGHT, gtk.gdk.Color(0x8000,0x8000,0x8000,
2))
else: i[2]
= 1
i[0].modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(0,0x7700,0,
1))
i[0].modify_bg(gtk.STATE_PRELIGHT, gtk.gdk.Color(0,0x7700,0,
2))
self.set_channel(i[1], i[2])
Thanks again for all your help.
Art Hunkins
----- Original Message -----
Sent: Friday, August 26, 2011 5:32
PM
Subject: Re: [Csnd] Python help
please
gtk.Container defined a method child_get_property(child,
property_name
). You can use
it to retrieve the position of the child. Can't try it because I'm on OSX
actually, but it will look like this:
index =
self.b3box.child_get_property(widget, "position")
I think everything
you need is on this page:
http://www.pygtk.org/docs/pygtk/class-gtkcontainer.html
Olivier
2011/8/26 Art Hunkins <abhunkin@uncg.edu>
Olivier,
Regarding your suggestion:
def choose(self, widget):
index = self.b3box.get_position(widget)
get_position is not implemented, as you
suspected (an error message states so).
However, self.b3box is generated by gtk.Hbox
which is a child of gtk.Box.
One of the child properties of gtk.Box is
"position" - which is exactly the value I need.
But
index =
self.b3box.position(widget)
and random variants thereof that I've
tried have led nowhere.
The error message: Attribute Error: "gtk.Hbox"
object has no attribute "position"
Any suggestion?
Art Hunkins
----- Original Message -----
Sent: Friday, August 26, 2011 3:46
PM
Subject: Re: [Csnd] Python help
please
I have not used gtk for a while but I'm sure
this line doesn't work: but6 =
win.cbbutton(self.b3box, self.choose(self, 1), " 1")
You execute
self.choose inside the definition of the widget, but what you want to do
is to pass a callback reference to the widget, something
like:
but6 =
win.cbbutton(self.b3box, self.choose, " 1")
The signature of the callback function is defined inside
win.cbutton, I don't think it's a good idea to try to modify it. Every
buttons will call the same function with the widget in argument, so you
have to grab the index from the widget... maybe the index inside the box
self.b3box:
def choose(self, widget): index =
self.b3box.get_position(widget) # this is only the idea, I don't know if
get_position is implemented in the class used to create
self.b3box...
Olivier
2011/8/26 Art Hunkins <abhunkin@uncg.edu>
Thanks both to Andres and
Olivier.
Using both of your suggestions, I modified
my Python script segments to the following. However I'm missing
something related to "index" (do I need to declare it?), and get various
error messages related to the choose function. Can you see what I'm
doing wrong?
self.paths =
["0"]*26 self.jobjects =
[None]*26
def choose(self, index, widget):
chooser = ObjectChooser(parent=self,
what_filter=mime.GENERIC_TYPE_AUDIO) result =
chooser.run() if result ==
gtk.RESPONSE_ACCEPT:
self.jobject[index] =
chooser.get_selected_object()
self.paths[index] =
str(self.jobjects[index].get_file_path())
else: self.jobject[index] =
None self.path[index] = "0"
def send_data(self):
for i in range(26):
self.w.set_filechannel("file%d" % i,
self.paths[i])
Choose is being called by one of 26
cbbuttons (from csndsugui, which is what win. refers to), as
in:
but6 =
win.cbbutton(self.b3box, self.choose(self, 1), " 1") This may well be
the source of my problem.
Am I perhaps passing the index value 1 to
the choose function incorrectly? (I tried: self.choose(self, index=1),
"1"
which made no difference.
Thanks again for your help.
Art Hunkins
----- Original Message -----
Sent: Friday, August 26, 2011
5:53 AM
Subject: Re: [Csnd] Python help
please
Hi Art,
Additionally, you could add the index input to the
choose function:
def choose (self, index,
widget)
Cheers, Andres
On Wed Aug 24 16:13:31 2011 Olivier Bélanger wrote:
self.path0 -> self.path25 must be a list where you store your
paths: Same thing for self.jobjects... (not sure you really need to
keep references to those objects). self.paths =
["0"]*26 self.jobjects = [None]*26 def choose(self,
widget): which = something here to grab the
order of "widget" ....
self.paths[which] =
str(self.jobjects[which].get_file_path()) def
send_data(self): for i in
range(26):
self.w.set_filechannel("file%d" % i,
self.paths[i]) Olivier
2011/8/24 Art Hunkins <abhunkin@uncg.edu>
I've written a Python script for a new XO/Sugar
activity for children (SamplePlay). It includes 26 buttons that
allow a user to select (from the Journal) up to 26
audio samples/loops to play. AFAIK, the "filename" must be sent
to Csound as a discrete variable, on its own channel (see
below).
As a result, I've 26 iterations(!) (0-25) of the same
basic code. I'd like to simplify it if possible (the code itself
works fine). Any suggestions from you Python/Csound enthusiasts
are very much welcomed. (The code references Victor's
csndsugui.py, but I don't think this is significant
her
self.path0 = "0" (up
through) self.path25 = "0"
self.jobject0 =
None (through) self.jobject25 = None
def
choose0(self, widget): chooser = ObjectChooser(parent=self,
what_filter=mime.GENERIC_TYPE_AUDIO) result =
chooser.run() if result == gtk.RESPONSE_ACCEPT:
self.jobject0 = chooser.get_selected_object()
self.path0 =
str(self.jobject0.get_file_path()) else:
self.jobject0 = None self.path0 =
"0" (through) def choose25(self,
widget): chooser = ObjectChooser(parent=self,
what_filter=mime.GENERIC_TYPE_AUDIO) result =
chooser.run() if result == gtk.RESPONSE_ACCEPT:
self.jobject25 = chooser.get_selected_object()
self.path25 =
str(self.jobject25.get_file_path()) else:
self.jobject25 = None self.path25 =
"0"
def
send_data(self): self.w.set_filechannel("file0",
self.path0) self.w.set_filechannel("file1",
self.path1) (through) self.w.set_filechannel("file24",
self.path24) self.w.set_filechannel("file25",
self.path25)
Hoping (as a Python novice) to be shown a
more efficient way; I'm in the dark -
Art
Hunkins
Send bugs reports to the Sourceforge bug
tracker https://sourceforge.net/tracker/?group_id=81968&atid=564599 Discussions
of bugs and features can be posted here To unsubscribe, send
email sympa@lists.bath.ac.uk with body "unsubscribe
csound"
|