add generic Extras menu contribution extension point

gtk2 implementation.
This commit is contained in:
Eric Le Lay 2017-06-25 09:43:36 +02:00
parent a4365c99d6
commit ab7b97e830
3 changed files with 48 additions and 0 deletions

View file

@ -37,3 +37,17 @@ class gPodderExtension:
def on_unload(self):
logger.info('Extension is being unloaded.')
def on_ui_object_available(self, name, ui_object):
"""
Called by gPodder when ui is ready
"""
if name == 'gpodder-gtk':
self.gpodder = ui_object
def on_create_menu(self):
return [("Say Hello", self.say_hello_cb)]
def say_hello_cb(self):
print("HELLO")
self.gpodder.notification("Hello Extension", "Message", widget=self.gpodder.main_window)

View file

@ -505,6 +505,20 @@ class ExtensionManager(object):
"""
pass
@call_extensions
def on_create_menu(self):
"""Called when the Extras menu is created
You can add additional Extras menu entries here. You have to return a
list of tuples, where the first item is a label and the second item is a
callable that will get no parameter.
Example return value:
[('Sync to Smartphone', lambda : ...)]
"""
pass
@call_extensions
def on_episodes_context_menu(self, episodes):
"""Called when the episode list context menu is opened

View file

@ -231,6 +231,8 @@ class gPodder(BuilderWidget, dbus.service.Object):
# Set up the first instance of MygPoClient
self.mygpo_client = my.MygPoClient(self.config)
self.inject_extensions_menu()
gpodder.user_extensions.on_ui_initialized(self.model,
self.extensions_podcast_update_cb,
self.extensions_episode_download_cb)
@ -277,6 +279,24 @@ class gPodder(BuilderWidget, dbus.service.Object):
self.config.software_update.last_check = int(time.time())
self.check_for_updates(silent=True)
def inject_extensions_menu(self):
def gen_callback(label, callback):
return lambda widget: callback()
extension_entries = gpodder.user_extensions.on_create_menu()
if extension_entries:
for i, (label, callback) in enumerate(extension_entries):
action_id = "ext.action_%d" % i
action = gtk.Action(action_id, label, label, None)
action.connect('activate', gen_callback(label, callback))
self.actiongroup1.add_action(action)
uimanager = self.uimanager1
merge_id = uimanager.new_merge_id()
uimanager.add_ui(merge_id, "ui/mainMenu/menuExtras", action_id, action_id, gtk.UI_MANAGER_MENUITEM, False)
def find_partial_downloads(self):
def start_progress_callback(count):
self.partial_downloads_indicator = ProgressIndicator(