Programming GTK GUIs by gtkIOStream: 2 vboxes and 2 hboxes?


9 posts
by 1dot0 » Fri May 19, 2017 10:55 am
Programming GTK GUIs by gtkIOStream: trying to add 2 vboxes and 2 hboxes I get an error, that would not be possible (?)
(gtkVBoxHBoxBtn001:8899): Gtk-WARNING **:
Attempting to add a widget with type GtkHBox to a GtkWindow,
but as a GtkBin subclass a GtkWindow can only contain one widget at a time;
it already contains a widget of type GtkHBox


what I want to do is to extend the example of lesson 4 https://www.raspberrypi.org/forums/view ... 7&t=173446
Image
by an additional quit button at the bottom:

Code: Select all
_____________________
string 1    string 4 |
                     |
                     |
string 2             |
            string 5 |
                     |
string 3             |
                     |
---------------------|
        quit         |
---------------------|
_____________________|



But I always fail, no idea what I am missing or doing wrong - can some one help me please?
This is my attempt:

Code: Select all
// gtkVBoxHBox_L4.c

#include <gtkInterface.H>
#include <Labels.H>
#include <Box.H>



// Quit button callback
static void quit(void *wid, gpointer data) {
    gtk_main_quit();
}




int main(int argc, char *argv[]){

  gtk_init( &argc, &argv ); // init GTK                                         

  GtkInterface topWindow; // Create the top box                                 

  Labels labs1, labs2; // Instantiate the Labels class 
                           
  // iostream:
  labs1 << "Hello world !"<<"You are programming me"<<"thank you";
  labs2 << "I feel"<<"alive!";

  VBox vBox1, vBox2; // Instantiate the two vertical packing box variables       
  vBox1 << Box::EXPAND << Box::FILL<<labs1;   // Load the labels into the box                                   
  vBox2 << Box::EXPAND << Box::FILL<<labs2;   // Load the labels into the second box                         

  HBox hBox1, hBox2; // Instantiate the vertical packing box class                     
  hBox1<< Box::EXPAND << Box::FILL<<vBox1.show()<<vBox2.show(); // Load the labels into the box 
 
  Buttons buttons;   // Instantiate the Buttons class and variable
  buttons << LabelFuncData("Quit", quit, NULL); // Create a string button
   
  hBox2 << buttons;             


  topWindow << hBox1.show() << hBox2.show() ; // Show the box and load the box into the GtkInterface 
                                                                           

  gtk_main(); // run GTK+                                                       
}

Posts: 261
Joined: Mon Nov 28, 2016 12:31 pm
by PeterO » Fri May 19, 2017 12:08 pm
Why aren't you looking these sorts of things up on the GTK web site ? All the information is there.
https://developer.gnome.org/gtk3/stable/GtkBin.html
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),Aeromodelling,1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson
User avatar
Posts: 3290
Joined: Sun Jul 22, 2012 4:14 pm
by 1dot0 » Fri May 19, 2017 1:22 pm
my question is just about gtkIOstream, not the entire gtk thing.

Programming GTK GUIs by gtkIOStream: trying to add 2 vboxes and 2 hboxes I get an error, that would not be possible (?)
Posts: 261
Joined: Mon Nov 28, 2016 12:31 pm
by PeterO » Fri May 19, 2017 1:28 pm
1dot0 wrote:my question is just about gtkIOstream, not the entire gtk thing.


How do you expect to use gtkIOStream without understanding GTK+ ?

(gtkVBoxHBoxBtn001:8899): Gtk-WARNING **:
Attempting to add a widget with type GtkHBox to a GtkWindow,
but as a GtkBin subclass a GtkWindow can only contain one widget at a time;
it already contains a widget of type GtkHBox

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),Aeromodelling,1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson
User avatar
Posts: 3290
Joined: Sun Jul 22, 2012 4:14 pm
by 1dot0 » Fri May 19, 2017 1:32 pm
PeterO wrote:
1dot0 wrote:my question is just about gtkIOstream, not the entire gtk thing.


How do you expect to use gtkIOStream without understanding GTK+ ?

(gtkVBoxHBoxBtn001:8899): Gtk-WARNING **:
Attempting to add a widget with type GtkHBox to a GtkWindow,
but as a GtkBin subclass a GtkWindow can only contain one widget at a time;
it already contains a widget of type GtkHBox

PeterO


I expect to use it by the simple iostream approach and supported by good, valuable, and helpful tutorials and support
- so far as I have already been starting with Matt's tutorials 0-6 :roll:
Posts: 261
Joined: Mon Nov 28, 2016 12:31 pm
by PeterO » Fri May 19, 2017 1:33 pm
1dot0 wrote:
PeterO wrote:
1dot0 wrote:my question is just about gtkIOstream, not the entire gtk thing.


