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 Mar 03, 2015 8:55 am

All times are UTC




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: GTK+ 3.0 resource files?
PostPosted: Sun Jan 04, 2015 10:44 am 
Offline
Familiar Face

Joined: Sat Jan 03, 2015 7:10 pm
Posts: 7
I have spent some time trying to configure menus through a gtk/menus.ui file, cf. https://developer.gnome.org/gtk3/stable/GtkApplication.html: "GtkApplication will automatically load menus from the GtkBuilder file located at "gtk/menus.ui", relative to the application's resource base path ". However, in https://developer.gnome.org/gtk3/stable/gtk3-Resource-Files.html I read "In GTK+ 3.0, resource files have been deprecated and replaced by CSS-like style sheets, which are understood by GtkCssProvider." So, what is the recommended way to configure menus? Any pointer to documantation is appreciated...


Top
 Profile  
 
 Post subject: Re: GTK+ 3.0 resource files?
PostPosted: Sun Jan 04, 2015 1:21 pm 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 833
Location: UK
Hallo,

I think you are getting confused with the various files and objects that are used in GTK to make a complete application.

"Styling Resource" files and CSS are both used to change the look and styling of the displayed widgets. You do not have to learn these yet to create an application. When you come to learn the widget styling use CSS and not the resource files, this way you will not be learning stuff that is old. You may need to use CSS if you need to change colours of buttons, the layout and grouping, etc. It does not describe what widgets to display.

Example uses of CSS can be found in this forum starting at http://www.gtkforums.com/viewtopic.php?f=3&t=988&p=72088=GTK3+with+CSS#p72088 and at GNOME at https://developer.gnome.org/Buttons/

GtkBuilder files are another part of a GTK application. These describe which widgets to use and how they are placed. It is a XML file which you can create by hand or use an application called Glade to help you do this.

Under GTK there are several types of menus. It can automatically load the application menu and the menu bar menu from "gtk/menus.ui" (This is a GtkBuilder file) when the base path is set for the resource file (note this is different from the styling resource file).

An example of building a trivial application is in the documentation at https://developer.gnome.org/gtk3/stable/ch01s05.html

_________________
E.


Top
 Profile  
 
 Post subject: Re: GTK+ 3.0 resource files?
PostPosted: Sun Jan 04, 2015 6:50 pm 
Offline
Familiar Face

Joined: Sat Jan 03, 2015 7:10 pm
Posts: 7
errol wrote:
I think you are getting confused with the various files and objects that are used in GTK to make a complete application.


If I understand you correctly, "In GTK+ 3.0, resource files have been deprecated and replaced by CSS-like style sheets" is not correct, as menus can still be defined through resource files?"

Quote:
An example of building a trivial application is in the documentation at https://developer.gnome.org/gtk3/stable/ch01s05.html


Thanks for the reference, I will take a look at it!


Top
 Profile  
 
 Post subject: Re: GTK+ 3.0 resource files?
PostPosted: Sun Jan 04, 2015 7:25 pm 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 833
Location: UK
It is the confusion in the English language. Using the same word for two different things.

1 - There is the old resource file used for describing the style of widgets including colour, font, size, etc. of widgets. This has now been replaced by using CSS. Neither are needed to create a menu in normal use, unless you need to alter the styling.

2 - The new resource file. This is in reality can be a collection of files that is compiled into the binary of your application. There are a number of API calls to access these files using a path. These can include GtkBuilder files used for building menus and user interfaces, images for icons etc, CSS files or almost any other file that could be needed by your application that you do not want as a separately installed file.

What you will have for your menu is ;
- A GtkBuilder file than describes your menu
- That is contained in a resource file
- Which is contained in your application binary.

_________________
E.


Top
 Profile  
 
 Post subject: Re: GTK+ 3.0 resource files?
PostPosted: Mon Jan 05, 2015 5:47 pm 
Offline
Familiar Face

Joined: Sat Jan 03, 2015 7:10 pm
Posts: 7
The example given does not explicitly mention how to compile/link the generated resource file, in order to include the resource into the binary? Any pointers to this would really help.


