[Fwd: Re: signal_timeout vs loops (changing label text continuously)]
- From: Bob Caryl <bob fis-cal com>
- To: Gtkmm Mailing List <gtkmm-list gnome org>
- Subject: [Fwd: Re: signal_timeout vs loops (changing label text continuously)]
- Date: Tue, 27 Jun 2006 08:42:29 -0500
Oops! Forgot to "reply all."
Bob
-------- Original Message --------
Subject: Re: signal_timeout vs loops (changing label text continuously)
Date: Tue, 27 Jun 2006 08:41:31 -0500
From: Bob Caryl <bob fis-cal com>
Reply-To: bob fis-cal com
Organization: Fiscal Systems, Inc.
To: Gezim Hoxha <gezimetc shaw ca>
References: <1151388900 7752 7 camel localhost localdomain>
Anytime you create a "loop" in the GUI thread, all GUI operations
(including your call to Gtk::Label::set_text()) are suspended until your
loop finishes and the function in which it runs returns. You must allow
Gtk::Main to do its job at some point during your loop iteration by
inserting the following statements:
while(Gtk::Main::events_pending())
Gtk::Main::iteration();
After your call to Gtk::Label::set_text(). This will allow the GUI to
update. However, you should always avoid doing this sort of processing
in the GUI thread. A well written application will do such processing
in a separate thread and use a Gtk::Dispatcher to update the GUI if
needed. See Gtk::Dispatcher
<http://www.gtkmm.org/docs/glibmm-2.4/docs/reference/html/classGlib_1_1Dispatcher.html>
for more information on how to do this.
<http://www.gtkmm.org/docs/glibmm-2.4/docs/reference/html/classGlib_1_1Dispatcher.html>
Bob Caryl
Gezim Hoxha wrote:
Hi all.
Luis Federico in the "displaying text" thread asks how can he print some
text to the screen on each loop iteration.
I though I should try to help him but I found myself in trouble. I
thought that having a Label and just changing it's text with the
set_text() method would do the job. However this doesn't really work,
and I was wondering if someone could help me understand why the label
changes only after the last loop iteration completes. It seems that when
the loop is executing the window doesn't redraw itself at all. What
gives?
Thanks,
-Gezim
------------------------------------------------------------------------
#include <gtkmm.h>
#include <sstream>
#include <iostream>
#include <unistd.h>
class MyWindow: public Gtk::Window
{
public:
MyWindow ();
virtual ~MyWindow ();
void on_button1_clicked ();
void loop ();
Gtk::Label showIterLabel;
Gtk::Button button1;
Gtk::HBox boxy;
int i;
};
int main (int argc, char * argv[])
{
Gtk::Main kit (argc, argv);
MyWindow window;
kit.run (window);
return 0;
}
MyWindow::MyWindow ()
: button1("Start"),
i(0)
{
set_default_size (400, 400);
add (boxy);
showIterLabel.set_text("stopped");
boxy.pack_start (showIterLabel);
boxy.pack_start (button1);
button1.signal_clicked ().connect (sigc::mem_fun (*this, &MyWindow::loop) );
show_all_children();
}
MyWindow::~MyWindow ()
{}
void MyWindow::loop ()
{
std::ostringstream stream1;
while (i < 5)
{
stream1.str("");
stream1 << i;
std::cout << i << std::endl;
showIterLabel.set_text (stream1.str());
i++;
sleep (1);
}
}
------------------------------------------------------------------------
_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
http://mail.gnome.org/mailman/listinfo/gtkmm-list
--
/*Bob Caryl*
Fiscal Systems,Inc.
256.772.8920 Ext. 108
http://www.fis-cal.com <http://www.fis-cal.com/>/
/This email message may contain privileged or confidential information.
If you are not the intended recipient, you may not disclose, use,
disseminate, distribute, copy or rely on this message or attachment in
any way. If you received this email message in error, please return by
forwarding the message and its attachment to the sender and then delete
the message and its attachment from your computer.
Neither Fiscal Systems, Inc., nor its affiliates, accept any liability
for any errors, omissions, corruption or virus in the contents of this
message or any attachments that arise as a result of e-mail transmission./
begin:vcard
fn:Robert Caryl
n:Caryl;Robert
org:Fiscal Systems, Inc.
adr:;;102 Commerce Circle;Madison;AL;35758;USA
email;internet:bob fis-cal com
title:Senior Software Design Engineer
tel;work:356-772-8920 X108
x-mozilla-html:TRUE
url:http://www.fis-cal.com
version:2.1
end:vcard
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]