How to create IDLE -like functionality to WinForms application

本秂侑毒 提交于 2019-12-11 15:13:48

问题


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?


回答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.




回答2:


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.




回答3:


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.




回答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.




回答5:


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.



来源:https://stackoverflow.com/questions/801432/how-to-create-idle-like-functionality-to-winforms-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!