1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
open Gtk_helper
module Kernel_hook = Hook.Make()
class type basic_main = object
inherit host
method main_window: GWindow.window
method reset: unit -> unit
end
let run (host:basic_main) dialog () =
ignore (host#protect ~cancelable:true ~parent:(dialog :> GWindow.window_skel)
(fun () ->
dialog#destroy ();
Kernel_hook.apply ();
!Db.Main.play ()));
ignore (host#protect ~cancelable:false ~parent:(dialog :> GWindow.window_skel)
host#reset);
Kernel_hook.clear ()
let add_parameter (box:GPack.box) p =
let name = p.Typed_parameter.name in
let tooltip = p.Typed_parameter.help in
let is_set = p.Typed_parameter.is_set in
let use_markup = is_set () in
let highlight s = "<span foreground=\"blue\">" ^ s ^ "</span>" in
let hname = highlight name in
(match p.Typed_parameter.accessor with
| Typed_parameter.Bool ({ Typed_parameter.get = get; set = set }, None) ->
let name = if use_markup then hname else name in
let old = get () in
let set r = if r <> old then set r in
Kernel_hook.extend (on_bool ~tooltip ~use_markup box name get set);
| Typed_parameter.Bool
({ Typed_parameter.get = get; set = set }, Some negative_name) ->
let use_markup = is_set () in
let name, _negative_name =
if use_markup then hname, highlight negative_name
else name, negative_name
in
let old = get () in
let set r = if r <> old then set r in
Kernel_hook.extend
(on_bool ~tooltip ~use_markup box name get set);
| Typed_parameter.Int ({ Typed_parameter.get = get; set = set }, range) ->
let use_markup = is_set () in
let name = if use_markup then hname else name in
let lower, upper = range () in
let old = get () in
let set r = if r <> old then set r in
Kernel_hook.extend
(on_int ~tooltip ~use_markup ~lower ~upper ~width:120 box name get set);
| Typed_parameter.String
({ Typed_parameter.get = get; set = set }, possible_values) ->
let use_markup = is_set () in
let hname = if use_markup then hname else name in
let old = get () in
let widget_value = ref old in
let w_set r = widget_value := r in
let w_get () = !widget_value in
(match possible_values () with
| [] ->
let _refresh =
on_string ~tooltip ~use_markup ~width:250 box hname w_get w_set
in
Kernel_hook.extend
(fun () -> if !widget_value <> old then set !widget_value)
| v ->
let validator s =
let b = List.mem s v in
if not b then Gui_parameters.error "invalid input `%s' for %s" s name;
b
in
let _refresh =
on_string_completion
~tooltip ~use_markup ~validator v box hname w_get w_set
in
Kernel_hook.extend
(fun () -> if !widget_value <> old then set !widget_value))
);
use_markup
let mk_text ~highlight text =
let markup =
if highlight then Format.sprintf "<span foreground=\"blue\">%s</span>" text
else text
in
let label = GMisc.label ~markup () in
label#coerce
let set_expander_text (exp: GBin.expander) s ~tooltip highlight =
let text = mk_text ~highlight s in
Gtk_helper.do_tooltip ?tooltip text;
exp#set_label_widget text;
exp#set_expanded highlight
let add_group (box:GPack.box) label options =
let box, set_expander_text =
if label = "" then
box, fun _ -> ()
else
let expander = GBin.expander ~packing:box#pack () in
let frame = GBin.frame ~border_width:5 ~packing:expander#add () in
GPack.vbox ~packing:frame#add (),
set_expander_text expander ~tooltip:None label
in
let highlight =
List.fold_right
(fun p b ->
if p.Typed_parameter.reconfigurable then
let is_set = add_parameter box p in b || is_set
else b)
options
false
in
set_expander_text highlight;
highlight
let box_plugin p =
let frame = GBin.frame ~border_width:5 () in
let vbox = GPack.vbox ~packing:frame#add () in
let markup =
"<span font_weight=\"bold\">" ^
String.capitalize_ascii p.Plugin.p_help ^
"</span>"
in
ignore (GMisc.label ~markup ~packing:(vbox#pack ~padding:15) ());
let sorted_groups =
List.sort
(fun (s1, _) (s2, _) -> String.compare s1 s2)
(Hashtbl.fold
(fun l g acc ->
if g = [] then acc
else (String.capitalize_ascii l, g) :: acc)
p.Plugin.p_parameters
[])
in
let highlight =
List.fold_left
(fun b (l, g) -> let is_set = add_group vbox l g in b || is_set)
false
sorted_groups
in
frame, highlight
let compare_plugin_name n1 n2 =
if n1 = "Kernel" then
if n2 = "Kernel" then 0 else -1
else if n2 = "Kernel" then 1
else String.compare n1 n2
type plugin_options =
string * bool * GBin.frame
let listview_plugins ~(packing:?from:Gtk.Tags.pack_type ->
?expand:bool -> ?fill:bool -> ?padding:int -> GObj.widget -> unit) plugins =
let module Data = Indexer.Make(
struct
type t = plugin_options
let compare (x,_,_) (y,_,_) = compare_plugin_name x y
end)
in
let model = object(self)
val mutable m = Data.empty
method data = m
method size = Data.size m
method index i = Data.index i m
method get i = Data.get i m
method add i = m <- Data.add i m; i
method reload = m <- Data.empty
method coerce = (self:> plugin_options Wtable.listmodel)
end in
let scrolling_list_plugins =
GBin.scrolled_window
~packing:(packing ~expand:false ~padding:5) ~vpolicy:`AUTOMATIC ~hpolicy:`NEVER ()
in
let w = new Wtable.list ~headers:false model#coerce in
scrolling_list_plugins#add_with_viewport (w#view :> GObj.widget);
let box = GPack.vbox () in
let scrolling_right =
GBin.scrolled_window
~packing:(packing ~expand:true ~padding:5)
~vpolicy:`AUTOMATIC ~hpolicy:`AUTOMATIC ()
in
scrolling_right#add_with_viewport (box :> GObj.widget);
let append e = w#insert_row (model#add e) in
let _ = w#add_column_text [`YALIGN 0.0]
(fun (name, highlight, _expander) ->
let bold = [`FOREGROUND (if highlight then "blue" else "black")] in
`TEXT name :: bold )
in
w#on_click (fun (_, _, expander) _col ->
List.iter box#remove (box#all_children);
box#pack (expander :> GObj.widget));
List.iter (fun (pname, p) ->
let frame, highlight = box_plugin p in
append (pname, highlight, frame);
) plugins;
(w#view#get_column 0)#set_sizing `AUTOSIZE
let show ?height ?width ~(host:basic_main) () =
let dialog =
GWindow.dialog
~title:"Launching analysis"
~modal:true
~position:`CENTER_ON_PARENT
~resizable:true
?width
?height
~parent:host#main_window
()
in
ignore (dialog#misc#connect#size_allocate
~callback:(fun ({Gtk.width=w;Gtk.height=h}) ->
Configuration.set "launcher_width" (Configuration.ConfInt w);
Configuration.set "launcher_height" (Configuration.ConfInt h)));
ignore
(GMisc.label
~text:"Customize parameters, then click on `Execute'"
~packing:(dialog#vbox#pack ~padding:10)
());
let hbox = GPack.hbox ~packing:(dialog#vbox#pack ~fill:true ~expand:true) () in
let buttons =
GPack.button_box
`HORIZONTAL ~layout:`END ~packing:dialog#action_area#pack ()
in
let cancel =
GButton.button ~label:"Close" ~stock:`CANCEL ~packing:buttons#pack ()
in
ignore (cancel#connect#released ~callback:dialog#destroy);
let button_run =
GButton.button
~label:"Configure analysis" ~stock:`EXECUTE ~packing:buttons#pack ()
in
ignore (button_run#connect#released ~callback:(run host dialog));
let plugins = ref [] in
Plugin.iter_on_plugins
(fun p ->
plugins :=
(String.capitalize_ascii p.Plugin.p_name, p)
:: !plugins);
plugins :=
List.sort (fun (n1, _) (n2, _) -> compare_plugin_name n1 n2)!plugins;
listview_plugins ~packing:hbox#pack !plugins;
dialog#show ()