GTK: Closing child widget when main widget is closed? - Linux

This is a discussion on GTK: Closing child widget when main widget is closed? - Linux ; Hello, I have two buttons with the following signals (in the main window): buttonInput.signal_clicked().connect(sigc::mem_fun (*this, &GUIMenu: nInputClick) ); buttonClose.signal_clicked().connect(sigc::mem_fun (*this, &GUIMenu: nExitClick) ); methods: void GUIMenu: nExitClick() { hide_all(); } void GUIMenu: nInputClick() { Gtk::Main kit(int argc, char **argv); Gtk::Main::run(window); ...

+ Reply to Thread
Results 1 to 8 of 8

Thread: GTK: Closing child widget when main widget is closed?

  1. GTK: Closing child widget when main widget is closed?

    Hello,

    I have two buttons with the following signals (in the main window):

    buttonInput.signal_clicked().connect(sigc::mem_fun (*this,
    &GUIMenu:nInputClick) );
    buttonClose.signal_clicked().connect(sigc::mem_fun (*this,
    &GUIMenu:nExitClick) );


    methods:
    void GUIMenu:nExitClick() {
    hide_all();
    }

    void GUIMenu:nInputClick() {
    Gtk::Main kit(int argc, char **argv);
    Gtk::Main::run(window);
    }


    ....for this example: "window" is just a simple window declared in the
    main window with "Gtk::Window window".


    My problem is that closing the main program won't close the child
    window. When I try something like window.hide(), the program still seems
    to be executed in the console but I don't see any window anymore.
    I guess this behaviour appears because of this new main loop in the
    second method.
    Do I open the child window in the right way and how can I close every
    child when I close the main window?

    Markus

  2. Re: GTK: Closing child widget when main widget is closed?

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.6 (GNU/Linux)

    iD8DBQFGiWTiVcFcaSW/uEgRAnMaAJwOB0Bj8onkkKJ+q+urdW4sA/nnnACg6CYS
    nv1q88cJeAdwn73A38LoufU=
    =bgnN
    -----END PGP SIGNATURE-----

  3. Re: GTK: Closing child widget when main widget is closed?

    Hello,

    Roger Leigh wrote:
    > Why are you starting a new mainloop in order to display a new window?
    > You should have one mainloop only in the entire application. Simply
    > creating (if needed) and showing the child window in the signal
    > handler should suffice.


    Yes, I don't like those two main loops too, but how can I start a new
    windows from another one with just one main loop?
    Unfortunately I didn't find any solution yet.

    Markus

  4. Re: GTK: Closing child widget when main widget is closed?

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.6 (GNU/Linux)

    iD8DBQFGiqQyVcFcaSW/uEgRAsPLAKCI5yNngk1a/QFnIzB0a2dVX1sk/QCbBBJ/
    8v/o/GxHOHmyXAZKcKbz2e4=
    =1nc1
    -----END PGP SIGNATURE-----

  5. Re: GTK: Closing child widget when main widget is closed?

    Roger Leigh wrote:
    > If it's derived from Gtk:ialog, use Gtk:ialog::run (gtk_dialog_run
    > in C).


    Actually it isn't. It's a complex window with a table layout inside.
    Isn't there a better way than overriding Gtk:ialog, if this is possible?

  6. Re: GTK: Closing child widget when main widget is closed?

    Ok, now I was able to manage it.
    I copied the important stuff from my previous class to this method:


    void GUIMenu:nInputClick() {
    Gtk::Table table;
    int knotenAnzahl = spinbutton.get_value_as_int();
    for(int i = 0; i < knotenAnzahl; i++) {
    for(int j = 0; j < knotenAnzahl; j++) {
    Gtk::Button* pButton = Gtk::manage(new Gtk::Button(" 0 "));
    table.attach(*pButton, j, j+1, i, i+1);

    pButton->signal_clicked().connect(sigc::bind
    (sigc::mem_fun(*this, &GUIMenu:nMatrixClick), j, i));
    }
    }
    Gtk:ialog matrixWindow;
    matrixWindow.get_action_area()->pack_start(table);
    matrixWindow.show_all_children();
    matrixWindow.run();
    }

    void GUIMenu:nMatrixClick(int j, int i) {
    //some code
    }


    By the way. I have also problems to set the label of these dynamically
    created buttons. My target is it to change the button label from "0" to
    a "1" if the button is pressed, but how can I access these buttons in an
    intelligent way.
    I already posted this problem in the c++ newsgroup but I still wasn't
    able to find a suitable solution.




    Markus


  7. Re: GTK: Closing child widget when main widget is closed?

    I saw that the dialog box effects a very annoying situation.
    I can't leave the modal state, but I need to use the main window as well.
    I tried different methods where I thought they would help, but they had
    no effect.
    What is going on here?

    //this method is invoked by the main window....
    void GUIMenu:nInputClick() {
    Gtk::Table table;
    createTable(table);
    Gtk:ialog matrixWindow("Adjazenzmatrix", false, false); //title,
    modal, seperator
    matrixWindow.get_action_area()->pack_start(table);
    matrixWindow.set_resizable(false);
    matrixWindow.set_keep_below(true);
    matrixWindow.set_modal(false);
    matrixWindow.show_all();
    matrixWindow.run();
    }

    void GUIMenu:nMatrixClick(int j, int i) {
    //some code
    }

    void GUIMenu::createTable(Gtk::Table &tab) {

    int knotenAnzahl = spinbutton.get_value_as_int();
    for(int i = 0; i < knotenAnzahl; i++) {
    for(int j = 0; j < knotenAnzahl; j++) {
    Gtk::Button* pButton = Gtk::manage(new Gtk::Button(" 0 "));
    tab.attach(*pButton, j, j+1, i, i+1);

    pButton->signal_clicked().connect(sigc::bind
    (sigc::mem_fun(*this, &GUIMenu:nMatrixClick), j, i));
    }
    }
    }



  8. Re: GTK: Closing child widget when main widget is closed?

    Ok, I read that dialog.run will cause the window to keep the modal state
    as long as the "response" signal is not sended and emitting the response
    signal at any time would not be a good idea. The post-run code would not
    know if ther window is closed or not when the window will be quit while
    the run method.
    I think the Dialog was no good idea.

+ Reply to Thread