GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Tue Sep 02, 2014 11:38 am

All times are UTC




Post new topic Reply to topic  [ 14 posts ] 
Author Message
 Post subject: menus in gtk+-3.0
PostPosted: Sat Dec 01, 2012 3:43 pm 
Offline
Familiar Face

Joined: Wed Nov 28, 2012 9:57 pm
Posts: 7
Hello everyone,

I'm new to the forum and pretty new to GTK+. I'm using GTK+3.0 and having a hard time creating a menu that is VISIBLE. I've rewritten code for menus in GTK+2.0 that worked fine. The rewrites involved changing gtk_menu_bar_append() to gtk_menu_shell_append. But, those were the only changes the compiler and linker demanded I make. Is there a tute or a good example of writing menus in GTK+3? The existing standard tutorial is fine, but as you know it is for v. 2.0+.

Thank you.

Mark Allyn


Top
 Profile  
 
 Post subject: Re: menus in gtk+-3.0
PostPosted: Sat Dec 01, 2012 6:44 pm 
Offline
GTK+ Guru

Joined: Fri Mar 25, 2011 5:16 pm
Posts: 177
Location: USA
I posted an example in the tutorials section:
http://www.gtkforums.com/viewtopic.php?f=3&t=988&p=196157=Changing+menubar+content%2C+by+selecting+a+notebook+tab#p196157

Also look in the folder gtk+-3.0 -> tests -> testgtk.c
Run the script testgtk then click the "Menus" button from the main GUI to see it run.

In testgtk.c the menus demo is made with the function create_menus() on on about line 3209.


Top
 Profile  
 
 Post subject: Re: menus in gtk+-3.0
PostPosted: Sat Dec 01, 2012 7:12 pm 
Offline
Familiar Face

Joined: Wed Nov 28, 2012 9:57 pm
Posts: 7
Thanks for your help, Zerohour. Looking at your code makes it plain that more is involved than I had suspected. You write:

Quote:
Also look in the folder gtk+-3.0 -> tests -> testgtk.c

Where is this gtk+-3.0 folder?

Cheers,
Mark


Top
 Profile  
 
 Post subject: Re: menus in gtk+-3.0
PostPosted: Sat Dec 01, 2012 7:40 pm 
Offline
GTK+ Guru

Joined: Fri Mar 25, 2011 5:16 pm
Posts: 177
Location: USA
Where ever you installed GTK.
You didn't say if your on Linux, Windows or Mac but if your on Linux and you didn't do a manual install, you can find the files by searching in the package manager for libgtk-3-dev.
Mine is a manual installation so maybe it's in a different location than yours. You could also download the source:
http://ftp.gnome.org/pub/gnome/sources/gtk+/3.0/


Top
 Profile  
 
 Post subject: Re: menus in gtk+-3.0
PostPosted: Sat Dec 01, 2012 8:06 pm 
Offline
Familiar Face

Joined: Wed Nov 28, 2012 9:57 pm
Posts: 7
Hello zerohour,

I was working from ubuntu box so I installed from a repository, not manually. I downloaded a 3.0.9 tarball and found the tests folder. I looked at testgtk.c and was intimidated by its size. Nearby was menubars.c and this looks much more digestible, at least for a newcomer.

Cheers and thanks,
Mark Allyn


Top
 Profile  
 
 Post subject: Re: menus in gtk+-3.0
PostPosted: Sat Dec 01, 2012 8:17 pm 
Offline
GTK+ Guru

Joined: Fri Mar 25, 2011 5:16 pm
Posts: 177
Location: USA
Be aware there's some deprecated (obsolete) code in testmenubars.c:
box1 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
...
...

gtk_box_new() should be replace with gtk_grid_new()
http://developer.gnome.org/gtk3/3.0/GtkGrid.html

There's official GTK documentation to help you make the switch from other container widgets to GtkGrid.
http://developer.gnome.org/gtk3/stable/gtk-migrating-GtkGrid.html


Top
 Profile  
 
 Post subject: Re: menus in gtk+-3.0
PostPosted: Sat Dec 01, 2012 8:57 pm 
Offline
Familiar Face

Joined: Wed Nov 28, 2012 9:57 pm
Posts: 7
Hi Zerohour,

Hmmmm....I'm wondering about the deprecated box code. Here's why. I compiled and ran testmenubars.c. I got the window. But, I didn't get the menubar. Nothing. So, this may be the explanation for why my own menubars are failing, i.e. I need a grid, not a box. We'll test this out. In running previous v2.0 code using 3.0 lib, box has worked OK for buttons and labels. I would have thought the same would be true for menubars, but maybe not.

Meantime, I ran your example. I did get a portion of the menubar. As portrayed in the screenshots at the beginning of the article, I got the "First Tab" and "Second Tab" items. However, I did not get "File", "Search", or "Quit". Any ideas on why this might be true?

Thanks again,
Mark


Top
 Profile  
 
 Post subject: Re: menus in gtk+-3.0
PostPosted: Sat Dec 01, 2012 9:39 pm 
Offline
GTK+ Guru

Joined: Fri Mar 25, 2011 5:16 pm
Posts: 177
Location: USA
gtk_vbox() and gtk_hbox() are depredicated as of gtk+-3.1.
Actually gtk_box_new() isn't deprecated yet but it will be soon. The gtk+-3.1 docs say:
Quote:
If you want your code to be future-proof, the recommendation is to switch to GtkGrid, since GtkBox is going to be deprecated in favor of the more flexible grid widget eventually. For more information about migrating to GtkGrid, see Migrating from other containers to GtkGrid.

http://developer.gnome.org/gtk3/3.1/GtkVBox.html

