1dot0
Posts: 360
Joined: Mon Nov 28, 2016 12:31 pm

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

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 viewtopic.php?f=67&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+                                                       
}


User avatar
PeterO
Posts: 3589
Joined: Sun Jul 22, 2012 4:14 pm

Re: Programming GTK GUIs by gtkIOStream: 2 vboxes and 2 hbox

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

1dot0
Posts: 360
Joined: Mon Nov 28, 2016 12:31 pm

Re: Programming GTK GUIs by gtkIOStream: 2 vboxes and 2 hbox

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 (?)

User avatar
PeterO
Posts: 3589
Joined: Sun Jul 22, 2012 4:14 pm

Re: Programming GTK GUIs by gtkIOStream: 2 vboxes and 2 hbox

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

1dot0
Posts: 360
Joined: Mon Nov 28, 2016 12:31 pm

Re: Programming GTK GUIs by gtkIOStream: 2 vboxes and 2 hbox

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:

User avatar
PeterO
Posts: 3589
Joined: Sun Jul 22, 2012 4:14 pm

Re: Programming GTK GUIs by gtkIOStream: 2 vboxes and 2 hbox

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

1dot0
Posts: 360
Joined: Mon Nov 28, 2016 12:31 pm

Re: Programming GTK GUIs by gtkIOStream: 2 vboxes and 2 hbox

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 viewtopic.php?f=67&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+                                                       
}


1dot0
Posts: 360
Joined: Mon Nov 28, 2016 12:31 pm

Re: Programming GTK GUIs by gtkIOStream: 2 vboxes and 2 hbox

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.

User avatar
Paeryn
Posts: 1574
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: Programming GTK GUIs by gtkIOStream: 2 vboxes and 2 hbox

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.

1dot0
Posts: 360
Joined: Mon Nov 28, 2016 12:31 pm

Re: Programming GTK GUIs by gtkIOStream: 2 vboxes and 2 hbox

Mon May 22, 2017 3:37 pm

hmm - so how to have 2 vertical boxes with a different number of labels at the top, side to side one another in a horizontal box,
and then have another box beneath for the buttons?
If you mentioned a way eventually above, then I surely didn't understand it.

Actually the most crucial point is that I do not understand C++, and I never will: tbh, I hate OOP.
So all and everything about gtk will remain closed to me as it's all based on C++.
Additionally, also my skills about pointer juggling is very, let's say, basic.
But if there were easy wrappers in C++ libs like for Arduino (or, perhaps, by gtkiostream) then perhaps it would be feasable, just using them ANSI-C-like.
Admittedly then only if there also was a reasonable support afterwards though -
Finally the next crucial problems and issues are already pending... :-/

User avatar
PeterO
Posts: 3589
Joined: Sun Jul 22, 2012 4:14 pm

Re: Programming GTK GUIs by gtkIOStream: 2 vboxes and 2 hbox

Mon May 22, 2017 4:10 pm

1dot0 wrote:So all and everything about gtk will remain closed to me as it's all based on C++.
If you had actually done any reading you would not have been labouring under that misconception from the start !

https://www.gtk.org/
"What languages are supported?
GTK+ is written in C but has been designed from the ground up to support a wide range of languages, not only C/C++."

Several times I pointed you at GTK+ documentation which is all written for the C (not C++) API.

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

1dot0
Posts: 360
Joined: Mon Nov 28, 2016 12:31 pm

Re: Programming GTK GUIs by gtkIOStream: 2 vboxes and 2 hbox

Mon May 22, 2017 4:14 pm

yes, good point about C, but without easy wrappers it's still a monster, and only gtkiostream provided easy wrappers so far (CMIIW), nonetheless by C++, and the support about that is, let's say, rather, hmm, improvable.

it's like about the Linux monster libs for GPIOs: they are monsters, too, but feasable thanks to wiringPi, and no need then anymore to read into those original monster source codes.

User avatar
PeterO
Posts: 3589
Joined: Sun Jul 22, 2012 4:14 pm

Re: Programming GTK GUIs by gtkIOStream: 2 vboxes and 2 hbox

Mon May 22, 2017 4:20 pm

1dot0 wrote:yes, good point about C, but without easy wrappers it's still a monster
No it's not. It's like any large library, you just use the bits you need and ignore the rest.

Glade and GtkBuilder provide a much easier way to design and realise your GUIs than gtkIOstream.

