[Bf-python] Embedding Blender - XEmbed protocol
Dietrich Bollmann
diresu at web.de
Mon Jul 26 05:45:10 CEST 2010
On Tue, 2010-07-20 at 09:11 +0800, Goat Man wrote:
> I didn't realize Blender can be embedded in a PyGTK window using
> gtk.Socket.
> Its an ugly hack to use the command line "xwininfo" to get the xid, it
> would be better if Blender printed on the command line its windowID or
> was available in the python API.
> This demo works most of the time, if the window loses focus then mouse
> clicking stops working, but keyboard and the mouse wheel seems to
> always work.
>
>
> http://pastebin.com/vYtJmmAC
>
>
> To make this useful we need a way to run a python loop in blender that
> talks on a socket or pipe to the parent process running pygtk.
Hi, not sure if this is usable in your case, but here is the code I use
for executing python code from the blender main event loop. Code can be
sent to blender via a socket from all kind of client applications (in my
case emacs and a lisp client automatically generating blender models).
See the part enclosed between '#ifdef WITH_COMMAND_PORT' and '#endif',
file: blender/source/blender/windowmanager/intern/wm.c
---
void WM_main(bContext *C)
{
int hasevent;
while(1) {
/* get events from ghost, handle window events, add to window queues
*/
hasevent = wm_window_process_events(C);
/* are there new ghost events to process? */
if (hasevent) {
/* processing new events */
/* per window, all events to the window, screen, area and region
handlers */
wm_event_do_handlers(C);
/* events have left notes about changes, we handle and cache it */
wm_event_do_notifiers(C);
/* execute cached changes draw */
wm_draw_update(C);
}
#ifdef WITH_COMMAND_PORT
/* process command port events -
returns the number of processed events. */
hasevent += commandport_process_events();
#endif
/* sleep for 5 milliseconds
when neither ghost nor command port events have been found */
if (!hasevent) {
/* no event, we sleep 5 milliseconds */
PIL_sleep_ms(5);
}
}
}
---
The function 'commandport_process_events()' processes python code send
to blender via a socket and stored in a special event queue.
This way I can do both in parallel, using the blender 2.5 GUI as well as
sending blender python code to blender via socket connections...
The code is on launchpad:
https://code.launchpad.net/~diresu/blender/blender-command-port-002
Cheers, Dietrich
PS:
I implemented everything from scratch: the socket functionality, the
protocol, .... Substituting some messaging queue for my own
functionality would make the code about 90% shorter I suppose :)
> _______________________________________________
> Bf-python mailing list
> Bf-python at blender.org
> http://lists.blender.org/mailman/listinfo/bf-python
More information about the Bf-python
mailing list