[libgda] Updated UI demo programs
- From: Vivien Malerba <vivien src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda] Updated UI demo programs
- Date: Wed, 18 Apr 2012 18:58:06 +0000 (UTC)
commit b87910d2cce42f45269e4637d2d980490db842da
Author: Vivien Malerba <malerba gnome-db org>
Date: Wed Apr 18 20:18:33 2012 +0200
Updated UI demo programs
libgda-ui/demos/Makefile.am | 2 +
libgda-ui/demos/form_model_change.c | 117 ++++++++++++++++++++++++++++++++++
libgda-ui/demos/grid.c | 1 +
libgda-ui/demos/grid_model_change.c | 119 +++++++++++++++++++++++++++++++++++
libgda-ui/demos/grid_rw.c | 6 +-
5 files changed, 242 insertions(+), 3 deletions(-)
---
diff --git a/libgda-ui/demos/Makefile.am b/libgda-ui/demos/Makefile.am
index ef7cd8f..82a74cf 100644
--- a/libgda-ui/demos/Makefile.am
+++ b/libgda-ui/demos/Makefile.am
@@ -17,10 +17,12 @@ demos = \
form_rw.c \
form_pict.c \
form_data_layout.c \
+ form_model_change.c \
grid.c \
grid_rw.c \
grid_pict.c \
grid_data_layout.c \
+ grid_model_change.c \
linked_grid_form.c \
linked_model_param.c \
ddl_queries.c \
diff --git a/libgda-ui/demos/form_model_change.c b/libgda-ui/demos/form_model_change.c
new file mode 100644
index 0000000..fac7d1c
--- /dev/null
+++ b/libgda-ui/demos/form_model_change.c
@@ -0,0 +1,117 @@
+/* Forms/Changing data model
+ *
+ * This example shows how to set and change the data model displayed by a GdauiForm widget.
+ */
+
+#include <libgda-ui/libgda-ui.h>
+#include <sql-parser/gda-sql-parser.h>
+
+extern GdaConnection *demo_cnc;
+extern GdaSqlParser *demo_parser;
+static GtkWidget *window = NULL;
+static GtkWidget *form = NULL;
+
+static void
+model_toggled_cb (GtkToggleButton *rb, GdaDataModel *model)
+{
+ if (gtk_toggle_button_get_active (rb))
+ gdaui_data_selector_set_model (GDAUI_DATA_SELECTOR (form), model);
+}
+
+GtkWidget *
+do_form_model_change (GtkWidget *do_widget)
+{
+ if (!window) {
+ GdaStatement *stmt;
+ GtkWidget *vbox;
+ GtkWidget *label;
+ GdaDataModel *models [3];
+
+ window = gtk_dialog_new_with_buttons ("Changing data in a GdauiForm",
+ GTK_WINDOW (do_widget),
+ 0,
+ GTK_STOCK_CLOSE,
+ GTK_RESPONSE_NONE,
+ NULL);
+
+ g_signal_connect (window, "response",
+ G_CALLBACK (gtk_widget_destroy), NULL);
+ g_signal_connect (window, "destroy",
+ G_CALLBACK (gtk_widget_destroyed), &window);
+
+ vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
+ gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (window))),
+ vbox, TRUE, TRUE, 0);
+ gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
+
+ label = gtk_label_new ("The data in the same GdauiForm widget can be change don the fly.");
+ gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
+
+ /* creating data models */
+ stmt = gda_sql_parser_parse_string (demo_parser, "SELECT * FROM products ORDER BY ref, category LIMIT 15", NULL, NULL);
+ models[0] = gda_connection_statement_execute_select (demo_cnc, stmt, NULL, NULL);
+ gda_data_select_compute_modification_statements (GDA_DATA_SELECT (models[0]), NULL);
+ g_object_unref (stmt);
+
+ stmt = gda_sql_parser_parse_string (demo_parser, "SELECT * FROM products WHERE price > 20.2 ORDER BY ref, category LIMIT 10", NULL, NULL);
+ models[1] = gda_connection_statement_execute_select (demo_cnc, stmt, NULL, NULL);
+ gda_data_select_compute_modification_statements (GDA_DATA_SELECT (models[1]), NULL);
+ g_object_unref (stmt);
+
+ stmt = gda_sql_parser_parse_string (demo_parser, "SELECT name, price, ref, category FROM products WHERE price > 20.2 ORDER BY name LIMIT 30", NULL, NULL);
+ models[2] = gda_connection_statement_execute_select (demo_cnc, stmt, NULL, NULL);
+ gda_data_select_compute_modification_statements (GDA_DATA_SELECT (models[2]), NULL);
+ g_object_unref (stmt);
+
+
+ /* allow choosing which data model to display */
+ label = gtk_label_new ("");
+ gtk_misc_set_alignment (GTK_MISC (label), 0., -1);
+ gtk_label_set_markup (GTK_LABEL (label), "<b>Choose which data model to display:</b>");
+ gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
+
+ GtkWidget *layout, *rb;
+ GSList *group = NULL;
+ gint i;
+ layout = gtk_grid_new ();
+ gtk_box_pack_start (GTK_BOX (vbox), layout, FALSE, FALSE, 0);
+
+ for (i = 0; i < 3; i++) {
+ gchar *str;
+ str = g_strdup_printf ("%d columns x %d rows", gda_data_model_get_n_columns (models[i]),
+ gda_data_model_get_n_rows (models[i]));
+ rb = gtk_radio_button_new_with_label (group, str);
+ g_free (str);
+ gtk_grid_attach (GTK_GRID (layout), rb, i, 0, 1, 1);
+ g_signal_connect (rb, "toggled", G_CALLBACK (model_toggled_cb), models[i]);
+ g_object_set_data_full (G_OBJECT (rb), "model", models[i], g_object_unref);
+ group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (rb));
+ }
+
+ /* Create the form widget */
+ label = gtk_label_new ("");
+ gtk_misc_set_alignment (GTK_MISC (label), 0., -1);
+ gtk_label_set_markup (GTK_LABEL (label), "<b>GdauiForm:</b>");
+ gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
+
+ form = gdaui_form_new (models[0]);
+ g_object_set (G_OBJECT (form), "info-flags",
+ GDAUI_DATA_PROXY_INFO_CURRENT_ROW |
+ GDAUI_DATA_PROXY_INFO_ROW_MOVE_BUTTONS |
+ GDAUI_DATA_PROXY_INFO_ROW_MODIFY_BUTTONS, NULL);
+ gtk_box_pack_start (GTK_BOX (vbox), form, TRUE, TRUE, 0);
+ }
+
+ gboolean visible;
+ g_object_get (G_OBJECT (window), "visible", &visible, NULL);
+ if (!visible)
+ gtk_widget_show_all (window);
+ else {
+ gtk_widget_destroy (window);
+ window = NULL;
+ }
+
+ return window;
+}
+
+
diff --git a/libgda-ui/demos/grid.c b/libgda-ui/demos/grid.c
index 5f33439..a7888af 100644
--- a/libgda-ui/demos/grid.c
+++ b/libgda-ui/demos/grid.c
@@ -46,6 +46,7 @@ do_grid (GtkWidget *do_widget)
model = gda_connection_statement_execute_select (demo_cnc, stmt, NULL, NULL);
g_object_unref (stmt);
grid = gdaui_grid_new (model);
+ gtk_widget_set_size_request (grid, -1, 350);
g_object_unref (model);
gdaui_grid_set_sample_size (GDAUI_GRID (grid), 100);
g_object_set (G_OBJECT (grid), "info-flags",
diff --git a/libgda-ui/demos/grid_model_change.c b/libgda-ui/demos/grid_model_change.c
new file mode 100644
index 0000000..02436c0
--- /dev/null
+++ b/libgda-ui/demos/grid_model_change.c
@@ -0,0 +1,119 @@
+/* Grids/Changing data model
+ *
+ * This example shows how to set and change the data model displayed by a GdauiRawGrid widget.
+ */
+
+#include <libgda-ui/libgda-ui.h>
+#include <sql-parser/gda-sql-parser.h>
+
+extern GdaConnection *demo_cnc;
+extern GdaSqlParser *demo_parser;
+static GtkWidget *window = NULL;
+static GtkWidget *grid = NULL;
+
+static void
+model_toggled_cb (GtkToggleButton *rb, GdaDataModel *model)
+{
+ if (gtk_toggle_button_get_active (rb))
+ gdaui_data_selector_set_model (GDAUI_DATA_SELECTOR (grid), model);
+}
+
+GtkWidget *
+do_grid_model_change (GtkWidget *do_widget)
+{
+ if (!window) {
+ GdaStatement *stmt;
+ GtkWidget *vbox;
+ GtkWidget *label;
+ GdaDataModel *models [3];
+ GtkWidget *sw;
+
+ window = gtk_dialog_new_with_buttons ("Changing data in a GdauiRawGrid",
+ GTK_WINDOW (do_widget),
+ 0,
+ GTK_STOCK_CLOSE,
+ GTK_RESPONSE_NONE,
+ NULL);
+
+ g_signal_connect (window, "response",
+ G_CALLBACK (gtk_widget_destroy), NULL);
+ g_signal_connect (window, "destroy",
+ G_CALLBACK (gtk_widget_destroyed), &window);
+
+ vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
+ gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (window))),
+ vbox, TRUE, TRUE, 0);
+ gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
+
+ label = gtk_label_new ("The data in the same GdauiRawGrid widget can be change don the fly.");
+ gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
+
+ /* creating data models */
+ stmt = gda_sql_parser_parse_string (demo_parser, "SELECT * FROM products ORDER BY ref, category LIMIT 15", NULL, NULL);
+ models[0] = gda_connection_statement_execute_select (demo_cnc, stmt, NULL, NULL);
+ gda_data_select_compute_modification_statements (GDA_DATA_SELECT (models[0]), NULL);
+ g_object_unref (stmt);
+
+ stmt = gda_sql_parser_parse_string (demo_parser, "SELECT * FROM products WHERE price > 20.2 ORDER BY ref, category LIMIT 10", NULL, NULL);
+ models[1] = gda_connection_statement_execute_select (demo_cnc, stmt, NULL, NULL);
+ gda_data_select_compute_modification_statements (GDA_DATA_SELECT (models[1]), NULL);
+ g_object_unref (stmt);
+
+ stmt = gda_sql_parser_parse_string (demo_parser, "SELECT name, price, ref, category FROM products WHERE price > 20.2 ORDER BY name LIMIT 30", NULL, NULL);
+ models[2] = gda_connection_statement_execute_select (demo_cnc, stmt, NULL, NULL);
+ gda_data_select_compute_modification_statements (GDA_DATA_SELECT (models[2]), NULL);
+ g_object_unref (stmt);
+
+
+ /* allow choosing which data model to display */
+ label = gtk_label_new ("");
+ gtk_misc_set_alignment (GTK_MISC (label), 0., -1);
+ gtk_label_set_markup (GTK_LABEL (label), "<b>Choose which data model to display:</b>");
+ gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
+
+ GtkWidget *layout, *rb;
+ GSList *group = NULL;
+ gint i;
+ layout = gtk_grid_new ();
+ gtk_box_pack_start (GTK_BOX (vbox), layout, FALSE, FALSE, 0);
+
+ for (i = 0; i < 3; i++) {
+ gchar *str;
+ str = g_strdup_printf ("%d columns x %d rows", gda_data_model_get_n_columns (models[i]),
+ gda_data_model_get_n_rows (models[i]));
+ rb = gtk_radio_button_new_with_label (group, str);
+ g_free (str);
+ gtk_grid_attach (GTK_GRID (layout), rb, i, 0, 1, 1);
+ g_signal_connect (rb, "toggled", G_CALLBACK (model_toggled_cb), models[i]);
+ g_object_set_data_full (G_OBJECT (rb), "model", models[i], g_object_unref);
+ group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (rb));
+ }
+
+ /* Create the grid widget */
+ label = gtk_label_new ("");
+ gtk_misc_set_alignment (GTK_MISC (label), 0., -1);
+ gtk_label_set_markup (GTK_LABEL (label), "<b>GdauiRawGrid in a scrolled window:</b>");
+ gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
+
+ grid = gdaui_raw_grid_new (models[0]);
+
+ sw = gtk_scrolled_window_new (NULL, NULL);
+ gtk_container_add (GTK_CONTAINER (sw), grid);
+ gtk_widget_set_size_request (sw, 600, 350);
+
+ gtk_box_pack_start (GTK_BOX (vbox), sw, TRUE, TRUE, 0);
+ }
+
+ gboolean visible;
+ g_object_get (G_OBJECT (window), "visible", &visible, NULL);
+ if (!visible)
+ gtk_widget_show_all (window);
+ else {
+ gtk_widget_destroy (window);
+ window = NULL;
+ }
+
+ return window;
+}
+
+
diff --git a/libgda-ui/demos/grid_rw.c b/libgda-ui/demos/grid_rw.c
index ab5b139..b2ee8a2 100644
--- a/libgda-ui/demos/grid_rw.c
+++ b/libgda-ui/demos/grid_rw.c
@@ -1,6 +1,6 @@
/* Grids/Read-write grid
*
- * The GdauiGrid widget displays data stored in a GdaDataModel.
+ * The GdauiGrid widget displays data stored in a GdaDataModel; this example shows how to make the data writable.
*/
#include <libgda-ui/libgda-ui.h>
@@ -38,8 +38,7 @@ do_grid_rw (GtkWidget *do_widget)
gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
label = gtk_label_new ("The following GdauiGrid widget displays data from the 'products' table.\n\n"
- "As modification queries are provided, the data is read-write\n(except for the 'price' "
- "field as these queries voluntarily omit that field).");
+ "As modification queries are provided, the data is read-write.");
gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
/* Create the demo widget */
@@ -48,6 +47,7 @@ do_grid_rw (GtkWidget *do_widget)
g_object_unref (stmt);
gda_data_select_compute_modification_statements (GDA_DATA_SELECT (model), NULL);
grid = gdaui_grid_new (model);
+ gtk_widget_set_size_request (grid, -1, 350);
g_object_unref (model);
g_object_set (G_OBJECT (grid), "info-flags",
GDAUI_DATA_PROXY_INFO_CURRENT_ROW | GDAUI_DATA_PROXY_INFO_ROW_MODIFY_BUTTONS, NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]