Using Python GTK GUI front end with C++ backend

一笑奈何 提交于 2021-02-09 07:00:23

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!