Re: What is the minimum number of lines to update a gui window without user clicking a button



2013-08-11 02:30, L. D. James skrev:
Thanks, Chris.  I may end up using Glib::spawn_async (but I it doesn't appear to be a call for updating text to a gui window) and I may end up using Glib::signal_io().connect()) to send text to the gui window.  This is the first time i see these as ways of updating the gui.

Keep in mind that what I'm trying to do is develop a reusable function that I have named, "gprint()".  I'm sure I'm just about close enough to post a prototype by tomorrow.

Thanks again for all your contributions, and patient for my newness with using a gtkmm widgets.

My only problem with Kjell's example if being able to remove the unwanted ones.  My problem with Alan's solution (which worked perfect) was changing it from label to textview (because of some gaps I was having at the time).

I finally got it figured out how to change the widget from label to text view, now I'm trying to implement the gprint() function.  I have it in place, but it's not clean enough to post it for comments yet.

-- L. James

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

You seem convinced that the shorter a program is, the easier it is to understand it. I'm not so sure.

I get the impression that you don't understand how a GUI system works, Much work is going on behind the scene.
An example: When you call m_TextView.get_buffer()->set_text("Hello world!"), the text is stored somewhere, the TextView is invalidated (marked that it shall be redrawn), but the text is not written to the screen. That's done later, after your function has returned.
If your window is later hidden because another window is moved on top of it, and your window is then still later made visible again, the TextView is once again redrawn without your function being called. It your function contains a long calculation, taking minutes or hours, your window is not redrawn. The best way to avoid that is, like several people have mentioned, to create a separate thread of execution for the long calculation.

You are trying to learn two interesting but rather difficult techniques, GUI programming and multi-threading, at the same time and mixed up. Well, GUI programming is not always difficult. It becomes more difficult when your application also needs multi-threading.

I wish I could point out some good web sites for you to start with. I'm sure there are some, but I don't know where. There is of course the gtkmm tutorial, https://developer.gnome.org/gtkmm-tutorial/stable/, but it does not explain what's going on behind the scene in a GUI system. I once learnt that by reading "Programming Windows" by Charles Petzold. It's an excellent introduction to MS Windows programming in C, but it's not the book to read when you want to learn gtkmm.

The description of glib's main event loop, https://developer.gnome.org/glib/stable/glib-The-Main-Event-Loop.html, is definitely not written for beginners.

Since you dislike buttons, can't you remove all buttons and the button box from my example program? Remove all code that has anything to do with the buttons except

    // Start a new worker thread.
    m_WorkerThread = Glib::Threads::Thread::create(
      sigc::bind(sigc::mem_fun(m_Worker, &ExampleWorker::do_work), this));

which you move to ExampleWindow's constructor. And you can change the loop in ExampleWorker::do_work() to make it run forever, if you like.

Kjell



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