As far as why your not getting "File", "Search", or "Quit" I'm not sure. It worked for me with gtk+-3.2 under Ubuntu Natty.
Are you getting any error messages?
What version of Ubuntu are you running?
What theme?


Top
 Profile  
 
 Post subject: Re: menus in gtk+-3.0
PostPosted: Sat Dec 01, 2012 10:56 pm 
Offline
Familiar Face

Joined: Wed Nov 28, 2012 9:57 pm
Posts: 7
Hello Zerohour,

I'm getting no error messages.

The version is 12.10 of Ubuntu (Precise).

Since last we chatted, I have switched over to grid from box. Makes no difference. But, at least I learned about grid...

Regards,
Mark


Top
 Profile  
 
 Post subject: Re: menus in gtk+-3.0
PostPosted: Sun Dec 02, 2012 1:56 am 
Offline
Never Seen the Sunlight

Joined: Thu Mar 24, 2011 2:10 pm
Posts: 328
Location: Sydney, Australia
When you say things were working fine in gtk2, what version operating system were you using then?
the reason I ask is that when Ubuntu switched over to have unity as the default desktop environment, the menu bar was torn off the windows and placed in the top bar of the screen.
I imagine using Ubuntu 12.10/12.04 (precise is actually .04), you'll be aware of this already and the answer is not that simple. In this case there are a few things you might try:

I) Is the menu not there for both maximised and unmaximised windows?
II) Does the gtk2 version display wth or without the menubar on 12.10/12.04?
III) gtk_menu_shell_append also is in gtk2. If you change all the menu_bar_append to menu_shell_append and compile under gtk2 is the menu bar there or not?
IV) How are you putting the menus in the window? In gtk2 I would put a gtk_vbox in my window and then pack the menubar as the first widget in it. Under gtk3 box packing is different and will need to be changed too.
V) If using GtkGrid, you may need to make use of gtk_widget_set_vexpand and gtk_widget_set_hexpand else somethings default to 0 width and height.


Top
 Profile  
 
 Post subject: Re: menus in gtk+-3.0
PostPosted: Sun Dec 02, 2012 1:25 pm 
Offline
Familiar Face

Joined: Wed Nov 28, 2012 9:57 pm
Posts: 7
Good morning, Paul Childs,

Man I feel stupid! I didn't think to look at the "torn off" menu. Rerunning the little app I now see where the menubar is. Thanks for tipping me off to what should have been obvious. I just kept staring at the bloomin' window...

You have saved me many hours of fruitless searching and experimentation.

Regards,
Mark


Top
 Profile  
 
 Post subject: Re: menus in gtk+-3.0
PostPosted: Sun Dec 02, 2012 3:07 pm 
Offline
Familiar Face

Joined: Wed Nov 28, 2012 9:57 pm
Posts: 7
Good morning Zerohour,

Now that Paul Childs has straightened me out on the location of the menu bar I want to report to you that your tutorial menu bar does in fact work too...but the menu bar is not on the window, it's "torn" off in Ubuntu 12.04. I'm interested to know why the ubuntu folks made this design decision.

Thanks for your help.

Mark


Top
 Profile  
 
 Post subject: Re: menus in gtk+-3.0
PostPosted: Sun Dec 02, 2012 6:17 pm 
Offline
GTK+ Guru

Joined: Fri Mar 25, 2011 5:16 pm
Posts: 177
Location: USA
I can't guess about the design decisions for Ubuntu.
I don't know if it will override the window manager in Ubuntu Precise (12.04) and since I don't run Precise I can't check it, but there's the function: gtk_menu_set_tearoff_state ()
http://developer.gnome.org/gtk3/3.1/GtkMenu.html#gtk-menu-set-tearoff-state

If your running Ubuntu Precise (12.04) and installed from the repositories, your gtk version should be gtk+-3.4.1
I believe it's the only repository version that's ever been available for Precise. (Only one repo version is made available per Ubuntu release.)
http://packages.ubuntu.com/search?keywords=libgtk-3-dev&searchon=names&suite=precise&section=all

In Linux you can find your GTK+ version using your package manager by searching for: libgtk-3-dev or from the command line:
Command Line:
1) Open a terminal: CTRL+ALT+T
2) Copy the following and paste it into the terminal using: Edit->Paste OR SHIFT+CTRL+v Then press enter:
pkg-config --modversion gtk+-2.0
Do the same for: pkg-config --modversion gtk+-3.0


Top
 Profile  
 
 Post subject: Re: menus in gtk+-3.0
PostPosted: Sun Dec 02, 2012 9:48 pm 
Offline
Never Seen the Sunlight

Joined: Thu Mar 24, 2011 2:10 pm
Posts: 328
Location: Sydney, Australia
As a lot of linux distributions got popular with netbooks and other small screen devices coming out, a lot of design decisions were made to make things a bit more space conservative. GNOME2->3 also make a few of its own changes too. With Ubuntu, the unity desktop decided that rather having one menubar for each application, they'd combine them all in the one place. Similar deal with the scrollbars being narrowed down to a thin line. For a standard desktop screen it makes barely any difference, but you can at least disable the feature for yourself.

Don't worry about missing the obvious. It's amazing how when you get used to something, that this original mindset is so inherent that it doesn't get questioned unless there are major changes. I can remember getting used to firefox and everything having the menus up there, but when it came to my own menus I couldn't find them and spent a week scratching my head trying to figure out where it went.

The gtk_*_tearoff functions do something a bit different and aren't really related. Ubuntu's top menu is organised by the window manager rather than by gtk itself, which only gives a rough description of how to display things; the window manager applies its own native look and feel to make the final judgement on how to display things. Best to not meddle with forcing the window manager to perform a certain way though as each user will have their own preferences (e.g. users with disabilities) that you don't want to override.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group