CEBL  2.1
CEBLViewGTK.cpp
Go to the documentation of this file.
1 
9 #include "CEBLViewGTK.hpp"
10 #include "ToolbarMenu.hpp"
11 #include "WidgetUtils.hpp"
12 
13 //combo factories
14 #include "DataSourceCombo.hpp"
15 #include "InterfaceCombo.hpp"
16 
17 //tabs
18 #include "TabEEGRecording.hpp"
19 #include "TabDevice.hpp"
20 #include "TabMonitor.hpp"
21 #include "TabFilter.hpp"
22 #include "TabFeatures.hpp"
23 #include "TabDecision.hpp"
24 #include "TabClassifiers.hpp"
25 #include "TabTraining.hpp"
27 
28 //model classes
29 #include "../model/StringTable.hpp"
30 #include "../CompiledStrings.hpp"
31 
32 //other widgets
33 #include "StatusBar.hpp"
34 #include "InfoBar.hpp"
35 
36 //----------------------------------------------------------------------
37 // Constructors / Destructors
38 
39 CEBLViewGTK::CEBLViewGTK(CEBLModel *model, int ac, char ** av) : CEBLView(model)
40 {
41  this->ac = ac;
42  this->av = av;
43 
44  //set up some defaults
45  WINDOW_WIDTH = 800;
46  WINDOW_HEIGHT = 700;
47 
48  //initialize tabs
49  tabs.resize(0);
50 
51  //create string table
52  //TODO: load path from prefs
53  string string_table_filename = string(HOMEDIR)
54  + "/.cebl/conf/gui-string-table-en.txt";
55  string_table = new StringTable();
56  string_table->loadFromString(gui_string_table_en);
57  //string_table->loadFromFile(string_table_filename);
58 }
59 
60 
62 {
63  delete main_menu;
64  for(unsigned int i=0;i<tabs.size();i++)
65  delete tabs[i];
66  delete data_source;
67  delete interface_combo;
68  delete status_bar;
69  delete string_table;
70  delete info_bar;
71 }
72 
73 //----------------------------------------------------------------------
74 // GTK Event Callbacks
75 
76 gboolean CEBLViewGTK::CB_WindowDelete(GtkWidget *widget,
77  GdkEvent *event,gpointer data)
78 {
79  CEBLViewGTK * view = (CEBLViewGTK*) data;
80  for(unsigned int i=0; i<view->tabs.size();i++)
81  {
82  view->tabs[i]->onHide();
83  }
84  return false; //destroy event will occur
85 }
86 void CEBLViewGTK::CB_WindowDestroy(GtkWidget *widget, gpointer data)
87 {
88  gtk_main_quit();
89 }
90 
91 
92 //----------------------------------------------------------------------
93 // Start the view
94 
96 {
97  // GTK Initialization
98  gtk_init(&ac, &av);
99 
100  // create the gui
101  CreateMainWindow();
102  CreateLayout();
103 
104  //show the main container
105  gtk_widget_show(main_container);
106  //show the window
107  gtk_widget_show(main_window);
108  //start up gtk
109  gtk_main();
110 }
111 
112 
113 
114 //----------------------------------------------------------------------
115 //Create the GUI
116 
117 
118 void CEBLViewGTK::CreateMainWindow()
119 {
120  main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
121 
122  gtk_window_set_title(GTK_WINDOW(main_window),"CSU Electroencepholagram Brain-Computer Interface Lab (CEBL)");
123 
124  // extract the window's colors for later use
125  GtkStyle *style = gtk_rc_get_style(main_window);
126  BG_RED = style->bg[0].red;
127  BG_GREEN = style->bg[0].green;
128  BG_BLUE = style->bg[0].blue;
129 
130  // set window properties
131  gtk_window_set_default_size(GTK_WINDOW(main_window), WINDOW_WIDTH, WINDOW_HEIGHT);
132  gtk_container_set_border_width(GTK_CONTAINER(main_window),2);
133 
134  //connect destroy and delete signals
135  g_signal_connect (G_OBJECT (main_window), "delete_event",
136  G_CALLBACK (CB_WindowDelete), this);
137  g_signal_connect (G_OBJECT (main_window), "destroy",
138  G_CALLBACK (CB_WindowDestroy), this);
139 
140  //set main window in widget utils
141  WidgetUtils::setMainWindow(main_window);
142 }
143 
144 
146 void CEBLViewGTK::CreateLayout()
147 {
148 
149  //create main container and add it to the window
150  main_container = gtk_vbox_new(false,0);
151  gtk_container_add(GTK_CONTAINER(main_window), main_container);
152 
153  //----------------------------------------
154  // TOP
155 
156  // menu bar
157  main_menu = new ToolbarMenu(this);
158  main_menu->attachMenu(main_window,main_container);
159 
160 
161  //----------------------------------------
162  // SEPARATE LEFT AND RIGHT
163 
164  // horizontal pane
165  GtkWidget * main_pane = gtk_hpaned_new();
166  gtk_box_pack_start(GTK_BOX(main_container),main_pane, true, true, 1);
167  gtk_widget_show(main_pane);
168 
169  GtkWidget *right_container = gtk_vbox_new(false,0);
170  gtk_widget_show(right_container);
171  gtk_paned_pack2(GTK_PANED(main_pane), right_container, true, false);
172 
173 
174  //----------------------------------------
175  // RIGHT
176 
177  //title bar
178  GtkWidget *align = gtk_alignment_new(0,0,0,1);
179  //GtkWidget *title_label = gtk_label_new("");
180  //gtk_container_add(GTK_CONTAINER(align),title_label);
181  gtk_widget_show_all(align);
182  gtk_box_pack_start(GTK_BOX(right_container), align, false, true, 5);
183 
184  //create notebook
185  main_notebook = gtk_notebook_new();
186  gtk_box_pack_start(GTK_BOX(right_container), main_notebook, true, true, 0);
187 
188  //gtk_notebook_popup_enable(GTK_NOTEBOOK(main_notebook));
189  gtk_notebook_set_tab_pos(GTK_NOTEBOOK(main_notebook), GTK_POS_LEFT);
190 
191  //create combo factories
192  data_source = new DataSourceCombo(this);
193  interface_combo = new InterfaceCombo(this);
194 
195  //create tabs
196  tabs.push_back(new TabEEGRecording("EEG Recording", main_notebook, this));
197  tabs.push_back(new TabDevice("EEG Data Source", main_notebook, this));
198  tabs.push_back(new TabMonitor("Monitor", main_notebook, this));
199  tabs.push_back(new TabFilter("Filter", main_notebook, this));
200  tabs.push_back(new TabFeatures("Features", main_notebook, this));
201  tabs.push_back(new TabClassifiers("Classifiers", main_notebook, this));
202  tabs.push_back(new TabDecision("Decision Process", main_notebook, this));
203  tabs.push_back(new TabTraining("Training", main_notebook, this));
204  tabs.push_back(new TabRealTimeClassification("Real-Time Classification", main_notebook, this));
205  old_page = 0;
206 
207 
208  //show the notebook
209  gtk_widget_show(main_notebook);
210 
211  //add change tab signal to notebook
212  g_signal_connect(G_OBJECT(main_notebook),
213  "switch-page",
214  G_CALLBACK(CB_ChangeTab),
215  (gpointer) this);
216 
217  //Status and Info Bars
218  info_bar = new InfoBar(this);
219  gtk_box_pack_end(GTK_BOX(main_container), info_bar->getContainer(), false, false, 1);
220  status_bar = new StatusBar();
221  gtk_box_pack_end(GTK_BOX(main_container), status_bar->getContainer(), false, false, 1);
222 }
223 
224 
225 //----------------------------------------------------------------------
226 // UPDATING TAB VIEWS
227 
228 /*
229  * Change the visible tab from old_page to page_num
230  */
231 void CEBLViewGTK::CB_ChangeTab(GtkNotebook *notebook,
232  GtkNotebookPage *page,
233  guint page_num,
234  gpointer data)
235 {
236  CEBLViewGTK *view = (CEBLViewGTK*)data;
237 
238  //hide last page
239  if(view->old_page >= 0
240  && view->old_page < int(view->tabs.size()))
241  {
242  view->tabs[view->old_page]->onHide();
243  view->tabs[view->old_page]->updateModel();
244  }
245  //show selected page
246  view->tabs[page_num]->onShow();
247  view->tabs[page_num]->updateView();
248  view->old_page = page_num;
249 }
250 
251 /*
252  * Update display for main window (and current tab)
253  */
255 {
256  if(this->old_page >= 0
257  && this->old_page < int(this->tabs.size()))
258  {
259  tabs[this->old_page]->updateView();
260  }
261  this->getDataSource()->updateView();
262 }
263 
264 /*
265  * Updates settings in corresponding model for current tab
266  */
268 {
269  if(this->old_page >= 0
270  && this->old_page < int(this->tabs.size()))
271  {
272  tabs[this->old_page]->updateModel();
273  }
274 }
275 
276 /*
277  * Update the InfoBar information
278  */
280  if(info_bar!=NULL)
281  info_bar->update();
282 }
283 
284 /*
285  * Gets a string from the string table for display
286  * See conf/gui-string-table-en.txt for strings
287  */
288 const char * CEBLViewGTK::getString(string name)
289 {
290  try
291  {
292  return string_table->getString(name);
293  }
294  catch(exception &e)
295  {
296  cerr << e.what();
297  return "";
298  }
299 }
300