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



I haven't forgotten your end goal. You need threading to get there if you want the GUI to be responsive while the long computations are taking place. I sent you a little sample code already but I can show you how it fits together on Monday. There's not much left to be done.

Sent from my Android phone using TouchDown (www.nitrodesk.com)

-----Original Message-----
From: L. D. James [ljames apollo3 com]
Received: Friday, 02 Aug 2013, 5:45pm
To: Mazer, Alan S (389M) [Alan S Mazer jpl nasa gov]
CC: gtkmm-list gnome org [gtkmm-list gnome org]
Subject: Re: How to update both the Console and the GTKMM gui window after running other functions

Thanks.

I forgot to remind you of important details.  For one I forget to mention that the “sleep(10)” function represented a function that is processing such as searching all the network drives for a string and doing other chores that might take up to three hours or more.

Then when it gets back it's supposed to update the gui screen and console.

I thought I had tested run(mylabel) and had problems.  I should have left the line there commented out.  But I'm glad to see that your update prints.  However, it prints all the text at once.  It doesn't print anything after a function.

I uncommented the sleep(10) function.  There is no window until the function ends.  Then everything is printed.

So if the user ran the program he would have no idea what is happening until three hours later.  He might try to run the application numerous times to get something on the screen and really cause problems.

My objective is to immediately print something on the gui.  Then run functions.  The print and update to the gui, the same way you see the console output updated.

And yes.  I appreciate anything I can learn about those terms (threading, etc), especially if this is what is going to be needed to update what is on the gui.

I'm adding what might be a clearer description of what I'm trying to do to your new code that prints.

Most likely the threading is where the sleep() and myprocess1() functions should be.

// code begin
// -------------------------------------------
#include <gtkmm.h>
#include <iostream>

using namespace std;

class myLabel: public Gtk::Window
{
// blah blah blah
public:
myLabel();
   virtual ~myLabel();

protected:
Gtk::Label m_label;
string labeltext;
string newtext;
};

myLabel::myLabel() : m_label("Hello World")
{
// myLabel.set_text("hello"); // This line gives errors (*1)
void myprocess1();

set_title("Gtkmm Programming - C++");
add(m_label);

m_label.show();
labeltext = "About to preform a number of processes.\n";
labeltext += "Each process may take up to three hours.\n";
labeltext += "Please carry your daily chores and wait.\n";
cout << labeltext << endl;
m_label.set_text(labeltext);

sleep(10); // Back from a three hour function
newtext = "Back from a three hour function\n";
labeltext += newtext;
m_label.set_text(labeltext);
cout << newtext << endl;

myprocess1();

cout << "Window should be displayed" << endl;
}
myLabel::~myLabel()
{
}
void myprocess1()
{
cout << "Running another process that is generating output..." << endl;
}

int main(int argc, char* argv[])
{
     Gtk::Main kit(argc, argv);

     myLabel mylabel;
     Gtk::Main::run(mylabel);
     return 0;
}
// -------------------------------------------
// code end

-- L. James

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


On Fri, 2013-08-02 at 15:05 -0700, Alan Mazer wrote:
This is tricky to explain, but, in a nutshell, myLabel, because it's 
derived from Gtk::Window, is itself a window you can pass to "run". You 
don't want to create a separate Gtk::Window object as you're doing, 
because "run" can't see it.  I've removed the "Gtk::Window window;" 
line, and changed "window.set_title" to just "set_title", and 
"window.add" to just "add".  With these changes, there's text in your 
window.  I'll include the code below so you can see what I did.  (I also 
needed to change back to the "kit" approach in "main" which you had 
originally, because I don't have gtkmm 3 on my computer, but you can 
keep your "main" routine using the newer approach if you prefer.)

Do you want me to show you threading or would you prefer to explore that 
on your own?

-- Alan

#include <gtkmm.h>
#include <iostream>

using namespace std;

class myLabel: public Gtk::Window
{
// blah blah blah
public:
myLabel();
   virtual ~myLabel();

protected:
Gtk::Label m_label;
string labeltext;
string newtext;
};

myLabel::myLabel() : m_label("Hello World")
{
// myLabel.set_text("hello"); // This line gives errors (*1)
void myprocess1();

set_title("Gtkmm Programming - C++");
add(m_label);

m_label.show();
labeltext = "About to preform a number of processes.\n";
labeltext += "Each process may take up to three hours.\n";
labeltext += "Please carry your daily chores and wait.\n";
cout << labeltext << endl;
m_label.set_text(labeltext);

// sleep(10); // Back from a three hour function
newtext = "Back from a three hour function\n";
labeltext += newtext;
cout << newtext << endl;

myprocess1();

cout << "Window should be displayed" << endl;
}
myLabel::~myLabel()
{
}
void myprocess1()
{
cout << "Running another process that is generating output..." << endl;
}

int main(int argc, char* argv[])
{
     Gtk::Main kit(argc, argv);

     myLabel mylabel;
     Gtk::Main::run(mylabel);
     return 0;
}




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