-
Notifications
You must be signed in to change notification settings - Fork 2
/
configuration.ml
1675 lines (1491 loc) · 63.7 KB
/
configuration.ml
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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(*
* prooftree --- proof tree display for Proof General
*
* Copyright (C) 2011 - 2024 Hendrik Tews
*
* This file is part of "prooftree".
*
* "prooftree" is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* "prooftree" is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License in file COPYING in this or one of the parent
* directories for more details.
*
* You should have received a copy of the GNU General Public License
* along with "prooftree". If not, see <http://www.gnu.org/licenses/>.
*)
(** Prooftree Configuration and the Configuration Dialog *)
open Util
open Gtk_ext
(**/**)
module U = Unix
(**/**)
(*****************************************************************************
*****************************************************************************)
(** {2 Exceptions} *)
(** Raised when the configuration file has an unexpected version tag. *)
exception Config_file_wrong_version
(** Raised when the configuration file cannot be read *)
exception Config_file_invalid
(*****************************************************************************
*****************************************************************************)
(** {2 Configuration record and global variables} *)
(** Hardwired location of the user-specific configuration file. *)
let config_file_location =
Filename.concat
(Sys.getenv "HOME")
".prooftree"
(** Configuration record. For simplicity the user specific
configuration file is (mostly) a marshaled configuration record.
In order to be independent of Gdk marshaling, the configuration
record consists only of pure OCaml values. Fonts and colors are
therefore not accessed via the configuration record, but via their
own references (of some suitable Gdk type). These references must,
of course, be kept in sync with the current configuration. All
other configurable values are accessed through the current
configuration record, which is stored in {!current_config}.
*)
(* IMPORTANT: INCREASE config_file_version BELOW WHEN CHANGING THIS RECORD *)
type t = {
turnstile_radius : int;
(** Radius (in pixel) of the circle around the turnstile symbol for
the current node. Used also as kind of circular bounding box of
the turnstile symbol.
*)
turnstile_left_bar_x_offset : int;
(** X-offset of the vertical bar of the turnstile symbol. *)
turnstile_left_bar_y_offset : int;
(** Y-offset of the upper and lower end of the vertical bar of the
turnstile symbol (with respect to the centre of the vertical
bar).
*)
turnstile_horiz_bar_x_offset : int;
(** Length of the horizontal bar of the turnstile symbol. *)
turnstile_line_width : int;
(** Line width of all lines (including the turnstile symbol). *)
turnstile_number_x_offset : int;
(** X-offset (with respect to the centre of the turnstile symbol) at
which the number of the external sequent window is printed, if
there is any.
*)
proof_command_length : int;
(** Maximal number of characters that are displayed for a proof
command in the proof-tree display.
*)
subtree_sep : int;
(** Additional space added between two adjacent subtrees. (More
precisely, this value is added to the width of every node in the
proof-tree display.)
*)
line_sep : int;
(** Space left between nodes and connecting lines. *)
level_distance : int;
(** Vertical distance between two levels of the proof tree. *)
proof_tree_sep : int;
(** Horizontal distance between two independent proof trees in one layer *)
layer_sep : int;
(** Vertical distance between two layers of proof trees *)
button_1_drag_acceleration : float;
(** Acceleration multiplier for dragging the proof-tree display
inside its viewport. Positive values move the viewport (i.e.,
the tree underneath moves in the opposite direction of the
mouse), negative values move the tree (i.e., the tree underneath
moves in the same direction as the mouse).
*)
proof_tree_font : string;
(** Font description (as for {xref lablgtk class
GPango.font_description}) for the text inside the proof-tree
display.
*)
sequent_font : string;
(** Font description (as for {xref lablgtk class
GPango.font_description}) for the text in the sequent display
and in the additional node windows.
*)
current_color : (int * int * int);
(** The color for the current branch, as 16-bit RGB value. *)
cheated_color : (int * int * int);
(** The color for branches that have been finished with a cheating
command, as 16-bit RGB value
*)
proved_complete_color : (int * int * int);
(** The color for branches that have been proved and which depend on no
non-instantiated existential variables, as 16-bit RGB value.
*)
proved_incomplete_color : (int * int * int);
(** The color for branches that have been proved and that have
non-instantiated existential variables, as 16-bit RGB value.
*)
proved_partial_color : (int * int * int);
(** The color for branches that have been proved and whose own
existential variables are all instantiated, but where the
instantiations depend on some not-yet instantiated existential
variables. The value is the 16-bit RGB triple.
*)
(*
* mark_subtree_color : (int * int * int);
* (\** The color for marked subtrees, as 16 bit RGB value. *\)
*)
existential_create_color : (int * int * int);
(** The color for marking nodes that introduce a given existential
variable, as 16 bit RGB value.
*)
existential_instantiate_color : (int * int * int);
(** The color for marking nodes that intantiate a given existential
variable, as 16 bit RGB value.
*)
display_doc_tooltips : bool;
(** Whether to display documentation/help tool-tips. *)
display_turnstile_tooltips : bool;
(** Whether to display complete sequents as tool-tips over sequent
symbols.
*)
display_command_tooltips : bool;
(** Whether to display complete proof commands as tool-tips over
proof commands.
*)
default_width_proof_tree_window : int;
(** Default width of the proof-tree window, used if there was no
[-geometry] option.
*)
default_height_proof_tree_window : int;
(** Default heigth of the proof-tree window, used if there was no
[-geometry] option.
*)
internal_sequent_window_lines : int;
(** Number of text lines in the internal sequent window. If [0] the
internal sequent window is hidden.
*)
node_window_max_lines : int;
(** Maximal number of text lines in external node windows. *)
ext_table_lines : int;
(** Default number of lines for the table of existential variables. *)
debug_mode : bool;
(** Print more exception backtraces for internal errors, if true. *)
copy_input : bool;
(** Write all read input into the file [copy_input_file], if true. *)
copy_input_file : string;
(** File to write read input to, if [copy_input] is true. *)
}
(** Set the fields [turnstile_left_bar_x_offset],
[turnstile_left_bar_y_offset] and [turnstile_horiz_bar_x_offset]
as function of the field [turnstile_radius]. Set
[turnstile_number_x_offset] as function of [turnstile_line_width]
(see {!t}).
*)
let update_sizes config =
let radius = config.turnstile_radius in
{ config with
turnstile_left_bar_x_offset =
int_of_float(-0.23 *. (float_of_int radius) +. 0.5);
turnstile_left_bar_y_offset =
int_of_float(0.65 *. (float_of_int radius) +. 0.5);
turnstile_horiz_bar_x_offset =
int_of_float(0.7 *. (float_of_int radius) +. 0.5);
turnstile_number_x_offset = -(config.turnstile_line_width + 1);
}
(** Create the default, builtin configuration record. *)
let default_configuration =
let radius = 10 in
let blue = GDraw.color (`NAME "blue") in
let red = GDraw.color (`NAME "red") in
let c = {
turnstile_radius = radius;
turnstile_line_width = 2;
proof_command_length = 15;
subtree_sep = 5;
line_sep = 3;
level_distance = 38;
proof_tree_sep = 15;
layer_sep = 30;
turnstile_left_bar_x_offset = 0;
turnstile_left_bar_y_offset = 0;
turnstile_horiz_bar_x_offset = 0;
turnstile_number_x_offset = 0;
button_1_drag_acceleration = 4.0;
proof_tree_font = "Sans 8";
sequent_font = "Sans 8";
current_color =
(Gdk.Color.red blue, Gdk.Color.green blue, Gdk.Color.blue blue);
cheated_color =
(Gdk.Color.red red, Gdk.Color.green red, Gdk.Color.blue red);
proved_complete_color = (19 * 255, 197 * 256, 19 * 255);
proved_partial_color = (100 * 256, 114 * 256, 0 * 256);
proved_incomplete_color = (26 * 255, 226 * 256, 216 * 256);
(* mark_subtree_color = (0,0,0); *)
existential_create_color = (255 * 256, 0xF5 * 256, 0x8F * 256);
existential_instantiate_color = (255 * 256, 0xB6 * 256, 0x6D * 256);
display_doc_tooltips = true;
display_turnstile_tooltips = true;
display_command_tooltips = true;
default_width_proof_tree_window = 400;
default_height_proof_tree_window = 400;
internal_sequent_window_lines = 1;
node_window_max_lines = 35;
ext_table_lines = 8;
debug_mode = false;
copy_input = false;
copy_input_file = "/tmp/prooftree.log";
}
in
update_sizes c
(** Reference of the internal configuration record. Most configuration
values are accessed through this reference. For fonts and colors
there are separate references, which are always updated, when the
configuration changes.
*)
let current_config = ref default_configuration
(** Font description for the text inside the proof-tree display, as
value of {xref lablgtk class GPango.font_description} type. Should
always be in sync with the [proof_tree_font] field of
{!current_config}.
*)
let proof_tree_font_desc =
ref(GPango.font_description default_configuration.proof_tree_font)
(** Font description for the text in the sequent display and in the
additional node windows, as value of {xref lablgtk class
GPango.font_description} type. Should always be in sync with the
[sequent_font] field of {!current_config}.
*)
let sequent_font_desc =
ref(GPango.font_description default_configuration.sequent_font)
(** Color for the current branch, as {xref lablgtk type Gdk.color}.
Should always be in sync with the [current_color] field of
{!current_config}.
*)
let current_gdk_color =
ref(GDraw.color (`RGB default_configuration.current_color))
(** Color for branches that have been finished with a cheating
command, as {xref lablgtk type Gdk.color}. Should always be in
sync with the [cheated_color] field of {!current_config}.
*)
let cheated_gdk_color =
ref(GDraw.color (`RGB default_configuration.cheated_color))
(** Color for branches that have been proved and which have no
non-instantiated esistential variables, as {xref lablgtk type
Gdk.color}. Should always be in sync with the
[proved_complete_color] field of {!current_config}.
*)
let proved_complete_gdk_color =
ref(GDraw.color (`RGB default_configuration.proved_complete_color))
(** Color for branches that have been proved and that have
non-instantiated existential variables as {xref lablgtk type
Gdk.color}. Should always be in sync with the
[proved_incomplete_color] field of {!current_config}.
*)
let proved_incomplete_gdk_color =
ref(GDraw.color (`RGB default_configuration.proved_incomplete_color))
(** Color for branches that have been proved and whose own existential
variables are all instantiated, but where the instantiations
depend on some not-yet instantiated existential variables. The
value is given as {xref lablgtk type Gdk.color} and should always
be in sync with the [proved_partial_color] field of
{!current_config}.
*)
let proved_partial_gdk_color =
ref(GDraw.color (`RGB default_configuration.proved_partial_color))
(*
* (\** Color for marked subtrees, as {xref lablgtk type Gdk.color}.
* Should always be in sync with the {!mark_subtree_color} field of
* {!current_config}.
* *\)
* let mark_subtree_gdk_color =
* ref(GDraw.color (`RGB default_configuration.mark_subtree_color))
*)
(** Color for marking nodes that introduce a given existential
variable, as {xref lablgtk type Gdk.color}. Should always be in
sync with the [existential_create_color] field of
{!current_config}.
*)
let existential_create_gdk_color =
ref(GDraw.color (`RGB default_configuration.existential_create_color))
(** Color for marking nodes that instantiate a given existential
variable, as {xref lablgtk type Gdk.color}. Should always be in
sync with the [existential_instantiate_color] field of
{!current_config}.
*)
let existential_instantiate_gdk_color =
ref(GDraw.color (`RGB default_configuration.existential_instantiate_color))
(** Update the references for fonts and colors after the current
configuration has been changed.
*)
let update_font_and_color () =
proof_tree_font_desc :=
GPango.font_description !current_config.proof_tree_font;
sequent_font_desc :=
GPango.font_description !current_config.sequent_font;
current_gdk_color :=
GDraw.color (`RGB !current_config.current_color);
cheated_gdk_color :=
GDraw.color (`RGB !current_config.cheated_color);
proved_complete_gdk_color :=
GDraw.color (`RGB !current_config.proved_complete_color);
proved_incomplete_gdk_color :=
GDraw.color (`RGB !current_config.proved_incomplete_color);
proved_partial_gdk_color :=
GDraw.color (`RGB !current_config.proved_partial_color);
(*
* mark_subtree_gdk_color :=
* GDraw.color (`RGB !current_config.mark_subtree_color);
*)
existential_create_gdk_color :=
GDraw.color (`RGB !current_config.existential_create_color);
existential_instantiate_gdk_color :=
GDraw.color (`RGB !current_config.existential_instantiate_color)
(** This function reference solves the recursive module dependency
between modules {!Proof_tree}, {!Input} and this module. It is
filled with {!Main.configuration_updated} when [Main] is
initialized.
*)
let configuration_updated_callback = ref (fun () -> ())
(** Update the configuration and all directly derived state variables. *)
let update_configuration_record c =
current_config := c;
update_font_and_color ()
(** [update_configuration c] does all the necessary actions to make
[c] the current configuration. It stores [c] in {!current_config},
updates the references for fonts and colors and calls all
[configuration_updated] functions/methods.
*)
let update_configuration c =
update_configuration_record c;
!configuration_updated_callback ()
(** Reference for the argument of the [-geometry] option. *)
let geometry_string = ref ""
(** Flag for option [-config]. *)
let start_config_dialog = ref false
(*****************************************************************************
*****************************************************************************)
(** {2 Save / Restore configuration records}
A configuration file consists of an ASCII header (followed by a
newline) and a marshaled configuration record (of type {!t}).
Because of the header one can easily identify the file by opening
it in any editor. The header contains also a version field, which
changes whenever the type of the marshaled value changes.
*)
(** Common header of all configuration files. *)
let config_file_header_start = "Prooftree configuration file version "
(** Version specific header of the current config file version. *)
let config_file_version = "04"
(** The complete ASCII header of configuration files. *)
let config_file_header = config_file_header_start ^ config_file_version ^ "\n"
(** [write_config_file file c] writes a config file at [file],
containing the configuration record [c].
*)
let write_config_file file_name (config : t) =
let oc = open_out_bin file_name in
output_string oc config_file_header;
Marshal.to_channel oc config [];
close_out oc
(** Read a configuration file at the specified location. Raises
[Sys_error] if the file is not present or not readable. Raises
[Failure] if there is no configuration file or if the file has an
incompatible version. Return the read configuration file on success.
*)
let read_config_file file_name : t =
let header_len = String.length config_file_header in
let ic = open_in_bin file_name in
let header = really_input_string ic header_len in
if header = config_file_header
then begin
let c = (Marshal.from_channel ic : t) in
close_in ic;
c
end
else if string_starts header config_file_header_start
then raise Config_file_wrong_version
else raise Config_file_invalid
(** Try to load the configuration file at {!config_file_location},
ignoring all errors. If a valid configuration file is found, the
current configuration record is updated. If an incompatible
version is found, a warning message is displayed. Used during
start-up.
*)
let try_load_config_file () =
let copt =
try
(* print_endline "before read"; *)
let res = Some(read_config_file config_file_location) in
(* print_endline "after read"; *)
res
with
| Config_file_wrong_version ->
print_endline "version error";
run_message_dialog
("File " ^ config_file_location ^
" is not compatible with this version of Prooftree!\n\
Using default configuration.")
`WARNING;
None
| _ ->
Printf.printf "Configuration file %s cannot be read.\n"
config_file_location;
None
in
match copt with
| None -> ()
| Some c -> update_configuration_record c
(*****************************************************************************
*****************************************************************************)
(** {2 Configuration Dialog} *)
(** Reference to ensure that at most one configuration window does
exist.
*)
let config_window = ref None
(** Class for managing configuration windows. Objects are created when
the widget tree is completely constructed. Contains the necessary
state and methods to handle all callbacks. The callbacks must be
set up by the function that creates objects.
Arguments are
- old_config current config at config window start time
- top_window {xref lablgtk class GWindow.window}
of the top-level widget
- line_width_adjustment {xref lablgtk class GData.adjustment}
for line width
- turnstile_size_adjustment {xref lablgtk class GData.adjustment}
for turnstile size
- line_sep_adjustment {xref lablgtk class GData.adjustment}
for line gap
- proof_tree_sep_adjustment {xref lablgtk class GData.adjustment}
for proof tree sep
- subtree_sep_adjustment {xref lablgtk class GData.adjustment}
for node padding
- command_length_adjustment {xref lablgtk class GData.adjustment}
for command length
- level_dist_adjustment {xref lablgtk class GData.adjustment}
for vertical distance
- layer_sep_adjustment {xref lablgtk class GData.adjustment}
layer sep
- tree_font_button {xref lablgtk class GButton.font_button}
for proof tree font
- sequent_font_button {xref lablgtk class GButton.font_button}
for sequent window font
- current_color_button {xref lablgtk class GButton.color_button}
for current color
- cheated_color_button {xref lablgtk class GButton.color_button}
for cheated color
- proved_complete_color_button {xref lablgtk class GButton.color_button}
for complete color
- proved_incomplete_color_button {xref lablgtk class GButton.color_button}
for incomplete color
- proved_partial_color_button {xref lablgtk class GButton.color_button}
for partial color
- ext_create_color_button {xref lablgtk class GButton.color_button}
for create exist.
- ext_inst_color_button {xref lablgtk class GButton.color_button}
for instant. exist.
- drag_accel_adjustment {xref lablgtk class GData.adjustment}
for drac acceleration
- doc_tooltip_check_box {xref lablgtk class GButton.toggle_button}
for the help tool-tips check bock
- turnstile_tooltip_check_box {xref lablgtk class GButton.toggle_button}
for the turnstile tool-tips check bock
- command_tooltip_check_box {xref lablgtk class GButton.toggle_button}
for the command tool-tips check bock
- default_size_width_adjustment {xref lablgtk class GData.adjustment}
for default window size width
- default_size_height_adjustment {xref lablgtk class GData.adjustment}
for default window size height
- internal_seq_lines_adjustment {xref lablgtk class GData.adjustment}
for lines in the internal sequent window
- external_node_lines_adjustment {xref lablgtk class GData.adjustment}
for lines in external node windows
- ext_table_lines_adjustment {xref lablgtk class GData.adjustment}
for lines in evar table
- debug_check_box {xref lablgtk class GButton.toggle_button}
for the more-debug-info check box
- tee_file_box_check_box {xref lablgtk class GButton.toggle_button}
for log-input check box
- tee_file_name_entry {xref lablgtk class GEdit.entry}
of the log-file text entry
- tooltip_misc_objects list of {xref lablgtk class GObj.misc_ops}
of config dialog elements that have a tool-tip
to switch on and off
*)
class config_window
old_config
top_window
line_width_adjustment
turnstile_size_adjustment
line_sep_adjustment
proof_tree_sep_adjustment
subtree_sep_adjustment
command_length_adjustment
level_dist_adjustment
layer_sep_adjustment
tree_font_button
sequent_font_button
current_color_button
cheated_color_button
proved_complete_color_button
proved_incomplete_color_button
proved_partial_color_button
(* mark_subtree_color_button *)
ext_create_color_button
ext_inst_color_button
drag_accel_adjustment
doc_tooltip_check_box
turnstile_tooltip_check_box
command_tooltip_check_box
default_size_width_adjustment default_size_height_adjustment
internal_seq_lines_adjustment
external_node_lines_adjustment
ext_table_lines_adjustment
debug_check_box
tee_file_box_check_box
tee_file_name_entry
tooltip_misc_objects
=
object (self)
(** The callbacks for the configuration update may trigger several
config updates in a row. When this setting is [true], then the
config update is not done.
*)
val mutable delay_config_update = false
(** Set to [true] when the log-file chooser dialog sets the log-file
name to avoid switching off the log file check box.
*)
val mutable clean_tee_file_check_box = true
(** Make this configuration dialog visible. *)
method present = top_window#present()
(** [set_configuration c] changes spinners and buttons to show the
configuration of the configuration record [c].
*)
method set_configuration conf =
(* print_endline "set config start"; *)
line_width_adjustment#set_value (float_of_int conf.turnstile_line_width);
turnstile_size_adjustment#set_value (float_of_int conf.turnstile_radius);
subtree_sep_adjustment#set_value (float_of_int conf.subtree_sep);
line_sep_adjustment#set_value (float_of_int conf.line_sep);
proof_tree_sep_adjustment#set_value (float_of_int conf.proof_tree_sep);
command_length_adjustment#set_value (float_of_int conf.proof_command_length);
level_dist_adjustment#set_value (float_of_int conf.level_distance);
layer_sep_adjustment#set_value (float_of_int conf.layer_sep);
tree_font_button#set_font_name conf.proof_tree_font;
sequent_font_button#set_font_name conf.sequent_font;
current_color_button#set_color (GDraw.color (`RGB conf.current_color));
cheated_color_button#set_color (GDraw.color (`RGB conf.cheated_color));
proved_complete_color_button#set_color
(GDraw.color (`RGB conf.proved_complete_color));
proved_incomplete_color_button#set_color
(GDraw.color (`RGB conf.proved_incomplete_color));
proved_partial_color_button#set_color
(GDraw.color (`RGB conf.proved_partial_color));
(*
* mark_subtree_color_button#set_color
* (GDraw.color (`RGB conf.mark_subtree_color));
*)
ext_create_color_button#set_color
(GDraw.color (`RGB conf.existential_create_color));
ext_inst_color_button#set_color
(GDraw.color (`RGB conf.existential_instantiate_color));
drag_accel_adjustment#set_value conf.button_1_drag_acceleration;
doc_tooltip_check_box#set_active conf.display_doc_tooltips;
turnstile_tooltip_check_box#set_active conf.display_turnstile_tooltips;
command_tooltip_check_box#set_active conf.display_command_tooltips;
default_size_width_adjustment#set_value
(float_of_int conf.default_width_proof_tree_window);
default_size_height_adjustment#set_value
(float_of_int conf.default_height_proof_tree_window);
internal_seq_lines_adjustment#set_value
(float_of_int conf.internal_sequent_window_lines);
external_node_lines_adjustment#set_value
(float_of_int conf.node_window_max_lines);
ext_table_lines_adjustment#set_value
(float_of_int conf.ext_table_lines);
debug_check_box#set_active conf.debug_mode;
tee_file_box_check_box#set_active conf.copy_input;
tee_file_name_entry#set_text conf.copy_input_file;
(* print_endline "set config end"; *)
()
(** Change spinners and buttons to show the compile-time default
configuration.
*)
method reset_to_default () =
self#change_config_and_config_window default_configuration
(** Switch the help/documentation tool-tips on or off, according to
the argument [flag].
*)
method toggle_tooltips flag =
List.iter (fun misc -> misc#set_has_tooltip flag) tooltip_misc_objects
(** Start and manage the modal file selection dialog for the
log-file button. If the user makes a selection, the log-file
text entry is updated. The current configuration is then changed
via the [notify_text] signal of this entry.
*)
method tee_file_button_click () =
let file_chooser = GWindow.file_chooser_dialog
~action:`SAVE
~parent:top_window
~destroy_with_parent:true
~title:"Prooftree log file selection"
~focus_on_map:true
~modal:true ()
in
file_chooser#add_select_button_stock `APPLY `SELECT;
file_chooser#add_button_stock `CANCEL `CANCEL;
ignore(file_chooser#set_current_folder
(Filename.dirname tee_file_name_entry#text));
let chooser_file =
match file_chooser#run() with
| `SELECT -> file_chooser#filename
| `CANCEL
| `DELETE_EVENT -> None
in
file_chooser#destroy();
(match chooser_file with
| Some file ->
clean_tee_file_check_box <- false;
tee_file_name_entry#set_text file
| None -> ()
);
()
(** Create a new configuration record with the current values of the
spinners and buttons of this configuration dialog.
*)
method private extract_configuration =
let round_to_int f = int_of_float(f +. 0.5) in
let c = {
turnstile_line_width = round_to_int line_width_adjustment#value;
turnstile_radius = round_to_int turnstile_size_adjustment#value;
line_sep = round_to_int line_sep_adjustment#value;
proof_tree_sep = round_to_int proof_tree_sep_adjustment#value;
subtree_sep = round_to_int subtree_sep_adjustment#value;
proof_command_length = round_to_int command_length_adjustment#value;
level_distance = round_to_int level_dist_adjustment#value;
layer_sep = round_to_int layer_sep_adjustment#value;
turnstile_left_bar_x_offset = 0;
turnstile_left_bar_y_offset = 0;
turnstile_horiz_bar_x_offset = 0;
turnstile_number_x_offset = 0;
button_1_drag_acceleration = drag_accel_adjustment#value;
proof_tree_font = tree_font_button#font_name;
sequent_font = sequent_font_button#font_name;
current_color = (let c = current_color_button#color in
(Gdk.Color.red c, Gdk.Color.green c, Gdk.Color.blue c));
cheated_color = (let c = cheated_color_button#color in
(Gdk.Color.red c, Gdk.Color.green c, Gdk.Color.blue c));
proved_complete_color =
(let c = proved_complete_color_button#color in
(Gdk.Color.red c, Gdk.Color.green c, Gdk.Color.blue c));
proved_incomplete_color =
(let c = proved_incomplete_color_button#color in
(Gdk.Color.red c, Gdk.Color.green c, Gdk.Color.blue c));
proved_partial_color =
(let c = proved_partial_color_button#color in
(Gdk.Color.red c, Gdk.Color.green c, Gdk.Color.blue c));
(*
* mark_subtree_color =
* (let c = mark_subtree_color_button#color in
* (Gdk.Color.red c, Gdk.Color.green c, Gdk.Color.blue c));
*)
existential_create_color =
(let c = ext_create_color_button#color in
(Gdk.Color.red c, Gdk.Color.green c, Gdk.Color.blue c));
existential_instantiate_color =
(let c = ext_inst_color_button#color in
(Gdk.Color.red c, Gdk.Color.green c, Gdk.Color.blue c));
display_doc_tooltips = doc_tooltip_check_box#active;
display_turnstile_tooltips = turnstile_tooltip_check_box#active;
display_command_tooltips = command_tooltip_check_box#active;
default_width_proof_tree_window =
round_to_int default_size_width_adjustment#value;
default_height_proof_tree_window =
round_to_int default_size_height_adjustment#value;
internal_sequent_window_lines =
round_to_int internal_seq_lines_adjustment#value;
node_window_max_lines =
round_to_int external_node_lines_adjustment#value;
ext_table_lines =
round_to_int ext_table_lines_adjustment#value;
debug_mode = debug_check_box#active;
copy_input = tee_file_box_check_box#active;
copy_input_file = tee_file_name_entry#text;
}
in
update_sizes c
(** Callback when any item of the configuration changed. This simply
updates the complete configuration in the whole program.
*)
method config_changed () =
(* Printf.printf "change config delay %b\n%!" delay_config_update; *)
if not delay_config_update then begin
(* let app_start = U.gettimeofday () in *)
let c = self#extract_configuration in
self#toggle_tooltips c.display_doc_tooltips;
(try
update_configuration c;
with
| Log_input_file_error msg ->
run_message_dialog
(Printf.sprintf
"Opening the input log file failed with\n %s.\n\
Disabeling input logging."
msg)
`WARNING;
tee_file_box_check_box#set_active false
);
(*
* let app_end = U.gettimeofday () in
* Printf.printf "apply config %f ms\n%!" ((app_end -. app_start) *. 1000.)
*)
end
(** Update the current configuration record and all displayed values
in the config window. This method makes sure that the body of
the callback {config_changed} is only executed ones and that the
input logging flag is not reset.
*)
method private change_config_and_config_window c =
delay_config_update <- true;
clean_tee_file_check_box <- false;
self#set_configuration c;
delay_config_update <- false;
self#config_changed ()
(** Callback for the case that the log file entry has changed. To
avoid lots of file openings, the tee file check box is disabled.
*)
method log_file_entry_changed (_ : string) =
(* Printf.printf "log entry start clean %b\n%!" clean_tee_file_check_box; *)
if clean_tee_file_check_box then begin
let delay = delay_config_update in
delay_config_update <- true;
tee_file_box_check_box#set_active false;
delay_config_update <- delay;
end;
clean_tee_file_check_box <- true;
(* print_endline "log entry middle"; *)
self#config_changed ();
(* print_endline "log entry end"; *)
()
(** Action for the Save button: Saves the current configuration in
the user specific configuration file {!config_file_location}. If
the values of this configuration dialog differ from the current
configuration, a suitable warning is displayed.
*)
method save () =
try
write_config_file config_file_location !current_config
with
| Sys_error s when Util.string_ends s "Permission denied" ->
run_message_dialog
("No permission to write the configuration file at "
^ config_file_location ^ "!")
`WARNING
| e ->
let backtrace = Printexc.get_backtrace () in
let buf = Buffer.create 4095 in
let print_backtrace = ref !current_config.debug_mode in
(match e with
| e ->
Buffer.add_string buf "Internal error: Escaping exception ";
Buffer.add_string buf (Printexc.to_string e);
Buffer.add_string buf " in write_config_file";
(match e with
| U.Unix_error(error, _func, _info) ->
Buffer.add_char buf '\n';
Buffer.add_string buf (U.error_message error);
| _ -> ()
)
);
if !print_backtrace then begin
Buffer.add_char buf '\n';
Buffer.add_string buf backtrace;
end;
prerr_endline (Buffer.contents buf);
run_message_dialog (Buffer.contents buf) `WARNING;
()
(** Action for the Restore button: Restore the configuration in the
the user specific configuration file {!config_file_location} as
current configuration and update this dialog accordingly.
*)
method restore () =
try
let c = read_config_file config_file_location in
self#change_config_and_config_window c
with
| Sys_error s when Util.string_ends s "No such file or directory" ->
run_message_dialog
("No configuration file at " ^ config_file_location ^ "!")
`WARNING
| Config_file_wrong_version ->
run_message_dialog
("File " ^ config_file_location ^
" is not compatible with this version of Prooftree!")
`WARNING
| Config_file_invalid ->
run_message_dialog
("File " ^ config_file_location ^ " is not a valid Prooftree \
configuration file!")
`WARNING
| e ->
let backtrace = Printexc.get_backtrace () in
let buf = Buffer.create 4095 in
let print_backtrace = ref !current_config.debug_mode in
(match e with
| e ->
Buffer.add_string buf "Internal error: Escaping exception ";
Buffer.add_string buf (Printexc.to_string e);
Buffer.add_string buf " in read_config_file";
(match e with
| U.Unix_error(error, _func, _info) ->
Buffer.add_char buf '\n';
Buffer.add_string buf (U.error_message error);
| _ -> ()
)
);
if !print_backtrace then begin
Buffer.add_char buf '\n';
Buffer.add_string buf backtrace;
end;
prerr_endline (Buffer.contents buf);
run_message_dialog (Buffer.contents buf) `WARNING;
()
(** Action for the Cancel button and the destroy signal. *)
method destroy () =
config_window := None;
top_window#destroy();
if !start_config_dialog then exit 0
(** Action for the Cancel button: Reset config to start time. *)
method cancel () =
self#change_config_and_config_window old_config;
self#destroy ()
(** Action of the OK button. *)
method ok () =
self#destroy ()
end
(** [adjustment_set_pos_int ~lower adjustment] configures [adjustment]
for integer values between [~lower] and [100].
*)
let adjustment_set_pos_int ?(lower = 1.0) (adjustment : GData.adjustment) =
adjustment#set_bounds
~lower ~upper:100.0
~step_incr:1.0 ~page_incr:1.0 ()
(** Create a new configuation dialog. Creates the widget hierarchy,