Csound Csound-dev Csound-tekno Search About

[Csnd] Re: Re: Re: Re: Re: csndsugui

Date2009-03-26 20:50
From"Art Hunkins"
Subject[Csnd] Re: Re: Re: Re: Re: csndsugui
Andres,

I surely do have a lot to learn about event-driven programming. (And I guess 
I'll need to work my way through the PyGTK tutorial as well.)

Yes, there is a button callback function. Is this how it should work if you 
only want something in csndsugui to happen when a button is pressed? (Please 
note here that apparently my .csd is not involved here at all - just the 
script itself. Is this correct?)

b1 = win.button(fb1, "", "PLAY!")
v1 = win.buttcallback(b1)
if v1 = 1:
  print "Button 1 pressed!"

When I run this, button one lights up (red) on the display (I don't think it 
should), but "Button 1 pressed!" is not present in the log (which I think it 
should be).

Art Hunkins

----- Original Message ----- 
From: "Andres Cabrera" 
To: 
Sent: Wednesday, March 25, 2009 11:48 PM
Subject: [Csnd] Re: Re: Re: Re: csndsugui


Hi Art,

I'm not really sure, but I would think there is a callback function
you can set for the button, which will be called when the button is
pressed, instead of having to loop. This is event driven programming,
which is surely something new if you've programmed mostly Csound.

Cheers,
Andrés

On Wed, Mar 25, 2009 at 10:45 PM, Art Hunkins  wrote:
> Here's the essence:
>
> v1 = 0
> while True:
> v1 = win.button(fb1, "", "PLAY!")
> if v1 == 0:
> continue
> break
> print "Finished!"
>
> The idea is an infinite loop which only gets broken when the button is
> pressed.
>
> As it is, the code fails with the message, "'int' object is not iterable".
>
> If I leave out "v1 = 0" the loop falls through immediately, printing
> "Finished" without pressing the button.
>
> There's clearly something basic I don't understand, probably having to do
> with the win.button line. Perhaps variables output by widgets only get 
> sent
> to the API and the .csd file, and are unavailable to the Python code 
> itself?
>
> If so, is there any method for holding in a loop with csndsugui until a 
> GUI
> button is pressed?
>
> Art Hunkins
>
> ----- Original Message ----- From: "Michael Gogins"
> 
> To: 
> Sent: Wednesday, March 25, 2009 4:14 PM
> Subject: [Csnd] Re: Re: csndsugui
>
>
> Give us the code that is not working, and maybe we can see what is wrong.
>
> Regards,
> Mike
>
> On Wed, Mar 25, 2009 at 4:00 PM, Andres Cabrera 
> wrote:
>>
>> Yes, since it's python, you can use ordinary python syntax.
>>
>> Cheers,
>> Andrés
>>
>> On 3/25/09, Art Hunkins  wrote:
>>>
>>> Is it possible to use "while" and/or "if" constructions in csndsugui? I
>>> need
>>> some sort of conditional to work with.
>>>
>>> (With what I've come up with so far, the script seems to blast through
>>> the
>>> conditional with nary a blink.)
>>>
>>> Art Hunkins
>>> Send bugs reports to this list.
>>> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe
>>> csound"
>>
>>
>> --
>>
>>
>> Andrés
>>
>>
>> Send bugs reports to this list.
>> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe
>> csound"
>
>
>
> --
> Michael Gogins
> Irreducible Productions
> http://www.michael-gogins.com
> Michael dot Gogins at gmail dot com
>
>
> Send bugs reports to this list.
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe
> csound"=
>
>
> Send bugs reports to this list.
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe
> csound"
>



-- 


Andrés


Send bugs reports to this list.
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe 
csound"= 


Date2009-03-26 21:43
FromAndres Cabrera
Subject[Csnd] Re: Re: Re: Re: Re: Re: csndsugui
Hi Art,

Callbacks are functions which are called whenever an event occurs. So
you just assign a callback to a given event, and when the event takes
place, the callback is executed.
I'm not sure about csndsugui, but for pygtk, which I think is what
most sugar activities and csndsugui are based on, you can se:
http://www.pygtk.org/pygtk2tutorial/sec-TheoryOfSignalsAndCallbacks.html

Cheers,
Andrés

On Thu, Mar 26, 2009 at 3:50 PM, Art Hunkins  wrote:
> Andres,
>
> I surely do have a lot to learn about event-driven programming. (And I guess
> I'll need to work my way through the PyGTK tutorial as well.)
>
> Yes, there is a button callback function. Is this how it should work if you
> only want something in csndsugui to happen when a button is pressed? (Please
> note here that apparently my .csd is not involved here at all - just the
> script itself. Is this correct?)
>
> b1 = win.button(fb1, "", "PLAY!")
> v1 = win.buttcallback(b1)
> if v1 = 1:
>  print "Button 1 pressed!"
>
> When I run this, button one lights up (red) on the display (I don't think it
> should), but "Button 1 pressed!" is not present in the log (which I think it
> should be).
>
> Art Hunkins
>
> ----- Original Message ----- From: "Andres Cabrera" 
> To: 
> Sent: Wednesday, March 25, 2009 11:48 PM
> Subject: [Csnd] Re: Re: Re: Re: csndsugui
>
>
> Hi Art,
>
> I'm not really sure, but I would think there is a callback function
> you can set for the button, which will be called when the button is
> pressed, instead of having to loop. This is event driven programming,
> which is surely something new if you've programmed mostly Csound.
>
> Cheers,
> Andrés
>
> On Wed, Mar 25, 2009 at 10:45 PM, Art Hunkins  wrote:
>>
>> Here's the essence:
>>
>> v1 = 0
>> while True:
>> v1 = win.button(fb1, "", "PLAY!")
>> if v1 == 0:
>> continue
>> break
>> print "Finished!"
>>
>> The idea is an infinite loop which only gets broken when the button is
>> pressed.
>>
>> As it is, the code fails with the message, "'int' object is not iterable".
>>
>> If I leave out "v1 = 0" the loop falls through immediately, printing
>> "Finished" without pressing the button.
>>
>> There's clearly something basic I don't understand, probably having to do
>> with the win.button line. Perhaps variables output by widgets only get
>> sent
>> to the API and the .csd file, and are unavailable to the Python code
>> itself?
>>
>> If so, is there any method for holding in a loop with csndsugui until a
>> GUI
>> button is pressed?
>>
>> Art Hunkins
>>
>> ----- Original Message ----- From: "Michael Gogins"
>> 
>> To: 
>> Sent: Wednesday, March 25, 2009 4:14 PM
>> Subject: [Csnd] Re: Re: csndsugui
>>
>>
>> Give us the code that is not working, and maybe we can see what is wrong.
>>
>> Regards,
>> Mike
>>
>> On Wed, Mar 25, 2009 at 4:00 PM, Andres Cabrera 
>> wrote:
>>>
>>> Yes, since it's python, you can use ordinary python syntax.
>>>
>>> Cheers,
>>> Andrés
>>>
>>> On 3/25/09, Art Hunkins  wrote:
>>>>
>>>> Is it possible to use "while" and/or "if" constructions in csndsugui? I
>>>> need
>>>> some sort of conditional to work with.
>>>>
>>>> (With what I've come up with so far, the script seems to blast through
>>>> the
>>>> conditional with nary a blink.)
>>>>
>>>> Art Hunkins
>>>> Send bugs reports to this list.
>>>> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe
>>>> csound"
>>>
>>>
>>> --
>>>
>>>
>>> Andrés
>>>
>>>
>>> Send bugs reports to this list.
>>> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe
>>> csound"
>>
>>
>>
>> --
>> Michael Gogins
>> Irreducible Productions
>> http://www.michael-gogins.com
>> Michael dot Gogins at gmail dot com
>>
>>
>> Send bugs reports to this list.
>> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe
>> csound"=
>>
>>
>> Send bugs reports to this list.
>> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe
>> csound"
>>
>
>
>
> --
>
>
> Andrés
>
>
> Send bugs reports to this list.
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe
> csound"=
>
>
> Send bugs reports to this list.
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe
> csound"
>



-- 


Andrés