widget-factory: Add a flowbox example

This is now really polished yet, but will let us work towards
'responsive grid'.
This commit is contained in:
Matthias Clasen 2014-08-12 20:22:14 -04:00
parent c46ca9b25b
commit 9fab7a684b
2 changed files with 135 additions and 1 deletions

View File

@ -531,6 +531,75 @@ populate_colors (GtkWidget *widget)
gtk_list_box_invalidate_headers (GTK_LIST_BOX (widget));
}
static void
background_loaded_cb (GObject *source,
GAsyncResult *res,
gpointer data)
{
GtkWidget *flowbox = data;
GtkWidget *child;
GdkPixbuf *pixbuf;
GError *error = NULL;
pixbuf = gdk_pixbuf_new_from_stream_finish (res, &error);
if (error)
{
g_warning ("%s", error->message);
g_error_free (error);
return;
}
child = gtk_image_new_from_pixbuf (pixbuf);
gtk_widget_show (child);
gtk_flow_box_insert (GTK_FLOW_BOX (flowbox), child, -1);
}
static void
populate_flowbox (GtkWidget *button, GtkWidget *flowbox)
{
const gchar *location;
GDir *dir;
GError *error = NULL;
const gchar *name;
gchar *filename;
GFile *file;
GInputStream *stream;
g_signal_handlers_disconnect_by_func (button, populate_flowbox, flowbox);
location = "/usr/share/backgrounds/gnome";
dir = g_dir_open (location, 0, &error);
if (error)
{
g_warning ("%s", error->message);
g_error_free (error);
return;
}
while ((name = g_dir_read_name (dir)) != NULL)
{
filename = g_build_filename (location, name, NULL);
file = g_file_new_for_path (filename);
stream = G_INPUT_STREAM (g_file_read (file, NULL, &error));
if (error)
{
g_warning ("%s", error->message);
g_clear_error (&error);
}
else
{
gdk_pixbuf_new_from_stream_at_scale_async (stream, 110, 110, TRUE, NULL,
background_loaded_cb, flowbox);
}
g_object_unref (file);
g_object_unref (stream);
g_free (filename);
}
g_dir_close (dir);
}
static void
row_activated (GtkListBox *box, GtkListBoxRow *row)
{
@ -686,6 +755,14 @@ activate (GApplication *app)
widget = (GtkWidget *)gtk_builder_get_object (builder, "preference_dialog_button");
g_signal_connect (widget, "clicked", G_CALLBACK (show_dialog), dialog);
dialog = (GtkWidget *)gtk_builder_get_object (builder, "selection_dialog");
g_signal_connect (dialog, "response", G_CALLBACK (close_dialog), NULL);
widget = (GtkWidget *)gtk_builder_get_object (builder, "selection_dialog_button");
g_signal_connect (widget, "clicked", G_CALLBACK (show_dialog), dialog);
widget2 = (GtkWidget *)gtk_builder_get_object (builder, "selection_flowbox");
g_signal_connect (widget, "clicked", G_CALLBACK (populate_flowbox), widget2);
widget = (GtkWidget *)gtk_builder_get_object (builder, "charletree");
populate_model ((GtkTreeStore *)gtk_tree_view_get_model (GTK_TREE_VIEW (widget)));
gtk_tree_view_expand_all (GTK_TREE_VIEW (widget));

View File

@ -2919,7 +2919,8 @@ Suspendisse feugiat quam quis dolor accumsan cursus. </property>
<property name="can_focus">True</property>
<property name="shadow_type">in</property>
<property name="hscrollbar_policy">automatic</property>
<property name="height_request">200</property>
<property name="margin-top">6</property>
<property name="height_request">226</property>
<child>
<object class="GtkIconView" id="iconview1">
<property name="visible">True</property>
@ -2968,6 +2969,13 @@ Suspendisse feugiat quam quis dolor accumsan cursus. </property>
<property name="use_underline">True</property>
</object>
</child>
<child>
<object class="GtkButton" id="selection_dialog_button">
<property name="visible">True</property>
<property name="label" translatable="yes">_Select</property>
<property name="use_underline">True</property>
</object>
</child>
</object>
</child>
</object>
@ -3322,6 +3330,55 @@ bad things might happen.</property>
</object>
</child>
</object>
<object class="GtkDialog" id="selection_dialog">
<property name="transient-for">window</property>
<property name="modal">True</property>
<property name="use-header-bar">1</property>
<property name="title" translatable="yes">Choose one</property>
<signal name="delete-event" handler="gtk_widget_hide_on_delete"/>
<child internal-child="vbox">
<object class="GtkBox">
<child>
<object class="GtkScrolledWindow">
<property name="visible">True</property>
<property name="hscrollbar-policy">never</property>
<property name="vscrollbar-policy">never</property>
<child>
<object class="GtkFlowBox" id="selection_flowbox">
<property name="visible">True</property>
<property name="selection-mode">single</property>
<property name="row-spacing">10</property>
<property name="column-spacing">10</property>
<property name="margin">10</property>
<property name="min-children-per-line">3</property>
<property name="max-children-per-line">9</property>
</object>
</child>
</object>
</child>
</object>
</child>
<child type="action">
<object class="GtkButton" id="cancel_selection_dialog">
<property name="visible">True</property>
<property name="label" translatable="yes">_Cancel</property>
<property name="use_underline">True</property>
</object>
</child>
<child type="action">
<object class="GtkButton" id="select_selection_dialog">
<property name="visible">True</property>
<property name="can-default">True</property>
<property name="has-default">True</property>
<property name="label" translatable="yes">_Select</property>
<property name="use_underline">True</property>
</object>
</child>
<action-widgets>
<action-widget response="cancel">cancel_selection_dialog</action-widget>
<action-widget response="ok" default="true">select_selection_dialog</action-widget>
</action-widgets>
</object>
<object class="GtkSizeGroup">
<property name="mode">vertical</property>
<widgets>