On Sep 20, 6:22 pm, "Edward K. Ream" <[EMAIL PROTECTED]> wrote:
> On Sat, Sep 20, 2008 at 6:50 AM, zpcspm <[EMAIL PROTECTED]> wrote:
> Please follow the example carefully.  Here is a tested script:
>
> @@@
> def getInput (event=None):
>
>     stateName = 'get-input'
>     k = c.k ; state = k.getState(stateName)
>
>     if state == 0:
>         k.setLabelBlue('Input: ',protect=True)
>         k.getArg(event,stateName,1,getInput)
>     else:
>         k.clearState()
>         g.es_print('input:',k.arg)
>
> getInput()
> QQQ
>
> The trick is that you must define a function that can be used as a callback.

Since it is not possible to return the user input from this function,
I have tried the opposite way. I have tried to pass another function
to getInput() as argument, a function that would accept k.arg as
argument and would actually do something instead of the hardcoded
g.es_print('input:',k.arg). Something like:

--- cut here ---
def my_print(s):

    g.es_print('input:',s)

def getInput (myfunc, event=None):

    stateName = 'get-input'
    k = c.k ; state = k.getState(stateName)

    if state == 0:
        k.setLabelBlue('Input: ',protect=True)
        k.getArg(event,stateName,1,getInput)
    else:
        k.clearState()
        myfunc(k.arg)

getInput(my_print)
--- cut here ---

This didn't work as well. Investigation of the leo source code stopped
at

Code-->
Gui Base classes-->
@thin leoKeys.py-->
class keyHandlerClass-->
Externally visible helpers-->
getArg

line 41 of this method is:

if handler: handler(event)

So it looks that the interaction with the handler is hardcoded. I
can't have a getInput() function with more arguments.
This is a double lock: I can't return anything from the handler
function and I can't pass anything to the handler function, so I'm
stuck again. Of course, instead of calling a function I can just do
what I need explicitly after clearing the state in the "else" code
block. But I expect that this would lead to a lot of redundancy in
every piece of code that needs input from user. That's why I need a
way to avoid this.

It is very possible that I'm just missing some subtle point here, but
I don't see what it could be ATM.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/leo-editor?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to