Commit 3d7dec0b authored by bguillaum's avatar bguillaum

reload button

error handling

git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/semagramme/dep2pict/trunk@8151 7838e531-6607-4d57-9587-6c381814729c
parent cabaf23a
......@@ -43,6 +43,19 @@
<property name="position">1</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="reload">
<property name="label" translatable="yes">Reload</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">2</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="to_svg">
<property name="label" translatable="yes">To SVG</property>
......@@ -53,7 +66,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">2</property>
<property name="position">3</property>
<property name="secondary">True</property>
</packing>
</child>
......@@ -67,7 +80,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">3</property>
<property name="position">4</property>
<property name="secondary">True</property>
</packing>
</child>
......@@ -81,7 +94,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">4</property>
<property name="position">5</property>
<property name="secondary">True</property>
</packing>
</child>
......
......@@ -5,6 +5,8 @@ open Ui
open Rsvg
open GMain
let (input_file : string option ref) = ref None
let (output_file : string option ref) = ref None
let refresh_svg (ui:ui) () =
let input_text =
......@@ -21,36 +23,20 @@ let refresh_svg (ui:ui) () =
let pixbuf = Rsvg.render_from_string ~size_cb:(Rsvg.at_zoom 1.0 1.0) svg in
ui#svg_view#set_pixbuf pixbuf;
ui#error_view#buffer#set_text "";
with _ ->
try
let svg =
Dep2pict.fromDepStringToSvgString
(ui#dep_source#buffer#get_text
~start:ui#dep_source#buffer#start_iter
~stop:ui#dep_source#buffer#end_iter
~slice:true
~visible:true ()) in
let pixbuf = Rsvg.render_from_string ~size_cb:(Rsvg.at_zoom 1.0 1.0) svg in
ui#svg_view#set_pixbuf pixbuf;
ui#error_view#buffer#set_text "";
with
| Dep2pict.Parse_error msgs ->
ui#error_view#buffer#set_text "";
let err = ref "" in
List.iter ( fun (l,m) ->
err := Printf.sprintf "%sLine %d : %s\n" !err l m
) msgs;
ui#error_view#buffer#set_text !err
| Dep2pict.Id_already_in_use_ id -> ui#error_view#buffer#set_text ("Id already in use : "^id)
| Dep2pict.Unknown_index id -> ui#error_view#buffer#set_text ("Can't find index : "^id)
| Dep2pict.Loop_in_dep msg -> ui#error_view#buffer#set_text ("Loop in dependency : "^msg)
| Dep2pict.Conll_format msg -> ui#error_view#buffer#set_text ("Conll format : "^msg)
with
| Dep2pict.Parse_error msgs ->
ui#error_view#buffer#set_text
(String.concat "\n" (List.map (fun (l,m) -> sprintf "Line %d: %s" l m) msgs));
| Dep2pict.Id_already_in_use_ id -> ui#error_view#buffer#set_text ("Id already in use : "^id)
| Dep2pict.Unknown_index id -> ui#error_view#buffer#set_text ("Can't find index : "^id)
| Dep2pict.Loop_in_dep msg -> ui#error_view#buffer#set_text ("Loop in dependency : "^msg)
| Dep2pict.Conll_format msg -> ui#error_view#buffer#set_text ("Conll format : "^msg)
let writeFile path str =
let file = open_out path in
output file str 0 (String.length str);
flush file;
close_out file
let file = open_out path in
output file str 0 (String.length str);
flush file;
close_out file
let readFile path =
let text =
......@@ -77,16 +63,22 @@ let save (ui:ui) () =
()
let open_dep (ui:ui) () =
let compute file () =
ui#dep_source#buffer#set_text (readFile file#filename)
in
let sel = GWindow.file_selection ~title:"Open file" ~show:true() in
ignore(sel#ok_button#connect#clicked ~callback:(compute sel));
ignore(sel#ok_button#connect#clicked ~callback:(sel#destroy));
ignore(sel#cancel_button#connect#clicked ~callback:(sel#destroy));
sel#complete ~filter:"*.dep";
()
let compute file () =
ui#dep_source#buffer#set_text (readFile file#filename);
input_file := Some file#filename in
let sel = GWindow.file_selection ~title:"Open file" ~show:true() in
ignore(sel#ok_button#connect#clicked ~callback:(compute sel));
ignore(sel#ok_button#connect#clicked ~callback:(sel#destroy));
ignore(sel#cancel_button#connect#clicked ~callback:(sel#destroy));
sel#complete ~filter:"*.dep";
()
let reload (ui:ui) () =
match !input_file with
| Some filename -> ui#dep_source#buffer#set_text (readFile filename)
| None -> ()
let to_svg (ui:ui) () =
let compute file () =
writeFile file#filename (Dep2pict.fromDepStringToSvgString (ui#dep_source#buffer#get_text
......@@ -137,21 +129,23 @@ let main ?file () =
let ui = new ui () in
ui#toplevel#set_title ("Dep2pict v. "^VERSION);
ignore(ui#dep_source#buffer#connect#changed ~callback:(refresh_svg ui));
ignore(ui#toplevel#connect#destroy ~callback:GMain.Main.quit);
ignore(ui#save#connect#clicked ~callback:(save ui));
ignore(ui#open_btn#connect#clicked ~callback:(open_dep ui));
ignore(ui#reload#connect#clicked ~callback:(reload ui));
ignore(ui#to_svg#connect#clicked ~callback:(to_svg ui));
ignore(ui#to_png#connect#clicked ~callback:(to_png ui));
ignore(ui#to_pdf#connect#clicked ~callback:(to_pdf ui));
refresh_svg ui ();
(match file with
| None -> ()
| Some f -> ui#dep_source#buffer#set_text (readFile f)
);
refresh_svg ui ();
ignore(ui#dep_source#buffer#connect#changed ~callback:(refresh_svg ui));
ui#check_widgets ();
ui#toplevel#show ();
......
......@@ -6,6 +6,9 @@ open Gui
let gui ?file () = Gui.main ?file ()
ELSE
let input_file = ref None
let output_file = ref None
let gui ?file () = Log.critical "Gui not available"
END
......@@ -24,7 +27,7 @@ let version = VERSION
let usage = String.concat "\n" [
"Usage:";
" * dep2pict <options> -dep <dep_file> -o <output_file>";
" * dep2pict <options> -conll <<conll_file> -o <output_file>";
" * dep2pict <options> -conll <conll_file> -o <output_file>";
"Options:";
" -png: set output format to png (this is the default)";
" -pdf: set output format to pdf";
......@@ -43,9 +46,6 @@ let input = ref Dep
let debug = ref false
let input_file = ref None
let output_file = ref None
let eps_ref = ref false
let conll_features = ref ""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment