From b7da290bd39728e127b8fb5498685596e0dfe5bb Mon Sep 17 00:00:00 2001
From: Erwan Jahier <erwan.jahier@univ-grenoble-alpes.fr>
Date: Fri, 7 May 2021 19:22:47 +0200
Subject: [PATCH] Refactoring

---
 tools/rdbg4sasa/gtkgui.ml | 71 ++++++++++++++++++++-------------------
 1 file changed, 36 insertions(+), 35 deletions(-)

diff --git a/tools/rdbg4sasa/gtkgui.ml b/tools/rdbg4sasa/gtkgui.ml
index 6abbd6f6..3b9f5a01 100644
--- a/tools/rdbg4sasa/gtkgui.ml
+++ b/tools/rdbg4sasa/gtkgui.ml
@@ -1,4 +1,4 @@
-(* Time-stamp: <modified the 07/05/2021 (at 17:21) by Erwan Jahier> *)
+(* Time-stamp: <modified the 07/05/2021 (at 17:28) by Erwan Jahier> *)
 
 #thread
 #require "lablgtk3"
@@ -84,6 +84,8 @@ let init_rdbg_hook () =
   in
   rdbg_mv_hook := Some guidaemon
 
+let set_tooltip b = b#misc#set_tooltip_text 
+
 let custom_daemon p gtext vbox step_button round_button =
   (* création du rdbg_mv_hook et de tout ce qu'il faut autour *)
   init_rdbg_hook ();
@@ -100,12 +102,12 @@ let custom_daemon p gtext vbox step_button round_button =
   let dk_sd = make_but  (!daemon_kind=Synchronous) "Synchronous" in
   let dk_manual = make_but (!daemon_kind=Manual) "Manual" in
   let dk_manual_central = make_but (!daemon_kind=ManualCentral) "Manual Central" in
-  dk_dd#misc#set_tooltip_text (Printf.sprintf "Set the automatic distributed mode");
-  dk_sd#misc#set_tooltip_text (Printf.sprintf "Set the automatic synchronous mode");
-  dk_cd#misc#set_tooltip_text (Printf.sprintf "Set the automatic central mode");
-  dk_lcd#misc#set_tooltip_text (Printf.sprintf "Set the automatic locally central mode");
-  dk_manual#misc#set_tooltip_text (Printf.sprintf "Set the manual mode");
-  dk_manual_central#misc#set_tooltip_text (Printf.sprintf "Set the manual central mode");
+  set_tooltip dk_dd (Printf.sprintf "Set the automatic distributed mode");
+  set_tooltip dk_sd (Printf.sprintf "Set the automatic synchronous mode");
+  set_tooltip dk_cd (Printf.sprintf "Set the automatic central mode");
+  set_tooltip dk_lcd (Printf.sprintf "Set the automatic locally central mode");
+  set_tooltip dk_manual (Printf.sprintf "Set the manual mode");
+  set_tooltip dk_manual_central (Printf.sprintf "Set the manual central mode");
 
   let nodes_enabled = rdbg_nodes_enabled !e in
 
@@ -158,7 +160,7 @@ let custom_daemon p gtext vbox step_button round_button =
       (* cf. classe toggle_button de lablgtk3 *)
       let checkbox = GButton.check_button ~label:name ~packing:!checkbox_line_ref#add () in
       (* Quand on coche/décoche, met à jour le rdbg_mv_hook *)
-      checkbox#misc#set_tooltip_text (Printf.sprintf "check to activate %s at the next step" name);
+      set_tooltip checkbox (Printf.sprintf "check to activate %s at the next step" name);
       ignore(checkbox#connect#toggled
                ~callback: (fun () -> update_rdbg_hook name checkbox#active));
       checkbox#set_sensitive enabled; (* désactive la box si le noeud n'est pas activable *)
@@ -188,7 +190,7 @@ let custom_daemon p gtext vbox step_button round_button =
       );
       (* cf. classe toggle_button de lablgtk3 *)
       let pushbox = GButton.button ~label:name ~packing:!pushbox_line_ref#add () in
-      pushbox#misc#set_tooltip_text (Printf.sprintf "Press to activate %s" name);
+      set_tooltip pushbox (Printf.sprintf "Press to activate %s" name);
       (* Quand on appuie, met à jour le rdbg_mv_hook *)
       ignore(pushbox#event#connect#button_press
                ~callback: (fun _ ->
@@ -236,7 +238,7 @@ let custom_daemon p gtext vbox step_button round_button =
       ignore (adj#connect#value_changed ~callback:(fun () -> counter#set (truncate adj#value)));
       ignore (counter#connect#changed ~callback:(fun n -> counter_lbl#set_text (string_of_int n)));
       counter#set 1;
-      counter_container#misc#set_tooltip_text (Printf.sprintf "Set the priority of %s" name);
+      set_tooltip counter_container (Printf.sprintf "Set the priority of %s" name);
       Hashtbl.add counter_map name counter
     )
     nodes_enabled;
@@ -382,7 +384,7 @@ let main () =
   let sw2 = GBin.scrolled_window ~border_width:10 ~shadow_type:`OUT ~height:250
       ~packing:box#add ()
   in
-  sw2#misc#set_tooltip_text "This window displays commands outputs";
+  set_tooltip sw2 "This window displays commands outputs";
   let text_out = GText.view ~wrap_mode:`CHAR ~height:250 ~editable:false 
       ~packing: sw2#add () ~cursor_visible:true 
   in 
@@ -438,7 +440,7 @@ let main () =
   in
 
   let back_step_button = button ~use_mnemonic:true ~stock:`GO_BACK ~packing:bbox#add () in
-  back_step_button#misc#set_tooltip_text "Move BACKWARD to the previous STEP";
+  set_tooltip back_step_button "Move BACKWARD to the previous STEP";
   change_label back_step_button "Ste_p";
   ignore (back_step_button#connect#clicked ~callback:(button_cb bd));
 
@@ -460,19 +462,19 @@ let main () =
     d()
   in
 
-  step_button#misc#set_tooltip_text "Move FORWARD to the next STEP";
+  set_tooltip step_button "Move FORWARD to the next STEP";
   change_label step_button "_Step";
   ignore (step_button#connect#clicked ~callback:(button_cb step));
-  round_button#misc#set_tooltip_text "Move FORWARD to the next ROUND";
+  set_tooltip round_button "Move FORWARD to the next ROUND";
   change_label round_button "_Round";
   ignore (round_button#connect#clicked ~callback:(button_cb nr));
-  back_round_button#misc#set_tooltip_text "Move BACKWARD to the previous ROUND";
+  set_tooltip back_round_button "Move BACKWARD to the previous ROUND";
   change_label back_round_button "Roun_d";
   ignore (back_round_button#connect#clicked ~callback:(button_cb pr));
 
   let legitimate () = 
     let legitimate_button = button ~use_mnemonic:true ~packing:bbox#add () in
-    legitimate_button#misc#set_tooltip_text
+    set_tooltip legitimate_button
       "Move FORWARD until a legitimate configuration is reached (silence by default)";
     let image = GMisc.image ~file:(libui_prefix^"/chut_small.svg") () in
     legitimate_button#set_image image#coerce; 
@@ -484,8 +486,7 @@ let main () =
 
   let graph () = 
     let graph_button = button  ~use_mnemonic:true  ~packing:bbox#add () in
-    graph_button#misc#set_tooltip_text
-      "Visualize the Topology states: Green=Enabled ; Gold=Active";
+    set_tooltip graph_button "Visualize the Topology states: Green=Enabled ; Gold=Active";
     let image = GMisc.image ~file:(libui_prefix^"/graph_small.png") () in
     graph_button#set_image image#coerce; 
     ignore (graph_button#connect#clicked ~callback:(button_cb graph_view));
@@ -495,7 +496,7 @@ let main () =
 
   let make_button stock lbl msg cmd =
     let butt = button ~use_mnemonic:true ~stock:stock ~packing:bbox#add ~label:lbl () in
-    butt#misc#set_tooltip_text msg;
+    set_tooltip butt msg;
     change_label butt lbl;
     ignore (butt#connect#clicked ~callback:cmd);
     butt
@@ -555,14 +556,14 @@ let main () =
     let par_ci_button = make_but "circo*" in
     let par_pa_button = make_but "patchwork*" in
     let par_os_button = make_but "osage*" in
-    par_dot_button#misc#set_tooltip_text "Use dot, but show only links to the parent";
-    par_fd_button#misc#set_tooltip_text  "Use fdp, but show only links to the parent";
-    par_sf_button#misc#set_tooltip_text  "Use sfdp, but show only links to the parent";
-    par_ne_button#misc#set_tooltip_text  "Use neato, but show only links to the parent";
-    par_tw_button#misc#set_tooltip_text  "Use twopi, but show only links to the parent";
-    par_ci_button#misc#set_tooltip_text  "Use circo, but show only links to the parent";
-    par_pa_button#misc#set_tooltip_text  "Use patchwork, but show only links to the parent";
-    par_os_button#misc#set_tooltip_text  "Use osage, but show only links to the parent";
+    set_tooltip par_dot_button "Use dot, but show only links to the parent";
+    set_tooltip par_fd_button  "Use fdp, but show only links to the parent";
+    set_tooltip par_sf_button  "Use sfdp, but show only links to the parent";
+    set_tooltip par_ne_button  "Use neato, but show only links to the parent";
+    set_tooltip par_tw_button  "Use twopi, but show only links to the parent";
+    set_tooltip par_ci_button  "Use circo, but show only links to the parent";
+    set_tooltip par_pa_button  "Use patchwork, but show only links to the parent";
+    set_tooltip par_os_button  "Use osage, but show only links to the parent";
     connect par_dot_button "d_par" d_par;
     connect par_fd_button "fd_par" fd_par;
     connect par_sf_button "sf_par" sf_par;
@@ -572,14 +573,14 @@ let main () =
     connect par_pa_button "pa_par" pa_par;
     connect par_os_button "os_par" os_par;
   );
-  dot_button#misc#set_tooltip_text "Use the dot engine to display the graph";
-  fd_button#misc#set_tooltip_text "Use the fdp engine to display the graph";
-  sf_button#misc#set_tooltip_text "Use the sfdp engine to display the graph";
-  ne_button#misc#set_tooltip_text "Use the neato engine to display the graph";
-  tw_button#misc#set_tooltip_text "Use the twopi engine to display the graph";
-  ci_button#misc#set_tooltip_text "Use the circo engine to display the graph";
-  pa_button#misc#set_tooltip_text "Use the patchwork engine to display the graph";
-  os_button#misc#set_tooltip_text "Use the osage engine to display the graph";
+  set_tooltip dot_button "Use the dot engine to display the graph";
+  set_tooltip fd_button "Use the fdp engine to display the graph";
+  set_tooltip sf_button "Use the sfdp engine to display the graph";
+  set_tooltip ne_button "Use the neato engine to display the graph";
+  set_tooltip tw_button "Use the twopi engine to display the graph";
+  set_tooltip ci_button "Use the circo engine to display the graph";
+  set_tooltip pa_button "Use the patchwork engine to display the graph";
+  set_tooltip os_button "Use the osage engine to display the graph";
 
   connect dot_button "d" dot;
   connect fd_button "fd" fd;
-- 
GitLab