fix plugin loading

This commit is contained in:
Tim Bentley 2018-10-26 19:30:59 +01:00
parent 9546c1d9bf
commit 20dc4f81ed
12 changed files with 73 additions and 67 deletions

View File

@ -129,6 +129,9 @@ class MediaManagerItem(QtWidgets.QWidget, RegistryProperties):
self.has_file_icon = False
self.has_delete_icon = True
self.add_to_service_item = False
self.can_preview = True
self.can_make_live = True
self.can_add_to_service = True
def retranslateUi(self):
"""
@ -210,27 +213,30 @@ class MediaManagerItem(QtWidgets.QWidget, RegistryProperties):
icon=UiIcons().edit,
triggers=self.on_edit_click)
create_widget_action(self.list_view, separator=True)
create_widget_action(self.list_view,
'listView{plugin}{preview}Item'.format(plugin=self.plugin.name.title(),
preview=StringContent.Preview.title()),
text=self.plugin.get_string(StringContent.Preview)['title'],
icon=UiIcons().preview,
can_shortcuts=True,
triggers=self.on_preview_click)
create_widget_action(self.list_view,
'listView{plugin}{live}Item'.format(plugin=self.plugin.name.title(),
live=StringContent.Live.title()),
text=self.plugin.get_string(StringContent.Live)['title'],
icon=UiIcons().live,
can_shortcuts=True,
triggers=self.on_live_click)
create_widget_action(self.list_view,
'listView{plugin}{service}Item'.format(plugin=self.plugin.name.title(),
service=StringContent.Service.title()),
can_shortcuts=True,
text=self.plugin.get_string(StringContent.Service)['title'],
icon=UiIcons().add,
triggers=self.on_add_click)
if self.can_preview:
create_widget_action(self.list_view,
'listView{plugin}{preview}Item'.format(plugin=self.plugin.name.title(),
preview=StringContent.Preview.title()),
text=self.plugin.get_string(StringContent.Preview)['title'],
icon=UiIcons().preview,
can_shortcuts=True,
triggers=self.on_preview_click)
if self.can_make_live:
create_widget_action(self.list_view,
'listView{plugin}{live}Item'.format(plugin=self.plugin.name.title(),
live=StringContent.Live.title()),
text=self.plugin.get_string(StringContent.Live)['title'],
icon=UiIcons().live,
can_shortcuts=True,
triggers=self.on_live_click)
if self.can_add_to_service:
create_widget_action(self.list_view,
'listView{plugin}{service}Item'.format(plugin=self.plugin.name.title(),
service=StringContent.Service.title()),
can_shortcuts=True,
text=self.plugin.get_string(StringContent.Service)['title'],
icon=UiIcons().add,
triggers=self.on_add_click)
if self.has_delete_icon:
create_widget_action(self.list_view, separator=True)
create_widget_action(self.list_view,

View File

@ -103,6 +103,7 @@ class PluginManager(RegistryBase, LogMixin, RegistryProperties):
"""
Create the plugins' media manager items.
"""
aa = State().list_plugins()
for plugin in State().list_plugins():
if plugin.status is not PluginStatus.Disabled:
plugin.create_media_manager_item()
@ -114,7 +115,7 @@ class PluginManager(RegistryBase, LogMixin, RegistryProperties):
Tabs are set for all plugins not just Active ones
"""
for plugin in self.plugins:
for plugin in State().list_plugins():
if plugin.status is not PluginStatus.Disabled:
plugin.create_settings_tab(self.settings_form)
@ -124,7 +125,7 @@ class PluginManager(RegistryBase, LogMixin, RegistryProperties):
item to the import menu.
"""
for plugin in self.plugins:
for plugin in State().list_plugins():
if plugin.status is not PluginStatus.Disabled:
plugin.add_import_menu_item(self.main_window.file_import_menu)
@ -133,7 +134,7 @@ class PluginManager(RegistryBase, LogMixin, RegistryProperties):
Loop through all the plugins and give them an opportunity to add an
item to the export menu.
"""
for plugin in self.plugins:
for plugin in State().list_plugins():
if plugin.status is not PluginStatus.Disabled:
plugin.add_export_menu_item(self.main_window.file_export_menu)
@ -142,7 +143,7 @@ class PluginManager(RegistryBase, LogMixin, RegistryProperties):
Loop through all the plugins and give them an opportunity to add an
item to the tools menu.
"""
for plugin in self.plugins:
for plugin in State().list_plugins():
if plugin.status is not PluginStatus.Disabled:
plugin.add_tools_menu_item(self.main_window.tools_menu)
@ -152,7 +153,7 @@ class PluginManager(RegistryBase, LogMixin, RegistryProperties):
:param settings: The Settings object containing the old settings.
"""
for plugin in self.plugins:
for plugin in State().list_plugins():
if plugin.status is not PluginStatus.Disabled:
plugin.upgrade_settings(settings)
@ -160,7 +161,7 @@ class PluginManager(RegistryBase, LogMixin, RegistryProperties):
"""
Loop through all the plugins and give them an opportunity to initialise themselves.
"""
for plugin in self.plugins:
for plugin in State().list_plugins():
self.log_info('initialising plugins {plugin} in a {state} state'.format(plugin=plugin.name,
state=plugin.is_active()))
if plugin.is_active():
@ -171,7 +172,7 @@ class PluginManager(RegistryBase, LogMixin, RegistryProperties):
"""
Loop through all the plugins and give them an opportunity to clean themselves up
"""
for plugin in self.plugins:
for plugin in State().list_plugins():
if plugin.is_active():
plugin.finalise()
self.log_info('Finalisation Complete for {plugin}'.format(plugin=plugin.name))
@ -180,7 +181,7 @@ class PluginManager(RegistryBase, LogMixin, RegistryProperties):
"""
Return the plugin which has a name with value ``name``.
"""
for plugin in self.plugins:
for plugin in State().list_plugins():
if plugin.name == name:
return plugin
return None
@ -189,6 +190,6 @@ class PluginManager(RegistryBase, LogMixin, RegistryProperties):
"""
Loop through all the plugins and give them an opportunity to handle a new service
"""
for plugin in self.plugins:
for plugin in State().list_plugins():
if plugin.is_active():
plugin.new_service_created()

