00001
00002
00003
00004
00005 #include <sys/types.h>
00006 #include <sys/stat.h>
00007 #include <unistd.h>
00008 #include <string.h>
00009
00010 #include <gdk/gdkkeysyms.h>
00011 #include <gtk/gtk.h>
00012
00013 #include "callbacks.h"
00014 #include "interface.h"
00015
00016 GtkWidget*
00017 create_window (void)
00018 {
00019 GtkWidget *window;
00020 GtkWidget *vbox1;
00021 extern GtkWidget *draw_main;
00022 GtkWidget *hbox1;
00023 GtkWidget *button_change;
00024 GtkWidget *button_run;
00025 GtkWidget *button_clear;
00026 GtkWidget *button_save;
00027 GtkWidget *button_load;
00028 extern GtkWidget *entry_option;
00029
00030 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
00031 gtk_object_set_data (GTK_OBJECT (window), "window", window);
00032 gtk_window_set_title (GTK_WINDOW (window), "SVM Toy");
00033
00034 vbox1 = gtk_vbox_new (FALSE, 0);
00035 gtk_widget_ref (vbox1);
00036 gtk_object_set_data_full (GTK_OBJECT (window), "vbox1", vbox1,
00037 (GtkDestroyNotify) gtk_widget_unref);
00038 gtk_widget_show (vbox1);
00039 gtk_container_add (GTK_CONTAINER (window), vbox1);
00040
00041 draw_main = gtk_drawing_area_new ();
00042 gtk_widget_ref (draw_main);
00043 gtk_object_set_data_full (GTK_OBJECT (window), "draw_main", draw_main,
00044 (GtkDestroyNotify) gtk_widget_unref);
00045 gtk_widget_show (draw_main);
00046 gtk_box_pack_start (GTK_BOX (vbox1), draw_main, TRUE, TRUE, 0);
00047 gtk_widget_set_usize (draw_main, 500, 500);
00048 gtk_widget_set_events (draw_main, GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK);
00049
00050 hbox1 = gtk_hbox_new (FALSE, 0);
00051 gtk_widget_ref (hbox1);
00052 gtk_object_set_data_full (GTK_OBJECT (window), "hbox1", hbox1,
00053 (GtkDestroyNotify) gtk_widget_unref);
00054 gtk_widget_show (hbox1);
00055 gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, FALSE, 0);
00056
00057 button_change = gtk_button_new_with_label ("Change");
00058 gtk_widget_ref (button_change);
00059 gtk_object_set_data_full (GTK_OBJECT (window), "button_change", button_change,
00060 (GtkDestroyNotify) gtk_widget_unref);
00061 gtk_widget_show (button_change);
00062 gtk_box_pack_start (GTK_BOX (hbox1), button_change, FALSE, FALSE, 0);
00063
00064 button_run = gtk_button_new_with_label ("Run");
00065 gtk_widget_ref (button_run);
00066 gtk_object_set_data_full (GTK_OBJECT (window), "button_run", button_run,
00067 (GtkDestroyNotify) gtk_widget_unref);
00068 gtk_widget_show (button_run);
00069 gtk_box_pack_start (GTK_BOX (hbox1), button_run, FALSE, FALSE, 0);
00070
00071 button_clear = gtk_button_new_with_label ("Clear");
00072 gtk_widget_ref (button_clear);
00073 gtk_object_set_data_full (GTK_OBJECT (window), "button_clear", button_clear,
00074 (GtkDestroyNotify) gtk_widget_unref);
00075 gtk_widget_show (button_clear);
00076 gtk_box_pack_start (GTK_BOX (hbox1), button_clear, FALSE, FALSE, 0);
00077
00078 button_save = gtk_button_new_with_label ("Save");
00079 gtk_widget_ref (button_save);
00080 gtk_object_set_data_full (GTK_OBJECT (window), "button_save", button_save,
00081 (GtkDestroyNotify) gtk_widget_unref);
00082 gtk_widget_show (button_save);
00083 gtk_box_pack_start (GTK_BOX (hbox1), button_save, FALSE, FALSE, 0);
00084
00085 button_load = gtk_button_new_with_label ("Load");
00086 gtk_widget_ref (button_load);
00087 gtk_object_set_data_full (GTK_OBJECT (window), "button_load", button_load,
00088 (GtkDestroyNotify) gtk_widget_unref);
00089 gtk_widget_show (button_load);
00090 gtk_box_pack_start (GTK_BOX (hbox1), button_load, FALSE, FALSE, 0);
00091
00092 entry_option = gtk_entry_new ();
00093 gtk_widget_ref (entry_option);
00094 gtk_object_set_data_full (GTK_OBJECT (window), "entry_option", entry_option,
00095 (GtkDestroyNotify) gtk_widget_unref);
00096 gtk_widget_show (entry_option);
00097 gtk_box_pack_start (GTK_BOX (hbox1), entry_option, TRUE, TRUE, 0);
00098
00099 gtk_signal_connect (GTK_OBJECT (window), "destroy",
00100 GTK_SIGNAL_FUNC (on_window1_destroy),
00101 NULL);
00102 gtk_signal_connect (GTK_OBJECT (draw_main), "button_press_event",
00103 GTK_SIGNAL_FUNC (on_draw_main_button_press_event),
00104 NULL);
00105 gtk_signal_connect (GTK_OBJECT (draw_main), "expose_event",
00106 GTK_SIGNAL_FUNC (on_draw_main_expose_event),
00107 NULL);
00108 gtk_signal_connect (GTK_OBJECT (button_change), "clicked",
00109 GTK_SIGNAL_FUNC (on_button_change_clicked),
00110 NULL);
00111 gtk_signal_connect (GTK_OBJECT (button_run), "clicked",
00112 GTK_SIGNAL_FUNC (on_button_run_clicked),
00113 NULL);
00114 gtk_signal_connect (GTK_OBJECT (button_clear), "clicked",
00115 GTK_SIGNAL_FUNC (on_button_clear_clicked),
00116 NULL);
00117 gtk_signal_connect (GTK_OBJECT (button_save), "clicked",
00118 GTK_SIGNAL_FUNC (on_button_save_clicked),
00119 NULL);
00120 gtk_signal_connect (GTK_OBJECT (button_load), "clicked",
00121 GTK_SIGNAL_FUNC (on_button_load_clicked),
00122 NULL);
00123 gtk_signal_connect (GTK_OBJECT (entry_option), "activate",
00124 GTK_SIGNAL_FUNC (on_button_run_clicked),
00125 NULL);
00126
00127 return window;
00128 }
00129
00130 GtkWidget*
00131 create_fileselection (void)
00132 {
00133 GtkWidget *fileselection;
00134 GtkWidget *filesel_ok;
00135 GtkWidget *filesel_cancel;
00136
00137 fileselection = gtk_file_selection_new ("Select File");
00138 gtk_object_set_data (GTK_OBJECT (fileselection), "fileselection", fileselection);
00139 gtk_container_set_border_width (GTK_CONTAINER (fileselection), 10);
00140 gtk_window_set_modal (GTK_WINDOW (fileselection), TRUE);
00141
00142 filesel_ok = GTK_FILE_SELECTION (fileselection)->ok_button;
00143 gtk_object_set_data (GTK_OBJECT (fileselection), "filesel_ok", filesel_ok);
00144 gtk_widget_show (filesel_ok);
00145 GTK_WIDGET_SET_FLAGS (filesel_ok, GTK_CAN_DEFAULT);
00146
00147 filesel_cancel = GTK_FILE_SELECTION (fileselection)->cancel_button;
00148 gtk_object_set_data (GTK_OBJECT (fileselection), "filesel_cancel", filesel_cancel);
00149 gtk_widget_show (filesel_cancel);
00150 GTK_WIDGET_SET_FLAGS (filesel_cancel, GTK_CAN_DEFAULT);
00151
00152 gtk_signal_connect (GTK_OBJECT (fileselection), "destroy",
00153 GTK_SIGNAL_FUNC (on_fileselection_destroy),
00154 NULL);
00155 gtk_signal_connect (GTK_OBJECT (filesel_ok), "clicked",
00156 GTK_SIGNAL_FUNC (on_filesel_ok_clicked),
00157 NULL);
00158 gtk_signal_connect (GTK_OBJECT (filesel_cancel), "clicked",
00159 GTK_SIGNAL_FUNC (on_filesel_cancel_clicked),
00160 NULL);
00161
00162 return fileselection;
00163 }
00164