From 03a423185db118e85658403f40905c575bafe036 Mon Sep 17 00:00:00 2001 From: Pascal Brisset Date: Sat, 6 Jun 2009 13:51:17 +0000 Subject: [PATCH] combo utilities moved to Gtk_tools --- sw/supervision/Makefile | 2 +- sw/supervision/paparazzicenter.ml | 22 +++++++------- sw/supervision/pc_aircraft.ml | 47 ++++++++++++------------------ sw/supervision/pc_common.ml | 36 ----------------------- sw/supervision/pc_control_panel.ml | 28 +++++++++--------- 5 files changed, 45 insertions(+), 90 deletions(-) diff --git a/sw/supervision/Makefile b/sw/supervision/Makefile index 76100def97..c9c8fcba68 100644 --- a/sw/supervision/Makefile +++ b/sw/supervision/Makefile @@ -12,7 +12,7 @@ all: paparazzicenter paparazzicenter : $(PAPARAZZICENTERCMO) $(OCAMLLIB)/lib-pprz.cma @echo OL $@ - $(Q)$(OCAMLC) -custom $(INCLUDES) -o $@ unix.cma str.cma xml-light.cma lablgtk.cma lablglade.cma gtkInit.cmo lib-pprz.cma lablgnomeui.cma $^ + $(Q)$(OCAMLC) -custom $(INCLUDES) -o $@ unix.cma str.cma xml-light.cma lablgtk.cma lablglade.cma gtkInit.cmo lib-pprz.cma xlib-pprz.cma lablgnomeui.cma $^ gtk_pc.ml : paparazzicenter.glade lablgladecc2 -hide-default -root window $< > $@ diff --git a/sw/supervision/paparazzicenter.ml b/sw/supervision/paparazzicenter.ml index 455edf871c..4be2e7047d 100644 --- a/sw/supervision/paparazzicenter.ml +++ b/sw/supervision/paparazzicenter.ml @@ -40,7 +40,7 @@ let get_entry_value = fun xml name -> let e = ExtXml.child ~select:(fun x -> Xml.attrib x "name" = name) xml "entry" in Xml.attrib e "value" -let read_preferences = fun (gui:Gtk_pc.window) file (ac_combo:Utils.combo) (session_combo:Utils.combo) (target_combo:Utils.combo) -> +let read_preferences = fun (gui:Gtk_pc.window) file (ac_combo:Gtk_tools.combo) (session_combo:Gtk_tools.combo) (target_combo:Gtk_tools.combo) -> let xml = Xml.parse_file file in let read_one = fun name use -> @@ -50,13 +50,13 @@ let read_preferences = fun (gui:Gtk_pc.window) file (ac_combo:Utils.combo) (sess with Not_found -> () in (*********** Last A/C *) - read_one "last A/C" (Utils.select_in_combo ac_combo); + read_one "last A/C" (Gtk_tools.select_in_combo ac_combo); (*********** Last session *) - read_one "last session" (Utils.select_in_combo session_combo); + read_one "last session" (Gtk_tools.select_in_combo session_combo); (*********** Last target *) - read_one "last target" (Utils.select_in_combo target_combo); + read_one "last target" (Gtk_tools.select_in_combo target_combo); (*********** Window Size *) read_one "width" @@ -82,24 +82,24 @@ let add_entry = fun xml name value -> Xml.Element (Xml.tag xml, Xml.attribs xml, entry::Xml.children xml) -let write_preferences = fun (gui:Gtk_pc.window) file (ac_combo:Utils.combo) (session_combo:Utils.combo) (target_combo:Utils.combo) -> +let write_preferences = fun (gui:Gtk_pc.window) file (ac_combo:Gtk_tools.combo) (session_combo:Gtk_tools.combo) (target_combo:Gtk_tools.combo) -> let xml = if Sys.file_exists file then Xml.parse_file file else Xml.Element ("gconf", [], []) in (* Save A/C name *) let xml = try - let ac_name = Utils.combo_value ac_combo in + let ac_name = Gtk_tools.combo_value ac_combo in add_entry xml "last A/C" ac_name with Not_found -> xml in (* Save session *) let xml = - let session_name = Utils.combo_value session_combo in + let session_name = Gtk_tools.combo_value session_combo in add_entry xml "last session" session_name in (* Save target *) let xml = - let name = Utils.combo_value target_combo in + let name = Gtk_tools.combo_value target_combo in add_entry xml "last target" name in let xml = @@ -183,9 +183,9 @@ let () = Utils.build_aircrafts (); let ac_combo = AC.parse_conf_xml gui#vbox_ac - and target_combo = Utils.combo ["sim";"fbw";"ap"] gui#vbox_target in + and target_combo = Gtk_tools.combo ["sim";"fbw";"ap"] gui#vbox_target in - (Utils.combo_widget target_combo)#misc#set_sensitive false; + (Gtk_tools.combo_widget target_combo)#misc#set_sensitive false; gui#button_clean#misc#set_sensitive false; gui#button_build#misc#set_sensitive false; @@ -262,7 +262,7 @@ let () = (* Run the command line session *) if !session <> "" then begin - Utils.select_in_combo session_combo !session; + Gtk_tools.select_in_combo session_combo !session; execute_session !session end; diff --git a/sw/supervision/pc_aircraft.ml b/sw/supervision/pc_aircraft.ml index 76d6279471..803d466b26 100644 --- a/sw/supervision/pc_aircraft.ml +++ b/sw/supervision/pc_aircraft.ml @@ -79,18 +79,9 @@ let new_ac_id = fun () -> let parse_conf_xml = fun vbox -> let strings = ref [] in Hashtbl.iter (fun name _ac -> strings := name :: !strings) Utils.aircrafts; - Utils.combo ("" :: !strings) vbox + Gtk_tools.combo ("" :: !strings) vbox -let combo_connect = fun ((combo: #GEdit.combo_box), (_,column)) cb -> - ignore (combo#connect#changed - (fun () -> - match combo#active_iter with - | None -> () - | Some row -> - let data = combo#model#get ~row ~column in - cb data)) - let editor = try Sys.getenv "EDITOR" with _ -> "gedit" @@ -116,7 +107,7 @@ let ac_files = fun gui -> let current_color = ref "white" let save_callback = fun ?user_save gui ac_combo () -> - let ac_name = Utils.combo_value ac_combo in + let ac_name = Gtk_tools.combo_value ac_combo in if ac_name <> "" then begin let color = !current_color in let aircraft = @@ -148,7 +139,7 @@ let first_word = fun s -> (* Link A/C to airframe & flight_plan labels *) -let ac_combo_handler = fun gui (ac_combo:Utils.combo) target_combo -> +let ac_combo_handler = fun gui (ac_combo:Gtk_tools.combo) target_combo -> let update_params = fun ac_name -> try let aircraft = Hashtbl.find Utils.aircrafts ac_name in @@ -165,23 +156,23 @@ let ac_combo_handler = fun gui (ac_combo:Utils.combo) target_combo -> gui#eventbox_gui_color#misc#modify_bg [`NORMAL, `NAME gui_color]; current_color := gui_color; gui#entry_ac_id#set_text ac_id; - (Utils.combo_widget target_combo)#misc#set_sensitive true; + (Gtk_tools.combo_widget target_combo)#misc#set_sensitive true; with Not_found -> gui#label_airframe#set_text ""; gui#label_flight_plan#set_text ""; gui#button_clean#misc#set_sensitive false; gui#button_build#misc#set_sensitive false; - (Utils.combo_widget target_combo)#misc#set_sensitive false + (Gtk_tools.combo_widget target_combo)#misc#set_sensitive false in - combo_connect ac_combo update_params; + Gtk_tools.combo_connect ac_combo update_params; (* New A/C button *) let callback = fun _ -> match GToolbox.input_string ~title:"New A/C" ~text:"MYAC" "New A/C name ?" with None -> () | Some s -> - Utils.add_to_combo ac_combo s; + Gtk_tools.add_to_combo ac_combo s; let a = aircraft_sample s (string_of_int (new_ac_id ())) in Hashtbl.add Utils.aircrafts s a; update_params s @@ -190,16 +181,16 @@ let ac_combo_handler = fun gui (ac_combo:Utils.combo) target_combo -> (* Delete A/C *) let callback = fun _ -> - let ac_name = Utils.combo_value ac_combo in + let ac_name = Gtk_tools.combo_value ac_combo in if ac_name <> "" then match GToolbox.question_box ~title:"Delete A/C" ~buttons:["Cancel"; "Delete"] ~default:2 (sprintf "Delete %s ? (no undo after Save)" ac_name) with 2 -> begin begin try Hashtbl.remove Utils.aircrafts ac_name with _ -> () end; - let combo_box = Utils.combo_widget ac_combo in + let combo_box = Gtk_tools.combo_widget ac_combo in match combo_box#active_iter with | None -> () | Some row -> - let (store, _column) = Utils.combo_model ac_combo in + let (store, _column) = Gtk_tools.combo_model ac_combo in ignore (store#remove row); combo_box#set_active 1 end @@ -245,9 +236,9 @@ let ac_combo_handler = fun gui (ac_combo:Utils.combo) target_combo -> ignore(gui#menu_item_save_ac#connect#activate ~callback:(save_callback ~user_save:true gui ac_combo)) -let build_handler = fun ~file gui ac_combo (target_combo:Utils.combo) (log:string->unit) -> +let build_handler = fun ~file gui ac_combo (target_combo:Gtk_tools.combo) (log:string->unit) -> (* Link target to upload button *) - combo_connect target_combo + Gtk_tools.combo_connect target_combo (fun target -> gui#button_upload#misc#set_sensitive (target <> "sim")); @@ -256,30 +247,30 @@ let build_handler = fun ~file gui ac_combo (target_combo:Utils.combo) (log:strin match GToolbox.input_string ~title:"New Target" ~text:"tunnel" "New build target ?" with None -> () | Some s -> - let (store, column) = Utils.combo_model target_combo in + let (store, column) = Gtk_tools.combo_model target_combo in let row = store#append () in store#set ~row ~column s; - (Utils.combo_widget target_combo)#set_active_iter (Some row) + (Gtk_tools.combo_widget target_combo)#set_active_iter (Some row) in ignore (gui#button_new_target#connect#clicked ~callback); (* Clean button *) let callback = fun () -> - Utils.command ~file gui log (Utils.combo_value ac_combo) "clean_ac" in + Utils.command ~file gui log (Gtk_tools.combo_value ac_combo) "clean_ac" in ignore (gui#button_clean#connect#clicked ~callback); (* Build button *) let callback = fun () -> - let ac_name = Utils.combo_value ac_combo - and target = Utils.combo_value target_combo in + let ac_name = Gtk_tools.combo_value ac_combo + and target = Gtk_tools.combo_value target_combo in let target = if target="sim" then target else sprintf "%s.compile" target in Utils.command ~file gui log ac_name target in ignore (gui#button_build#connect#clicked ~callback); (* Upload button *) let callback = fun () -> - let ac_name = Utils.combo_value ac_combo - and target = Utils.combo_value target_combo in + let ac_name = Gtk_tools.combo_value ac_combo + and target = Gtk_tools.combo_value target_combo in Utils.command ~file gui log ac_name (sprintf "%s.upload" target) in ignore (gui#button_upload#connect#clicked ~callback) diff --git a/sw/supervision/pc_common.ml b/sw/supervision/pc_common.ml index aa66c2b3bc..398f916c57 100644 --- a/sw/supervision/pc_common.ml +++ b/sw/supervision/pc_common.ml @@ -60,42 +60,6 @@ let run_and_log = fun log com -> let io_watch_out = Glib.Io.add_watch [`IN; `HUP] cb channel_out in pid, channel_out, com_stdout, io_watch_out -type combo = GEdit.combo_box * (GTree.list_store * string GTree.column) -let combo_widget = fst -let combo_model = snd - -let combo_value = fun ((combo: #GEdit.combo_box), (_,column)) -> - match combo#active_iter with - | None -> raise Not_found - | Some row -> combo#model#get ~row ~column - -let combo_separator = "--" - -let combo = fun strings vbox -> - let (combo, (tree, column)) = - GEdit.combo_box_text ~packing:vbox#add ~strings () in - combo#set_active 0; - combo#set_row_separator_func - (Some (fun m row -> m#get ~row ~column = combo_separator)) ; - (combo, (tree, column)) - -let add_to_combo = fun (combo : combo) string -> - let (store, column) = combo_model combo in - let row = store#append () in - store#set ~row ~column string; - (combo_widget combo)#set_active_iter (Some row) - - -let select_in_combo = fun (combo : combo) string -> - let (store, column) = combo_model combo in - store#foreach - (fun _path row -> - if store#get ~row ~column = string then begin - (combo_widget combo)#set_active_iter (Some row); - true - end else - false) - let choose_xml_file = fun ?(multiple = false) title subdir cb -> let dir = conf_dir // subdir in let dialog = GWindow.file_chooser_dialog ~action:`OPEN ~title () in diff --git a/sw/supervision/pc_control_panel.ml b/sw/supervision/pc_control_panel.ml index bdc4c0c22f..74e71d6360 100644 --- a/sw/supervision/pc_control_panel.ml +++ b/sw/supervision/pc_control_panel.ml @@ -115,7 +115,7 @@ let parse_process_args = fun (name, args) -> let save_session = fun gui session_combo -> (* Ask for a session name *) - let text = Utils.combo_value session_combo in + let text = Gtk_tools.combo_value session_combo in let text = if text = "" then "My session" else text in match GToolbox.input_string ~ok:"Save" ~text ~title:"Session name" "Save custom session ?" with None -> "" @@ -143,7 +143,7 @@ let double_quote = fun s -> else s -let supervision = fun ?file gui log (ac_combo : Utils.combo) -> +let supervision = fun ?file gui log (ac_combo : Gtk_tools.combo) -> let run_gcs = fun () -> run_and_monitor ?file gui log "GCS" "" and run_server = fun args -> @@ -154,25 +154,25 @@ let supervision = fun ?file gui log (ac_combo : Utils.combo) -> in (* Sessions *) - let session_combo = Utils.combo [] gui#vbox_session in + let session_combo = Gtk_tools.combo [] gui#vbox_session in let remove_custom_sessions = fun () -> - let (store, _column) = Utils.combo_model session_combo in + let (store, _column) = Gtk_tools.combo_model session_combo in store#clear () in let register_custom_sessions = fun () -> remove_custom_sessions (); - Utils.add_to_combo session_combo "Simulation"; - Utils.add_to_combo session_combo "Replay"; - Utils.add_to_combo session_combo Utils.combo_separator; + Gtk_tools.add_to_combo session_combo "Simulation"; + Gtk_tools.add_to_combo session_combo "Replay"; + Gtk_tools.add_to_combo session_combo Gtk_tools.combo_separator; Hashtbl.iter (fun name _session -> - Utils.add_to_combo session_combo name) + Gtk_tools.add_to_combo session_combo name) sessions in register_custom_sessions (); - Utils.select_in_combo session_combo "Simulation"; + Gtk_tools.select_in_combo session_combo "Simulation"; let execute_custom = fun session_name -> let session = try Hashtbl.find sessions session_name with Not_found -> failwith (sprintf "Unknown session: %s" session_name) in @@ -200,11 +200,11 @@ let supervision = fun ?file gui log (ac_combo : Utils.combo) -> let simulation = fun () -> run_gcs (); run_server "-n"; - run_sitl (Utils.combo_value ac_combo) in + run_sitl (Gtk_tools.combo_value ac_combo) in (* Run session *) let callback = fun () -> - match Utils.combo_value session_combo with + match Gtk_tools.combo_value session_combo with "Simulation" -> simulation () | "Replay" -> replay () | custom -> execute_custom custom in @@ -237,7 +237,7 @@ let supervision = fun ?file gui log (ac_combo : Utils.combo) -> match GToolbox.input_string ~title:"New session" ~text:"My session" "New session name ?" with None -> () | Some s -> - Utils.add_to_combo session_combo s in + Gtk_tools.add_to_combo session_combo s in ignore (gui#menu_item_new_session#connect#activate ~callback); (* Save new session *) @@ -246,13 +246,13 @@ let supervision = fun ?file gui log (ac_combo : Utils.combo) -> "" -> () | session_name -> register_custom_sessions (); - Utils.select_in_combo session_combo session_name + Gtk_tools.select_in_combo session_combo session_name in ignore (gui#menu_item_save_session#connect#activate ~callback); (* Remove current session *) let callback = fun () -> - let session_name = Utils.combo_value session_combo in + let session_name = Gtk_tools.combo_value session_combo in match GToolbox.question_box ~title:"Delete custom session" ~buttons:["Cancel"; "Delete"] ~default:2 (sprintf "Delete '%s' custom session ? (NO undo)" session_name) with 2 -> if Hashtbl.mem sessions session_name then begin