[Glade-users] Sending events (somewhat OT)



On Sat, Mar 14, 2009 at 6:59 PM, Tristan Van Berkom
<tristan.van.berkom at gmail.com> wrote:
On Sat, Mar 14, 2009 at 12:28 AM, Steve Blackwell <zephod at cfl.rr.com> wrote:
I have written a program using glade 3 that has 2 threads. The main
thread handles user input from the GUI while the second thread monitors
a USB port for input. When data arrives at the USB port, it is processed
and written to a GtkTreeView widget.

The problem is that the data does not appear in the TreeView until I
move the mouse or press a key. I think that this is because the main
thread controlling the GUI is blocking in gtk_main() until an event
arrives. So I added code to the second thread to send a
GDK_CLIENT_EVENT to the GtkDialog widget that contains the TreeView.

It didn't work.

When you recieve data from your USB in your worker thread; call
g_idle_add() to schedule a one time idle function in the main thread.

From that function - call gtk_widget_queue_draw() on your treeview.


Further more, I hope you are not unsafely accessing the TreeModel
from the thread while its connected to the view, this will cause
errors (unless protected with threads_enter/leave calls properly
everywhere). I recommend not using the threads_enter/leave
code at all and really only accessing UI objects from the UI
thread (well I've just found threading to be simpler to understand/debug
that way).

To do it with a dedicated UI thread, you probably want to push
the data to the GUI thread using a GAsyncQueue or just
some data queue and an idle callback.

Cheers,
                        -Tristan




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]