0
我正在研究一個簡單的程序,它使用GTK +/Glade/C編程語言打印使用打印對話框在textview中編寫的文本。用GTK +/C打印textView
這裏是源:
的ui.glade文件:
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.0 -->
<object class="GtkTextBuffer" id="textbuffer1"/>
<object class="GtkWindow" id="window1">
<property name="width_request">440</property>
<property name="height_request">250</property>
<property name="can_focus">False</property>
<child>
<object class="GtkFixed" id="fixed1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkTextView" id="textview1">
<property name="width_request">416</property>
<property name="height_request">186</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="buffer">textbuffer1</property>
</object>
<packing>
<property name="x">13</property>
<property name="y">13</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button1">
<property name="label" translatable="yes">Print</property>
<property name="width_request">145</property>
<property name="height_request">30</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="x">284</property>
<property name="y">210</property>
</packing>
</child>
</object>
</child>
</object>
</interface>
MAIN.C的源代碼:
#include <gtk/gtk.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
/************************ widgets variables **************************/
GtkBuilder *builder;
GtkWidget *window;
GtkButton *button1;
GtkTextView *textview1;
GtkTextBuffer *textbuffer1;
/************************ Printing button ***************************/
void on_button1_clicked()
{
//I'm blocked here
}
int main(int argc, char *argv[])
{
gtk_init(&argc, &argv);
builder = gtk_builder_new();
gtk_builder_add_from_file(builder,"ui.glade",NULL);
/************************** Getting widgets from UI file *****************************/
window = GTK_WIDGET(gtk_builder_get_object(builder, "window1"));
textview1 = GTK_WIDGET(gtk_builder_get_object(builder, "textview1"));
textbuffer1 = GTK_WIDGET(gtk_builder_get_object(builder, "textbuffer1"));
button1 = GTK_WIDGET(gtk_builder_get_object(builder, "button1"));
/************************** Connecting button signal **************************************/
g_signal_connect (G_OBJECT (button1), "clicked", (GCallback)on_button1_clicked, NULL);
gtk_builder_connect_signals(builder, NULL);
g_object_unref(builder);
gtk_widget_show(window);
gtk_main();
return 0;
}
所以我在編碼時被阻止打印功能,在這種情況下爲on_button1_clicked
。
我試過閱讀關於GtkPrintOperation的GTK文檔,但這對我來說並不是非常有幫助和不明白,因爲初學者+關於使用C和GTK的這個特殊主題的教程很少見!