[英]how to embed plot in gtk and glade
我正在尝试使用 Glade 和 C 中的 gtk 创建一个简单的 gui。 在 GUI 中,我想添加一个绘制数据的小部件(一行 plot 和一个直方图都是我想要的)(不断更新),我不知道该使用什么。 我已经看到 gnuplot 很流行,但我不知道如何在应用程序中使用它。 我想要一些建议和一些说明,因为我找不到它。
这是我用作基础的一些示例代码,只是为了给您一个想法
更新:我在我的电脑上构建了 gnuplot,现在当我运行代码时,它不会打开一个新的 window 并且似乎在我的 window 中是 plot。 唯一的问题是我的 gtkbox 容器中的小部件没有调整大小,所以它看起来像一个小白条。 我假设它正在工作,因为我删除了
gui.graph = gnuplot_init(); gnuplot_setstyle(gui.graph, "lines"); gnuplot_cmd(gui.graph, "set terminal x11 window \"%x\"", (int)gtk_socket_get_id (gui.socket)); gnuplot_plot_slope(gui.graph, 1.0, 0.0, "unity slope");
并在单独的终端上运行命令,我提到的白条会弹出。
#include <gtk/gtk.h> #include <gtk/gtkx.h> #include "variables.h" #include "gnuplot_i.h" struct test tv; struct GUI gui; // Functions void GUISetup(); int main(int argc, char *argv[]) { gtk_init(&argc, &argv); gui.builder = gtk_builder_new_from_file("glade/window_main.glade"); gui.window = GTK_WIDGET(gtk_builder_get_object(gui.builder, "window_main")); gtk_builder_connect_signals(gui.builder, NULL); GUISetup(); g_object_unref(gui.builder); // start fullbuilderscreen gtk_window_fullscreen(GTK_WINDOW(gui.window)); gtk_widget_show(gui.window); gtk_main(); return 0; } void GUISetup(){ gui.socket = gtk_socket_new (); gtk_container_add (GTK_CONTAINER (gui.MainContainer), gui.socket); //gtk_widget_show (gui.socket); //gtk_widget_realize (gui.socket); gui.graph = gnuplot_init(); gnuplot_setstyle(gui.graph, "lines"); gnuplot_cmd(gui.graph, "set terminal x11 window \"%x\"", (int)gtk_socket_get_id (gui.socket)); gnuplot_plot_slope(gui.graph, 1.0, 0.0, "unity slope"); }
当我让我得到这个:
gcc -c -g -O0 -Wall -pthread -pipe src/main.c `pkg-config --cflags --libs gtk+-3.0` -o main.o src/main.c: In function 'GUISetup': src/main.c:66:86: warning: passing argument 1 of 'gtk_socket_get_id' from incompatible pointer type [-Wincompatible-pointer-types] ui.graph, "set terminal x11 window \"%x\"", (int)gtk_socket_get_id (gui.socket)); ^~~ In file included from /usr/include/gtk-3.0/gtk/gtkx.h:29:0, from src/main.c:25: /usr/include/gtk-3.0/gtk/gtksocket.h:81:12: note: expected 'GtkSocket * {aka struct _GtkSocket *}' but argument is of type 'GtkWidget * {aka struct _GtkWidget *}' Window gtk_socket_get_id (GtkSocket *socket_); ^~~~~~~~~~~~~~~~~ gcc -o interface main.o gnuplot_i.o -pthread `pkg-config --cflags --libs gtk+-3.0` -export-dynamic
我手动测试了代码并得到了与此处相同的结果,因此我将尝试构建 gnuplot 并更改配置文件。 该帖子中找到的解决方案是否有任何替代方案?
对于 gnuplot:
http://ndevilla.free.fr/gnuplot/gnuplot_i/index.html
或者您可以使用 Gtk::Socket,首先创建一个Gtk::Socket
并将其添加到您的小部件中。 然后将套接字 ID(作为十六进制)传递给 gnuplot 'set terminal x11 window "ID"'。 就是这样!
Matplot 可以更好:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.