gaze  0.1.0
Perform gaze tracking with common webcams.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
gui_cb.cpp
1 #include "where_people_look/gui_cb.h"
2 
3 #include <string>
4 
5 #include "gtk/gtk.h"
6 
7 #include "where_people_look/experiment.h"
8 
9 
10 namespace wpl {
11 
12 namespace gui {
13 
14 bool cb_finish_assistant(const GtkWidget*,
15  const GtkWidget* window) {
16  gtk_window_present(GTK_WINDOW(window));
17  gtk_window_fullscreen(GTK_WINDOW(window));
18  return false;
19 }
20 
21 bool cb_key_press(const GtkWidget*,
22  const GdkEventKey* event_key) {
23  switch (event_key->keyval) {
24  case GDK_KEY_F4:
25  if (event_key->state & GDK_MOD1_MASK) {
26  gtk_main_quit();
27  }
28  break;
29  case GDK_KEY_q: case GDK_KEY_W:
30  if (event_key->state & GDK_META_MASK) {
31  gtk_main_quit();
32  }
33  break;
34  }
35  return false;
36 }
37 
38 bool cb_update_config(GtkWidget* const widget,
39  Experiment* const experiment) {
40  std::string widget_name = std::string(gtk_widget_get_name(widget));
41  if (!widget_name.compare("subject_id")) {
42  experiment->get_config()->set_subject_id(
43  std::string(gtk_entry_get_text(GTK_ENTRY(widget))));
44  } else if (!widget_name.compare("stimuli_dir_path")) {
45  experiment->get_config()->set_stimuli_dir_path(
46  std::string(gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(widget))));
47  }
48 
49  if (experiment->get_config()->assistant_data_complete()) {
50  GtkWidget* grid = gtk_widget_get_parent(widget);
51  GtkWidget* assistant = gtk_widget_get_ancestor(grid, GTK_TYPE_ASSISTANT);
52  gtk_assistant_set_page_complete(GTK_ASSISTANT(assistant),
53  grid, true);
54  }
55  return false;
56 }
57 
58 void register_and_connect_callbacks(GtkBuilder* const builder,
59  Experiment* const experiment) {
60  gtk_builder_add_callback_symbols(builder,
61  "cb_finish_assistant", G_CALLBACK(cb_finish_assistant),
62  "cb_key_press", G_CALLBACK(cb_key_press),
63  "cb_prepare_experiment", G_CALLBACK(Experiment::experiment_prepare),
64  "cb_start_experiment", G_CALLBACK(Experiment::experiment_start),
65  "cb_update_config", G_CALLBACK(cb_update_config),
66  static_cast<void*>(0));
67 
68  gtk_builder_connect_signals(builder, experiment);
69 }
70 
71 void set_css_style(GtkWidget* const window,
72  const char* const css_resource) {
73  GtkStyleContext* style_context = gtk_widget_get_style_context(window);
74  GtkCssProvider* style_provider = gtk_css_provider_new();
75  gtk_css_provider_load_from_resource(style_provider, css_resource);
76  gtk_style_context_add_provider(style_context,
77  GTK_STYLE_PROVIDER(style_provider),
78  GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
79 }
80 
81 } // namespace gui
82 
83 } // namespace wpl
static bool experiment_prepare(const GtkWidget *const assistant, Experiment *const experiment)
Definition: experiment.cpp:123
static bool experiment_start(const GtkWidget *const window, const GdkEventKey *const event_key, Experiment *const experiment)
Definition: experiment.cpp:129
int compare(const basic_string &__str) const
basic_string< char > string