Using Actions + MenuItems + Accelerators + AccelLabels

View: New views
4 Messages — Rating Filter:   Alert me  

Using Actions + MenuItems + Accelerators + AccelLabels

by Manuel Alejandro Cerón Estrada-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello.

I have a bunch of actions and a MenuBar. Every MenuItem in the MenuBar
has an associated action. I'm using "related action" and "use action
appearance" to connect the actions with the menu. Now I want to assign
some shortcut keys to each action. I haven't found a way to do that in
Glade, so I'm doing it with code. I'm creating an ActionGroup and then
adding each action to that group using add_action_with_accel. Then I
create an AccelGroup and assign each action to it using
action.set_accel_group and connect the accelerator using
action.connect_accelerator. After that, I add the AccelGroup to the
window using window.set_accel_group. This seems to work, when I press
the keyboard shortcut the action is activated, however, the menu item
does not show the AccelLabel indicating the accelerator for that item.
How do I achieve this? Is there an easier way?

I'm using PyGTK and glade 3.6.3

Manuel.
_______________________________________________
Glade-users maillist  -  Glade-users@...
http://lists.ximian.com/mailman/listinfo/glade-users

Re: Using Actions + MenuItems + Accelerators + AccelLabels

by Alexey Kurochkin :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Sat, 2009-10-03 at 20:43 -0500, Manuel Alejandro Cerón Estrada wrote:

> Hello.
>
> I have a bunch of actions and a MenuBar. Every MenuItem in the MenuBar
> has an associated action. I'm using "related action" and "use action
> appearance" to connect the actions with the menu. Now I want to assign
> some shortcut keys to each action. I haven't found a way to do that in
> Glade, so I'm doing it with code. I'm creating an ActionGroup and then
> adding each action to that group using add_action_with_accel. Then I
> create an AccelGroup and assign each action to it using
> action.set_accel_group and connect the accelerator using
> action.connect_accelerator. After that, I add the AccelGroup to the
> window using window.set_accel_group. This seems to work, when I press
> the keyboard shortcut the action is activated, however, the menu item
> does not show the AccelLabel indicating the accelerator for that item.
> How do I achieve this? Is there an easier way?

I'd like to see the answer too. Currently I create only the main menu
bar and empty sub menus with Glade, and all the menu items are created
and appended to the sub menus manually in the code. It results in
hundreds of lines of clutter which I'm looking forward to get rid of.

>
> I'm using PyGTK and glade 3.6.3
>
> Manuel.
> _______________________________________________
> Glade-users maillist  -  Glade-users@...
> http://lists.ximian.com/mailman/listinfo/glade-users
>


_______________________________________________
Glade-users maillist  -  Glade-users@...
http://lists.ximian.com/mailman/listinfo/glade-users

Parent Message unknown Re: Using Actions + MenuItems + Accelerators + AccelLabels

by Alexey Kurochkin :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Mon, 2009-10-05 at 11:41 -0500, Manuel Alejandro Cerón Estrada wrote:

> 2009/10/5 Alexey Kurochkin <alexey.kurochkin@...>:
>
> > I'd like to see the answer too. Currently I create only the main menu
> > bar and empty sub menus with Glade, and all the menu items are created
> > and appended to the sub menus manually in the code. It results in
> > hundreds of lines of clutter which I'm looking forward to get rid of.
>
> I've been looking information about it, and there are two problems:
> First, Glade currently doesn't support GtkActionGroup well. Second
> GTK+ doesn't have a property for accelerator in GtkAction, the only
> way to assign accelerators to actions is using
> GtkActionGroup.add_action_with_accel(). Thereby, we have for one of
> those problems to be fixed.
>
> My current approach for the problem, trying to avoid clutter code as
> much as possible, is: Creating the main menu using GtkUIManager
> instead of Glade. I manually wrote my main menu using a UIManager xml
> description. Something like this:
>
> <ui>
> <menubar name="mainmenu">
> <menu name="file_menu" action="file_action">
> <menuitem name="open_recording_menuitem" action="open_recording_action"/>
> <menuitem name="open_recording2_menuitem" action="open_recording2_action"/>
> <separator/>
> <menuitem name="quit_menuitem" action="quit_action"/>
> </menu>
> ...
> </menubar>
> </ui>
>
> The actions referred in the UIManager file are created in the Glade
> file. Then, in code I do:
>
> - Create an GtkActionGroup and add all the actions defined in the
> Glade file to it.
> - Create a UIManager and load the file with the menu defined.
> - Insert the ActionGroup to the UIManager
> - Assign the AccelGroup of the UIManager to the current window.
> - Get the main menu from the UIManager and manually insert it in the window.
>
> Manuel.
>

