Question

I'd like to add "IDLE-like functionality" to C# WinForms application, but I don't quite have an idea how to do that and couldn't find anything useful with Google.

So basically I want interactive command line interface, where user could enter some Python code and execute it (not just expressions, should be possible to define new functions).

So, where to start? Are there any good tutorials or samples available?

Was it helpful?

Solution 4

Thru IronPython mailing list I found IronTextBox2, which is good example how things are done. It needs a little tweaking, to get it running, but otherwise is good solution.

OTHER TIPS

If my memory serves me correctly there's a chapter on embedding Python in the book Python in a Nutshell. Perhaps you can find some useful information there, but since the book is not Windows specific, you may have to adapt it yourself.

I would setyp my WinForm like this: add 2 textboxes.

1: for output. Set the multiline property of the first to true, and make it read only.

2: for input. Use KeyUp Or KeyPress Event for e.g. the return key and use the text to do what you want: add command to output textbox, launch code against the engine and capture output of interpreter

This link (http://groups.google.com/group/ironpy/browse_thread/thread/5e61a944c7c94d4b/0cbf29ec0f5fbb64?pli=1) might give some answers about launching commands agains a python engine.

IronRuby comes with a command line interpreter. Doesn't IronPython also have one? If so, the source code would be a good start :) Oh, and if it doesn't, be sure to look at the IronRuby interpreter, because both languages are based on the DLR and are therefore similar enough to learn from both.

Here go my most generic solution:

Point cursorPoint;
int minutesIdle=0;

private bool isIdle(int minutes)
{
    return minutesIdle >= minutes;
}

private void idleTimer_Tick(object sender, EventArgs e)
{
    if (Cursor.Position != cursorPoint)
    {
        // The mouse moved since last check
        minutesIdle = 0;
    }
    else
    {
        // Mouse still stoped
        minutesIdle++;
    }

    // Save current position
    cursorPoint = Cursor.Position;
}

You can setup a timer running on 60000 interval. By this way you will just know how many minutes the user don't move the mice. You can also call "isIdle" on the Tick event itself to check on each interval.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top