On Mon, May 13, 2013 at 3:23 PM, Jacob Peck <[email protected]> wrote:

> Hello all,
>
> How do I add menu items to the File menu from a plugin?


Fidel's response will add items to the menus for already existing
commands.  As I understand your question, your plugin wants to add menus
programmatically.

The best way to do that is to use the wrapper methods in leoPy.leo:

    Code-->Qt gui-->@file ../plugins/qtGui.py-->
    Frame and component classes...-->class leoQtMenu (leoMenu)-->
    Tkinter menu bindings

As I write this, I see that this node is somewhat misnamed.  The methods
you want are likely:

   def add_cascade (self,parent,label,menu,underline):

        """Wrapper for the Tkinter add_cascade menu method.

        Adds a submenu to the parent menu, or the menubar."""

    def add_command (self,**keys):

        """Wrapper for the Tkinter add_command menu method."""

    def insert_cascade (self,parent,index,label,menu,underline):

        """Wrapper for the Tkinter insert_cascade menu method."""

    def getMenuLabel (self,menu,name):

        '''Return the index of the menu item whose name (or offset) is
given.
        Return None if there is no such menu item.'''

The code for these methods is relatively straightforward, and may be more
informative than the comments.

Because Leo allows menus to be created from @menu items, the code (in the
gui-independent leoMenu.py) that calls these methods from Leo's core is
hairy.  See, for example, createNewMenu.  But your plugin's code knows what
items it wants to create, and where, so the plugin's code will be simpler.

Please feel free to ask more questions.

Edward

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/leo-editor?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to