Merge pull request #322 from elelay/extensions-extras-menu
new on_create_menu and on_application_started extension points.
This commit is contained in:
commit
f75723311f
|
@ -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)
|
||||
|
|
|
@ -18,5 +18,8 @@ class gPodderExtension:
|
|||
|
||||
def on_ui_object_available(self, name, ui_object):
|
||||
if name == 'gpodder-gtk':
|
||||
ui_object.main_window.iconify()
|
||||
self.ui_object = ui_object
|
||||
|
||||
def on_application_started(self):
|
||||
if self.ui_object:
|
||||
self.ui_object.main_window.iconify()
|
||||
|
|
|
@ -30,6 +30,6 @@ class gPodderExtension:
|
|||
if name == 'gpodder-gtk':
|
||||
self.gpodder = ui_object
|
||||
|
||||
def on_ui_initialized(self, model, update_podcast_callback,
|
||||
download_episode_callback):
|
||||
def on_application_started(self):
|
||||
if self.gpodder:
|
||||
self.gpodder.update_feed_cache()
|
||||
|
|
|
@ -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
|
||||
|
@ -582,3 +596,15 @@ class ExtensionManager(object):
|
|||
"""
|
||||
pass
|
||||
|
||||
@call_extensions
|
||||
def on_application_started(self):
|
||||
"""Called when the application started.
|
||||
|
||||
This is for extensions doing stuff at startup that they don't
|
||||
want to do if they have just been enabled.
|
||||
e.g. minimize at startup should not minimize the application when
|
||||
enabled but only on following startups.
|
||||
|
||||
It is called after on_ui_object_available and on_ui_initialized.
|
||||
"""
|
||||
pass
|
||||
|
|
|
@ -409,6 +409,10 @@ class gPodderPreferences(BuilderWidget):
|
|||
|
||||
if new_enabled == now_enabled:
|
||||
model.set_value(it, self.C_TOGGLE, new_enabled)
|
||||
if now_enabled:
|
||||
self.on_extension_enabled(container.module)
|
||||
else:
|
||||
self.on_extension_disabled(container.module)
|
||||
elif container.error is not None:
|
||||
self.show_message(container.error.message,
|
||||
_('Extension cannot be activated'), important=True)
|
||||
|
|
|
@ -118,6 +118,8 @@ class gPodder(BuilderWidget, dbus.service.Object):
|
|||
self.db = self.core.db
|
||||
self.model = self.core.model
|
||||
self.options = options
|
||||
self.extensions_merge_ids = []
|
||||
self.extensions_actions = []
|
||||
BuilderWidget.__init__(self, None)
|
||||
|
||||
def new(self):
|
||||
|
@ -231,10 +233,14 @@ 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)
|
||||
|
||||
gpodder.user_extensions.on_application_started()
|
||||
|
||||
# load list of user applications for audio playback
|
||||
self.user_apps_reader = UserAppsReader(['audio', 'video'])
|
||||
util.run_in_background(self.user_apps_reader.read)
|
||||
|
@ -277,6 +283,35 @@ 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):
|
||||
"""
|
||||
Update Extras/Extensions menu.
|
||||
Called at startup and when en/dis-abling extenstions.
|
||||
"""
|
||||
def gen_callback(label, callback):
|
||||
return lambda widget: callback()
|
||||
|
||||
for action in self.extensions_actions:
|
||||
self.actiongroup1.remove_action(action)
|
||||
self.extensions_actions = []
|
||||
uimanager = self.uimanager1
|
||||
for merge_id in self.extensions_merge_ids:
|
||||
uimanager.remove_ui(merge_id)
|
||||
self.extensions_merge_ids = []
|
||||
|
||||
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)
|
||||
self.extensions_actions.append(action)
|
||||
|
||||
merge_id = uimanager.new_merge_id()
|
||||
uimanager.add_ui(merge_id, "ui/mainMenu/menuExtras", action_id, action_id, gtk.UI_MANAGER_MENUITEM, False)
|
||||
self.extensions_merge_ids.append(merge_id)
|
||||
|
||||
def find_partial_downloads(self):
|
||||
def start_progress_callback(count):
|
||||
self.partial_downloads_indicator = ProgressIndicator(
|
||||
|
@ -2915,7 +2950,9 @@ class gPodder(BuilderWidget, dbus.service.Object):
|
|||
parent_window=self.main_window, \
|
||||
mygpo_client=self.mygpo_client, \
|
||||
on_send_full_subscriptions=self.on_send_full_subscriptions, \
|
||||
on_itemExportChannels_activate=self.on_itemExportChannels_activate)
|
||||
on_itemExportChannels_activate=self.on_itemExportChannels_activate, \
|
||||
on_extension_enabled=self.on_extension_enabled, \
|
||||
on_extension_disabled=self.on_extension_disabled)
|
||||
|
||||
def on_goto_mygpo(self, widget):
|
||||
self.mygpo_client.open_website()
|
||||
|
@ -3503,6 +3540,17 @@ class gPodder(BuilderWidget, dbus.service.Object):
|
|||
for url, message in failed_urls]),
|
||||
_('Could not migrate some subscriptions'), important=True)
|
||||
|
||||
def on_extension_enabled(self, extension):
|
||||
if getattr(extension, 'on_ui_object_available', None) is not None:
|
||||
extension.on_ui_object_available('gpodder-gtk', self)
|
||||
if getattr(extension, 'on_ui_initialized', None) is not None:
|
||||
extension.on_ui_initialized(self.model,
|
||||
self.extensions_podcast_update_cb,
|
||||
self.extensions_episode_download_cb)
|
||||
self.inject_extensions_menu()
|
||||
|
||||
def on_extension_disabled(self, extension):
|
||||
self.inject_extensions_menu()
|
||||
|
||||
def main(options=None):
|
||||
gobject.threads_init()
|
||||
|
|
Loading…
Reference in a new issue