将Python GTK GUI前端与C ++后端一起使用 [英] Using Python GTK GUI front end with C++ backend

查看:60
本文介绍了将Python GTK GUI前端与C ++后端一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些C ++代码,现在正在为应用程序构建GUI.过去,我使用python和pygtk进行GUI编程,偶尔链接到一些C ++代码来完成一些繁重的工作.我想继续保持这种趋势,但是在这种情况下,我对此有一个疑问.C ++代码的一部分从相机获取图像,我想在GUI上显示这些图像.我过去使用过libvlc,可以将xid从DrawingArea传递到vlc来绘制视频.我想做同样的事情,但似乎无法弄清楚如何使用xid.我对vlc代码进行了一些研究,但尚未理解.如何将python中gtk小部件的xid传递给C ++,并让C ++代码在gtk小部件上绘制图像?

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?

推荐答案

如果您有绘图区域,则可以执行以下操作:

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);
}

然后,您可以将xid传递给您想要的任何东西.

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.

您需要使Python代码中的绘图区域可用于C ++代码.我不太了解pygtk的内部原理,所以这取决于您:)

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 :)

这篇关于将Python GTK GUI前端与C ++后端一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