Edit detail for PythonHelp button revision 1 of 1

1
Editor: edreamleo
Time: 2006/06/01 17:04:47 GMT+0
Note:

changed:
-
Here is an @button node that provides a clean interface to Python's help function.
It prompts for ``name`` in the minibuffer and sends help(name) to Leo's log pane::

    <?xml version="1.0" encoding="UTF-8"?>
    <?xml-stylesheet ekr_stylesheet?>
    <leo_file>
    <leo_header file_format="1" tnodes="2" max_tnode_index="2"/>
    <vnodes>
    <v t="ekr.20060601182602" a="EV"><vh>@button python-help</vh>
    <v t="ekr.20060601183949"><vh>stateHandler</vh></v>
    </v>
    </vnodes>
    <tnodes>
    <t tx="ekr.20060601182602">@others
    
    stateHandler()</t>
    <t tx="ekr.20060601183949">def stateHandler (event=None):
        
        '''Prompt for a arg for Python's help function, and put it to the log pane.'''
                
        k = c.k ; tag = 'python-help' ; state = k.getState(tag)
    
        if state == 0:
            c.frame.minibufferWantsFocus()
            k.setLabelBlue('Python help: ',protect=True)
            k.getArg(event,tag,1,stateHandler)
        else:
            k.clearState()
            k.resetLabel()
            s = k.arg.strip()
            if s:
                g.redirectStderr()
                g.redirectStdout()
                try:
                    help(str(s))
                except Exception:
                    pass
                g.restoreStderr()
                g.restoreStdout()</t>
    </tnodes>
    </leo_file>
   
Just copy this code, then paste it into Leo using Leo's Paste Node command.
You can run the script directly.
The next time you open the outline you will see a 'Python Help' button.

Here is an @button node that provides a clean interface to Python's help function. It prompts for name in the minibuffer and sends help(name) to Leo's log pane:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet ekr_stylesheet?>
<leo_file>
<leo_header file_format="1" tnodes="2" max_tnode_index="2"/>
<vnodes>
<v t="ekr.20060601182602" a="EV"><vh>@button python-help</vh>
<v t="ekr.20060601183949"><vh>stateHandler</vh></v>
</v>
</vnodes>
<tnodes>
<t tx="ekr.20060601182602">@others

stateHandler()</t>
<t tx="ekr.20060601183949">def stateHandler (event=None):

    '''Prompt for a arg for Python's help function, and put it to the log pane.'''

    k = c.k ; tag = 'python-help' ; state = k.getState(tag)

    if state == 0:
        c.frame.minibufferWantsFocus()
        k.setLabelBlue('Python help: ',protect=True)
        k.getArg(event,tag,1,stateHandler)
    else:
        k.clearState()
        k.resetLabel()
        s = k.arg.strip()
        if s:
            g.redirectStderr()
            g.redirectStdout()
            try:
                help(str(s))
            except Exception:
                pass
            g.restoreStderr()
            g.restoreStdout()</t>
</tnodes>
</leo_file>

Just copy this code, then paste it into Leo using Leo's Paste Node command. You can run the script directly. The next time you open the outline you will see a 'Python Help' button.