Re: How to update both the Console and the GTKMM gui window after running other functions



Thanks, Alan.  Your approach sounds very matter of fact, most likely exactly what I'm trying to do.

I do it easily with Java, Python, Visual Studio (modal dialog), Android sdk... to name a few.

Java is very easy.  The Window and Frame is up and has a buffer.  All you have to do is just append or change the buffer.  The window will always  reflect the content of the buffer you modify.

I'm sure the same may be possible with Gtkmm.  My problem is how to be in my routine while the window is displayed.  I believe you're describing something similar to just making changes to the buffer with will be reflected in the gtkmm window.

Each of your five line steps is a lesson in itself of which I'll study along with the other lessons.  I believe it should take priority over the signals I'm currently trying to understand (which I have to admit, I don't).

Thanks plenty!

I have lots of work cut out for me.

-- L. James

- -
L. D. James
ljames apollo3 com
www.apollo3.com/~ljames

On Wed, 2013-07-31 at 08:13 -0700, Alan Mazer wrote:
As I understand it, you just want a window that display the progress of a computation in ASCII readable text.

Here's how I would approach it.

1. Write a program that creates a window.  This should be trivial, something you already know how to do.
2. Derive a class from your window class and use that instead, e.g.,

class myFrame: public Gtk::Window
{
blah blah blah
}

myFrame frame;
Gtk::Main::run(frame);

3. Modify the constructor for myFrame to start a thread, something like this:

Glib::Thread *m_thread = Glib::Thread::create(sigc::mem_fun(*this, &myFrame::dataThread), true);

You'll need to add "void dataThread(void)" to your class.  Just make the thread write to stdout for now.

4. Put your computation in this new thread.

5. Put a scrolling text widget in your window.  Make sure that you know how to write to it.


Now here's where it gets tricky.

You can probably write to the text widget from your thread.  Try it.  In your thread, write stuff to the text widget.

The problem is that you may have a collision between the thread and the main part of the program, e.g., you try to move the window at the same time you're updating the thread.  For that you need to set up a dispatcher.  You should be able to do something like this:

A. Add Glib::Dispatcher m_dispatcher to your class definition.
B. Add a prototype "void dispatcherWork(void);" to your class definition.

C. You're going to link the dispatcher to this routine, so that the routine (dispatcherWork) can be called in the context of the main thread, but by the secondary thread you created.

In your constructor, add m_dispatcher.connect(sigc::mem_fun(*this, &myFrame::dispatcherWork));

D. Make the code in your compute thread that writes to the text widget write to a buffer instead.

E. Create your dispatcherWork() routine.  It should read from the buffer and write to the text widget.

F. In your thread, after you write to the buffer, call the dispatcher like this: m_dispatcher();

When you call the dispatcher, the main thread will update the widget synchronously with other window activities (like moves or repaints) that may be happening.

This is just an outline, but I think this approach is much more productive than messing with signals, since this approach lets you write asynchronously to the window, which I believe is what you want.

-- Alan


_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
https://mail.gnome.org/mailman/listinfo/gtkmm-list



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