View File

@ -28,6 +28,7 @@ logging and a plugin framework are contained within the openlp.core module.
"""
import logging
from openlp.core.common.registry import Registry
from openlp.core.common.mixins import LogMixin
from openlp.core.lib.plugin import PluginStatus
@ -42,7 +43,7 @@ class StateModule(LogMixin):
super(StateModule, self).__init__()
self.name = None
self.order = 0
self.isPlugin = None
self.is_plugin = None
self.status = PluginStatus.Inactive
self.pass_preconditions = True
self.requires = None
@ -67,12 +68,12 @@ class State(LogMixin):
def save_settings(self):
pass
def add_service(self, name, order, isPlugin=False, status=PluginStatus.Active, requires=None):
def add_service(self, name, order, is_plugin=False, status=PluginStatus.Active, requires=None):
"""
Add a module to the array and lod dependancies. There will only be one item per module
:param name: Module name
:param order: Order fo display
:param isPlugin: Am I a plugin
:param order: Order to display
:param is_plugin: Am I a plugin
:param status: The active status
:param requires: Module name this requires
:return:
@ -81,7 +82,7 @@ class State(LogMixin):
state = StateModule()
state.name = name
state.order = order
state.plugin = isPlugin
state.is_plugin = is_plugin
state.status = status
state.requires = requires
state.required_by = []
@ -99,6 +100,13 @@ class State(LogMixin):
:return:
"""
self.modules[name].pass_preconditions = status
if self.modules[name].is_plugin:
plugin = Registry().get('{mod}_plugin'.format(mod=name))
if status:
self.log_debug('Plugin {plugin} active'.format(plugin=str(plugin.name)))
plugin.set_status()
else:
plugin.status = PluginStatus.Disabled
def flush_preconditions(self):
"""
@ -109,7 +117,11 @@ class State(LogMixin):
for mods in self.modules:
for req in self.modules[mods].required_by:
self.modules[req].pass_preconditions = self.modules[mods].pass_preconditions
# plugins_list = sorted(plugin_objects, key=lambda plugin: plugin.weight)
plugins_list = sorted(self.modules, key=lambda state: self.modules[state].order)
mdl = {}
for pl in plugins_list:
mdl[pl] = self.modules[pl]
self.modules = mdl
def is_module_active(self, name):
return self.modules[name].status == PluginStatus.Active
@ -130,6 +142,6 @@ class State(LogMixin):
def list_plugins(self):
plugins = []
for mod in self.modules:
if mod.isPlugin:
plugins.append(mod.name)
if self.modules[mod].is_plugin:
plugins.append(Registry().get('{mod}_plugin'.format(mod=mod)))
return plugins

View File