Top
 Profile  
 
 Post subject: Re: GTK+ 3.0 resource files?
PostPosted: Mon Jan 05, 2015 8:50 pm 
Offline
GTK+ Guru

Joined: Sat Jul 26, 2014 11:43 pm
Posts: 102
I think that there are two ways to setup up menus. Still learning this stuff myself so I am not exactly sure how everything works here. For the GtkApplication you use GMenu and for a "standard" GTK+ program you use GtkMenu. Here are two examples that should compile easily with >GTK3.4.
For adding color and some basic drawing on widgets, CSS is easy. For more complicated drawing cairo works very well.

GMenu example.
Code:

// gcc -Wall gtk_app_menu1.c -o gtk_app_menu1 `pkg-config --cflags --libs gtk+-3.0`

#include<gtk/gtk.h>

static void quit_program(GSimpleAction *action, GVariant *parameter, gpointer user_data)
{
   g_application_quit(G_APPLICATION(user_data));
}
static void test1_callback(GSimpleAction *action, GVariant *parameter, gpointer user_data)
{
   g_print("Test1 Callback\n");
}
static void app_startup(GtkApplication *app, gpointer user_data)
{
   //Setup menu callbacks.
   GSimpleAction *test1;
   GSimpleAction *quit;
   test1 = g_simple_action_new("test1", NULL);
   g_signal_connect(test1, "activate", G_CALLBACK(test1_callback), app);
   g_action_map_add_action(G_ACTION_MAP(app), G_ACTION(test1));
   g_object_unref(test1);
   quit = g_simple_action_new("quit", NULL);
   g_signal_connect(quit, "activate", G_CALLBACK(quit_program), app);
   g_action_map_add_action(G_ACTION_MAP(app), G_ACTION(quit));
   g_object_unref(quit);

   //Setup menu.
   GMenu *menu;
   GMenu *submenu; 
   GMenu *section; 
   menu = g_menu_new();
   submenu = g_menu_new();
   g_menu_append_submenu(menu, "Application", G_MENU_MODEL(submenu));
   section = g_menu_new();
   g_menu_append_section(submenu, NULL, G_MENU_MODEL(section));
   g_menu_append(section, "Test1", "app.test1");
   g_menu_append(section, "Quit", "app.quit");
   g_object_unref(submenu);
   g_object_unref(section);

   gtk_application_set_menubar(GTK_APPLICATION(app), G_MENU_MODEL(menu));
   g_object_unref(menu);
}
static void app_activate(GtkApplication *app, gpointer user_data)
{
   GtkWidget *window, *label1, *grid;

   window=gtk_application_window_new(GTK_APPLICATION(app));
   gtk_window_set_title(GTK_WINDOW(window), "Application Test");
   gtk_window_set_default_size(GTK_WINDOW(window), 250, 100);
   gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
   gtk_container_set_border_width(GTK_CONTAINER(window), 20);

   label1=gtk_label_new("GMenu");
   gtk_widget_set_hexpand(label1, TRUE);

   grid=gtk_grid_new();
   gtk_grid_set_row_spacing(GTK_GRID(grid), 10);
   gtk_grid_attach(GTK_GRID(grid), label1, 0, 1, 1, 1);
   
   gtk_container_add(GTK_CONTAINER(window), grid);

   gtk_widget_show_all(window);
}
int main(int argc, char **argv)
{
   GtkApplication *app;
   int status;
   app = gtk_application_new("app.example", G_APPLICATION_FLAGS_NONE);
   g_signal_connect(app, "startup", G_CALLBACK(app_startup), NULL);
   g_signal_connect(app, "activate", G_CALLBACK(app_activate), NULL);
   status=g_application_run(G_APPLICATION(app), argc, argv);
   g_object_unref(app);
   return(status);
  }


And a GtkMenu example
Code:
//gcc -Wall gtk_app_menu2.c -o gtk_app_menu2 `pkg-config --cflags --libs gtk+-3.0`

#include<gtk/gtk.h>

