Re: Confused about radio menu items and signals



On Linux I built gtk2+-2.0 2.24.30 and linking against that library (instead of 2.24.23) solved my problem.

Thanks for your help that got me on the straight and narrow toward fixing this bug.

Matt

On 05/10/2016 09:07 PM, Matt Postiff wrote:
I tried same code on Windows with msys2, using gtk2 2.24.28 and it works correctly.

On Ubuntu Linux 14.04.4 trusty with gtk2 2.24.23 it fails to operate correctly.

I cannot condemn the library with 100% certainty, yet.

On 05/10/2016 02:48 PM, Matt Postiff wrote:
Thank you...you are enough of an expert! I had a mistake in how I connected the menu items together in a group. I had to init group=NULL and then do
    item = gtk_radio_menu_item_new_with_mnemonic (group, label);
    group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (item));
    three times in succession with A_item, B_item, and C_item
Now I do not get the situation where A=B=1 at one and the same time.

However, one 'feature' of my code still doesn't work. A,B, and C are different views that a textview can show. If I have two textviews T1 and T2 open, and T1 is in B state, and T2 is in A state, if I change active window from T1 to T2, the menu radio buttons are supposed to change accordingly.

So I should see a transition from state B to state A in the menu when I change textview focus. My debugging code shows that indeed happens. gtk_check_menu_item_set_active is called to set the new active state for the proper menu item. Everything shows the correct new state
A=1 (found via  calling gtk_check_menu_item_get_active(A_item))
B=0
C=0
However, even though B=0, the radio button next to B in the submenu is highlighted, and the next to A is not! I've been pulling my hair out on this...

Matt

On 05/09/2016 11:28 PM, Franco Broi wrote:
I'm no expert.., but seems like maybe your radio group isn't the same
for your 3 gtk_radio_menu_item_new_with_mnemonic calls, otherwise Gtk
handles toggling of the radio buttons for you.

Note, to prevent your callback being triggered when you call
gtk_check_menu_item_set_active, you can use
g_signal_handlers_block_by_func or one of its variants.

On Mon, 2016-05-09 at 22:34 -0400, Matt Postiff wrote:
Hi,

Still learning with gtk2. I have a menu with a submenu. That submenu
contains items for three mutually exclusive states in my program: A, B, and C.
Each menu item is created with code like:
A_menu_item = gtk_radio_menu_item_new_with_mnemonic(group, "label")

In the constructor, my program does
gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (A_menu_item),
true); // default
to set the checkmark next to A to start things.

Then if the user clicks on Menu | Submenu | B, it was my understanding
that B would get the checkmark/true, and A's checkmark would be auto
erased/false and I could process what is necessary when B becomes true.

I have a shared handler for activate signal on these menu items, and
when B is clicked, I see a situation where both A and B are true. What
am I missing?

I thought OK, maybe gtk leaves it to me to figure out which radio item
needs to be turned on, and turn the rest off. But this has me call
      gtk_check_menu_item_set_active(menuitem, false);
for each of the menuitems that shouldn't be on. This generates more
signals to my signal handler, and I end up with a mess of nested calls
to the signal handler and my program gets totally confused, not to
mention its author.

Thanks for any guidance. You all have been helpful to me before :-)

Matt

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






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