[gimp/wip/gum-lang: 2/2] app: add ui_meta keys for controlling some ui properties dynamically
- From: N/A <ell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/wip/gum-lang: 2/2] app: add ui_meta keys for controlling some ui properties dynamically
- Date: Sun, 30 Apr 2017 20:43:47 +0000 (UTC)
commit 51a51437ec7f81f2e90e2981b531e5f287613de6
Author: Ell <ell_se yahoo com>
Date: Sun Apr 30 16:07:38 2017 -0400
app: add ui_meta keys for controlling some ui properties dynamically
Add support for the "sensitive", "visible", "label", and "description"
property keys for gegl ops.
The "sensitive" and "visible" keys should be boolean GUM expressions,
and the "label" and "description" keys should be string GUM
expressions, controlling the sensitivity, visibility, label, and tool-
tip of the corresponding prop gui widget, respectively.
app/widgets/gimppropgui-constructors.c | 25 +++++
app/widgets/gimppropgui.c | 167 ++++++++++++++++++++++++++-----
2 files changed, 165 insertions(+), 27 deletions(-)
---
diff --git a/app/widgets/gimppropgui-constructors.c b/app/widgets/gimppropgui-constructors.c
index 6f786b6..0632d04 100644
--- a/app/widgets/gimppropgui-constructors.c
+++ b/app/widgets/gimppropgui-constructors.c
@@ -119,6 +119,13 @@ _gimp_prop_gui_new_generic (GObject *config,
gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0);
gtk_widget_show (hbox);
+ g_object_bind_property (widget_x, "sensitive",
+ hbox, "sensitive",
+ G_BINDING_SYNC_CREATE);
+ g_object_bind_property (widget_x, "visible",
+ hbox, "visible",
+ G_BINDING_SYNC_CREATE);
+
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2);
gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
gtk_widget_show (vbox);
@@ -199,6 +206,10 @@ _gimp_prop_gui_new_generic (GObject *config,
gtk_label_set_xalign (GTK_LABEL (l), 0.0);
gtk_widget_show (l);
+ g_object_bind_property (widget, "name",
+ l, "label",
+ G_BINDING_SYNC_CREATE);
+
if (GTK_IS_SCROLLED_WINDOW (widget))
{
GtkWidget *frame;
@@ -212,6 +223,13 @@ _gimp_prop_gui_new_generic (GObject *config,
gtk_container_add (GTK_CONTAINER (frame), widget);
gtk_widget_show (widget);
+
+ g_object_bind_property (widget, "sensitive",
+ frame, "sensitive",
+ G_BINDING_SYNC_CREATE);
+ g_object_bind_property (widget, "visible",
+ frame, "visible",
+ G_BINDING_SYNC_CREATE);
}
else
{
@@ -227,6 +245,13 @@ _gimp_prop_gui_new_generic (GObject *config,
gtk_box_pack_start (GTK_BOX (hbox), widget, TRUE, TRUE, 0);
gtk_widget_show (widget);
+
+ g_object_bind_property (widget, "sensitive",
+ hbox, "sensitive",
+ G_BINDING_SYNC_CREATE);
+ g_object_bind_property (widget, "visible",
+ hbox, "visible",
+ G_BINDING_SYNC_CREATE);
}
}
else if (widget)
diff --git a/app/widgets/gimppropgui.c b/app/widgets/gimppropgui.c
index e147e16..4de6432 100644
--- a/app/widgets/gimppropgui.c
+++ b/app/widgets/gimppropgui.c
@@ -44,6 +44,7 @@
#include "gimpspinscale.h"
#include "gimppropgui.h"
#include "gimppropgui-constructors.h"
+#include "gimppropgui-eval.h"
#include "gimppropwidgets.h"
#include "gimpwidgets-utils.h"
@@ -53,14 +54,19 @@
#define HAS_KEY(p,k,v) gimp_gegl_param_spec_has_key (p, k, v)
-static GtkWidget * gimp_prop_kelvin_presets_new (GObject *config,
- const gchar *property_name);
-static void gimp_prop_widget_new_seed_clicked (GtkButton *button,
- GtkAdjustment *adj);
-static gboolean gimp_prop_string_to_boolean (GBinding *binding,
- const GValue *from_value,
- GValue *to_value,
- gpointer user_data);
+static GtkWidget * gimp_prop_kelvin_presets_new (GObject *config,
+ const gchar *property_name);
+static void gimp_prop_widget_new_seed_clicked (GtkButton *button,
+ GtkAdjustment *adj);
+static gboolean gimp_prop_string_to_boolean (GBinding *binding,
+ const GValue *from_value,
+ GValue *to_value,
+ gpointer user_data);
+static void gimp_prop_config_notify (GObject *config,
+ GParamSpec *pspec,
+ GtkWidget *widget);
+static void gimp_prop_widget_show (GtkWidget *widget,
+ GObject *config);
/* public functions */
@@ -213,6 +219,10 @@ gimp_prop_widget_new_from_pspec (GObject *config,
gtk_box_pack_start (GTK_BOX (hbox), dial, FALSE, FALSE, 0);
gtk_widget_show (dial);
+ g_object_bind_property (hbox, "name",
+ widget, "label",
+ G_BINDING_DEFAULT);
+
widget = hbox;
}
else if (HAS_KEY (pspec, "unit", "kelvin"))
@@ -229,30 +239,41 @@ gimp_prop_widget_new_from_pspec (GObject *config,
gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
gtk_widget_show (button);
+ g_object_bind_property (hbox, "name",
+ widget, "label",
+ G_BINDING_DEFAULT);
+
widget = hbox;
}
- else if (area)
+ else
{
- if (HAS_KEY (pspec, "unit", "pixel-coordinate") ||
- HAS_KEY (pspec, "unit", "pixel-distance"))
- {
- if (HAS_KEY (pspec, "axis", "x"))
- {
- g_printerr ("XXX setting width %d on %s\n",
- area->width, pspec->name);
+ g_object_bind_property (widget, "name",
+ widget, "label",
+ G_BINDING_DEFAULT);
- gimp_spin_scale_set_scale_limits (GIMP_SPIN_SCALE (widget),
- area->x,
- area->x + area->width);
- }
- else if (HAS_KEY (pspec, "axis","y"))
+ if (area)
+ {
+ if (HAS_KEY (pspec, "unit", "pixel-coordinate") ||
+ HAS_KEY (pspec, "unit", "pixel-distance"))
{
- g_printerr ("XXX setting height %d on %s\n",
- area->height, pspec->name);
-
- gimp_spin_scale_set_scale_limits (GIMP_SPIN_SCALE (widget),
- area->y,
- area->y + area->height);
+ if (HAS_KEY (pspec, "axis", "x"))
+ {
+ g_printerr ("XXX setting width %d on %s\n",
+ area->width, pspec->name);
+
+ gimp_spin_scale_set_scale_limits (GIMP_SPIN_SCALE (widget),
+ area->x,
+ area->x + area->width);
+ }
+ else if (HAS_KEY (pspec, "axis","y"))
+ {
+ g_printerr ("XXX setting height %d on %s\n",
+ area->height, pspec->name);
+
+ gimp_spin_scale_set_scale_limits (GIMP_SPIN_SCALE (widget),
+ area->y,
+ area->y + area->height);
+ }
}
}
}
@@ -316,12 +337,20 @@ gimp_prop_widget_new_from_pspec (GObject *config,
{
widget = gimp_prop_check_button_new (config, pspec->name,
g_param_spec_get_nick (pspec));
+
+ g_object_bind_property (widget, "name",
+ widget, "label",
+ G_BINDING_DEFAULT);
}
else if (G_IS_PARAM_SPEC_ENUM (pspec))
{
widget = gimp_prop_enum_combo_box_new (config, pspec->name, 0, 0);
gimp_int_combo_box_set_label (GIMP_INT_COMBO_BOX (widget),
g_param_spec_get_nick (pspec));
+
+ g_object_bind_property (widget, "name",
+ widget, "label",
+ G_BINDING_DEFAULT);
}
else if (GIMP_IS_PARAM_SPEC_RGB (pspec))
{
@@ -356,6 +385,41 @@ gimp_prop_widget_new_from_pspec (GObject *config,
g_type_name (G_TYPE_FROM_INSTANCE (pspec)), pspec->name);
}
+ /* we use the widget's name property to store its label, so that our caller
+ * can bind the relevant label property to it.
+ */
+ gtk_widget_set_name (widget, g_param_spec_get_nick (pspec));
+
+ /* if we have any keys for dynamic properties, listen to config's notify
+ * signal, and update the properties accordingly.
+ */
+ if (gegl_param_spec_get_property_key (pspec, "sensitive") ||
+ gegl_param_spec_get_property_key (pspec, "visible") ||
+ gegl_param_spec_get_property_key (pspec, "label") ||
+ gegl_param_spec_get_property_key (pspec, "description"))
+ {
+ g_object_set_data (G_OBJECT (widget), "gimp-prop-pspec", pspec);
+
+ g_signal_connect_object (config, "notify",
+ G_CALLBACK (gimp_prop_config_notify),
+ widget, 0);
+
+ if (gegl_param_spec_get_property_key (pspec, "visible"))
+ {
+ /* a bit of a hack: if we have a dynamic "visible" property key,
+ * connect to the widget's "show" signal, so that we can intercept
+ * our caller's gtk_widget_show() call, and keep the widget hidden if
+ * necessary.
+ */
+ g_signal_connect (widget, "show",
+ G_CALLBACK (gimp_prop_widget_show),
+ config);
+ }
+
+ /* update all the properties now */
+ gimp_prop_config_notify (config, NULL, widget);
+ }
+
return widget;
}
@@ -607,3 +671,52 @@ gimp_prop_string_to_boolean (GBinding *binding,
return TRUE;
}
+
+static void
+gimp_prop_config_notify (GObject *config,
+ GParamSpec *pspec,
+ GtkWidget *widget)
+{
+ GParamSpec *widget_pspec;
+ gboolean sensitive;
+ gboolean visible;
+ gchar *label;
+ gchar *description;
+
+ widget_pspec = g_object_get_data (G_OBJECT (widget), "gimp-prop-pspec");
+
+ sensitive = gimp_prop_eval_boolean (config, widget_pspec, "sensitive", TRUE);
+ visible = gimp_prop_eval_boolean (config, widget_pspec, "visible", TRUE);
+ label = gimp_prop_eval_string (config, widget_pspec, "label",
+ g_param_spec_get_nick (widget_pspec));
+ description = gimp_prop_eval_string (config, widget_pspec, "description",
+ g_param_spec_get_blurb (widget_pspec));
+
+ g_signal_handlers_block_by_func (widget,
+ gimp_prop_widget_show, config);
+
+ gtk_widget_set_sensitive (widget, sensitive);
+ gtk_widget_set_visible (widget, visible);
+ gtk_widget_set_name (widget, label);
+ gimp_help_set_help_data (widget, description, NULL);
+
+ g_signal_handlers_unblock_by_func (widget,
+ gimp_prop_widget_show, config);
+
+ g_free (description);
+ g_free (label);
+}
+
+static void
+gimp_prop_widget_show (GtkWidget *widget,
+ GObject *config)
+{
+ GParamSpec *widget_pspec;
+ gboolean visible;
+
+ widget_pspec = g_object_get_data (G_OBJECT (widget), "gimp-prop-pspec");
+
+ visible = gimp_prop_eval_boolean (config, widget_pspec, "visible", TRUE);
+
+ gtk_widget_set_visible (widget, visible);
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]