Commit b835b304 authored by bguillaum's avatar bguillaum

2.13.0: It is possible to use conll in GUI and to start GUI with an input file

git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/semagramme/dep2pict/trunk@7972 7838e531-6607-4d57-9587-6c381814729c
parent e5e521df
VERSION = 2.12.0
VERSION = 2.13.0
INSTALL_DIR = @prefix@@bindir@
DATA_DIR = @prefix@@datarootdir@/dep2pict/
......
<?xml version="1.0"?>
<?xml version="1.0" encoding="UTF-8"?>
<glade-interface>
<!-- interface-requires gtk+ 2.16 -->
<!-- interface-naming-policy project-wide -->
<widget class="GtkWindow" id="ui">
<property name="can_focus">False</property>
<property name="window_position">center</property>
<property name="default_width">500</property>
<property name="default_height">768</property>
<child>
<widget class="GtkTable" id="table1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="n_rows">4</property>
<child>
<widget class="GtkHButtonBox" id="hbuttonbox1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="layout_style">start</property>
<child>
<widget class="GtkButton" id="save">
......@@ -85,32 +88,7 @@
</widget>
<packing>
<property name="x_options">GTK_FILL</property>
<property name="y_options"></property>
<property name="x_padding">5</property>
<property name="y_padding">5</property>
</packing>
</child>
<child>
<widget class="GtkViewport" id="svg_viewport">
<property name="visible">True</property>
<property name="resize_mode">queue</property>
<child>
<widget class="GtkViewport" id="viewport1">
<property name="visible">True</property>
<property name="resize_mode">queue</property>
<property name="shadow_type">none</property>
<child>
<widget class="GtkImage" id="svg_view">
<property name="visible">True</property>
<property name="stock">gtk-missing-image</property>
</widget>
</child>
</widget>
</child>
</widget>
<packing>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="y_options"/>
<property name="x_padding">5</property>
<property name="y_padding">5</property>
</packing>
......@@ -124,11 +102,13 @@
<child>
<widget class="GtkFrame" id="frame1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
<child>
<widget class="GtkAlignment" id="alignment1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="bottom_padding">12</property>
<property name="left_padding">12</property>
<property name="right_padding">12</property>
......@@ -157,6 +137,7 @@
<child>
<widget class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_markup">True</property>
</widget>
<packing>
......@@ -172,11 +153,13 @@
<child>
<widget class="GtkFrame" id="frame2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
<child>
<widget class="GtkAlignment" id="alignment2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="bottom_padding">12</property>
<property name="left_padding">12</property>
<property name="right_padding">12</property>
......@@ -199,6 +182,7 @@
<child>
<widget class="GtkLabel" id="label2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_markup">True</property>
</widget>
<packing>
......@@ -222,12 +206,49 @@
<child>
<widget class="GtkStatusbar" id="statusbar1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">2</property>
</widget>
<packing>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="y_options"></property>
<property name="y_options"/>
</packing>
</child>
<child>
<widget class="GtkScrolledWindow" id="scrolledwindow3">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hscrollbar_policy">automatic</property>
<property name="vscrollbar_policy">automatic</property>
<child>
<widget class="GtkViewport" id="svg_viewport">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="resize_mode">queue</property>
<child>
<widget class="GtkViewport" id="viewport1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="resize_mode">queue</property>
<property name="shadow_type">none</property>
<child>
<widget class="GtkImage" id="svg_view">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stock">gtk-missing-image</property>
</widget>
</child>
</widget>
</child>
</widget>
</child>
</widget>
<packing>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_padding">5</property>
<property name="y_padding">5</property>
</packing>
</child>
</widget>
......
open Printf
open Dep2pict
open Ui
......@@ -6,29 +7,44 @@ open GMain
let refresh_svg (ui:ui) () =
begin 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)
end
let input_text =
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
try
let svg =
if input_text <> "" && input_text.[0] = '1'
then Dep2pict.fromConllStringToSvgString input_text
else Dep2pict.fromDepStringToSvgString input_text 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 _ ->
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)
let writeFile path str =
let file = open_out path in
......@@ -37,7 +53,7 @@ let writeFile path str =
close_out file
let readFile path =
let text =
let text =
let file = open_in path in
let fileSize = in_channel_length file in
let buffer = String.create fileSize in
......@@ -116,26 +132,27 @@ let to_pdf (ui:ui) () =
sel#complete ~filter:"*.pdf";
()
let main () =
ignore (GMain.Main.init ());
let ui = new ui () in
let main ?file () =
ignore (GMain.Main.init ());
let ui = new ui () in
ui#toplevel#set_title ("Dep2pict v. "^VERSION);
ui#toplevel#set_title ("Dep2pict v. "^VERSION);
ignore(ui#dep_source#buffer#connect#changed ~callback:(refresh_svg ui));
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#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)
);
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#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 ();
ui#check_widgets ();
ui#toplevel#show ();
GMain.Main.main ()
ui#check_widgets ();
ui#toplevel#show ();
GMain.Main.main ()
......@@ -3,6 +3,10 @@ open Log
open Dep2pict
IFDEF BUILD_GUI THEN
open Gui
let gui ?file () = Gui.main ?file ()
ELSE
let gui ?file () = Log.critical "Gui not available"
END
let _ =
......@@ -45,57 +49,53 @@ let eps_ref = ref false
let conll_features = ref ""
let _ =
if Array.length Sys.argv = 1
then (IFDEF BUILD_GUI THEN Gui.main () ELSE Log.critical "Gui not available" END)
else
begin
let rec opt = function
| [] -> ()
| "-v"::_ -> printf "%s\n%!" version; exit 0
| "-help"::_ -> printf "%s\n%!" usage; exit 0
| "-conll"::file::tail -> input_file := Some file; input := Conll; opt tail
| "-dep"::file::tail -> input_file := Some file; opt tail
(* NB: the xml option is used by parconine: arg is an integer, the xml_file is given with the -dep option *)
| "-xml"::n::tail -> input := Xml (int_of_string n); opt tail
let rec opt = function
| [] -> ()
| "-v"::_ -> printf "%s\n%!" version; exit 0
| "-help"::_ -> printf "%s\n%!" usage; exit 0
| "-conll"::file::tail -> input_file := Some file; input := Conll; opt tail
| "-dep"::file::tail -> input_file := Some file; opt tail
(* NB: the xml option is used by parconine: arg is an integer, the xml_file is given with the -dep option *)
| "-xml"::n::tail -> input := Xml (int_of_string n); opt tail
| "-o"::file::tail -> output_file := Some file; opt tail
| "-png"::tail -> output := Png; opt tail
| "-svg"::tail -> output := Svg; opt tail
| "-pdf"::tail -> output := Pdf; opt tail
| "-features"::feats::tail -> conll_features := feats; opt tail
| "-ref"::tail -> eps_ref := true; opt tail
| "-d"::tail -> debug := true; opt tail
| others::tail -> Log.fcritical "%s : option unknown!\n%s" others usage
in opt (List.tl (Array.to_list Sys.argv));
match (!input_file, !output_file) with
| (None,_) -> Log.critical "No input file."
| (Some input,_) when not (Sys.file_exists input) -> Log.fcritical "The file %s doesn't exist." input
| (_,None) -> Log.critical "No ouput file specified."
| (Some in_file, Some out_file) ->
try
(match (!input, !output) with
| (Xml i, Png) -> ignore (Dep2pict.fromXmlFileToPng in_file out_file i)
| (Dep, Png) -> ignore (Dep2pict.fromDepFileToPng in_file out_file)
| (Conll, Png) -> ignore (Dep2pict.fromConllFileToPng ~features:!conll_features ~eps_ref:!eps_ref in_file out_file)
| (Xml i, Svg) -> ignore (Dep2pict.fromXmlFileToSvgFile ~debug:(!debug) in_file out_file i)
| (Dep, Svg) -> ignore (Dep2pict.fromDepFileToSvgFile ~debug:(!debug) in_file out_file)
| (Conll, Svg) -> ignore (Dep2pict.fromConllFileToSvgFile ~debug:(!debug) ~features:!conll_features ~eps_ref:!eps_ref in_file out_file)
| (Xml i, Pdf) -> ignore (Dep2pict.fromXmlFileToPdf in_file out_file i)
| (Dep, Pdf) -> ignore (Dep2pict.fromDepFileToPdf in_file out_file)
| (Conll, Pdf) -> ignore (Dep2pict.fromConllFileToPdf ~features:!conll_features ~eps_ref:!eps_ref in_file out_file));
Log.finfo "File %s generated." out_file
with
| Dep2pict.Parse_error msgs -> List.iter (fun (l,m) -> printf "Line %d: %s\n" l m) msgs; Log.fcritical "Parse error"
| Dep2pict.Id_already_in_use_ id -> Log.fcritical "Id already in use : %s" id
| Dep2pict.Unknown_index id -> Log.fcritical "Can't find index : %s" id
| Dep2pict.Loop_in_dep msg -> Log.fcritical "Loop in dependency : %s" msg
end
| "-o"::file::tail -> output_file := Some file; opt tail
| "-png"::tail -> output := Png; opt tail
| "-svg"::tail -> output := Svg; opt tail
| "-pdf"::tail -> output := Pdf; opt tail
| "-features"::feats::tail -> conll_features := feats; opt tail
| "-ref"::tail -> eps_ref := true; opt tail
| "-d"::tail -> debug := true; opt tail
| others::tail -> Log.fcritical "%s : option unknown!\n%s" others usage
in opt (List.tl (Array.to_list Sys.argv));
match (!input_file, !output_file) with
| (None, None) -> gui ()
| (None, Some _) -> Log.critical "No input file."
| (Some file,_) when not (Sys.file_exists file) -> Log.fcritical "The file %s doesn't exist." file
| (Some file, None) -> gui ~file ()
| (Some in_file, Some out_file) ->
try
(match (!input, !output) with
| (Xml i, Png) -> ignore (Dep2pict.fromXmlFileToPng in_file out_file i)
| (Dep, Png) -> ignore (Dep2pict.fromDepFileToPng in_file out_file)
| (Conll, Png) -> ignore (Dep2pict.fromConllFileToPng ~features:!conll_features ~eps_ref:!eps_ref in_file out_file)
| (Xml i, Svg) -> ignore (Dep2pict.fromXmlFileToSvgFile ~debug:(!debug) in_file out_file i)
| (Dep, Svg) -> ignore (Dep2pict.fromDepFileToSvgFile ~debug:(!debug) in_file out_file)
| (Conll, Svg) -> ignore (Dep2pict.fromConllFileToSvgFile ~debug:(!debug) ~features:!conll_features ~eps_ref:!eps_ref in_file out_file)
| (Xml i, Pdf) -> ignore (Dep2pict.fromXmlFileToPdf in_file out_file i)
| (Dep, Pdf) -> ignore (Dep2pict.fromDepFileToPdf in_file out_file)
| (Conll, Pdf) -> ignore (Dep2pict.fromConllFileToPdf ~features:!conll_features ~eps_ref:!eps_ref in_file out_file));
Log.finfo "File %s generated." out_file
with
| Dep2pict.Parse_error msgs -> List.iter (fun (l,m) -> printf "Line %d: %s\n" l m) msgs; Log.fcritical "Parse error"
| Dep2pict.Id_already_in_use_ id -> Log.fcritical "Id already in use : %s" id
| Dep2pict.Unknown_index id -> Log.fcritical "Can't find index : %s" id
| Dep2pict.Loop_in_dep msg -> Log.fcritical "Loop in dependency : %s" msg
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