There are many tutorials on using Gtk+ and Glade, here's one that Google found : http://prognotes.net/2016/03/gtk-3-c-co ... g-glade-3/

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

1dot0
Posts: 360
Joined: Mon Nov 28, 2016 12:31 pm

Re: Programming GTK GUIs by gtkIOStream: 2 vboxes and 2 hbox

Mon May 22, 2017 4:25 pm

excellent link, thank you, admittedly it looks very promising at first sight.
I'll immediately look into that and see if it will be feasable to me, as a noob. :)

1dot0
Posts: 360
Joined: Mon Nov 28, 2016 12:31 pm

Re: Programming GTK GUIs by gtkIOStream: 2 vboxes and 2 hbox

Mon May 22, 2017 4:28 pm

ps,
first question:
as I now have installed gtk 1.5 or 2 (not sure which one):
which are the detailed (!) steps (possibly ba a script) to upgrade to gtk 3 ?

User avatar
PeterO
Posts: 3589
Joined: Sun Jul 22, 2012 4:14 pm

Re: Programming GTK GUIs by gtkIOStream: 2 vboxes and 2 hbox

Mon May 22, 2017 4:32 pm

1dot0 wrote:ps,
first question:
as I now have installed gtk 1.5 or 2 (not sure which one):
which are the detailed (!) steps (possibly ba a script) to upgrade to gtk 3 ?
Follow the instructions linked form that tutorial page : http://prognotes.net/2015/12/installing ... -in-linux/

Don't worry if it wants to install/update a lot of packages when you do that, once it's done you're all set to go....
and install glade as well.

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

1dot0
Posts: 360
Joined: Mon Nov 28, 2016 12:31 pm

Re: Programming GTK GUIs by gtkIOStream: 2 vboxes and 2 hbox

Mon May 22, 2017 4:42 pm

ah, cross post, I got it, thank you!

User avatar
PeterO
Posts: 3589
Joined: Sun Jul 22, 2012 4:14 pm

Re: Programming GTK GUIs by gtkIOStream: 2 vboxes and 2 hbox

Mon May 22, 2017 4:44 pm

1dot0 wrote: as my English is a little poor, what do you mean by "...and install glade as well":
do you mean that glade is also then automatically installed by the procedure

sudo apt-get install glade
or must it be installed additionally afterwards, additionally?
I mean just follow the instructions on that page for installing glade and Gtk3+ development packages. That's all you need.
If you use pkg-config to construct the compiler commands then Gtk3 will be used and any Gtk2 includes and libraries will be ignored.

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
PeterO
Posts: 3589
Joined: Sun Jul 22, 2012 4:14 pm

Re: Programming GTK GUIs by gtkIOStream: 2 vboxes and 2 hbox

Mon May 22, 2017 4:45 pm

We're somewhat "off topic" for this thread now, so I suggest you start a new thread with any Gtk+3 and Glade problems you have.

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
Paeryn
Posts: 1574
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: Programming GTK GUIs by gtkIOStream: 2 vboxes and 2 hbox

Mon May 22, 2017 4:54 pm

1dot0 wrote:hmm - so how to have 2 vertical boxes with a different number of labels at the top, side to side one another in a horizontal box,
and then have another box beneath for the buttons?
If you mentioned a way eventually above, then I surely didn't understand it.
The example code already had 2 VBox's in a HBox. If you want a button underneath that then create another VBox with that HBox at the top and the Button at the bottom. If you've got multiple buttons there are button boxes for grouping buttons, HBBox and VBBox. You can put your buttons in one of those and add that to the VBox.

Code: Select all

  HBox hBox1; // 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

  HBBox hButtonBox;
  hButtonBox << buttons;

  // Another VBox to hold the HBox and Button.
  // Use NOEXPAND before adding the button box so that the button box doesn't
  // take up more vertical space than needed.
  VBox vBox3;
  vBox3 << Box::EXPAND << Box::FILL << hBox1.show() << Box::NOEXPAND << hButtonBox.show();

  topWindow << vBox3.show() ; // Show the box and load the box into the GtkInterface
