Delete menu

23 views
Skip to first unread message

Fidel Pérez

unread,
Jun 18, 2013, 9:09:08 AM6/18/13
to leo-e...@googlegroups.com
Hi, I was wondering if someone could give me a hand with deleting a menu:

#This creates the menu:
menuname='test1'
MenuToDelete = c.frame.menu.createNewMenu(menuname)

#Then i try to delete it with several comands found in leopyref:
MenuToDelete.deleteMenu(menuname)
MenuToDelete.destroyMenu(menuname)

#And then:
c.frame.top.leo_menubar.repaint()

But cant remove the new created menu from the menu bar. Using Qt.

Thank you.

Fidel Pérez

unread,
Jun 18, 2013, 6:54:31 PM6/18/13
to leo-e...@googlegroups.com
Well, I think I should be able to extract those functionalities from studying "file -> recent files" menu.
It is located in leopyref.leo. This is the class:

class RecentFilesManager
 
The important part seems to be:

    # Delete all previous entries.
menu.deleteRecentFilesMenuItems(recentFilesMenu)
# Create the permanent (static) menu entries.
table = rf.getRecentFilesTable()
menu.createMenuEntries(recentFilesMenu,table)

 Tomorrow will go on studying and see if I can pop that one out.

I would like to replicate that possibility, to add a list of commands with pre-set hotkeys such as "A B C D E F..." on the dinamic menu I will create, same as it already happens with the recent files menu.


Fidel Pérez

unread,
Jun 19, 2013, 1:10:01 PM6/19/13
to leo-e...@googlegroups.com
And finally got the solution!! =)
Sample working code on how to create menu, buttons on the menu, then delete them:

#Get the menu in case it alread exists
MenuToDelete = c.frame.menu.createNewMenu('Programming')

def MyCommand():
    g.es('yeah')

#Add command to the menu. It will add it with the corresponding hotkey, number [c.db['Button_NextID']] from the string 1234... etc
c.add_command(c.frame.menu.getMenu('Programming'), label = "%s %s" % ('1234567890QWERTYUIOPASDFGHJKLZXCVBNM'[c.db['Button_NextID']],c.db['Button_NextStatusLine']), command=MyCommand, underline=0)


#And now we delete the button range we want on the menu:

MenuToDelete .delete_range(MenuToDelete ,0,2)

Terry Brown

unread,
Jun 19, 2013, 1:12:41 PM6/19/13
to leo-e...@googlegroups.com
On Tue, 18 Jun 2013 06:09:08 -0700 (PDT)
Fidel Pérez <fidel...@gmail.com> wrote:

> Hi, I was wondering if someone could give me a hand with deleting a menu:

Sounds like you've done enough investigating do be more familiar with
that code than I am. For your use I would probably just try and
isolate the Qt level menu representation and use Qt methods to delete
things, but if you can find Leo API calls that will do it that's good.

Cheers -Terry
Reply all
Reply to author
Forward
0 new messages