Panda in GUI

is there a way to add panda to a traditional GUI window ? I need a lots of complicated widgets that are already available with GUI libraries such as wxWidgets, tcl or GTK. Alternatively, I could also get hold of pandas window handle and add my stuff - every hint is welcome

Gabriel

You really have three choices.

One easy way would be to use the tcl/tk stuff that other panda panels use. For example, take a look at the particle panel sample program. The downside is that the rendering would still be in a separate window.

A second easy way would be to use panda’s built-in widgets. But the downside here is that the built-in widgets are a little primitive.

If neither of those appeals, then you have to go the difficult route. Here’s a rough outline. First, find a widget set that’s well-integrated with python - say, tcl/tk or pyGtk. Use that to create your main window, before you initialize panda.

Then, modify the code that initializes the panda window. In showbase.py, you’ll find this code:

    if type == 'onscreen':
        win = self.graphicsEngine.makeWindow(gsg, name, 0)
    elif type == 'offscreen':
        win = self.graphicsEngine.makeBuffer(
            gsg, name, 0, props.getXSize(), props.getYSize(), 0)

This is where it creates the window. It is not picky about where it renders to — it can render to an opengl window, a directx window, an onscreen window, an offscreen buffer, to no window at all. It seems to me that it would probably not be hard to add another option - render to an already-existing subwindow of a tcl/tk or pygtk application. This may involve doing some C++ hacking, though. In the source tree, in the subdirectory panda/src/windisplay, is the code that creates a window from scratch. It may be necessary to add another, similar module that creates a window within an existing application.

Frankly, all this sounds like a lot of work to me. I actually think it would be easier to use panda’s built-in widgets, despite their limitations.

FWIW, I’ve got wxWidgets working in parallel with an OpenGL renderer, within the same process. You can have a look at the source here:


cvs -d:pserver:anonymous@cvs.sf.net:/cvsroot/metaverse export metaversealpha -r HEAD

You can also browse from your web browser at cvs.sf.net/viewcvs.py/metaverse/metaversealpha , although its a lot easier to browse through the source if you just download it using the cvs command above.

The source modules to look at are metaverseclient.py and pyMainThread.py

Now, its not putting wxWidgets stuff in exactly the same physical window as the OpenGL stuff, but they are in the same application, and they look fairly integrated.

We basically have the following:

  • OpenGL window, for renderering the 3d world
  • rightclick context menu
  • chat window
  • lots of other menus and dialogs accessible from the context menu

The way it is working is:

  • Python runs the show
  • there are two threads in Python: pyMainThread.py and pyGUIApp, in metaverseclient.py
  • pyGUIApp starts the OpenGL renderer, passing in itself as a callback object (swig lets you do this, using directors)
  • the OpenGL application passes up all mouseclicks on its window up to pyMainThread, which passes them on to pyGUIApp
  • this lets pyGUIApp handle displaying right-click context menus
  • and obviously the chat window and the context window derivatives can easily be handled by pyGUIApp without any major issues

Now, with your application, you obviously cant use swig directors, since they’re incompatible with Panda. However, Panda does provide a bunch of built-in callback/event classes, such as the TaskMgr, and presumably stuff for keyboard and mouse. So, the same principle could hold.

This works transparently for context menus and chat windows.

Hugh

A very warm “thank you” to both of you - your reply was super-fast and really up to the point. For me, showing a window in pyGtk and then customizing “showbase.py” to use a subwindow as rendering surface sounds like a charm. Furthermore, routing the gtk events through TaskMgr will let me handle gtk widgets in a natural way - just the way I imagined it to be. A big thank you, again !

Hmmm…
Speaking of GUI’s. What about making a GUI for panda game development?
Sortof like microsofts XNA?
But better because it is panda and python.
Wouldn’t this make game development even faster?
Plus to prevent stupid automatic coding by the gui, it could be
made to export the appropriate python code, so the game
developer can add speed optimizations.

If nobody is available to do this I would. I wanna help

@irnyad: there is one. try the SceneEditor that ships with panda by default.

For Windows right you can get panda to be a sub window of a win32 dialog we are working on this for OSX right know. We have made it work with MFC and native win32 code. The key is being on the head of he CVS tree and knowing how to run python as a sub thread of your win32 app.(If you are using the python parts of the engine.) Extreme care must be taken to manage keyboard and mouse events. Sub windowing is easy. If you do not need keyboard and mouse input in the panda window(s) you are cooking, if you do get real familiar with the WIN32 setfocus() function.

See the new win_property for a parent window handle

Cheers
Roger