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



//main.cpp:
//-----------
// Look at this modified code and pay attention to the order of
execution and call th the functions 
#include <gtkmm.h>
#include <iostream>

using namespace std;

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

        Gtk::Window window;
        Gtk::TextView textview;
        Gtk::Label label;

  string mylabeltext = "This is the first line of text in my gui
window.\n";

        window.set_default_size(600, 360);
        window.set_title("Gtkmm Programming - C++");
        window.set_position(Gtk::WIN_POS_CENTER);

        label.show();
        window.add(label);

        label.set_text(mylabeltext);

        mylabeltext += "About to run some routines...\n";

        label.set_text(mylabeltext);

        cout << "An initial line has been set to the gui window." <<
endl;
        // The Gui Window is displayed
  //==> YOURS      Gtk::Main::run(window);
  // Now my main program has performed some functions and wants to
update
        // the console and the gui window.
    cout << "Continuing after various functions and processing..." <<
endl;
    
    //A MODIFICATION HERE '+=' instead of yours '=''
        mylabeltext += "Showing the results of the functions and
processing.";
        label.set_text(mylabeltext);
 // AND NOW        
        Gtk::Main::run(window);
        return 0;
}
//----------------------------------------------
//code end

/////////////// Makefile ///////////////////
#Begin of Makefile
all:
        
        @echo " "
        @echo " 1- Compiling..."
        g++ -Wall -g -c *.cpp `pkg-config gtkmm-3.0 --cflags`
        
        @echo " "
        @echo " 2- Linking..."
        g++ -Wall -g *.o `pkg-config gtkmm-3.0 --libs` -o
Gtkmm34-popup-menu-test
        
        @echo " "
        @echo " DONE!!!";
#       @echo " "
        chmod +x Gtkmm34-popup-menu-test
        ls . -all

clean:
        rm *.o Gtkmm34-popup-menu-test

/////////////// Makefile ///////////////////
#End of Makefile

On Tue, 2013-07-30 at 12:02 -0400, L. D. James wrote:
Can someone help to clear up the confusion of how to update a gui window
without user input.

In other words, I would like to be able to output text to either or both
the console our the gui window.

At present I can call the gui window (Window with a label for example)
and output the initial text.  However, the process doesn't return to my
c++ code until the window closes.  I'm trying to figure out how to (or
where to have my code) for updating the gui screen before the gui window
exits.

This is an example:

main.cpp:
-----------
#include <gtkmm.h>
#include <iostream>

using namespace std;

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

      Gtk::Window window;
      Gtk::TextView textview;
      Gtk::Label label;

      string mylabeltext = "This is the first line of text in my gui
window.\n";

      window.set_default_size(600, 360);
      window.set_title("Gtkmm Programming - C++");
      window.set_position(Gtk::WIN_POS_CENTER);

      label.show();
      window.add(label);

      label.set_text(mylabeltext);

      mylabeltext += "About to run some routines...\n";

      label.set_text(mylabeltext);

      cout << "An initial line has been set to the gui window." << endl;
      // The Gui Window is displayed
      Gtk::Main::run(window);
      // Now my main program has performed some functions and wants to
update
      // the console and the gui window.
      cout << "Continuing after various functions and processing..." <<
endl;
      mylabeltext = "Showing the results of the functions and processing.";
      label.set_text(mylabeltext);

      return 0;
}
----------------------------------------------
code end

The last line of text is never printed to the console until the gui is
exited.  The last line of the mylabeltext is never printed to the label
window.

What I'm trying to describe is how to keep the gtkmm window active while
I run other routines in my c++ code and update the output to both the
console and the gui window without closing the gui window to continue
the c++ routines.

All the examples that I can find uses a button in the code.  I have
tested and experimented enough that I can update the gui screen after a
button is pressed.  However, I don't want to have to rely on the user
for screen updates.  I hope to be able to run disc scans and other
functions and periodically update the screen so that the user can see
the progress and know that the program is still working and not dead.

Some of the resources that I have studied in my attempts at
understanding this include:

https://developer.gnome.org/
https://developer.gnome.org/gtkmm-tutorial/3.2/gtkmm-tutorial.html
http://en.wikipedia.org/wiki/Gtkmm

-- L. James





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