From 82d3631ad415cab11e2efd448450cd03d3232825 Mon Sep 17 00:00:00 2001 From: Enrico Zini Date: Thu, 13 Aug 2009 16:33:48 +0100 Subject: [PATCH] Show polygen results in a clickable text area --- src/app_polygen.vala | 46 +++++++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/src/app_polygen.vala b/src/app_polygen.vala index af01b8f..7ee4ea8 100644 --- a/src/app_polygen.vala +++ b/src/app_polygen.vala @@ -58,8 +58,9 @@ protected class PolygenPage : Object protected class PolygenRun : Gtk.VBox { - protected Gtk.Label text; - protected Gtk.Button text_button; + public Gtk.ScrolledWindow scroll; + protected Gtk.TextBuffer text_buffer; + protected Gtk.TextView text; private string _grammar; public string grammar { @@ -73,20 +74,43 @@ protected class PolygenRun : Gtk.VBox public PolygenRun() { _grammar = ""; - text = new Gtk.Label(""); - text.use_markup = true; - text.wrap = true; - text_button = new Gtk.Button(); - text_button.set_image(text); - pack_start(text_button, true, true, 0); - text_button.clicked += on_clicked; + text_buffer = new Gtk.TextBuffer(null); + text = new Gtk.TextView.with_buffer(text_buffer); + text.wrap_mode = Gtk.WrapMode.WORD; + text.cursor_visible = false; + text.editable = false; + text.add_events(Gdk.EventMask.BUTTON_PRESS_MASK); + text.button_press_event += on_button_press; + scroll = new Gtk.ScrolledWindow (null, null); + scroll.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC); + scroll.add(text); + pack_start(scroll, true, true, 0); } - public void on_clicked(Gtk.Button button) { update(); } + public bool on_button_press(Gdk.EventButton event) + { + update(); + return true; + } public void update() { - text.label = "ciao " + _grammar; + string[] args = new string[3]; + args[0] = "/usr/bin/polygen"; + args[1] = "/usr/share/polygen/" + _grammar + ".grm"; + args[2] = null; + int pipe_out; + Process.spawn_async_with_pipes(config.homedir, args, null, 0, null, null, null, out pipe_out, null); + IOChannel ch = new IOChannel.unix_new(pipe_out); + string result; + ch.read_to_end(out result, null); + ch.shutdown(false); + + text_buffer.text = result; + Gtk.TextIter iter; + text_buffer.get_iter_at_offset(out iter, 0); + Gtk.TextMark mark = text_buffer.create_mark(null, iter, true); + text.scroll_mark_onscreen(mark); } } -- 2.30.2