mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-14 20:51:07 +00:00
Merge branch 'matthiasc/for-master' into 'master'
gtk-demo: Fix the builder demo See merge request GNOME/gtk!2437
This commit is contained in:
commit
0ae7f794a3
@ -21,15 +21,38 @@ about_activate (GSimpleAction *action,
|
||||
gpointer user_data)
|
||||
{
|
||||
GtkWidget *window = user_data;
|
||||
GtkBuilder *builder;
|
||||
GtkWidget *about_dlg;
|
||||
|
||||
builder = g_object_get_data (G_OBJECT (window), "builder");
|
||||
about_dlg = GTK_WIDGET (gtk_builder_get_object (builder, "aboutdialog1"));
|
||||
gtk_window_set_transient_for (GTK_WINDOW (about_dlg), GTK_WINDOW (window));
|
||||
gtk_window_set_hide_on_close (GTK_WINDOW (about_dlg), TRUE);
|
||||
g_signal_connect (about_dlg, "response", G_CALLBACK (gtk_widget_hide), NULL);
|
||||
gtk_widget_show (about_dlg);
|
||||
about_dlg = GTK_WIDGET (g_object_get_data (G_OBJECT (window), "about"));
|
||||
gtk_window_present (GTK_WINDOW (about_dlg));
|
||||
}
|
||||
|
||||
static void
|
||||
remove_timeout (gpointer data)
|
||||
{
|
||||
guint id = GPOINTER_TO_UINT (data);
|
||||
|
||||
g_source_remove (id);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
pop_status (gpointer data)
|
||||
{
|
||||
gtk_statusbar_pop (GTK_STATUSBAR (data), 0);
|
||||
g_object_set_data (G_OBJECT (data), "timeout", NULL);
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
|
||||
static void
|
||||
status_message (GtkStatusbar *status,
|
||||
const char *text)
|
||||
{
|
||||
guint id;
|
||||
|
||||
gtk_statusbar_push (GTK_STATUSBAR (status), 0, text);
|
||||
id = g_timeout_add (5000, pop_status, status);
|
||||
|
||||
g_object_set_data_full (G_OBJECT (status), "timeout", GUINT_TO_POINTER (id), remove_timeout);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -37,7 +60,10 @@ help_activate (GSimpleAction *action,
|
||||
GVariant *parameter,
|
||||
gpointer user_data)
|
||||
{
|
||||
g_print ("Help not available\n");
|
||||
GtkWidget *status;
|
||||
|
||||
status = GTK_WIDGET (g_object_get_data (G_OBJECT (user_data), "status"));
|
||||
status_message (GTK_STATUSBAR (status), "Help not available");
|
||||
}
|
||||
|
||||
static void
|
||||
@ -45,7 +71,13 @@ not_implemented (GSimpleAction *action,
|
||||
GVariant *parameter,
|
||||
gpointer user_data)
|
||||
{
|
||||
g_print ("Action “%s” not implemented\n", g_action_get_name (G_ACTION (action)));
|
||||
GtkWidget *status;
|
||||
char *text;
|
||||
|
||||
text = g_strdup_printf ("Action “%s” not implemented", g_action_get_name (G_ACTION (action)));
|
||||
status = GTK_WIDGET (g_object_get_data (G_OBJECT (user_data), "status"));
|
||||
status_message (GTK_STATUSBAR (status), text);
|
||||
g_free (text);
|
||||
}
|
||||
|
||||
static GActionEntry win_entries[] = {
|
||||
@ -70,6 +102,8 @@ do_builder (GtkWidget *do_widget)
|
||||
if (!window)
|
||||
{
|
||||
GtkBuilder *builder;
|
||||
GtkWidget *about;
|
||||
GtkWidget *status;
|
||||
|
||||
builder = gtk_builder_new_from_resource ("/builder/demo.ui");
|
||||
|
||||
@ -83,6 +117,16 @@ do_builder (GtkWidget *do_widget)
|
||||
window);
|
||||
gtk_widget_insert_action_group (window, "win", actions);
|
||||
|
||||
about = GTK_WIDGET (gtk_builder_get_object (builder, "aboutdialog1"));
|
||||
gtk_window_set_transient_for (GTK_WINDOW (about), GTK_WINDOW (window));
|
||||
gtk_window_set_hide_on_close (GTK_WINDOW (about), TRUE);
|
||||
g_signal_connect (about, "response", G_CALLBACK (gtk_widget_hide), NULL);
|
||||
g_object_set_data_full (G_OBJECT (window), "about",
|
||||
about, (GDestroyNotify)gtk_window_destroy);
|
||||
|
||||
status = GTK_WIDGET (gtk_builder_get_object (builder, "statusbar1"));
|
||||
g_object_set_data (G_OBJECT (window), "status", status);
|
||||
|
||||
g_object_unref (builder);
|
||||
}
|
||||
|
||||
|
@ -732,7 +732,7 @@ GtkSearchBar, GtkListBox, and more.
|
||||
|
||||
The full, buildable sources for these examples can be found in the `examples/`
|
||||
directory of the GTK source distribution, or
|
||||
[online](https://gitlab.gnome.org/GNOME/gtk/blob/master/examples in the GTK git
|
||||
[online](https://gitlab.gnome.org/GNOME/gtk/blob/master/examples) in the GTK git
|
||||
repository. You can build each example separately by using make with the
|
||||
`Makefile.example` file. For more information, see the `README` included in the
|
||||
examples directory.
|
||||
@ -976,6 +976,10 @@ into the application together with the other source files. To do so, we use the
|
||||
glib-compile-resources exampleapp.gresource.xml --target=resources.c --generate-source
|
||||
```
|
||||
|
||||
The gnome module of the meson build system provides the
|
||||
[gnome.compile_resources()](https://mesonbuild.com/Gnome-module.html#gnomecompile_resources)
|
||||
method for this task.
|
||||
|
||||
Our application now looks like this:
|
||||
|
||||
![The application](getting-started-app2.png)
|
||||
@ -1037,7 +1041,7 @@ example_app_window_open (ExampleAppWindow *win,
|
||||
|
||||
basename = g_file_get_basename (file);
|
||||
|
||||
scrolled = gtk_scrolled_window_new (NULL, NULL);
|
||||
scrolled = gtk_scrolled_window_new ();
|
||||
gtk_widget_set_hexpand (scrolled, TRUE);
|
||||
gtk_widget_set_vexpand (scrolled, TRUE);
|
||||
view = gtk_text_view_new ();
|
||||
@ -1204,7 +1208,9 @@ a schema that describes our settings:
|
||||
Before we can make use of this schema in our application, we need to compile
|
||||
it into the binary form that GSettings expects. GIO provides
|
||||
[macros](https://developer.gnome.org/gio/2.36/ch31s06.html) to do this in
|
||||
autotools-based projects.
|
||||
autotools-based projects, and the gnome module of the meson build system
|
||||
provides the [gnome.compile_schemas()](https://mesonbuild.com/Gnome-module.html#gnomecompile_schemas)
|
||||
method for this task.
|
||||
|
||||
Next, we need to connect our settings to the widgets that they are supposed
|
||||
to control. One convenient way to do this is to use GSettings bind
|
||||
|
@ -4,9 +4,20 @@
|
||||
|
||||
The examples in this directory are built alongside the rest of GTK.
|
||||
|
||||
The examples under the `application[1-10]` directories are also included in
|
||||
The examples under the `application[1-9]` directories are also included in
|
||||
the GTK API reference documentation, and can be built independently, using
|
||||
the system libraries, by doing:
|
||||
|
||||
$ cd application1
|
||||
$ make -f Makefile.example
|
||||
|
||||
== Running the examples ==
|
||||
|
||||
The examples can be run uninstalled.
|
||||
|
||||
The later demos are using GSettings,so they need a GSettings schema.
|
||||
The code for these demos contains a workaround to look for the schema
|
||||
in the current directory, so this works:
|
||||
|
||||
$ cd application5
|
||||
& ./exampleapp window.ui
|
||||
|
@ -11,7 +11,7 @@ OBJS = $(BUILT_SRC:.c=.o) $(SRC:.c=.o)
|
||||
|
||||
all: exampleapp
|
||||
|
||||
resources.c: exampleapp.gresource.xml window.ui app-menu.ui
|
||||
resources.c: exampleapp.gresource.xml window.ui
|
||||
$(GLIB_COMPILE_RESOURCES) exampleapp.gresource.xml --target=$@ --sourcedir=. --generate-source
|
||||
|
||||
%.o: %.c
|
||||
|
@ -18,7 +18,7 @@ org.gtk.exampleapp.gschema.valid: org.gtk.exampleapp.gschema.xml
|
||||
gschemas.compiled: org.gtk.exampleapp.gschema.valid
|
||||
$(GLIB_COMPILE_SCHEMAS) .
|
||||
|
||||
resources.c: exampleapp.gresource.xml window.ui app-menu.ui
|
||||
resources.c: exampleapp.gresource.xml window.ui
|
||||
$(GLIB_COMPILE_RESOURCES) exampleapp.gresource.xml --target=$@ --sourcedir=. --generate-source
|
||||
|
||||
%.o: %.c
|
||||
|
@ -18,7 +18,7 @@ org.gtk.exampleapp.gschema.valid: org.gtk.exampleapp.gschema.xml
|
||||
gschemas.compiled: org.gtk.exampleapp.gschema.valid
|
||||
$(GLIB_COMPILE_SCHEMAS) .
|
||||
|
||||
resources.c: exampleapp.gresource.xml window.ui app-menu.ui
|
||||
resources.c: exampleapp.gresource.xml window.ui
|
||||
$(GLIB_COMPILE_RESOURCES) exampleapp.gresource.xml --target=$@ --sourcedir=. --generate-source
|
||||
|
||||
%.o: %.c
|
||||
|
@ -107,7 +107,7 @@ done:
|
||||
row = gtk_button_new_with_label (key);
|
||||
g_signal_connect (row, "clicked",
|
||||
G_CALLBACK (find_word), win);
|
||||
gtk_box_append (GTK_BOX (win->words), row);
|
||||
gtk_list_box_insert (GTK_LIST_BOX (win->words), row, -1);
|
||||
}
|
||||
|
||||
g_hash_table_unref (strings);
|
||||
|
@ -109,7 +109,7 @@ done:
|
||||
row = gtk_button_new_with_label (key);
|
||||
g_signal_connect (row, "clicked",
|
||||
G_CALLBACK (find_word), win);
|
||||
gtk_box_append (GTK_BOX (win->words), row);
|
||||
gtk_list_box_insert (GTK_LIST_BOX (win->words), row, -1);
|
||||
}
|
||||
|
||||
g_hash_table_unref (strings);
|
||||
|
Loading…
Reference in New Issue
Block a user