13 #include "../Exceptions.hpp"
20 this->interface_parameters_panel = NULL;
22 this->window_created =
false;
23 this->window_open =
false;
24 this->updating_view =
false;
37 GtkWidget* btn = gtk_button_new_with_label(
"Open Interface Configuration");
38 this->open_close_buttons.push_back(btn);
39 g_signal_connect(G_OBJECT(btn),
41 G_CALLBACK(CB_openCloseWindow),
50 void InterfaceConfigurationWindow::createWindow()
52 if(!this->window_created)
55 EEGInterface *
interface = this->view->getInterfaceCombo()->getInterface();
60 this->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
63 gtk_window_set_title(GTK_WINDOW(window),
"Configure Interface");
64 gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER_ON_PARENT);
65 gtk_window_set_transient_for(GTK_WINDOW(window),GTK_WINDOW(main_window));
66 gtk_window_set_destroy_with_parent(GTK_WINDOW(window),
true);
67 gtk_window_set_default_size(GTK_WINDOW(window),200,0);
70 GtkWidget *container = gtk_vbox_new(
false, 0);
71 gtk_container_add(GTK_CONTAINER(window), container);
73 g_signal_connect(G_OBJECT(window),
"delete_event",
74 G_CALLBACK(CB_windowDelete),
this);
76 GtkWidget *params_label_box = gtk_hbox_new(
false, 0);
77 GtkWidget *classes_label_box = gtk_hbox_new(
false, 0);
80 GtkWidget *pref_image;
81 pref_image = gtk_image_new_from_stock(GTK_STOCK_PREFERENCES,GTK_ICON_SIZE_LARGE_TOOLBAR);
82 gtk_box_pack_start(GTK_BOX(params_label_box), pref_image,
false,
true, 0);
86 GtkWidget *param_text;
87 param_text = gtk_label_new(
"");
88 gtk_label_set_markup(GTK_LABEL(param_text),
"<b><big>Interface Parameters</big></b>");
89 gtk_box_pack_start(GTK_BOX(params_label_box), param_text,
false,
true, 0);
92 gtk_box_pack_start(GTK_BOX(container), params_label_box,
false,
false, 0);
93 gtk_box_pack_start(GTK_BOX(container), gtk_hseparator_new(),
false,
false, 0);
97 gtk_box_pack_start(GTK_BOX(container),gtk_hseparator_new(),
false,
false, 0);
98 gtk_box_pack_start(GTK_BOX(container),gtk_label_new(
"Interface Params"),
false,
false, 0);
101 GtkWidget *panel_container = gtk_hbox_new(
false,0);
102 if(interface != NULL)
104 if(interface_parameters_panel!=NULL)
105 delete interface_parameters_panel;
106 std::map<std::string, CEBL::Param> params = interface->getParamsList();
107 interface_parameters_panel =
new WidgetPanel(params);
109 if(params.size() > 0)
110 panel_container = interface_parameters_panel->
getContainer();
112 panel_container = gtk_label_new(
"No options for selected interface.");
114 gtk_box_pack_start(GTK_BOX(container),panel_container,
false,
false, 0);
118 GtkWidget *pref_text;
119 pref_text = gtk_label_new(
"");
120 gtk_label_set_markup(GTK_LABEL(pref_text),
"<b><big>Classes</big></b>");
121 gtk_box_pack_start(GTK_BOX(classes_label_box), pref_text,
false,
true, 0);
124 gtk_box_pack_start(GTK_BOX(container), classes_label_box,
false,
false, 0);
125 gtk_box_pack_start(GTK_BOX(container), gtk_hseparator_new(),
false,
false, 0);
130 class_labels_entries.resize(num_classes);
133 for(
int i=0; i<num_classes;i++)
135 GtkWidget *box = gtk_hbutton_box_new();
136 gtk_button_box_set_layout(GTK_BUTTON_BOX(box),GTK_BUTTONBOX_START);
139 l <<
"Class " << (i);
140 std::string label = l.str();
141 gtk_box_pack_start(GTK_BOX(box),gtk_label_new(label.c_str()),
false,
false, 0);
143 class_labels_entries[i] = gtk_entry_new();
144 gtk_entry_set_text(GTK_ENTRY(class_labels_entries[i]), class_labels[i].c_str());
145 gtk_box_pack_start(GTK_BOX(box),class_labels_entries[i],
true,
true, 0);
147 gtk_box_pack_start(GTK_BOX(container),box,
true,
true, 0);
152 GtkWidget *btn_ok = gtk_button_new_from_stock(GTK_STOCK_OK);
153 g_signal_connect(G_OBJECT(btn_ok),
"clicked",
154 G_CALLBACK(CB_windowClose),
this);
155 gtk_box_pack_start(GTK_BOX(container), btn_ok,
false,
false, 0);
158 this->window_created =
true;
163 void InterfaceConfigurationWindow::closeWindow()
165 if(this->window_open && this->window_created)
167 gtk_widget_hide(this->window);
168 this->window_open =
false;
173 void InterfaceConfigurationWindow::openWindow()
176 if(!this->window_open)
178 if(!this->window_created)
180 this->createWindow();
182 gtk_widget_show_all(this->window);
183 this->window_open =
true;
190 void InterfaceConfigurationWindow::applyConfig()
193 EEGInterface *
interface = this->view->getInterfaceCombo()->getInterface();
195 this->class_labels.resize(num_classes);
196 for(
unsigned i=0; i<class_labels_entries.size();i++)
198 if(
int(i) < num_classes)
199 class_labels[i] = gtk_entry_get_text(GTK_ENTRY(class_labels_entries[i]));
208 if(interface_parameters_panel!=NULL)
209 interface->setParamsList(interface_parameters_panel->
getParams());
210 interface->setClassLabels(class_labels);
220 this->updating_view =
true;
221 if(this->window_created)
223 gtk_widget_destroy(this->window);
225 this->window_created =
false;
226 this->createWindow();
227 if(this->window_open)
229 gtk_widget_show_all(this->window);
232 this->updating_view =
false;
238 void InterfaceConfigurationWindow::CB_openCloseWindow(GtkWidget *widget, gpointer data)
252 gboolean InterfaceConfigurationWindow::CB_windowDelete(GtkWidget *widget, GdkEvent *event, gpointer data)
259 void InterfaceConfigurationWindow::CB_windowClose(GtkWidget *widget, gpointer data)