-
Notifications
You must be signed in to change notification settings - Fork 0
/
GUI.ml
165 lines (143 loc) · 4.39 KB
/
GUI.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
(* This file is distributed under the terms of the GNU Lesser General Public License Version 2.1 *)
(* Jeongbong Seo, Jonghyun Park, Sungwoo Park *)
(* Programming Language Laboratory, POSTECH *)
(* {baramseo, parjong, gla}@postech.ac.kr *)
open Core.Std
open Common
open Interactive
(** Setting up UI *)
let window = GWindow.window ~title:"Interactive Prover for Labelled CSBBI" ~border_width:10 ~width:800 ~height:400 ()
let hpaned = GPack.paned `HORIZONTAL ()
~packing:window#add;;
(* Left Column *)
let vbox = GPack.vbox ~spacing:5 ~width:315 ~packing:(hpaned#pack1) ()
(* Left Column : State View & Message View*)
let vpaned = GPack.paned `VERTICAL ()
~packing:(vbox#pack ~expand:true);;
let sw_state = GBin.scrolled_window ()
~hpolicy:`AUTOMATIC
~vpolicy:`AUTOMATIC
~packing:(vpaned#pack1);;
let state_view = GText.view ()
~editable:false
~cursor_visible:false
~border_width:2
~packing:sw_state#add;;
let sw_message = GBin.scrolled_window ()
~hpolicy:`AUTOMATIC
~vpolicy:`AUTOMATIC
~packing:(vpaned#pack2);;
let message_view = GText.view ()
~editable:false
~cursor_visible:false
~border_width:2
~packing:sw_message#add;;
(* Left Column : Message View & Entry *)
let entry = GEdit.entry ()
~packing:(vbox#pack ~from:`END);;
(* Right Column *)
let sw_img = GBin.scrolled_window ()
~hpolicy:`AUTOMATIC
~vpolicy:`AUTOMATIC
~packing:(hpaned#pack2 ~resize:true);;
let image = GMisc.image () ~packing:sw_img#add_with_viewport;;
let show_hidden_worlds = ref false
(** Action *)
let update_state () =
state_view#buffer#set_text (Session.to_string ());
match Session.get_goalseq () with
| Ok seq -> begin
try
let tmp = Filename.temp_file "graph" ".png" in
Session.save_seq_pic tmp |! simpl_unwrap;
let pixbuf = GdkPixbuf.from_file tmp in
image#set_pixbuf pixbuf;
Sys.remove tmp;
with _ -> ()
end
| Error _ -> ();;
let run_command () =
try
let text = entry#text in
entry#set_text "";
let cmd = Command.from_string_exn text in
try
begin
match cmd with
| Command.Open prop ->
Session.start_fprop ~fprop:prop
|! simpl_unwrap
| Command.Restart ->
Session.restart ()
|! simpl_unwrap
| Command.Close ->
Session.close ()
|! simpl_unwrap
| Command.Apply tac ->
Session.step tac
|! simpl_unwrap
| Command.Undo ->
Session.undo ()
|! simpl_unwrap
| Command.Auto i ->
Session.auto i
|! simpl_unwrap
| Command.Trivial ->
Session.trivial ()
|! simpl_unwrap
| Command.Next_subgoal ->
Session.next_subgoal ()
|! simpl_unwrap
| Command.Prev_subgoal ->
Session.prev_subgoal ()
|! simpl_unwrap
| Command.Next_branch ->
Session.next_branch ()
|! simpl_unwrap
| Command.Prev_branch ->
Session.prev_branch ()
|! simpl_unwrap
| Command.Save filename ->
Session.save filename
|! simpl_unwrap
| Command.Fork ->
Session.fork ()
|! simpl_unwrap
| Command.Print_history ->
Session.print_history () |! message_view#buffer#set_text
| Command.Help ->
Session.help_msg () |! message_view#buffer#set_text
| Command.Quit ->
exit 0
| Command.Save_seq_pic filename ->
Session.save_seq_pic filename
|! simpl_unwrap
| Command.Show_all ->
Session.show_all ()
| Command.Show_visible ->
Session.show_visible ()
| Command.Show_toggle ->
Session.show_toggle ()
end;
begin
match cmd with
| Command.Print_history | Command.Help
| Command.Save_seq_pic _ | Command.Save _ -> ()
| _ ->
message_view#buffer#set_text "";
update_state ()
end
with
| Failure msg ->
message_view#buffer#set_text msg
with Failure msg -> String.concat ["Invalid command"; "\n"; msg] |! message_view#buffer#set_text
(** Initialize *)
let main () =
ignore (window#connect#destroy ~callback:GMain.Main.quit);
ignore (entry#connect#activate ~callback:run_command);
window#show ();
(* This code makes ''entry'' to pose a cursor! *)
(* GMain.Grab.add entry; *)
entry#misc#grab_focus ();
GMain.Main.main ()
let _ = main ()