@ -147,7 +147,7 @@ class AlertsPlugin(Plugin):
self.alert_form = AlertForm(self)
register_endpoint(alerts_endpoint)
register_endpoint(api_alerts_endpoint)
State().add_service(self.name, self.weight, isPlugin=True)
State().add_service(self.name, self.weight, is_plugin=True)
State().update_pre_conditions(self.name, self.check_pre_conditions())
def add_tools_menu_item(self, tools_menu):

View File

@ -77,8 +77,8 @@ class BiblePlugin(Plugin):
self.manager = BibleManager(self)
register_endpoint(bibles_endpoint)
register_endpoint(api_bibles_endpoint)
State().add_service(self.name, self.weight, isPlugin=True)
State().update_pre_conditions(self.name, self.check_pre_conditions())
State().add_service('bible', self.weight, is_plugin=True)
State().update_pre_conditions('bible', self.check_pre_conditions())
def initialise(self):
"""

View File

@ -69,7 +69,7 @@ class CustomPlugin(Plugin):
self.icon = build_icon(self.icon_path)
register_endpoint(custom_endpoint)
register_endpoint(api_custom_endpoint)
State().add_service(self.name, self.weight, isPlugin=True)
State().add_service(self.name, self.weight, is_plugin=True)
State().update_pre_conditions(self.name, self.check_pre_conditions())
@staticmethod

View File

@ -60,8 +60,8 @@ class ImagePlugin(Plugin):
self.icon = build_icon(self.icon_path)
register_endpoint(images_endpoint)
register_endpoint(api_images_endpoint)
State().add_service(self.name, self.weight, isPlugin=True)
State().update_pre_conditions(self.name, self.check_pre_conditions())
State().add_service('image', self.weight, is_plugin=True)
State().update_pre_conditions('image', self.check_pre_conditions())
@staticmethod
def about():

View File

@ -112,6 +112,10 @@ class MediaMediaItem(MediaManagerItem, RegistryProperties):
self.has_file_icon = True
self.has_new_icon = False
self.has_edit_icon = False
if not State().check_preconditions('media'):
self.can_preview = False
self.can_make_live = False
self.can_add_to_service = False
def add_list_view_to_toolbar(self):
"""

View File

@ -65,7 +65,7 @@ class MediaPlugin(Plugin):
self.dnd_id = 'Media'
register_endpoint(media_endpoint)
register_endpoint(api_media_endpoint)
State().add_service(self.name, self.weight, requires='mediacontroller')
State().add_service(self.name, self.weight, requires='mediacontroller', is_plugin=True)
State().update_pre_conditions(self.name, self.check_pre_conditions())
def initialise(self):
@ -149,20 +149,3 @@ class MediaPlugin(Plugin):
# Add html code to htmlbuilder.
# """
# return self.media_controller.get_media_display_html()
def process_check_binary(program_path):
"""
Function that checks whether a binary MediaInfo is present
:param openlp.core.common.path.Path program_path:The full path to the binary to check.
:return: If exists or not
:rtype: bool
"""
runlog = check_binary_exists(program_path)
# Analyse the output to see it the program is mediainfo
for line in runlog.splitlines():
decoded_line = line.decode()
if re.search('MediaInfo Command line', decoded_line, re.IGNORECASE):
return True
return False

View File

@ -75,8 +75,8 @@ class PresentationPlugin(Plugin):
self.icon = build_icon(self.icon_path)
register_endpoint(presentations_endpoint)
register_endpoint(api_presentations_endpoint)
State().add_service(self.name, self.weight, isPlugin=True)
State().update_pre_conditions(self.name, self.check_pre_conditions())
State().add_service('presentation', self.weight, is_plugin=True)
State().update_pre_conditions('presentation', self.check_pre_conditions())
def create_settings_tab(self, parent):
"""

View File

@ -100,7 +100,7 @@ class SongsPlugin(Plugin):
self.songselect_form = None
register_endpoint(songs_endpoint)
register_endpoint(api_songs_endpoint)
State().add_service(self.name, self.weight, isPlugin=True)
State().add_service(self.name, self.weight, is_plugin=True)
State().update_pre_conditions(self.name, self.check_pre_conditions())
def check_pre_conditions(self):

View File

@ -67,8 +67,8 @@ class SongUsagePlugin(Plugin):
self.weight = -4
self.icon = UiIcons().song_usage
self.song_usage_active = False
State().add_service(self.name, self.weight, isPlugin=True)
State().update_pre_conditions(self.name, self.check_pre_conditions())
State().add_service('song_usage', self.weight, is_plugin=True)
State().update_pre_conditions('song_usage', self.check_pre_conditions())
def check_pre_conditions(self):
"""