InteractiveConsole (irc support & code completion)

I have written a console for python and the commandline, making it possible to mess with your running programm.

Features:

  • Connect to irc with the new irc-backend.
  • Use tab to autocomplete code. (only in panda3d window)
  • Press F1 for code help. (only in panda3d window)
  • Press Esc to toggle the Console (only in panda3d window)
  • Copy paste (only in panda3d window)
  • tested under windows, osx & linux with most features

Download the current version:
http://www.nouser.org/WD/Development/python/panda3d/projects/interactivePandaConsole/interactiveConsole-2010-12-06.zip
Download older versions: ( not recommended :slight_smile:
http://www.nouser.org/WD/?dir=./Development/python/panda3d/projects/interactivePandaConsole/

Even though it has quite a high version number consider this alpha state!
I do test, but you might get up with something i do not. If you find any bugs or have other questions feel free to post them here or send me an email.

How to use it in your own application:

from src.interactiveConsole import pandaConsole, INPUT_CONSOLE, INPUT_GUI, OUTPUT_PYTHON, OUTPUT_IRC

# INPUT_CONSOLE: enables the commandline text input
# INPUT_GUI: create the panda3d interface for the console
# OUTPUT_PYTHON: enables the python code executer
# OUTPUT_IRC: enables the irc backend
console = pandaConsole( INPUT_CONSOLE|INPUT_GUI|OUTPUT_PYTHON|OUTPUT_IRC, locals() )
# you should disable all not used interfaces, as some of them use tasks to poll informations (from keyboard, network port etc.)

# to have it hidden, toggle with escape
console.toggle()

last changes:

  • some small fixes i encountered when adding a sample main.py (06.12.2010)
  • fixed bugs causing a crash when using the help (F1) (05.10.07)
  • changed the help function to show the doc string, if no doc is found, the first 5 lines of inspect.getsourcelines is printed
  • fixed some linux clipboard bugs, thanks to Laurens (5.08.07)
  • added pydcop module to clipboard (4.08.07)
  • fixed multiline pasting (2.08.07)
  • added autohelp for python code (2.08.07)
  • fixed some problems occuring under windows (2.08.07)
  • added autocompletion for python code
  • added autocompletion for some irc commands (2.08.07)
  • added scrolling for inputs (1.08.07)
  • added scrolling for output (1.08.07)
  • added copy/cut & paste (1.08.07)
  • added colored output for the panda3d output (31.07.07)
  • added a basic IRC backend (31.07.07)
  • fixed some bugs (30.07.07)
  • fixed some bugs / and maybe introduced some new (29.07.07)
  • improved the functionality (29.07.07)
  • improved the visuals (29.07.07)
  • changed to have the read command called as task (23.01.07)
  • added more documentations (23.01.07)
  • changed oldterm to self.oldterm (15.11.06)
  • changed oldflags to self.oldflags (15.11.06)
  • moved to the correct forum (15.11.06)

Idea’s for the coming versions (they might come or might not):

  • Tabs: for irc channels (would require quite a lot of changes)
  • Extended autocompletion for irc (for example usernames)
  • Single word coloring (instead of lines)
  • Extended help (changing from lines of code to doc) ?
  • Curses console interface (for dedicated servers)
  • No bugs :wink:

pressing tab & f1:

Connecting to a irc server:

1 Like

Wow.

Hey David - what would you think of including something like this in direct?

Sure, why not?

David

Say, hypnos… what happens if you put “console.read()” in a task, instead of creating your own main loop?

nice. whoever adds that to direct.gui with a entry field/text field for usage directly in a Panda3D application (without the need for a console) will get a beer (or any drink) payed by me at the first Panda3D conference. :wink:

or a free t-shirt “Panda3D - too good to be true!”.

amazing.

cheers,
kaweh

Make that a case … I’ll chip in big time.

— THIS IS OUTDATED, look at the first & the last post for current informations —

Hi,

Im bit late with my reply. However i would be happy if you include the code snipplet into panda3d, putting it into a task should work afaik. However i have not testet that. As it redirects stdout in this class it may cause problems…

There is one problem i know about. Under linux it’s changing the console behavior, which requires resetting (“reset” in bash) of the console to be functioning properly again (on a crash). The appropiate code is in the pandaInteractiveConsole.del function, (have found a problem in the code and fixed it in the online version). But i have not tested it…

— THIS IS OUTDATED, look at the first & the last post for current informations —

Another thing i wanted to mention. Running blocking scripts using this method will interrupt panda. (for example a “while True: pass”) The main purpose of the current implementation is for a dedicated server (without a 3d interface). If you want to change it to a panda3d interface, you can remove a lot of stuff from the input handling. ( setting non blocking console, platform depending stuff etc.)

  • If you want to write the output from the InteractiveConsole to a panda3d interface you have to add this in the write function. (aka label.setText( string ) )
  • In this class no print functions will work, use self.stdout.write to output info to a console.

If i find the time ill write a class to be used directly in panda3d.

— THIS IS OUTDATED, look at the first & the last post for current informations —

I have updated the console to have a console (ala quake etc) within panda3d. The text (cmd, bash) entry should still work if you call use the way described above. Please note that everything printed from you application will be output here as well…

I only tested it on windows, just tell me if any problem arises on a linux box and i’ll fix it.

i added a parameter that gives the possibility to enable gui and/or console input. The read call (as described above) is only required when using the console input (not panda3d gui). F1 is currently setup to toggle the console visibility on/off.

(get the code from the first post)

edit: added 2 parameters for vertical size setting of the console & added some documentation.

Just integrated this into my technical demo. It looks very FPS’ish, they way you get it :smiley:
The text was slightly off (on multiline output the commandline lighter background overlaps with the output), but it works :wink:

Hope it serves you well.
I know about the overlapping background part of the directentry into the OnscreenText, however i havent figured out how to change this by now.

Dont forget to add a:

from direct.directbase import DirectStart

to your code. Else you’ll get a error that a dev symbol isn’t defined…

Kind regards,
Andrew

When I run this. From a straight copy and past from the forum. I get this.

Terminated with exit code 0

The panda window close prior to that.

Does anyone know what the problem is?

as AndrewSmart already said, add the following line before the code.

from direct.directbase import DirectStart

And as I neglected to say in my post. I added that line already and still I get the error I mentioned.

Exit status 0 actually means it reached the end of the program and exited normally, with no errors.

You must be running it straight from the python command prompt. In that case, you probably want to put a call to run() at the end of the code.

David

Thanks David. I just need to read the script to see what this is supposed to do. I just downloaded it because I wanted to study the code and the title of the thread looked goo. :frowning:

I will get back to you when I actually read the thread all the way thru and if I end up having questions. Right now all I get is a grey panda3d screen.

Shaba1,

you may try out to use different scaling for the text. First I had also only a gray screen - if you start entering text suddenly text appears from the bottom of the screen…

I got lucky with:

# vertical space from top
V_SPACE = 0
# vertical size of console
V_SIZE = 1.5
# size of the text
SCALE = 0.1
# when changing scale change this as well
LINELENGTH = 80

Maybe this helps.

Regards,
Andrew

Thank you I tired that but still got just a grey window.

Please have a look at the first post again. I added some more documentation (press F1 for console) and changed a lot in the code.

Regards, Hypnos