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



On 08/15/2013 08:30 AM, Markus Elfring wrote:
You are telling me to do it a different way and at the same time telling me
how complicated it is.  Without examples of the different way, I don't know
where to start.
I guess that you want to become familiar with a general program structure
together with the GTK+ software. I assume that you want to display some text in
a log window for your use case. Would you like to reuse a list box or table
control? (Do you need any other higher sophisticated widget?)

How fast do you get the needed data for the desired output?

Regards,
Markus
Hi, Markus.

Thanks for the interest and your questions.  I appreciate any feedback.

You're right about my desire to log text in a gui window. I don't want a list box or control widgets in this particular case. As far as sophisticate widgets, I don't want any widgets at all.

I wouldn't mind an exit or close button, but at present the close button in the gui window (along with the minimize button) suits my immediate needs perfectly.

I had already got a developed a working example with the help of Alan:

Gui Update using the Label Widget:
https://mail.gnome.org/archives/gtkmm-list/2013-August/msg00052.html

It worked perfectly as desired... having only one widget, the label.

However, I decided to change the label widget to the textview widget. When I tried to change it, the code was broken at first, because I didn't fully understand what needed to be changed.

So, with this thread, I asked for the minimum amount of lines to do the same thing, so that I could study the lines and use it as a blank slate to build upon.

I eventually started to understand it, with the aid of the input from Kjell and change the widget from label to textview.

Now with the 47 lines of code I'm easily able to update a gui window. Wile, Chris has insisted there is a problem with the code, I can't identify a problem. As far as I can see it is exactly consistent with the HelloWorld tutorial that uses a Button widget. I changed the branch that happens with a button click to go directly to the function. I basically renamed the function from "void on_button_clicked()" to "void cpp_app()".

It's only 47 lines and should be very easy to check. I can't identify a problem with it. It does perfectly what I was trying to do.

With it having such a few lines I'm able to study each line in detail and easily repeat the code.

I'll eventually start to add other "sophisticated widgets" for other applications. This is easier to do now since I have what I believe is the minimum amount of lines to update text to a gui window.

If there's something wrong with my example, I appreciate any comments or suggestions. But if someone says it wrong and use programming terms that I don't fully understand, it's not much I can do with it as far as change and actually have it continue to perform the desired task (update the gui window after running a function).

The current cleaned up code is:
(By the way my programming environment is Ubuntu 13.04/Gtkmm3.0 from the repository)

// Code begin: HelloWorld.cpp
// --------------------------------------------------------
#include "HelloWorld.h"
#include <string>

using namespace std;

HelloWorld::HelloWorld() : m_textview() {

    add(m_textview);
    m_textview.show();
    Glib::Thread::create(sigc::mem_fun(*this, &HelloWorld::cpp_app), true);
}

HelloWorld::~HelloWorld() {
}

void HelloWorld::cpp_app() {
    string texttoprint = "";
    Glib::RefPtr<Gtk::TextBuffer> m_refTextBuffer;
    m_refTextBuffer = Gtk::TextBuffer::create();
    string runit(std::string c);

    texttoprint +=
"About to run a number of c++ functions\nand display the results\n";
    m_refTextBuffer->set_text(texttoprint);
    m_textview.set_buffer(m_refTextBuffer);

sleep(10); // This sleep function represents any c++ function performaing a task

    // This represents the resulting text from the function just run
    texttoprint += "Back from running a short 10 second function";
    m_refTextBuffer->set_text(texttoprint);
    m_textview.set_buffer(m_refTextBuffer);

sleep(60); // This is an example of a function that is responding with text

texttoprint += "Just got back from a function that took a minute to execute.\n";
    m_refTextBuffer->set_text(texttoprint);
    m_textview.set_buffer(m_refTextBuffer);
}
// --------------------------------------------------------
// Code end
// Code begin: HelloWorld.h
// --------------------------------------------------------
#ifndef GTKMM_EXAMPLE_HELLOWORLD_H
#define GTKMM_EXAMPLE_HELLOWORLD_H

// #include <gtkmm/button.h>
// #include <gtkmm/window.h>
#include <gtkmm.h>

class HelloWorld: public Gtk::Window {

public:
    HelloWorld();
    virtual ~HelloWorld();

protected:
    //Signal handlers:
    // // void on_button_clicked();

    //Member widgets:
    Gtk::TextView m_textview;
    void cpp_app();
};

#endif // GTKMM_EXAMPLE_HELLOWORLD_H
// --------------------------------------------------------
// Code End
// Code begin: main.cpp
// --------------------------------------------------------
#include "HelloWorld.h"
#include <gtkmm/application.h>

int main (int argc, char* argv[]){
Glib::RefPtr<Gtk::Application> app = Gtk::Application::create(argc, argv, "org.gtkmm.example");

 HelloWorld helloworld;

  //Shows the window and returns when it is closed.
  return app->run(helloworld);
}
// --------------------------------------------------------
// Code End


-- L. James

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


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