2 First run tutorial.glade through gtk-builder-convert with this command:
3 gtk-builder-convert tutorial.glade tutorial.xml
5 Then save this file as main.c and compile it using this command
6 (those are backticks, not single quotes):
7 gcc -Wall -g -o tutorial main.c `pkg-config --cflags --libs gtk+-2.0` -export-dynamic
20 GtkWidget
*window
, *entry_a
, *entry_b
, *entry_calc
, *entry_mem
, *label_op
;
21 char tempbuf
[128], *ptempchar
, nextop
;
24 void on_button_no_clicked(GtkWidget
*widget
, gpointer user_data
) {
25 gtk_entry_append_text(entry_calc
, gtk_button_get_label(widget
));
30 if(calculated
) return;
31 gtk_entry_set_text(entry_b
, gtk_entry_get_text(entry_calc
));
32 gtk_entry_set_text(entry_calc
, "");
34 a
= strtod(gtk_entry_get_text(entry_a
), NULL
);
35 b
= strtod(gtk_entry_get_text(entry_b
), NULL
);
38 case '+': e
= a
+ b
; break;
39 case '-': e
= a
- b
; break;
40 case '*': e
= a
* b
; break;
41 case '/': e
= a
/ b
; break;
42 case '^': e
= pow(a
, b
); break;
43 case 'S': e
= a
+ b
; break;
45 sprintf(tempbuf
, "%lf", e
);
46 //printf("%f %c %f = %f\n", a, nextop, b, e);
47 gtk_entry_set_text(entry_calc
, tempbuf
);
51 void on_button_op_clicked(GtkWidget
*widget
, gpointer user_data
) {
52 char *oplbl
= gtk_button_get_label(widget
);
55 case '+': case '-': case '*': case '/': case '^': case 'S':
56 if(!calculated
) calculate();
57 gtk_entry_set_text(entry_a
, gtk_entry_get_text(entry_calc
));
58 gtk_entry_set_text(entry_calc
, "");
59 gtk_entry_set_text(entry_b
, "");
60 gtk_label_set_label(label_op
, oplbl
);
66 if(!calculated
) calculate();
67 gtk_entry_set_text(entry_calc
, gtk_entry_get_text(entry_calc
));
73 void on_button_mem_clicked(GtkWidget
*widget
, gpointer user_data
) {
74 char *oplbl
= gtk_button_get_label(widget
);
76 e
= strtod(gtk_entry_get_text(entry_calc
), NULL
);
77 m
= strtod(gtk_entry_get_text(entry_mem
), NULL
);
79 case '+': m
+= e
; break;
80 case '-': m
-= e
; break;
81 case 'C': m
= 0; break;
83 sprintf(tempbuf
, "%lf", m
);
84 gtk_entry_set_text(entry_mem
, tempbuf
);
88 void on_button_clear_clicked() {
89 /*ptempchar = gtk_entry_get_text(entry_calc);
90 ptempchar[strlen(ptempchar)-1] = '\x00';
91 gtk_entry_set_text(entry_calc, ptempchar);*/
92 gtk_entry_append_text(entry_calc
, "\r");
97 gtk_label_set_label(label_op
, "?");
98 gtk_entry_set_text(entry_calc
, "");
99 gtk_entry_set_text(entry_a
, "");
100 gtk_entry_set_text(entry_b
, "");
103 void on_window_destroy (GtkObject
*object
, gpointer user_data
)
108 int main (int argc
, char *argv
[])
110 gtk_init (&argc
, &argv
);
112 builder
= gtk_builder_new ();
113 gtk_builder_add_from_file (builder
, "calc.xml", NULL
);
114 window
= GTK_WIDGET (gtk_builder_get_object (builder
, "window"));
116 entry_a
= GTK_WIDGET (gtk_builder_get_object (builder
, "entry_a"));
117 entry_b
= GTK_WIDGET (gtk_builder_get_object (builder
, "entry_b"));
118 entry_calc
= GTK_WIDGET (gtk_builder_get_object (builder
, "entry_calc"));
119 entry_mem
= GTK_WIDGET (gtk_builder_get_object (builder
, "entry_mem"));
120 label_op
= GTK_WIDGET (gtk_builder_get_object (builder
, "label_op"));
122 gtk_builder_connect_signals (builder
, NULL
);
123 g_object_unref (G_OBJECT (builder
));
126 gtk_widget_show (window
);
This page took 0.343601 seconds and 4 git commands to generate.