Re: Repainting
- From: klaus triendl <klaus triendl eu>
- To: Max Lynch <max_lynch sbcglobal net>
- Cc: gtkmm-list gnome org
- Subject: Re: Repainting
- Date: Wed, 16 Apr 2008 21:27:08 +0200
Max Lynch schrieb:
*/
/*
Max Lynch schrieb:
> I have a gtkmm application that needs to handle transferring files.
> However, the way I have it right now is that the transfer operation
> takes place in a separate thread. Thus, I am having issues
getting the
> application to repaint (if it is covered or to increment the
progress
> bar). I realize I should turn to a single-threaded approach, but I
> don't know how to get back into the main loop to allow gtk to
process
> any repaint events while my transfer runs.
Do you know the Glib::Dispatcher which can be used to notify a thread?
If you put an instance somewhere in your gui-classes then other threads
can notify the gui-thread.
Thank you for the response. I am now aware of the Dispatcher, however,
all the docs talk about this GUI thread, but how can I notify it? Is
there an object I can reference or a function to call to get to this thread?
The mystic GUI thread is the one responsible for the GUI. This will
normally be the main program thread that runs the application window
calling Gtk::Main::run(window).
This means that your gtkmm GUI thread runs in the default main loop with
the default main context. This so called "main loop" checks all kinds of
events; this happens all the time, e.g. when a button is clicked or if
you connect to the idle signal then the main loop checks its idle status
and emits a signal.
If you read Glib::Dispatcher's documentation then you know that you can
attach it on creation to a main context. So, if your gtkmm GUI thread
creates a dispatcher then this dispatcher is checked by the default main
loop whether another thread notified the dispatcher.
your steps:
- You probably have a class derived from Gtk::Window. You can place a
dispatcher instance as member variable in your class.
- connect a method of your class to the dispatcher:
m_disp.connect(sigc::mem_fun(this, &myclass::on_filethread_progress))
- find a way how your file thread gets a pointer to this dispatcher
- once the file thread has access to this dispatcher it can call emit()
like on any signal and myclass::on_filethread_progress() gets called (by
the GUI thread)
--
klaus triendl
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]