static void callback_test1(GtkWidget *menu, gpointer data)
{
   g_print("Test1 Callback\n");
}
static void callback_test2(GtkWidget *menu, gpointer data)
{
   g_print("Test2 Callback\n");
}
int main(int argc, char **argv)
{
   GtkWidget *menu_bar, *data_item, *data_menu, *test1, *test2, *window, *label1, *grid;

   gtk_init(&argc, &argv);

   window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
   gtk_window_set_title(GTK_WINDOW(window), "Application Test");
   gtk_window_set_default_size(GTK_WINDOW(window), 250, 100);
   gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
   gtk_container_set_border_width(GTK_CONTAINER(window), 20);
   g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

   data_menu=gtk_menu_new();
   test1=gtk_menu_item_new_with_label("Test1");
   test2=gtk_menu_item_new_with_label("Test2");
   gtk_menu_shell_append(GTK_MENU_SHELL(data_menu), test1);
   gtk_menu_shell_append(GTK_MENU_SHELL(data_menu), test2);
   g_signal_connect(test1, "activate", G_CALLBACK(callback_test1), NULL);
   g_signal_connect(test2, "activate", G_CALLBACK(callback_test2), NULL);
   menu_bar=gtk_menu_bar_new();
   data_item=gtk_menu_item_new_with_label("Data");
   gtk_menu_item_set_submenu(GTK_MENU_ITEM(data_item), data_menu);
   gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), data_item);

   label1=gtk_label_new("GtkMenu");
   gtk_widget_set_hexpand(label1, TRUE);

   grid=gtk_grid_new();
   gtk_grid_set_row_spacing(GTK_GRID(grid), 10);
   gtk_grid_attach(GTK_GRID(grid), menu_bar, 0, 0, 1, 1);
   gtk_grid_attach(GTK_GRID(grid), label1, 0, 1, 1, 1);
   
   gtk_container_add(GTK_CONTAINER(window), grid);

   gtk_widget_show_all(window);

   gtk_main();
   return 0;
 
}


Top
 Profile  
 
 Post subject: Re: GTK+ 3.0 resource files?
PostPosted: Tue Jan 06, 2015 12:43 pm 
Offline
Familiar Face

Joined: Sat Jan 03, 2015 7:10 pm
Posts: 7
cecashon wrote:
I think that there are two ways to setup up menus. Still learning this stuff myself so I am not exactly sure how everything works here. For the GtkApplication you use GMenu and for a "standard" GTK+ program you use GtkMenu. Here are two examples that should compile easily with >GTK3.4.


I appreciate your help, but I am really trying to wrap my head around using resource files...


Top
 Profile  
 
 Post subject: Re: GTK+ 3.0 resource files?
PostPosted: Thu Jan 08, 2015 11:13 am 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 833
Location: UK
eezacque, just trying to get some information about you and your system so that I can build a more tailored answer for you rather that being very general.

First, what versions of GTK+ are you using, what compiler are you using.

What experience have you got? Are you a beginner in C or have a good use of it? What experience of GTK+ have you got and have you used build systems before like 'make' and 'autotools'.

_________________
E.


Top
 Profile  
 
 Post subject: Re: GTK+ 3.0 resource files?
PostPosted: Mon Jan 12, 2015 10:54 am 
Offline
Familiar Face

Joined: Sat Jan 03, 2015 7:10 pm
Posts: 7
errol wrote:
eezacque, just trying to get some information about you and your system so that I can build a more tailored answer for you rather that being very general.

First, what versions of GTK+ are you using, what compiler are you using.

What experience have you got? Are you a beginner in C or have a good use of it? What experience of GTK+ have you got and have you used build systems before like 'make' and 'autotools'.


I have years of experience with C in a Unix evironment, using make, but currently using Eclipse under Ubuntu. GTK+ is new for me.

In the meantime, I have most of it figured out, can load and use menus from a resource included in my binary. I still cannot get 'Automatic resources' to work, as described in https://developer.gnome.org/gtk3/stable/GtkApplication.html. I can manually load a menu bar from resource "gtk/menus.ui", relative to the resource base path, but it does not load automatically. Any pointers on how to get this to work are appreciated.


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

All times are UTC


Who is online

Users browsing this forum: Google [Bot], Google Adsense [Bot], IshaanKarnik and 5 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:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group