From 857a1d06f6e9baaf11b78561a03fd513dd04ae63 Mon Sep 17 00:00:00 2001 From: Jonathan Springer Date: Thu, 9 Oct 2014 22:08:59 -0400 Subject: [PATCH 1/2] Intial changes for multiple toolbars for projector manager --- openlp/core/ui/projector/manager.py | 219 +++++++++++++++++++--------- 1 file changed, 147 insertions(+), 72 deletions(-) diff --git a/openlp/core/ui/projector/manager.py b/openlp/core/ui/projector/manager.py index 8e8bcf692..26283a346 100644 --- a/openlp/core/ui/projector/manager.py +++ b/openlp/core/ui/projector/manager.py @@ -80,56 +80,108 @@ class Ui_ProjectorManager(object): self.layout.setMargin(0) self.layout.setObjectName('layout') # Add toolbar - self.toolbar = OpenLPToolbar(widget) - self.toolbar.add_toolbar_action('newProjector', - text=translate('OpenLP.Projector', 'Add Projector'), - icon=':/projector/projector_new.png', - tooltip=translate('OpenLP.ProjectorManager', 'Add a new projector'), - triggers=self.on_add_projector) - self.toolbar.addSeparator() - self.toolbar.add_toolbar_action('connect_all_projectors', - text=translate('OpenLP.ProjectorManager', 'Connect to all projectors'), - icon=':/projector/projector_connect.png', - tootip=translate('OpenLP.ProjectorManager', 'Connect to all projectors'), - triggers=self.on_connect_all_projectors) - self.toolbar.add_toolbar_action('disconnect_all_projectors', - text=translate('OpenLP.ProjectorManager', 'Disconnect from all projectors'), - icon=':/projector/projector_disconnect.png', - tooltip=translate('OpenLP.ProjectorManager', 'Disconnect from all projectors'), - triggers=self.on_disconnect_all_projectors) - self.toolbar.addSeparator() - self.toolbar.add_toolbar_action('poweron_all_projectors', - text=translate('OpenLP.ProjectorManager', 'Power On All Projectors'), - icon=':/projector/projector_power_on.png', - tooltip=translate('OpenLP.ProjectorManager', 'Power on all projectors'), - triggers=self.on_poweron_all_projectors) - self.toolbar.add_toolbar_action('poweroff_all_projectors', - text=translate('OpenLP.ProjectorManager', 'Standby All Projector'), - icon=':/projector/projector_power_off.png', - tooltip=translate('OpenLP.ProjectorManager', 'Put all projectors in standby'), - triggers=self.on_poweroff_all_projectors) - self.toolbar.addSeparator() - self.toolbar.add_toolbar_action('blank_projector', - text=translate('OpenLP.ProjectorManager', 'Blank All Projector Screens'), - icon=':/projector/projector_blank.png', - tooltip=translate('OpenLP.ProjectorManager', 'Blank all projector screens'), - triggers=self.on_blank_all_projectors) - self.toolbar.add_toolbar_action('show_all_projector', - text=translate('OpenLP.ProjectorManager', 'Show All Projector Screens'), - icon=':/projector/projector_show.png', - tooltip=translate('OpenLP.ProjectorManager', 'Show all projector screens'), - triggers=self.on_show_all_projectors) - self.layout.addWidget(self.toolbar) + self.top_toolbar = OpenLPToolbar(widget) + self.top_toolbar.add_toolbar_action('newProjector', + text=translate('OpenLP.Projector', 'Add Projector'), + icon=':/projector/projector_new.png', + tooltip=translate('OpenLP.ProjectorManager', 'Add a new projector'), + triggers=self.on_add_projector) + self.top_toolbar.addSeparator() + self.top_toolbar.add_toolbar_action('connect_all_projectors', + text=translate('OpenLP.ProjectorManager', + 'Connect to selected projectors'), + icon=':/projector/projector_connect.png', + tootip=translate('OpenLP.ProjectorManager', + 'Connect to selected projectors'), + triggers=self.on_connect_projector) + self.top_toolbar.add_toolbar_action('disconnect_all_projectors', + text=translate('OpenLP.ProjectorManager', + 'Disconnect from selected projectors'), + icon=':/projector/projector_disconnect.png', + tooltip=translate('OpenLP.ProjectorManager', + 'Disconnect from selected projectors'), + triggers=self.on_disconnect_projector) + self.top_toolbar.addSeparator() + self.top_toolbar.add_toolbar_action('poweron_all_projectors', + text=translate('OpenLP.ProjectorManager', + 'Power on selected projectors'), + icon=':/projector/projector_power_on.png', + tooltip=translate('OpenLP.ProjectorManager', + 'Power on selected projectors'), + triggers=self.on_poweron_projector) + self.top_toolbar.add_toolbar_action('poweroff_all_projectors', + text=translate('OpenLP.ProjectorManager', 'Standby selected projectors'), + icon=':/projector/projector_power_off.png', + tooltip=translate('OpenLP.ProjectorManager', + 'Put selected projectors in standby'), + triggers=self.on_poweroff_projector) + self.top_toolbar.addSeparator() + self.top_toolbar.add_toolbar_action('blank_projector', + text=translate('OpenLP.ProjectorManager', + 'Blank selected projector screens'), + icon=':/projector/projector_blank.png', + tooltip=translate('OpenLP.ProjectorManager', + 'Blank selected projector screens'), + triggers=self.on_blank_projector) + self.top_toolbar.add_toolbar_action('show_all_projector', + text=translate('OpenLP.ProjectorManager', + 'Show selected projector screens'), + icon=':/projector/projector_show.png', + tooltip=translate('OpenLP.ProjectorManager', + 'Show selected projector screens'), + triggers=self.on_show_projector) + self.top_toolbar.addSeparator() + self.layout.addWidget(self.top_toolbar) # Add the projector list box - self.projector_widget = QtGui.QWidgetAction(self.toolbar) + self.projector_widget = QtGui.QWidgetAction(self.top_toolbar) self.projector_widget.setObjectName('projector_widget') # Create projector manager list self.projector_list_widget = QtGui.QListWidget(widget) + self.projector_list_widget.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection) self.projector_list_widget.setAlternatingRowColors(True) self.projector_list_widget.setIconSize(QtCore.QSize(90, 50)) self.projector_list_widget.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) self.projector_list_widget.setObjectName('projector_list_widget') self.layout.addWidget(self.projector_list_widget) + self.bottom_toolbar = OpenLPToolbar(widget) + self.bottom_toolbar.add_toolbar_action('connect_all_projectors', + text=translate('OpenLP.ProjectorManager', 'Connect to all projectors'), + icon=':/projector/projector_connect.png', + tootip=translate('OpenLP.ProjectorManager', 'Connect to all projectors'), + triggers=self.on_connect_all_projectors) + self.bottom_toolbar.add_toolbar_action('disconnect_all_projectors', + text=translate('OpenLP.ProjectorManager', + 'Disconnect from all projectors'), + icon=':/projector/projector_disconnect.png', + tooltip=translate('OpenLP.ProjectorManager', + 'Disconnect from all projectors'), + triggers=self.on_disconnect_all_projectors) + self.bottom_toolbar.addSeparator() + self.bottom_toolbar.add_toolbar_action('poweron_all_projectors', + text=translate('OpenLP.ProjectorManager', 'Power On All Projectors'), + icon=':/projector/projector_power_on.png', + tooltip=translate('OpenLP.ProjectorManager', 'Power on all projectors'), + triggers=self.on_poweron_all_projectors) + self.bottom_toolbar.add_toolbar_action('poweroff_all_projectors', + text=translate('OpenLP.ProjectorManager', 'Standby All Projector'), + icon=':/projector/projector_power_off.png', + tooltip=translate('OpenLP.ProjectorManager', + 'Put all projectors in standby'), + triggers=self.on_poweroff_all_projectors) + self.bottom_toolbar.addSeparator() + self.bottom_toolbar.add_toolbar_action('blank_projector', + text=translate('OpenLP.ProjectorManager', 'Blank All Projector Screens'), + icon=':/projector/projector_blank.png', + tooltip=translate('OpenLP.ProjectorManager', + 'Blank all projector screens'), + triggers=self.on_blank_all_projectors) + self.bottom_toolbar.add_toolbar_action('show_all_projector', + text=translate('OpenLP.ProjectorManager', 'Show All Projector Screens'), + icon=':/projector/projector_show.png', + tooltip=translate('OpenLP.ProjectorManager', + 'Show all projector screens'), + triggers=self.on_show_all_projectors) + self.layout.addWidget(self.bottom_toolbar, alignment=QtCore.Qt.AlignBottom) self.projector_list_widget.customContextMenuRequested.connect(self.context_menu) # Build the context menu self.menu = QtGui.QMenu() @@ -369,12 +421,16 @@ class ProjectorManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ProjectorMa try: ip = opt.link.ip projector = opt + projector.link.set_shutter_closed() except AttributeError: - list_item = self.projector_list_widget.item(self.projector_list_widget.currentRow()) - if list_item is None: - return - projector = list_item.data(QtCore.Qt.UserRole) - return projector.link.set_shutter_closed() + for list_item in self.projector_list_widget.selectedItems(): + if list_item is None: + return + projector = list_item.data(QtCore.Qt.UserRole) + try: + projector.link.set_shutter_closed() + except: + continue def on_connect_projector(self, opt=None): """ @@ -386,12 +442,16 @@ class ProjectorManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ProjectorMa try: ip = opt.link.ip projector = opt + projector.link.connect_to_host() except AttributeError: - list_item = self.projector_list_widget.item(self.projector_list_widget.currentRow()) - if list_item is None: - return - projector = list_item.data(QtCore.Qt.UserRole) - return projector.link.connect_to_host() + for list_item in self.projector_list_widget.selectedItems(): + if list_item is None: + return + projector = list_item.data(QtCore.Qt.UserRole) + try: + projector.link.connect_to_host() + except: + continue def on_connect_all_projectors(self, opt=None): """ @@ -459,12 +519,16 @@ class ProjectorManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ProjectorMa try: ip = opt.link.ip projector = opt + projector.link.disconnect_from_host() except AttributeError: - list_item = self.projector_list_widget.item(self.projector_list_widget.currentRow()) - if list_item is None: - return - projector = list_item.data(QtCore.Qt.UserRole) - return projector.link.disconnect_from_host() + for list_item in self.projector_list_widget.selectedItems(): + if list_item is None: + return + projector = list_item.data(QtCore.Qt.UserRole) + try: + projector.link.disconnect_from_host() + except: + continue def on_disconnect_all_projectors(self, opt=None): """ @@ -512,13 +576,16 @@ class ProjectorManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ProjectorMa try: ip = opt.link.ip projector = opt + projector.link.set_power_off() except AttributeError: - # Must have been called by a mouse-click on item - list_item = self.projector_list_widget.item(self.projector_list_widget.currentRow()) - if list_item is None: - return - projector = list_item.data(QtCore.Qt.UserRole) - return projector.link.set_power_off() + for list_item in self.projector_list_widget.selectedItems(): + if list_item is None: + return + projector = list_item.data(QtCore.Qt.UserRole) + try: + projector.link.set_power_off() + except: + continue def on_poweron_all_projectors(self, opt=None): """ @@ -540,12 +607,16 @@ class ProjectorManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ProjectorMa try: ip = opt.link.ip projector = opt + projector.link.set_power_on() except AttributeError: - lwi = self.projector_list_widget.item(self.projector_list_widget.currentRow()) - if lwi is None: - return - projector = lwi.data(QtCore.Qt.UserRole) - return projector.link.set_power_on() + for list_item in self.projector_list_widget.selectedItems(): + if list_item is None: + return + projector = list_item.data(QtCore.Qt.UserRole) + try: + projector.link.set_power_on() + except: + continue def on_show_all_projectors(self, opt=None): """ @@ -567,12 +638,16 @@ class ProjectorManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ProjectorMa try: ip = opt.link.ip projector = opt + projector.link.set_shutter_open() except AttributeError: - lwi = self.projector_list_widget.item(self.projector_list_widget.currentRow()) - if lwi is None: - return - projector = lwi.data(QtCore.Qt.UserRole) - return projector.link.set_shutter_open() + for list_item in self.projector_list_widget.selectedItems(): + if list_item is None: + return + projector = list_item.data(QtCore.Qt.UserRole) + try: + projector.link.set_shutter_open() + except: + continue def on_status_projector(self, opt=None): """ From 859ae13eb3f9365ca37105c1a2cc2d21d080825a Mon Sep 17 00:00:00 2001 From: Jonathan Springer Date: Thu, 9 Oct 2014 22:49:18 -0400 Subject: [PATCH 2/2] More work for top and bottom toolbars for the projector manager --- openlp/core/lib/toolbar.py | 13 +++++++++++ openlp/core/ui/projector/manager.py | 35 +++++++++++++++++++++++------ 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/openlp/core/lib/toolbar.py b/openlp/core/lib/toolbar.py index b24be89a8..b30d20a89 100644 --- a/openlp/core/lib/toolbar.py +++ b/openlp/core/lib/toolbar.py @@ -82,3 +82,16 @@ class OpenLPToolbar(QtGui.QToolBar): self.actions[handle].setVisible(visible) else: log.warning('No handle "%s" in actions list.', str(handle)) + + def set_widget_enabled(self, widgets, enabled=True): + """ + Set the enabled state for a widget or a list of widgets. + + :param widgets: A list of string with widget object names. + :param enabled: The new state as bool. + """ + for handle in widgets: + if handle in self.actions: + self.actions[handle].setEnabled(enabled) + else: + log.warning('No handle "%s" in actions list.', str(handle)) diff --git a/openlp/core/ui/projector/manager.py b/openlp/core/ui/projector/manager.py index 26283a346..7a4087209 100644 --- a/openlp/core/ui/projector/manager.py +++ b/openlp/core/ui/projector/manager.py @@ -87,14 +87,14 @@ class Ui_ProjectorManager(object): tooltip=translate('OpenLP.ProjectorManager', 'Add a new projector'), triggers=self.on_add_projector) self.top_toolbar.addSeparator() - self.top_toolbar.add_toolbar_action('connect_all_projectors', + self.top_toolbar.add_toolbar_action('connect_selected_projectors', text=translate('OpenLP.ProjectorManager', 'Connect to selected projectors'), icon=':/projector/projector_connect.png', tootip=translate('OpenLP.ProjectorManager', 'Connect to selected projectors'), triggers=self.on_connect_projector) - self.top_toolbar.add_toolbar_action('disconnect_all_projectors', + self.top_toolbar.add_toolbar_action('disconnect_selected_projectors', text=translate('OpenLP.ProjectorManager', 'Disconnect from selected projectors'), icon=':/projector/projector_disconnect.png', @@ -102,28 +102,28 @@ class Ui_ProjectorManager(object): 'Disconnect from selected projectors'), triggers=self.on_disconnect_projector) self.top_toolbar.addSeparator() - self.top_toolbar.add_toolbar_action('poweron_all_projectors', + self.top_toolbar.add_toolbar_action('poweron_selected_projectors', text=translate('OpenLP.ProjectorManager', 'Power on selected projectors'), icon=':/projector/projector_power_on.png', tooltip=translate('OpenLP.ProjectorManager', 'Power on selected projectors'), triggers=self.on_poweron_projector) - self.top_toolbar.add_toolbar_action('poweroff_all_projectors', + self.top_toolbar.add_toolbar_action('poweroff_selected_projectors', text=translate('OpenLP.ProjectorManager', 'Standby selected projectors'), icon=':/projector/projector_power_off.png', tooltip=translate('OpenLP.ProjectorManager', 'Put selected projectors in standby'), triggers=self.on_poweroff_projector) self.top_toolbar.addSeparator() - self.top_toolbar.add_toolbar_action('blank_projector', + self.top_toolbar.add_toolbar_action('blank_selected_projectors', text=translate('OpenLP.ProjectorManager', 'Blank selected projector screens'), icon=':/projector/projector_blank.png', tooltip=translate('OpenLP.ProjectorManager', 'Blank selected projector screens'), triggers=self.on_blank_projector) - self.top_toolbar.add_toolbar_action('show_all_projector', + self.top_toolbar.add_toolbar_action('show_selected_projectors', text=translate('OpenLP.ProjectorManager', 'Show selected projector screens'), icon=':/projector/projector_show.png', @@ -169,7 +169,7 @@ class Ui_ProjectorManager(object): 'Put all projectors in standby'), triggers=self.on_poweroff_all_projectors) self.bottom_toolbar.addSeparator() - self.bottom_toolbar.add_toolbar_action('blank_projector', + self.bottom_toolbar.add_toolbar_action('blank_all_projectors', text=translate('OpenLP.ProjectorManager', 'Blank All Projector Screens'), icon=':/projector/projector_blank.png', tooltip=translate('OpenLP.ProjectorManager', @@ -274,8 +274,13 @@ class ProjectorManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ProjectorMa def bootstrap_post_set_up(self): self.load_projectors() self.projector_form = ProjectorWizard(self, projectordb=self.projectordb) + self.top_toolbar.set_widget_enabled(['connect_selected_projectors', 'disconnect_selected_projectors', + 'poweron_selected_projectors', 'poweroff_selected_projectors', + 'blank_selected_projectors', 'show_selected_projectors'], + enabled=False) self.projector_form.edit_page.newProjector.connect(self.add_projector_from_wizard) self.projector_form.edit_page.editProjector.connect(self.edit_projector_from_wizard) + self.projector_list_widget.itemSelectionChanged.connect(self.update_icons) def context_menu(self, point): """ @@ -877,6 +882,22 @@ class ProjectorManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ProjectorMa log.debug('(%s) Updating icon' % item.link.name) item.widget.setIcon(item.icon) + @pyqtSlot() + def update_icons(self): + """ + Update the icons when the selected projectors change + """ + if not self.projector_list_widget.selectedItems(): + self.top_toolbar.set_widget_enabled(['connect_selected_projectors', 'disconnect_selected_projectors', + 'poweron_selected_projectors', 'poweroff_selected_projectors', + 'blank_selected_projectors', 'show_selected_projectors'], + enabled=False) + else: + self.top_toolbar.set_widget_enabled(['connect_selected_projectors', 'disconnect_selected_projectors', + 'poweron_selected_projectors', 'poweroff_selected_projectors', + 'blank_selected_projectors', 'show_selected_projectors'], + enabled=True) + class ProjectorItem(QObject): """