Gtk::Main::run runs until the window is
closed. If you want to let the window open while executing code
that takes time to finish (like copying many files in an
installation), you should create a seperate thread that does those
things and updates the UI respectively.
For changing the label after some not time-intensive calculations
that should be done right after the window is shown, you would
only need to pack those into a function that you connect to
signal_show of your window. You can find other signals that are
emitted when certain events happen in the documentation.
Am 31.07.2013 13:57, schrieb L. D. James:
Thanks, Ian. And yes. I know that my code is performing outside
the gui environment. I gave the example so that the community
would understand what I was trying to do and tell me what changes
had to happen to have the code perform inside the gui environment.
I have already found examples that use the new version you
mention. I'm using that version now and still having the same
problem. This is because I don't know where to place the lines to
perform output to the gui window.
I'm baffled that there isn't anyone in the community that has
every sent new text to a gui window without the user having to
press a key. It's similar to the way Windows used to perform a
fresh install. You had to sit at the console and keep pressing
keys to continue. They finally went to a method to allow you to
answer a few questions, then you can proceed with the install and
look at the status of the update without having to sit there and
press keys.
I'm glad, that from your description that you understand the
objective and have put it in very professional and descriptive
words. Hopefully the developer will add and example to the
elaborate code snippets of the documentation.
I'm investigating the use of sigc::timeout. I find that the
button widget uses it. I'm trying to figure out how to bypass the
button and perform the button function without pressing the
button.
Thanks again for all your input and any other hints that might
come to your mind of which I should look at.
-- L. James
--
L. D. James
ljames apollo3 com
www.apollo3.com/~ljames
On Wed, 2013-07-31 at 22:37 +1200, Ian Martin wrote:
Hi,
On review, you're using Gtk::Main::run(), which is in the
process of getting deprecated, and probably shouldn't be used in
new code unless you're working with a gtkmm version <3.0 The
progress bar example in the book has the "new" version,
Glib::RefPtr<Gtk::Application> app = Gtk::Application::create(argc, argv, "org.gtkmm.example");
ExampleWindow window;
//Shows the window and returns when it is closed.
return app->run(window);
which you should probably be using instead.
Regarding the original question, your underlying issue is you're
trying to modify information in isolation from the GUI
environment, but want the GUI to respond. The gtkmm window is
created on the display with Gtk::Main::run(window) or
app->run(window); in the code you started with, that's the
last line of the main function, so any changes before that will
happen before it becomes visible.
The examples in the book all(?) contain at least 3 files: one
brief and standardised for main.cpp, and two for the
ExampleWindow cpp and h files, where all the work is done (
including any terminal output). This helps emphasise that gtkmm
code is by definition for a GUI program. If you connect a
member function to a sigc::timeout then you should see the
behaviour you want.
Ian
On 31/07/13 14:02, L. D. James wrote:
Thanks, Ian. This is a great start.
I'll spend some time trying to figure out how to output to a
text window or label rather than the graphics bar.
I knew this was possible. I'm very surprise it's so hard to
find a natural way to do it with actual text.
After I get it done, I'll post the resolution back to the
group for anyone else that is stuck.
-- L. James
--
L. D. James
ljames apollo3 com
www.apollo3.com/~ljames
On Wed, 2013-07-31 at 12:48 +1200, Ian Martin wrote:
Hi,
Have you looked at the code for the progress bar example?
https://developer.gnome.org/gtkmm-tutorial/stable/sec-progressbar.html.en
Ian.
On 31/07/13 09:33, L. D. James wrote:
> On 07/30/2013 04:53 PM, Moh B. wrote:
>> //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
>>
>
> How are you doing, Moh B.
>
> I believe you misunderstood my problem. I can output all the text out
> to the gui window without problems. However, what I'm trying to do is
> output the text after an operation has taken place. I should have put
> sleep() functions to represent some operation taking place. I want to
> give the user a status of what is taking place between operations.
>
> I updated the code to better represent this.
>
> At present I see the output at each stage on the console. However, the
> gui window isn't updated. It doesn't show anything until after all
> the functions have completed (in this case sleep() functions.
>
> In the actually program some of the functions will take a few minutes
> and some of them might take over an hour. I don't want the user to be
> left with a no status update for the entire time, or between operations.
>
> Notice how the console is output immediately. Then a sleep function.
> Then the status is updated again informing the user how long the
> function took. Then another function (in this case a sleep() function.
>
> //code begin:
> //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
> guiwindow.\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;
>
> sleep(60); // This is the estimated time for a function to run.
> Some of them takes an hour.
> mylabeltext += "Continuing after the first fundtion that took 60
> seconds\n";
> cout << "Continuing after various functions and processing..." <<
> endl;
> label.set_text(mylabeltext);
>
> sleep(60); // This represents another stage of processes and
> operations. I'm attempting to update
> // the status to the user.
> //A MODIFICATION HERE '+=' instead of yours '=''
> mylabeltext += "Other events are taking place that has taken
> another 60 seconds\n";
> cout << "Other events have taken place" << endl;
> label.set_text(mylabeltext);
> // AND NOW
> Gtk::Main::run(window);
> return 0;
> }
> //----------------------------------------------
> //code end
>
> -- L. James
>
_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
https://mail.gnome.org/mailman/listinfo/gtkmm-list
_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
https://mail.gnome.org/mailman/listinfo/gtkmm-list
_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
https://mail.gnome.org/mailman/listinfo/gtkmm-list
_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
https://mail.gnome.org/mailman/listinfo/gtkmm-list
|