How to create IDLE -like functionality to WinForms application
Asked Answered
I

5

0

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?

Improvident answered 29/4, 2009 at 8:28 Comment(0)
I
0

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.

Improvident answered 30/4, 2009 at 21:34 Comment(0)
P
1

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.

Pegpega answered 29/4, 2009 at 8:33 Comment(4)
I think this is pretty .NET specific issue, so CPython related information is basically useless.Improvident
You're probably right. To be honest I don't know how much will carry over from CPython to IronPython in that respect.Pegpega
And I don't think so. Syntax and most libraries are same.Iambic
Of course the language is same, but backend is completely different.Improvident
J
1

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.

Jellied answered 29/4, 2009 at 10:36 Comment(0)
M
0

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.

Michaelson answered 29/4, 2009 at 8:34 Comment(2)
It is text mode application, is the IronPyhton interpreter embedded to WinForms application?Improvident
The IronRuby interpreter runs on the command line. I don't know how the IronPython interpreter, if available, works, but I suggest just looking for it in the IronPython distribution. There's nothing wrong with just looking for what you're looking for.Michaelson
I
0

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.

Improvident answered 30/4, 2009 at 21:34 Comment(0)
V
0

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.

Vickivickie answered 22/11, 2012 at 16:9 Comment(1)
Sorry, you didn't read the question carefully enough. IDLE is Python IDE which comes with Python interpreter.Improvident

© 2022 - 2024 — McMap. All rights reserved.