How do you expect to use gtkIOStream without understanding GTK+ ?

(gtkVBoxHBoxBtn001:8899): Gtk-WARNING **:
Attempting to add a widget with type GtkHBox to a GtkWindow,
but as a GtkBin subclass a GtkWindow can only contain one widget at a time;
it already contains a widget of type GtkHBox

PeterO


I expect to use it by the simple iostream approach and supported by good, valuable, and helpful tutorials and support
- so far as I have already been starting with Matt's tutorials 0-6 :roll:


You will fail !

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),Aeromodelling,1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson
User avatar
Posts: 3290
Joined: Sun Jul 22, 2012 4:14 pm
by 1dot0 » Fri May 19, 2017 1:40 pm
PeterO, your posts are anything but helpful.
I actually prefer to wait for a really helpful answer to my TOP question.

But if my goal cannot be achived then indeed I will have to drop gtkIOstream and the entire gtk as well.

1dot0 wrote:Programming GTK GUIs by gtkIOStream: trying to add 2 vboxes and 2 hboxes I get an error, that would not be possible (?)
(gtkVBoxHBoxBtn001:8899): Gtk-WARNING **:
Attempting to add a widget with type GtkHBox to a GtkWindow,
but as a GtkBin subclass a GtkWindow can only contain one widget at a time;
it already contains a widget of type GtkHBox


what I want to do is to extend the example of lesson 4 https://www.raspberrypi.org/forums/view ... 7&t=173446
Image
by an additional quit button at the bottom:

Code: Select all
_____________________
string 1    string 4 |
                     |
                     |
string 2             |
            string 5 |
                     |
string 3             |
                     |
---------------------|
        quit         |
---------------------|
_____________________|



But I always fail, no idea what I am missing or doing wrong - can some one help me please?
This is my attempt:

Code: Select all
// gtkVBoxHBox_L4.c

#include <gtkInterface.H>
#include <Labels.H>
#include <Box.H>



// Quit button callback
static void quit(void *wid, gpointer data) {
    gtk_main_quit();
}




int main(int argc, char *argv[]){

  gtk_init( &argc, &argv ); // init GTK                                         

  GtkInterface topWindow; // Create the top box                                 

  Labels labs1, labs2; // Instantiate the Labels class 
                           
  // iostream:
  labs1 << "Hello world !"<<"You are programming me"<<"thank you";
  labs2 << "I feel"<<"alive!";

  VBox vBox1, vBox2; // Instantiate the two vertical packing box variables       
  vBox1 << Box::EXPAND << Box::FILL<<labs1;   // Load the labels into the box                                   
  vBox2 << Box::EXPAND << Box::FILL<<labs2;   // Load the labels into the second box                         

  HBox hBox1, hBox2; // Instantiate the vertical packing box class                     
  hBox1<< Box::EXPAND << Box::FILL<<vBox1.show()<<vBox2.show(); // Load the labels into the box 
 
  Buttons buttons;   // Instantiate the Buttons class and variable
  buttons << LabelFuncData("Quit", quit, NULL); // Create a string button
   
  hBox2 << buttons;             


  topWindow << hBox1.show() << hBox2.show() ; // Show the box and load the box into the GtkInterface 
                                                                           

  gtk_main(); // run GTK+                                                       
}

Posts: 261
Joined: Mon Nov 28, 2016 12:31 pm
by 1dot0 » Mon May 22, 2017 8:09 am
ok, I give up and abandon that whole gtk thing - the original gtk is too monstrous and for gtkIOstream (which might have been more handy) the support is unfortunately too poor.
Posts: 261
Joined: Mon Nov 28, 2016 12:31 pm
by Paeryn » Mon May 22, 2017 10:45 am
1dot0 wrote:ok, I give up and abandon that whole gtk thing - the original gtk is too monstrous and for gtkIOstream (which might have been more handy) the support is unfortunately too poor.

GTK+ isn't monstrous, it's quite easy when you take time to understand it. The warning that GTK+ was giving you practically told you the answer. It said that a window can only contain one widget and you were trying to add a second. The link that petero gave a bit more information and reading the GTK+ docs further would help you understand how GTK+ works the way it does. The solution around the one widget rule is used in the example code you were following anyway - you create a box which you put the other widgets in and just add that one box to the window.

It might seem odd to you that you can't add two widgets to a window but it makes sense, how would you expect the window to layout more than one widget? It has no way of knowing how you intend them to be placed in relation to each other, but a Box widget (and any of the other collection widgets) does know how to arrange multiple widgets inside it.
She who travels light — forgot something.
User avatar
Posts: 1381
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England