I used to do it before, but I've found it rather inconvenient for two
reasons. First, writing xml by hand is not that much different from
copy/paste five lines of code per menu item (get action from builder,
set accelerator group for it, add it to the group, create menu item from
the action, and append it to the menu shell). I can write GtkBuilder xml
too, but what I need Glade for then? Second, the changes to the ui file
have to be synchronized with code and/or glade anyway, so I figured it
is less hassle to keep it all in one source file despite the length. It
is easier to maintain this way. I'm not going back to ui manager unless
I'd really need to build dynamic (merge/unmerge) menus.


_______________________________________________
Glade-users maillist  -  Glade-users@...
http://lists.ximian.com/mailman/listinfo/glade-users

Re: Using Actions + MenuItems + Accelerators + AccelLabels

by Tristan Van Berkom-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Mon, Oct 5, 2009 at 12:54 PM, Alexey Kurochkin
<alexey.kurochkin@...> wrote:

> On Sat, 2009-10-03 at 20:43 -0500, Manuel Alejandro Cerón Estrada wrote:
>> Hello.
>>
>> I have a bunch of actions and a MenuBar. Every MenuItem in the MenuBar
>> has an associated action. I'm using "related action" and "use action
>> appearance" to connect the actions with the menu. Now I want to assign
>> some shortcut keys to each action. I haven't found a way to do that in
>> Glade, so I'm doing it with code. I'm creating an ActionGroup and then
>> adding each action to that group using add_action_with_accel. Then I
>> create an AccelGroup and assign each action to it using
>> action.set_accel_group and connect the accelerator using
>> action.connect_accelerator. After that, I add the AccelGroup to the
>> window using window.set_accel_group. This seems to work, when I press
>> the keyboard shortcut the action is activated, however, the menu item
>> does not show the AccelLabel indicating the accelerator for that item.
>> How do I achieve this? Is there an easier way?
>
> I'd like to see the answer too. Currently I create only the main menu
> bar and empty sub menus with Glade, and all the menu items are created
> and appended to the sub menus manually in the code. It results in
> hundreds of lines of clutter which I'm looking forward to get rid of.

Hmmm ok from what I understand there is probably a bug here, plus
a couple of shortcomings in the whole builder/menu system.

If I understand correctly the menu item not updating the accelerator
when the action accel path and accel group is setup is a bug, and
should be filed for GTK+.

One of the gaps that is ridiculously easy to bridge is the fact
that we cannot setup accel groups properly in Glade, this
requires that GtkActionGroup implement GtkBuildable in order
to implement the ->add_child() method to add actions to groups
from a GtkBuilder xml... (and then some code in Glade to allow
you to parent the actions).

The other I guess is that setting accelerators on action in Glade
is not obvious, so much so that I dont have a clue how it works
honestly... all I know is that we can setup the accel group, and
we can set the accel path... and I know the accel path is a const gchar *.
so I know we can set it up from Glade.

Apart from that I have no idea what an accel path does, I've looked
at the GTK+ docs several times this past week (because I wanted
to answer this email actually), and I still have no idea what to do
with a const gchar *accel_path :-/

So that being said, sorry for the delay in answering, these loose
strings are few.. but tying them up could undoubtedly save many
people hundreds of lines of code...

I do wish I could promise to address these issues myself, as
they are pretty simple, but I really cant find the time right now.


>
>>
>> I'm using PyGTK and glade 3.6.3
>>
>> Manuel.
>> _______________________________________________
>> Glade-users maillist  -  Glade-users@...
>> http://lists.ximian.com/mailman/listinfo/glade-users
>>
>
>
> _______________________________________________
> Glade-users maillist  -  Glade-users@...
> http://lists.ximian.com/mailman/listinfo/glade-users
>
_______________________________________________
Glade-users maillist  -  Glade-users@...
http://lists.ximian.com/mailman/listinfo/glade-users