簡體   English   中英

如何在 gtk 和空地中嵌入 plot

[英]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 可以更好:

https://github.com/lava/matplotlib-cpp

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM