[Gtk-sharp-list] refreshing Gtk.TextView and EntryCompletion
John Luke
john.luke@gmail.com
Thu, 23 Dec 2004 13:50:26 -0500
Hello,
The problem is: // Using threads....
Gtk# is thread-aware but not thread-safe. Please see Gtk.ThreadNotify
or GLib.Idle docs, or search the archives for the numerous posts about
Gtk# and threading, etc. You can only modify the gui through the main
thread.
Gtk# 2.0 will have Gtk.EntryCompletion (there is an unstable 1.9.1
release if you want to try it).
On Thu, 2004-12-23 at 07:27 -0600, Javier Díaz wrote:
> Hey guys
>
> I'm writing an example of how to use Google Suggest technology in
> gtk-sharp applications
>
> here is part of the code:
> ......
> public class GoogleCompletionGladeApp
> {
> [Widget] Gtk.Entry query_entry;
> [Widget] Gtk.TextView res_textview;
> [Widget] Gtk.Combo combo_res;
>
> static Gtk.TextBuffer buffer;
> static ACRequestHandler request_handler;
>
> private static Thread search_thread;
> private static string search_query;
> private static string[] Args;
>
> public GoogleCompletionGladeApp (string[] args)
> {
> Args = args;
> request_handler = new ACRequestHandler();
>
> Application.Init();
>
> Glade.XML gxml = new Glade.XML (null, "gui.glade", "window1", null);
> gxml.Autoconnect (this);
>
> buffer = res_textview.Buffer;
>
> Application.Run();
> }
> public void OnWindowDeleteEvent (object o, DeleteEventArgs args)
> {
> Application.Quit ();
> args.RetVal = true;
> }
> public void on_exec_button_clicked (object o, EventArgs args)
> {
> // Not using threads Here.....
>
> buffer.Clear();
> foreach (string s in request_handler.Require(query_entry.Text)){
> buffer.Text += s + '\n';
> }
> }
> public void on_query_entry_changed (object o, EventArgs args)
> {
> // Using threads....
>
> // "search_query" is a static member
> // it is going to be used by SearchThread()
> // I don't want SearchThread() to access "query_entry"
> search_query = query_entry.Text;
>
> if (search_thread != null){
> search_thread.Abort();
> }
>
> search_thread = new Thread (new ThreadStart (SearchThread));
> search_thread.Start();
> }
> private static void SearchThread()
> {
> try {
> lock (buffer){
> buffer.Clear();
>
> foreach (string s in request_handler.Require(search_query)){
> buffer.Text += s + '\n';
> }
> }
> } catch (ThreadAbortException) {
> buffer.Clear();
> }
> }
> }
> ------
> You can download the full source code from:
> http://isotopo.homeip.net/GooglehACe.tar.gz
>
> I have the following problem:
>
> The (Gtk.TextBuffer) buffer used to modify the (Gtk.TextView)
> res_textview, it is locked and modified by the thread that searches
> suggestions,... but the res_textview does not reloads the data from the
> buffer, I don't know how to explicitly refresh res_textview.
>
> I can see that res_textview redraws itself very well on Expose event.
>
> Is there any way SearchThread() can redraw res_textview safely ??.
>
> I wish I had some sort of Completion widget like Monodevelo's
> CodeCompletion.CompletionWindow
>
> is there something like a Gtk.EntryCompletion on Gtk# 1.0.4 ?
>