1dot0 wrote:Actually the most crucial point is that I do not understand C++, and I never will: I hate OOP.
If you don't understand C++ and have no intention of learning it then why are you writing your program in C++? You may get away with it for a while but you'll likely fall foul of the differences eventually.
1dot0 wrote:So all and everything about gtk will remain closed to me as it's all based on C++.
??? GTK+ is a C library, not C++. The official C++ binding is gtkmm.
1dot0 wrote:Additionally, also my skills about pointer juggling is very, let's say, basic.
But if there were easy wrappers in C++ libs like for Arduino (or, perhaps, by gtkiostream) then perhaps it would be feasable, just using them ANSI-C-like.
Admittedly then only if there also was a reasonable support afterwards though -
Finally the next crucial problems and issues are already pending... :-/
C != C++ especially when you are using things like iostreams, they aren't even remotely C.
GTK+ has been around for 20 years, there's tonnes of documentation and example code out there.
She who travels light — forgot something.

1dot0
Posts: 360
Joined: Mon Nov 28, 2016 12:31 pm

Re: Programming GTK GUIs by gtkIOStream: 2 vboxes and 2 hbox

Mon May 22, 2017 5:04 pm

I actually do not write programs in C++ but I need some libs which are written in C++.
Unfortunately, also gtkiostream was written in C++, but i wanted to give it a try.
I myself use the xxxx.yyyy or vvvvv::wwww things like in Arduino, but I don't write a code like that by myself -
but like for Arduino I try to get along with things like (comparatively) install() and loop() , so "procedure oriented", not "object oriented".
So also Arduino is C++, but the wrappers around the libs hide the most ugly things successfully and make things straight and fairly easy.

But this gtkiostream thing I will now abandon actually, it makes no sense with all the setbacks and C++ and callbacks and pointer code.

User avatar
Paeryn
Posts: 1574
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: Programming GTK GUIs by gtkIOStream: 2 vboxes and 2 hbox

Mon May 22, 2017 6:25 pm

1dot0 wrote:I actually do not write programs in C++ but I need some libs which are written in C++.
Unfortunately, also gtkiostream was written in C++, but i wanted to give it a try.
I myself use the xxxx.yyyy or vvvvv::wwww things like in Arduino, but I don't write a code like that by myself -
but like for Arduino I try to get along with things like (comparatively) install() and loop() , so "procedure oriented", not "object oriented".
So also Arduino is C++, but the wrappers around the libs hide the most ugly things successfully and make things straight and fairly easy.

But this gtkiostream thing I will now abandon actually, it makes no sense with all the setbacks and C++ and callbacks and pointer code.
Good luck finding a modern GUI library that doesn't use pointers and callbacks and isn't OO.

You mention xxxx.yyyy as if that's a C++ thing, that's perfectly valid C structure usage, nothing specifically C++ about it. vvvv::wwww is C++ as C doesn't have a scope operator.
Whether you write your own code using C++'s classes / namespaces / overloading / etc. or not, if you are using C++ features (albeit only when forced to by other libraries) and compiling it with a C++ compiler then you are writing in C++.
She who travels light — forgot something.

1dot0
Posts: 360
Joined: Mon Nov 28, 2016 12:31 pm

Re: Programming GTK GUIs by gtkIOStream: 2 vboxes and 2 hbox

Mon May 22, 2017 6:59 pm

about the xxxx.yyyy:
I know that for C structures,
but Arduino uses that for objects or classes or however it is called,
e.g.
Serial.begin()
Serial.write()
Wire.begin()
Wire.read()
and these are the C++ things which I use without needing to know all the C++ code behind it.
The same it's about the gtkIOstream things.
All the rest of my proprietary code is actually like ANSI C code, even if it's just a subset of C++ and the rest is out of my point of view (or interest).

User avatar
Paeryn
Posts: 1574
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: Programming GTK GUIs by gtkIOStream: 2 vboxes and 2 hbox

Mon May 22, 2017 7:13 pm

1dot0 wrote:about the xxxx.yyyy:
I know that for C structures,
but Arduino uses that for objects or classes or however it is called,
e.g.
Serial.begin()
Serial.write()
Wire.begin()
Wire.read()
and these are the C++ things which I use without needing to know all the C++ code behind it.
The same it's about the gtkIOstream things.
All the rest of my proprietary code is actually like ANSI C code, even if it's just a subset of C++ and the rest is out of my point of view.
You can have functions like that in C. If Serial is a struct with a member begin that is a function pointer (and correctly set to point to an actual function) then you can call it like that (though if it's Arduino then it probably is a C++ function in a class). C++ has the advantage that functions can belong to a struct/class rather than using function pointers.
She who travels light — forgot something.

Return to “Graphics programming”

Who is online

Users browsing this forum: No registered users and 1 guest