afrancoto / WebMenu

Rhythmbox 3 third party plugin WebMenu
6 stars 2 forks source link

Existing shortcuts don't update when changed #18

Closed afrancoto closed 12 years ago

afrancoto commented 12 years ago

Again, a draw_menu problem

 def draw_menu(self, shell):
    global action_group, action_group_submenus
    global ui_id, ui_manager

    menu_not_drawn=False #Usually the function is called by apply_settings, so the menu is already drawn

    try: ui_id
    except NameError: menu_not_drawn=True #If the ui_context_id does not exist, the menu is not yet drawn, so it is not deleted

    if not menu_not_drawn :
    ui_manager.remove_ui(ui_id) #Delete a previous drawn menu
    ui_manager.remove_action_group(action_group_submenus)
    del ui_id, action_group_submenus
    ui_manager.ensure_update()  

    #0. Web Menu
    action_group_submenus= Gtk.ActionGroup(name='WebMenuSubmenusActionGroup')
    ui_album=''
    for service in services_order:
    if services[service][1] is not '':  #If the album URL is empty does not display the option
        #Add a new submenu item 
            action_name = 'album_%s' % service
            ui_album += '' % (service, action_name) #ui_album is the Album submenu
            #Create the action
            action = Gtk.Action( action_name, service, _('Look for the current album on %s' % service), '' )
            action.connect( 'activate', self.unique_search_function, shell, 1, service)

        shortcut_exist=True #Checks if a shortcut exist for a service   
        try: shortcuts[service]
        except: shortcut_exist=False

            if (shortcut_exist) and (shortcuts[service][0] is not ''): #If the shortcut exist and we are in thr right submenu, it's added
            action_group_submenus.add_action_with_accel(action, shortcuts[service][0]) 
                        print "Album shortcut: "+service+" -->"+shortcuts[service][0
        else: action_group_submenus.add_action(action)
afrancoto commented 12 years ago

action_group_submenus is updated correctly:

(20:02:01) [0x836c0a0] [WebMenuPlugin.draw_menu] .local/share/rhythmbox/plugins/WebMenu/WebMenu.py:215: Album shortcut: Wikipedia -->L
(20:02:01) [0x836c0a0] [WebMenuPlugin.draw_menu] .local/share/rhythmbox/plugins/WebMenu/WebMenu.py:215: Album shortcut: RateYourMusic -->K

(20:02:20) [0x836c0a0] [WebMenuPlugin.draw_menu] .local/share/rhythmbox/plugins/WebMenu/WebMenu.py:215: Album shortcut: Wikipedia -->F
(20:02:20) [0x836c0a0] [WebMenuPlugin.draw_menu] .local/share/rhythmbox/plugins/WebMenu/WebMenu.py:215: Album shortcut: RateYourMusic -->K

But not the ui_manager! This is a problem only when an existing shortcut is edited, not when it is deleted or a new one is created.

afrancoto commented 12 years ago

Idea: change the name of the 'action_group_submenus' at every refresh, something like:

refresh_counter=0

def draw_menu (self, shell):
   global refresh counter
   [...]
   ui_manager.remove_action_group (action_group_submenus)
   del ui_id, action_group_submenus
   ui_manager.ensure_update ()  

   action_group_submenus = Gtk.ActionGroup (name = 'WebMenuSubmenusActionGroup'+str(refresh_counter))
   refresh_counter+=1

I can't use Linux until this night or tomorrow, but maybe it works!

afrancoto commented 12 years ago

It worked!