PIPS
gtk_status.c
Go to the documentation of this file.
1 /*
2 
3  $Id: gtk_status.c 23065 2016-03-02 09:05:50Z coelho $
4 
5  Copyright 1989-2016 MINES ParisTech
6 
7  This file is part of PIPS.
8 
9  PIPS is free software: you can redistribute it and/or modify it
10  under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  any later version.
13 
14  PIPS is distributed in the hope that it will be useful, but WITHOUT ANY
15  WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  FITNESS FOR A PARTICULAR PURPOSE.
17 
18  See the GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with PIPS. If not, see <http://www.gnu.org/licenses/>.
22 
23 */
24 #ifdef HAVE_CONFIG_H
25  #include "pips_config.h"
26 #endif
27 #include <stdlib.h>
28 #include <stdio.h>
29 #include <stdarg.h>
30 #include <unistd.h>
31 #include <sys/time.h>
32 #include <sys/resource.h>
33 
34 #include <sys/time.h>
35 #include <sys/resource.h>
36 
37 #undef test_undefined // also defined in glib included from gtk
38 #include <gtk/gtk.h>
39 
40 #if (defined(TEXT))
41 #undef TEXT
42 #endif
43 
44 #if (defined(TEXT_TYPE))
45 #undef TEXT_TYPE
46 #endif
47 
48 #include "genC.h"
49 #include "linear.h"
50 #include "ri.h"
51 #include "database.h"
52 
53 #include "misc.h"
54 #include "ri-util.h"
55 #include "pipsdbm.h"
56 
57 #include "gpips.h"
58 
59 enum {
60  DECALAGE_STATUS = 100
61 };
62 
63 /* Max number of digits displayed in the status panel: */
64 enum {
66 };
67 
68 typedef struct {
69  GtkWidget * label;
70  GtkWidget * entry;
71  GtkWidget * button;
73 
76 GtkWidget *module_name_entry;
77 GtkWidget *cpu_usage_item;
78 
79 //Server_image status_window_pips_image;
80 
81 /* Strange, "man end" says that end is a function! */
82 extern char etext, edata, end;
83 
85  char memory_string[17];
86  char cpu_string[CPU_USAGE_LENGTH + 1];
87  struct rusage an_rusage;
88 
89  /* etext, edata and end are only address symbols... */
90  debug(6, "display_memory_usage",
91  "_text %#x, _data %#x, _end %#x, _brk %#x\n", &etext, &edata, &end,
92  sbrk(0));
93 
94  sprintf(memory_string, "%10.3f", ((intptr_t) sbrk(0) - (intptr_t) &etext)
95  / (double) (1 << 20));
96 
97  gtk_label_set_text(GTK_LABEL(memory_name), memory_string);
98 
99  if (getrusage(RUSAGE_SELF, &an_rusage) == 0) {
100  double the_cpu_time = an_rusage.ru_utime.tv_sec
101  + an_rusage.ru_stime.tv_sec + (an_rusage.ru_utime.tv_usec
102  + an_rusage.ru_stime.tv_usec) * 1e-6;
103  sprintf(cpu_string, "%*.*g", CPU_USAGE_LENGTH, CPU_USAGE_LENGTH - 2,
104  the_cpu_time);
105  } else
106  /* getrusage() failed: */
107  sprintf(cpu_string, "%*s", CPU_USAGE_LENGTH, "?");
108 
109  gtk_label_set_text(GTK_LABEL(cpu_usage_item), cpu_string);
110 }
111 
112 //void window_number_notify(Panel_item item, int value, Event *event) {
113 // number_of_gpips_windows = (int) xv_get(item, PANEL_VALUE);
114 //
115 // display_memory_usage();
116 //}
117 
119  gtk_entry_set_text(GTK_ENTRY(directory_name_entry), get_cwd());
121 }
122 
124  static char *none = "(* none *)";
125  char *name = db_get_current_workspace_name();
126 
127  if (name == NULL)
128  name = none;
129  //
130  // xv_set(workspace_name_entry, PANEL_VALUE, name, 0);
132 }
133 
134 void show_module() {
135  static char *none = "(* none *)";
136  char *module_name_content = db_get_current_module_name();
137 
138  if (module_name_content == NULL)
139  module_name_content = none;
140  //
141  // xv_set(module_name_entry, PANEL_VALUE, module_name_content, 0);
143 }
144 
146  // if ((Server_image) xv_get(status_window_pips_image, PANEL_LABEL_IMAGE)
147  // == gpips_negative_server_image)
148  // xv_set(status_window_pips_image, PANEL_LABEL_IMAGE,
149  // gpips_positive_server_image, NULL);
150  // else
151  // xv_set(status_window_pips_image, PANEL_LABEL_IMAGE,
152  // gpips_negative_server_image, NULL);
153 
154 }
155 
157  // xv_set(status_window_pips_image, PANEL_LABEL_IMAGE,
158  // gpips_positive_server_image, NULL);
159 }
160 
161 void show_message(string message_buffer /*, ...*/) {
162  /* va_list some_arguments;
163  static char message_buffer[SMALL_BUFFER_LENGTH]; */
164 
165  /* va_start(some_arguments, a_printf_format); */
166 
167  /* (void) vsprintf(message_buffer, a_printf_format, some_arguments);*/
168 
169  // xv_set(message, PANEL_VALUE, message_buffer, 0);
171 }
172 
173 static void end_directory_notify_callback(GtkWidget * w, gpointer data __attribute__((unused))) {
174  if (GTK_IS_ENTRY(w))
175  end_directory_notify(gtk_entry_get_text(GTK_ENTRY(w)));
176 }
177 
178 static void choose_dir_callback(GtkWidget * w __attribute__((unused)), gpointer data) {
179  GtkWidget * file_chooser_dialog;
180 
181  file_chooser_dialog = gtk_file_chooser_dialog_new("Choose Directory",
182  GTK_WINDOW(main_window), GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
183  GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN,
184  GTK_RESPONSE_ACCEPT, NULL);
185 
186  if (gtk_dialog_run(GTK_DIALOG(file_chooser_dialog)) == GTK_RESPONSE_ACCEPT) {
187  char * dirname = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(
188  file_chooser_dialog));
189  gtk_entry_set_text(GTK_ENTRY(directory_name_entry), dirname);
190  g_free(dirname);
191  }
192  g_signal_emit_by_name(data, "activate");
193  //end_directory_notify_callback((GtkWidget *) data, NULL);
194 
195  gtk_widget_destroy(file_chooser_dialog);
196 }
197 
198 void open_or_create_workspace_callback(GtkWidget * w, gpointer data __attribute__((unused))) {
199  //gtk_entry_set_text(GTK_ENTRY(workspace_name_entry), gtk_entry_get_text(query_entry)); TODO: FIX ICI pour transferer le workspace name du query_entry au workspace_enamer_entry
200  open_or_create_workspace(gtk_entry_get_text(GTK_ENTRY(w)));
201  return;
202 }
203 // crée dans la fenetre principale (dans la vbox en fait) un bloc
204 // Label : Entry [bouton] pour choisir un répertoire
205 // et quand un répertoire est choisi on applique "end_directory_notify" dessus
206 static GtkWidget * create_dir_choose_entry(GtkWidget * vbox) {
207  GtkWidget * hbox = gtk_hbox_new(FALSE, 0);
208 
209  GtkWidget * label;
210  GtkWidget * entry;
211  GtkWidget * cd_button;
212 
213  label = gtk_label_new("Directory: ");
214  gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5);
215 
216  entry = gtk_entry_new();
217  gtk_box_pack_start(GTK_BOX(hbox), entry, TRUE, TRUE, 5);
218  g_signal_connect(GTK_OBJECT(entry), "activate",
219  G_CALLBACK(end_directory_notify_callback), NULL);
220  gtk_widget_set_sensitive(entry, FALSE);
221 
222  cd_button = gtk_button_new_with_label("CD");
223  gtk_box_pack_start(GTK_BOX(hbox), cd_button, FALSE, FALSE, 5);
224  g_signal_connect(GTK_OBJECT(cd_button), "clicked", G_CALLBACK(choose_dir_callback),
225  entry);
226 
227  gtk_widget_show_all(hbox);
228  gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, FALSE, 5);
229  return entry;
230 }
231 
232 static gboolean regenerate_workspace_menu_callback(GtkWidget * w,
233  GdkEventButton * ev, gpointer data) {
234  //GtkWidget * new_menu;
235  GtkWidget * menu = (GtkWidget *) data;
236 
237  if (menu != NULL)
238  gtk_menu_item_remove_submenu(GTK_MENU_ITEM(w));
239 
240  menu = generate_workspace_menu();
241  gtk_menu_item_set_submenu(GTK_MENU_ITEM(w), menu);
242 
243  return FALSE;
244 }
245 
246 static gboolean regenerate_module_menu_callback(GtkWidget * w,
247  GdkEventButton * ev, gpointer data) {
248  //GtkWidget * new_menu;
249  GtkWidget * menu = (GtkWidget *) data;
250 
251  if (menu != NULL)
252  gtk_menu_item_remove_submenu(GTK_MENU_ITEM(w));
253 
254  menu = generate_module_menu();
255  gtk_menu_item_set_submenu(GTK_MENU_ITEM(w), menu);
256 
257  return FALSE;
258 }
259 
260 // un bloc label / entry / menu, dans le menu la liste des actions possibles
261 // sur les workspace + la liste des workspace selon un algo a explorer
262 // entry "intelligente" (création ou ouverture de workspace)
263 static GtkWidget * create_workspace_entry(GtkWidget * vbox) {
264  GtkWidget * hbox = gtk_hbox_new(FALSE, 0);
265 
266  GtkWidget * label;
267  GtkWidget * entry;
268  GtkWidget * menu;
269  GtkWidget * menu_item;
270  GtkWidget * menu_bar;
271 
272  label = gtk_label_new("Workspace: ");
273  gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5);
274 
275  entry = gtk_entry_new();
276  gtk_box_pack_start(GTK_BOX(hbox), entry, TRUE, TRUE, 5);
277  g_signal_connect(GTK_OBJECT(entry), "activate",
278  G_CALLBACK(open_or_create_workspace_callback), NULL);
279 
280  menu_item = gtk_menu_item_new_with_label("Workspace list");
281  // regenerating the menu every time we try to access it
282  menu = NULL; // (necessary initialization for the callback)
283  g_signal_connect(G_OBJECT(menu_item), "button-press-event",
284  G_CALLBACK(regenerate_workspace_menu_callback), menu);
285  gtk_widget_show(menu_item);
286 
287  menu_bar = gtk_menu_bar_new();
288  gtk_box_pack_start(GTK_BOX(hbox), menu_bar, FALSE, FALSE, 0);
289  gtk_menu_bar_append(GTK_MENU_BAR(menu_bar), menu_item);
290  gtk_widget_show(menu_bar);
291 
292  gtk_widget_show_all(hbox);
293  gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, FALSE, 5);
294  return entry;
295 }
296 
297 static GtkWidget * create_module_entry(GtkWidget * vbox) {
298  GtkWidget * hbox = gtk_hbox_new(FALSE, 0);
299 
300  GtkWidget * label;
301  GtkWidget * entry;
302  GtkWidget * menu;
303  GtkWidget * menu_item;
304  GtkWidget * menu_bar;
305 
306  label = gtk_label_new("Module: ");
307  gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5);
308 
309  entry = gtk_entry_new();
310  gtk_box_pack_start(GTK_BOX(hbox), entry, TRUE, TRUE, 5);
311  g_signal_connect(GTK_OBJECT(entry), "activate",
312  G_CALLBACK(end_select_module_callback), NULL);
313 
314  menu_item = gtk_menu_item_new_with_label("Select module");
315  // regenerating the menu every time we try to access it
316  menu = NULL; // (necessary initialization for the callback)
317  g_signal_connect(G_OBJECT(menu_item), "button-press-event",
318  G_CALLBACK(regenerate_module_menu_callback), menu);
319  gtk_widget_show(menu_item);
320 
321  menu_bar = gtk_menu_bar_new();
322  gtk_box_pack_start(GTK_BOX(hbox), menu_bar, FALSE, FALSE, 0);
323  gtk_menu_bar_append(GTK_MENU_BAR(menu_bar), menu_item);
324  gtk_widget_show(menu_bar);
325 
326  gtk_widget_show_all(hbox);
327  gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, FALSE, 5);
328  return entry;
329 }
330 
332  //Server_image pips_icon_server_image;
333  status_frame = gtk_frame_new(NULL);
334  gtk_box_pack_start(GTK_BOX(main_window_vbox), status_frame, FALSE, FALSE, 5);
335 
336  GtkWidget * status_frame_vbox = gtk_vbox_new(FALSE, 0);
337  gtk_container_add(GTK_CONTAINER(status_frame), status_frame_vbox);
338 
339  gmessage = gtk_label_new("Message:");
340  gtk_box_pack_start(GTK_BOX(status_frame_vbox), gmessage, FALSE, FALSE, 5);
341 
342  directory_name_entry = create_dir_choose_entry(status_frame_vbox);
343 
344  workspace_name_entry = create_workspace_entry(status_frame_vbox);
345 
346  module_name_entry = create_module_entry(status_frame_vbox);
347 
348  GtkWidget * data_hbox = gtk_hbox_new(FALSE, 0);
349  gtk_box_pack_start(GTK_BOX(status_frame_vbox), data_hbox, FALSE, FALSE, 5);
350  gtk_box_pack_start(GTK_BOX(data_hbox), gtk_label_new("Memory (MB):"),
351  FALSE, FALSE, 5);
352  memory_name = gtk_label_new("");
353  gtk_box_pack_start(GTK_BOX(data_hbox), memory_name, FALSE, FALSE, 5);
354  gtk_box_pack_start(GTK_BOX(data_hbox), gtk_label_new("CPU (s):"), FALSE,
355  FALSE, 5);
356  cpu_usage_item = gtk_label_new("");
357  gtk_box_pack_start(GTK_BOX(data_hbox), cpu_usage_item, FALSE, FALSE, 5);
358  gtk_widget_show_all(data_hbox);
359 
360  // window_number = xv_create(main_panel, PANEL_NUMERIC_TEXT,
361  // /*PANEL_ITEM_X_GAP, DECALAGE_STATUS,
362  // PANEL_VALUE_Y, xv_rows(main_panel, 4),*/
363  // PANEL_VALUE_X, xv_col(main_panel, 50), PANEL_VALUE_Y,
364  // xv_rows(main_panel, 4), PANEL_LABEL_STRING, "# windows:",
365  // PANEL_MIN_VALUE, 1, PANEL_MAX_VALUE, MAX_NUMBER_OF_GPIPS_WINDOWS,
366  // PANEL_VALUE, number_of_gpips_windows, PANEL_VALUE_DISPLAY_LENGTH,
367  // 2, PANEL_NOTIFY_PROC, window_number_notify, NULL);
368 
369  // pips_icon_server_image = create_status_window_pips_image();
370 
371  // status_window_pips_image = xv_create(main_panel, PANEL_BUTTON,
372  // PANEL_LABEL_IMAGE, pips_icon_server_image, PANEL_NOTIFY_PROC,
373  // gpips_interrupt_pipsmake,
374  // /* Put the Pixmap above the Help button: */
375  // // quit_button a été remplacé par quit_menu_item
376  // XV_X, xv_get(quit_button, XV_X) + (xv_get(quit_button, XV_WIDTH)
377  // - xv_get(pips_icon_server_image, XV_WIDTH)) / 2, XV_Y,
378  // xv_rows(main_panel, 3) + 20, NULL);
379 
380  show_directory();
381  show_workspace();
382  show_module();
384 
385  gtk_widget_show_all(status_frame);
386 }
float a2sf[2] __attribute__((aligned(16)))
USER generates a user error (i.e., non fatal) by printing the given MSG according to the FMT.
Definition: 3dnow.h:3
string db_get_current_module_name(void)
Also used to check whether set...
Definition: database.c:1059
char * get_cwd(void)
returns the current working directory name.
Definition: file.c:486
GtkWidget * status_frame
Definition: gpips-local.h:42
GtkWidget * main_window_vbox
Definition: gpips.c:57
GtkWidget * main_window
Definition: gpips.c:54
GtkWidget * generate_module_menu()
participe Ã&#160; la génération du menu associés aux modules dans la fenetre principale
Definition: gtk_select.c:749
GtkWidget * generate_workspace_menu()
To use with schoose_create_abbrev_menu_with_text:
Definition: gtk_select.c:625
success end_directory_notify(const char *dir)
Definition: gtk_select.c:103
void end_select_module_callback(const char *name)
Definition: gtk_select.c:691
void open_or_create_workspace(const char *workspace_name_original)
To be used with schoose_create_abbrev_menu_with_text from the main panel:
Definition: gtk_select.c:570
@ DECALAGE_STATUS
Definition: gtk_status.c:60
static gboolean regenerate_workspace_menu_callback(GtkWidget *w, GdkEventButton *ev, gpointer data)
Definition: gtk_status.c:232
static gboolean regenerate_module_menu_callback(GtkWidget *w, GdkEventButton *ev, gpointer data)
Definition: gtk_status.c:246
static GtkWidget * create_module_entry(GtkWidget *vbox)
Definition: gtk_status.c:297
static GtkWidget * create_dir_choose_entry(GtkWidget *vbox)
Definition: gtk_status.c:206
GtkWidget * directory_name_entry_button
Definition: gtk_status.c:74
GtkWidget * module_name_entry
Definition: gtk_status.c:76
void open_or_create_workspace_callback(GtkWidget *w, gpointer data __attribute__((unused)))
Definition: gtk_status.c:198
void show_workspace()
Definition: gtk_status.c:123
@ CPU_USAGE_LENGTH
Definition: gtk_status.c:65
GtkWidget * workspace_name_entry
Definition: gtk_status.c:75
void gpips_interrupt_button_restore()
Definition: gtk_status.c:156
GtkWidget * gmessage
Definition: gtk_status.c:75
static void choose_dir_callback(GtkWidget *w __attribute__((unused)), gpointer data)
Definition: gtk_status.c:178
void show_directory()
Definition: gtk_status.c:118
static GtkWidget * create_workspace_entry(GtkWidget *vbox)
Definition: gtk_status.c:263
void display_memory_usage()
Definition: gtk_status.c:84
GtkWidget * memory_name
Definition: gtk_status.c:75
void gpips_interrupt_button_blink()
Definition: gtk_status.c:145
GtkWidget * directory_name_entry
Definition: gtk_status.c:74
void show_module()
Definition: gtk_status.c:134
GtkWidget * window_number
Definition: gtk_status.c:75
char end
Definition: gtk_status.c:82
static void end_directory_notify_callback(GtkWidget *w, gpointer data __attribute__((unused)))
Definition: gtk_status.c:173
void show_message(string message_buffer)
Definition: gtk_status.c:161
GtkWidget * cpu_usage_item
Definition: gtk_status.c:77
char etext
Strange, "man end" says that end is a function!
void create_status_subwindow()
Definition: gtk_status.c:331
char edata
Definition: gtk_status.c:82
void debug(const int the_expected_debug_level, const char *calling_function_name, const char *a_message_format,...)
ARARGS0.
Definition: debug.c:189
string db_get_current_workspace_name(void)
the function is used to check that there is some current workspace...
Definition: workspace.c:82
#define intptr_t
Definition: stdint.in.h:294
GtkWidget * button
Definition: gtk_status.c:71
GtkWidget * label
Definition: gtk_status.c:69
GtkWidget * entry
Definition: gtk_status.c:70