Cameron Laird mentioned Tk's send working with Python; if you are writing your
app with Tkinter, here is some code to let you use tcl commands like
    send <appname> python <expression or statement>
for remote control.  You could build a more sophisticated front-end for this,
and you'll probably also want to add stuff like sending the text of an
exception as the result of the 'send' command.

Jeff

#------------------------------------------------------------------------
import Tkinter

__all__ = 'python', 'setup_send'
def makecommand(master, name, func, subst=None, needcleanup=0):
    f = Tkinter.CallWrapper(func, subst, master).__call__
    master.tk.createcommand(name, f)
    if needcleanup:
        if master._tclCommands is None:
            master._tclCommands = []
        master._tclCommands.append(name)
    return name


def setup_send(app, ns, name="python"):
    def python(*args):
        s = " ".join(args)
        print args
        try:
            code = compile(s, '<send>', 'eval')
            return eval(code, ns)
        except SyntaxError:
            code = compile(s, '<send>', 'exec')
            exec code in ns
    makecommand(app, name, python)

if __name__ == '__main__':
    app = Tkinter.Tk()
    setup_send(app, {})
    app.mainloop()
#------------------------------------------------------------------------

Attachment: pgpEaC8F84pqI.pgp
Description: PGP signature

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to