[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: gEDA-user: Please test new grids for GTK PCB



On Mon, Feb 28, 2011 at 10:48:50AM +0000, jpka wrote:
> Krzysztof KoÅciuszkiewicz wrote:
> > * to have GtkTreeView updated you need to emit
> > "row-changed" signal, like:
> > 
> >     gtk_tree_model_row_changed (GTK_TREE_MODEL (model), path, &iter);
> 
> I find it, but unfortunately i can't write callback function correct
> (don't know or even can't imagine which arguments i must pass, i need 
> complete
> example)

There's no need to write a callback; default one will refresh the
GtkTreeView widget to include your changes to the model.

Please have a look at the attached patch.

BTW - selecting a grid that does have 0 spacing segfaults pcb.
BTW2 - why do you store grid mm and mil spacings as strings??
-- 
Krzysztof KoÅciuszkiewicz
"Simplicity is the ultimate sophistication" -- Leonardo da Vinci
From 73574b2f6d6736257bf22c9683ba2b9a45196a03 Mon Sep 17 00:00:00 2001
From: Krzysztof Kosciuszkiewicz <k.kosciuszkiewicz@xxxxxxxxx>
Date: Thu, 3 Mar 2011 01:12:06 +0100
Subject: [PATCH] hid/gtk: improvements to grid preferences window

---
 src/hid/gtk/gui-config.c |   76 ++++++++++++++++++++++-----------------------
 1 files changed, 37 insertions(+), 39 deletions(-)

diff --git a/src/hid/gtk/gui-config.c b/src/hid/gtk/gui-config.c
index 9eacfc0..e864da1 100644
--- a/src/hid/gtk/gui-config.c
+++ b/src/hid/gtk/gui-config.c
@@ -1394,42 +1394,42 @@ void dummy (void) {
 }
 
 
-void on_changed(GtkWidget *widget)
-//void on_changed(GtkWidget *widget, gpointer treeview)
-{
-  GtkTreeIter iter;
-  GtkTreeModel *model;
-  GtkTreePath *path;
-  gint *indexes;
-	//GtkListStore *store;
-	int i;
-
-  if (gtk_tree_selection_get_selected(
-      GTK_TREE_SELECTION(widget), &model, &iter)) {
-    path = gtk_tree_model_get_path(model, &iter);
-    indexes = gtk_tree_path_get_indices(path);
-    i = indexes[0];
-    if (i<0) i = 0;
-    if (i>(MAX_USER_GRIDS-1)) i = MAX_USER_GRIDS-1;
-//g_print("Row number %i selected.\n", i); /* FIXME remove after debug */
-	PCB->CurrentGrid = i;
-
-	if (Settings.DrawGrid) UpdateAll ();
-	ghid_set_status_line_label();
-
-/* FIXME */ g_print("Please fixme: \n"
-		"here's word 'Yes' must be placed at 'Current?' column and (i) line, \n"
-		"but i can't find a way to do it after a day fighting with gtk and hair tearing...\n");
-
-//	store = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (treeview)));
-//	gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (store), &iter, path);
-//	gtk_list_store_set (store, &iter, COL_GRIDCURRENT, "Yes", -1);
-
+static gboolean refresh_gridcurrent (GtkTreeModel *model,
+                                     GtkTreePath *path,
+                                     GtkTreeIter *iter,
+                                     gpointer data)
+{
+  GtkTreePath *selectedPath = (GtkTreePath*) data;
+  gtk_list_store_set (GTK_LIST_STORE (model),
+                      iter,
+                      COL_GRIDCURRENT,
+                      gtk_tree_path_compare (path, selectedPath) == 0 ? TRUE : FALSE,
+                      -1);
+  gtk_tree_model_row_changed (model, path, iter);
+  return FALSE;    // continue iterating
+}
+
+
+static void cb_toggled_active (GtkCellRendererToggle *cell,
+                               gchar                 *path_string,
+                               GtkTreeView           *view)
+{
+  GtkTreePath *path = gtk_tree_path_new_from_string (path_string);
+  gint *indices = gtk_tree_path_get_indices (path);
+  int i = CLAMP (indices[0], 0, MAX_USER_GRIDS-1);
+  if (PCB->CurrentGrid != i) {
+    PCB->CurrentGrid = i;
+    if (Settings.DrawGrid)
+      UpdateAll ();
+    ghid_set_status_line_label();
+    gtk_tree_model_foreach (gtk_tree_view_get_model (view),
+                            refresh_gridcurrent,
+                            path);
   }
+  gtk_tree_path_free (path);
 }
 
 
-
 static GtkWidget *create_grid_treeview (void) {
   GtkCellRenderer     *renderer;
   GtkTreeView         *treeview;
@@ -1439,7 +1439,7 @@ static GtkWidget *create_grid_treeview (void) {
   int i;
   char /*yyyyy[256],*/yyyyy2[256]; /* FIXME remove this ugly stuff */
 
-  store = gtk_list_store_new (NUM_COLS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT, G_TYPE_STRING);
+  store = gtk_list_store_new (NUM_COLS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT, G_TYPE_BOOLEAN);
   for (i=0; i<MAX_USER_GRIDS; i++) {
 //	  strcpy(yyyyy, c_dtostr((PCB->Grid[i])*COOR_TO_MM));
 	  strcpy(yyyyy2, c_dtostr((PCB->Grid[i]*COOR_TO_MIL)));
@@ -1449,12 +1449,18 @@ static GtkWidget *create_grid_treeview (void) {
 //						  COL_GRID_MIL, c_dtostr((PCB->Grid[i])*COOR_TO_MIL), - not work! :(
 						  COL_GRID_MIL, yyyyy2, // work but ugly...
 	                      COL_GRIDSTEP, PCB->GridStep[i],
-	                      COL_GRIDCURRENT, (i == PCB->CurrentGrid) ? "Yes":"",
+	                      COL_GRIDCURRENT, (i == PCB->CurrentGrid) ? TRUE : FALSE,
 	                      -1);
   }
   treeview = GTK_TREE_VIEW (gtk_tree_view_new_with_model (GTK_TREE_MODEL(store)));
   g_object_unref (store);
 
+  renderer = gtk_cell_renderer_toggle_new ();
+  gtk_cell_renderer_toggle_set_radio(renderer, true);
+  gtk_cell_renderer_toggle_set_activatable(renderer, true);
+  gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview), -1, "Current?", renderer, "active", COL_GRIDCURRENT, NULL);
+  g_signal_connect(renderer, "toggled", (GCallback) cb_toggled_active, treeview);
+
   renderer = gtk_cell_renderer_text_new ();
   g_object_set_data(G_OBJECT(renderer), "column", GUINT_TO_POINTER(COL_GRID_MM)); //give this column a some number to receive it in edit function
   g_object_set(renderer, "editable", TRUE, NULL);
@@ -1475,19 +1481,11 @@ static GtkWidget *create_grid_treeview (void) {
   gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview), -1, "Step", renderer, "text", COL_GRIDSTEP, NULL);
   g_signal_connect(renderer, "edited", (GCallback) cb_edited_step, treeview);
 
-  renderer = gtk_cell_renderer_text_new ();
-  gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview), -1, "Current?", renderer, "text", COL_GRIDCURRENT, NULL);
-
   select = gtk_tree_view_get_selection (treeview);
 /* FIXME next line is not work and looks as bug in GTK:
  * must be one line always selected, but no, when dialog opens,
  * no lines selected. */
   gtk_tree_selection_set_mode (select, GTK_SELECTION_BROWSE);
-//  g_signal_connect (G_OBJECT (select), "changed", G_CALLBACK (cb_get_selected), GTK_TREE_VIEW (treeview));
-//  g_signal_connect(select, "changed", G_CALLBACK(on_changed), NULL);
-//  g_signal_connect(select, "changed", G_CALLBACK(on_changed), GTK_TREE_VIEW (treeview));
-  g_signal_connect(select, "changed", G_CALLBACK(on_changed), select);
-
 
 
 //  return treeview;			// this was in example code,
-- 
1.7.1


_______________________________________________
geda-user mailing list
geda-user@xxxxxxxxxxxxxx
http://www.seul.org/cgi-bin/mailman/listinfo/geda-user