Api improvements

This commit is contained in:
Tim Bentley 2020-04-26 21:37:35 +00:00
parent b85245465e
commit da01b2a8f2
5 changed files with 68 additions and 9 deletions

View File

@ -18,7 +18,7 @@
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see <https://www.gnu.org/licenses/>. #
##########################################################################
import logging
from openlp.core.api.lib import login_required
from flask import jsonify, request, abort, Blueprint
@ -27,6 +27,7 @@ from openlp.core.common.registry import Registry
service_views = Blueprint('service', __name__)
log = logging.getLogger(__name__)
@service_views.route('/items')
@ -59,24 +60,44 @@ def service_items():
def service_set():
data = request.json
if not data:
log.error('Missing request data')
abort(400)
try:
id = int(data.get('id', -1))
except ValueError:
log.error('Invalid data passed ' + data)
abort(400)
Registry().get('service_manager').servicemanager_set_item.emit(id)
return '', 204
@service_views.route('/show_id', methods=['POST'])
@login_required
def service_set_by_uid():
data = request.json
if not data:
log.error('Missing request data')
abort(400)
try:
id = str(data.get('uid', ''))
except ValueError:
log.error('Invalid data passed ' + data)
abort(400)
Registry().get('service_manager').servicemanager_set_item_by_uuid.emit(id)
return '', 204
@service_views.route('/progress', methods=['POST'])
@login_required
def service_direction():
ALLOWED_ACTIONS = ['next', 'previous']
data = request.json
if not data:
log.error('Missing request data')
abort(400)
action = data.get('action', '').lower()
if action not in ALLOWED_ACTIONS:
log.error('Invalid data passed ' + str(data))
abort(400)
getattr(Registry().get('service_manager'), 'servicemanager_{action}_item'.format(action=action)).emit()
return '', 204

View File

@ -155,7 +155,6 @@ class PluginManager(RegistryBase, LogMixin, RegistryProperties):
Loop through all the plugins and give them an opportunity to initialise themselves.
"""
uninitialised_plugins = []
for plugin in State().list_plugins():
if plugin:
self.log_info('initialising plugins {plugin} in a {state} state'.format(plugin=plugin.name,
@ -168,7 +167,6 @@ class PluginManager(RegistryBase, LogMixin, RegistryProperties):
uninitialised_plugins.append(plugin.name.title())
self.log_exception('Unable to initialise plugin {plugin}'.format(plugin=plugin.name))
display_text = ''
if uninitialised_plugins:
display_text = translate('OpenLP.PluginManager', 'Unable to initialise the following plugins:') + \
'\n\n'.join(uninitialised_plugins) + '\n\n'

View File

@ -313,6 +313,7 @@ class ServiceManager(QtWidgets.QWidget, RegistryBase, Ui_ServiceManager, LogMixi
Also handles the UI tasks of moving things up and down etc.
"""
servicemanager_set_item = QtCore.pyqtSignal(int)
servicemanager_set_item_by_uuid = QtCore.pyqtSignal(str)
servicemanager_next_item = QtCore.pyqtSignal()
servicemanager_previous_item = QtCore.pyqtSignal()
@ -339,6 +340,7 @@ class ServiceManager(QtWidgets.QWidget, RegistryBase, Ui_ServiceManager, LogMixi
self.setup_ui(self)
# Need to use event as called across threads and UI is updated
self.servicemanager_set_item.connect(self.on_set_item)
self.servicemanager_set_item_by_uuid.connect(self.set_item_by_uuid)
self.servicemanager_next_item.connect(self.next_item)
self.servicemanager_previous_item.connect(self.previous_item)
@ -1028,6 +1030,21 @@ class ServiceManager(QtWidgets.QWidget, RegistryBase, Ui_ServiceManager, LogMixi
self.service_manager_list.setCurrentItem(item)
self.make_live()
def set_item_by_uuid(self, unique_identifier):
"""
Makes a specific item in the service live. Called directly by the API layer
:param unique_identifier: Unique Identifier for the item.
"""
row = 0
for sitem in self.service_items:
if sitem['service_item'].unique_identifier == unique_identifier:
item = self.service_manager_list.topLevelItem(sitem['order'] - 1)
self.service_manager_list.setCurrentItem(item)
self.make_live(row)
return
row += 1
def on_move_selection_up(self):
"""
Moves the cursor selection up the window. Called by the up arrow.

View File

@ -410,12 +410,7 @@ class SlideController(QtWidgets.QWidget, LogMixin, RegistryProperties):
self.seek_slider.valueChanged.connect(self.send_to_plugins)
self.volume_slider.valueChanged.connect(self.send_to_plugins)
if self.is_live:
# Build the Song Toolbar
self.song_menu = QtWidgets.QToolButton(self.toolbar)
self.song_menu.setObjectName('song_menu')
self.song_menu.setText(translate('OpenLP.SlideController', 'Go To'))
self.song_menu.setPopupMode(QtWidgets.QToolButton.InstantPopup)
self.song_menu.setMenu(QtWidgets.QMenu(translate('OpenLP.SlideController', 'Go To'), self.toolbar))
self.new_song_menu()
self.toolbar.add_toolbar_widget(self.song_menu)
self.toolbar.set_widget_visible('song_menu', False)
# Screen preview area
@ -495,6 +490,17 @@ class SlideController(QtWidgets.QWidget, LogMixin, RegistryProperties):
self.mediacontroller_live_pause.connect(self.media_controller.on_media_pause)
self.mediacontroller_live_stop.connect(self.media_controller.on_media_stop)
def new_song_menu(self):
"""
Rebuild the song menu object from scratch.
"""
# Build the Song Toolbar
self.song_menu = QtWidgets.QToolButton(self.toolbar)
self.song_menu.setObjectName('song_menu')
self.song_menu.setText(translate('OpenLP.SlideController', 'Go To'))
self.song_menu.setPopupMode(QtWidgets.QToolButton.InstantPopup)
self.song_menu.setMenu(QtWidgets.QMenu(translate('OpenLP.SlideController', 'Go To'), self.toolbar))
def _slide_shortcut_activated(self):
"""
Called, when a shortcut has been activated to jump to a chorus, verse, etc.
@ -891,6 +897,11 @@ class SlideController(QtWidgets.QWidget, LogMixin, RegistryProperties):
self.preview_display.show()
for display in self.displays:
display.load_verses(service_item.rendered_slides)
# Replace the song menu so the verses match the song and are not cumulative
if self.is_live:
self.toolbar.remove_widget('song_menu')
self.new_song_menu()
self.toolbar.add_toolbar_widget(self.song_menu)
for slide_index, slide in enumerate(self.service_item.display_slides):
if not slide['verse'].isdigit():
# These tags are already translated.

View File

@ -94,3 +94,15 @@ class OpenLPToolbar(QtWidgets.QToolBar):
self.actions[handle].setEnabled(enabled)
else:
log.warning('No handle "%s" in actions list.', str(handle))
def remove_widget(self, name):
"""
Find and remove an action from the toolbar
:param name: The name of the action to me removed
:return:
"""
try:
act = self.actions[name]
self.removeAction(act)
except KeyError:
log.warning(f'No handle {name} in actions list.')