问题
I have some C++ code and am now building a GUI for an application. In the past I've used python and pygtk for GUI programming and occasionally link to some C++ code to do some heavy lifting. I would like to continue that trend but have one question on how to do it in this case. Part of the C++ code gets images from a camera and I would like to display those images on the GUI. I've used libvlc in the past and could pass the xid from a DrawingArea to vlc to draw the video on. I would like to do the same thing but can't seem to figure out how to use the xid. I've looked into the vlc code a little but haven't made sense of it yet. How do I pass the xid for a gtk widget in python to C++ and have the C++ code draw an image on the gtk widget?
回答1:
If you have a drawing area, you can do this:
#include <gdk/gdkx.h>
GtkWidget *drawing_area;
GdkWindow *window;
Window xid;
if (gtk_widget_get_realized (drawing_area)) {
window = gtk_widget_get_window (drawing_area);
xid = gdk_x11_window_get_xid (window);
}
Then you can pass the xid to whatever you want.
Note that widgets only get their windows created when they are realized. So, don't do the above before the drawing area's "realize" signal has been emitted.
You'll need to make the drawing area from the Python code available to the C++ code. I don't know the internals of pygtk that well, so that's up to you :)
来源:https://stackoverflow.com/questions/11314599/using-python-gtk-gui-front-end-with-c-backend