Re: accessing widgets from different threads
- From: klaus triendl <klaus triendl eu>
- To: gtkmm-list gnome org
- Subject: Re: accessing widgets from different threads
- Date: Sat, 13 Dec 2008 20:54:21 +0100
Christopher Harvey schrieb:
Hi list,
I've got a gtksourceview widget (but this post isn't about the fact that
it's gtksourceview widget, it could be any widget) and I'd like to run
some regular expressions on the text in the source buffer when the user
isn't typing. I'd like the regular expressions to run in a separate
thread to keep the application responsive. So the questions is: how can
I get the text out of a widget when the user could be typing in it any
any time? I know I have to serialize access to the widget but when there
is another thread doing all of the GUI interaction I don't see how I can
tell it to not deal with a given widget at any given moment. I only need
to stop the GUI thread so I can get a copy of the current text buffer,
but I'm afraid at that moment of the copy the user may hit a key and
break something in the widget.
I can't just get a copy of the source every time the user hits a key and
changes the text because that would be too much copying. I need to wait
a second or two after the user has stopped typing then get the copy.
I would let the gui thread handle the timeout (wait 1 second to get the
user's input, see signal_timout), copy the text from the widget in the
timeout handler and send it to the regular expression thread which in
turn sends back an answer if necessary.
There is a Glib::Dispatcher which enables you to send notifications
inbetween threads. In GLib there exists something like asynchronous
queues or you could use a whole framework like sigx to handle the
interthread communication.
This is a rather generic answer for the sake of brevity, I'm afraid, but
it should give you a clue how to achieve what you want
Klaus
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]