I think I'm about to bite a big bullet I've been putting off for a very long time. I've put a lot of time into integrating Python as a scripting language for my little game engine. Most of my time has been in cooperating with Python. Since I started doing that, I've learned about Python's fickle nature with multithreading, the global interpreter lock, and a lot about asynchronous programming generally. I also switched over to Stackless Python. Stackless works by honoring explicit yield instructions in the code to allow a complete context switch to some other task. If I were to use the normal command prompt here, it would block on the keyboard input. So I need something that can peek on a keyboard buffer, react to interact with the interpreter, and otherwise not be stealing too much time.
Managing a console like this has turned out to be a huge pain in the ass. Given everything else, I'm not surprised at all anymore. The main issue is having to manage line discipline. A major tactile part of Python's console is using the arrow keys, tabs, and of course backspace and delete. A normal text box is going to take over these events for typical text box navigation. But instead I need to trap them and have the interpreter take care of them. There's a nice Python module (the cmd module) that can be used to completely imitate the interpreter, and it will receive traps for those keys.
The Irrlicht edit box is a good base candidate for doing this stuff but it looks like I'd have to go in and muck with it to transmit those keys as events that I can propagate over to some Python code that will pump it through the cmd module. All this so I don't have Python blocking on keyboard input.
I figured I'd just ask here for some advice on this, but it's been hard to come by anywhere, so I was just going to use this thread to complain about it while I slogged through it.
Python console GUI
-
- Posts: 48
- Joined: Tue Aug 31, 2010 6:27 am
Re: Python console GUI
Of course first thing in I clone the edit box source file into a project and the linker can't find getTime() anymore. Good old magic compilation settings. I guess I'll have to define the code in my Irrlicht project, build the DLL, then link it into my test app. I can't for the life of me figure whatever magic option I'm missing that keeps it from linking in that symbol.
-
- Posts: 48
- Joined: Tue Aug 31, 2010 6:27 am
Re: Python console GUI
After a lot of sleuthing around I found how Blender does their own Python console. They aren't using the cmd module but actually the code module like I had used in my first experiments. They take over the streams and have their own stuff in place.
It looks like the standard with Python text input functions is that the functions themselves are aware of command history and how to draw that right. So I have to make the GUI component have some awareness of command history, and what makes up a command. This is annoying since I had hoped there were some hooks into the Python runtime that could react to the arrow keys for me and tell me what to print. Oh well. At the very least with the cmd module I can do multiline commands and things like that.
It looks like the standard with Python text input functions is that the functions themselves are aware of command history and how to draw that right. So I have to make the GUI component have some awareness of command history, and what makes up a command. This is annoying since I had hoped there were some hooks into the Python runtime that could react to the arrow keys for me and tell me what to print. Oh well. At the very least with the cmd module I can do multiline commands and things like that.
-
- Posts: 48
- Joined: Tue Aug 31, 2010 6:27 am
Re: Python console GUI
Well I'm starting to get something out of it:
I need to do something about new messages coming in, because the code is treating it like input right now. So I think I need to make it block on new input until the interpreter comes back, or they hit CTRL-C or something. However, this is reassuring me.
Code: Select all
Prompt>Python 2.6.5 Stackless 3.1b3 060516 (release26-maint, Feb 15 2012, 09:11:40) [MSC v.1600 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
(Shell)
a = 2
Prompt>a =3
Prompt>c = 2
Prompt>print "Hi"
Prompt>Hi
Prompt>print "Ack!"
Prompt>Ack!
Prompt>print "Huh?"
Prompt>Huh?
Prompt>print a
Prompt>3