Re: Focus vs Sensitivity

2012-12-27 Thread Ivan Baldo
  David: Y O U   R O C K ! ! !
  Amazing explanation! Now I understand what happens! And excellent
workaround too!!!
  Thanks a lot for putting the effort to explain it, look for the GTK+
warning and providing a way to fix it!
  Just perfect!
  Now I have a lot of work to do to change a lot of spinbuttons ;-).
  Have a great 2013!
P.s.: sorry for the late reply but been too busy, crazy times, everyone
wants something before the year ends!

-- 
Iván Baldo
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Focus vs Sensitivity

2012-12-22 Thread David Nečas
On Fri, Dec 21, 2012 at 07:16:07PM -0200, Ivan Baldo wrote:
 What happens is that the Tab handler runs before the value-changed
 handler

This is the wrong view what happens.  The adjustment value is not
updated during user's editing of the entry.  If the spin button is not
set to numeric its entry can contain any text during the editing
(whereas setting numeric ensures the entry contents always parses as a
number, making impossible to enter numbers in the scientific format, for
instance).  The value is updated when editing finishes, for which one
possibility is that the entry loses focus.  So *first* the focus leaves
the entry then *in consequence* the adjustment value is updated.

However, this does not seem to be entirely the core of your problem.
The CRITICAL errors are printed becuase in gtk_window_real_set_focus()
this:

if (priv-has_focus)
do_focus_change (priv-focus_widget, TRUE);

g_object_notify (G_OBJECT (priv-focus_widget), is-focus);

assumes that do_focus_change() cannot make priv-focus_widget become
NULL.  IMO there may be sane use cases when this can occur (like yours)
so I would try to report a bug.

How to work around it?  Instead of connecting to value-changed monitor
all changes to the entry text:

g_signal_connect(spin_button, changed, G_CALLBACK(spin_entry_changed), 
spin_button2);

...

static void
spin_entry_changed(GtkEntry *entry, GtkWidget *target)
{
gtk_widget_set_sensitive(target, g_strtod(gtk_entry_get_text(entry), 
NULL) != 0);
}

This will *also* make the second entry insensitive when the content of
the first does not parse as a number at all (which is likely a good
thing though perhaps not).

Regards,

Yeti

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Focus vs Sensitivity

2012-12-21 Thread Ivan Baldo
/*
Given 3 spin buttons, I want the second one to be enabled or disabled
based on input from the
first one.
If in the first one the user puts 0 as value I want that when it
presses Tab the focus go to the
third spin button.
If in the first one the user puts a value different than zero I want
that when it presses Tab
the focus go to the seconds spin button.
What happens is that the Tab handler runs before the value-changed
handler so when the
value-changed handler sets the sensitivity of the second spin button Gtk+
complains of errors
internally or passes the focus to the third spin button instead of the
second.
I imagine I could solve it by setting the focus by hand in my
value-changed handler but I am
looking for an easier way because I have a large application with lots of
these interactions and
also I don't know if that solves the Gtk+ error.
I would love that Gtk+ emitted the value-changed signal before it
handled the Tab key...
If you know another way to solve the problem then please email
iba...@adinet.com.uy, thanks!!!
Based on
http://developer.gnome.org/gnome-devel-demos/unstable/spinbutton.c.html.
Compile with:
gcc focus_problem.c `pkg-config --cflags --libs gtk+-3.0` -o focus_problem
*/
#include gtk/gtk.h


static void spin_value_changed (GtkSpinButton *spin_button, gpointer
user_data)
{
fprintf (stderr, %s: before set_sensitive\n, __func__);
GtkWidget * const spin_button2 = user_data;
const gint value = gtk_spin_button_get_value_as_int (spin_button);
gtk_widget_set_sensitive (spin_button2, value);
fprintf (stderr, %s: after set_sensitive\n, __func__);
}


static void activate (GtkApplication *app, gpointer user_data)
{
GtkWidget * const window = gtk_application_window_new (app);
gtk_window_set_title (GTK_WINDOW (window), Focus Problem);
//gtk_window_set_default_size (GTK_WINDOW (window), 210, 70);
gtk_container_set_border_width (GTK_CONTAINER (window), 5);

GtkWidget * const label = gtk_label_new (
Enter 1 to enable middle spinbutton, 0 to disable it:);

GtkAdjustment * const adjustment = gtk_adjustment_new (1, 0, 100, 1,
10, 0);
GtkWidget * const spin_button = gtk_spin_button_new (adjustment, 0, 0);
//gtk_widget_set_hexpand (spin_button, TRUE);

GtkAdjustment * const adjustment2 = gtk_adjustment_new (0, 0, 100, 1,
10, 0);
GtkWidget * const spin_button2 = gtk_spin_button_new (adjustment2, 0,
0);

GtkAdjustment * const adjustment3 = gtk_adjustment_new (0, 0, 100, 1,
10, 0);
GtkWidget * const spin_button3 = gtk_spin_button_new (adjustment3, 0,
0);

g_signal_connect (spin_button, value-changed, G_CALLBACK
(spin_value_changed), spin_button2);

/* Create a grid and arrange everything accordingly */
GtkWidget * const grid = gtk_grid_new ();
gtk_grid_set_column_spacing (GTK_GRID (grid), 5);
//gtk_grid_set_column_homogeneous (GTK_GRID (grid), TRUE);
gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 1, 1);
gtk_grid_attach (GTK_GRID (grid), spin_button, 1, 0, 1, 1);
gtk_grid_attach (GTK_GRID (grid), spin_button2, 1, 1, 1, 1);
gtk_grid_attach (GTK_GRID (grid), spin_button3, 1, 2, 1, 1);

gtk_container_add (GTK_CONTAINER (window), grid);

gtk_widget_show_all (window);
}


int main (int argc, char **argv)
{
GtkApplication *app;
int status;

app = gtk_application_new (org.gtk.example, G_APPLICATION_FLAGS_NONE);
g_signal_connect (app, activate, G_CALLBACK (activate), NULL);
status = g_application_run (G_APPLICATION (app), argc, argv);
g_object_unref (app);

return status;
}


-- 
Iván Baldo
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list