diff --git a/openlp/core/projectors/db.py b/openlp/core/projectors/db.py index ef233999b..9249f0b60 100644 --- a/openlp/core/projectors/db.py +++ b/openlp/core/projectors/db.py @@ -417,11 +417,17 @@ class ProjectorDB(Manager): value: (str) From ProjectorSource, Sources tables or PJLink default code list """ source_dict = {} + # Apparently, there was a change to the projector object. Test for which object has db id + if hasattr(projector, "id"): + chk = projector.id + elif hasattr(projector.entry, "id"): + chk = projector.entry.id + # Get default list first for key in projector.source_available: item = self.get_object_filtered(ProjectorSource, and_(ProjectorSource.code == key, - ProjectorSource.projector_id == projector.id)) + ProjectorSource.projector_id == chk)) if item is None: source_dict[key] = PJLINK_DEFAULT_CODES[key] else: diff --git a/openlp/core/projectors/manager.py b/openlp/core/projectors/manager.py index 966da08f8..9445c3f70 100644 --- a/openlp/core/projectors/manager.py +++ b/openlp/core/projectors/manager.py @@ -46,31 +46,10 @@ from openlp.core.projectors.sourceselectform import SourceSelectSingle, SourceSe from openlp.core.ui.icons import UiIcons from openlp.core.widgets.toolbar import OpenLPToolbar - log = logging.getLogger(__name__) log.debug('projectormanager loaded') -# Dict for matching projector status to display icon -STATUS_ICONS = { - S_NOT_CONNECTED: ':/projector/projector_item_disconnect.png', - S_CONNECTING: ':/projector/projector_item_connect.png', - S_CONNECTED: ':/projector/projector_off.png', - S_OFF: ':/projector/projector_off.png', - S_INITIALIZE: ':/projector/projector_off.png', - S_STANDBY: ':/projector/projector_off.png', - S_WARMUP: ':/projector/projector_warmup.png', - S_ON: ':/projector/projector_on.png', - S_COOLDOWN: ':/projector/projector_cooldown.png', - E_ERROR: ':/projector/projector_error.png', - E_NETWORK: ':/projector/projector_not_connected_error.png', - E_SOCKET_TIMEOUT: ':/projector/projector_not_connected_error.png', - E_AUTHENTICATION: ':/projector/projector_not_connected_error.png', - E_UNKNOWN_SOCKET_ERROR: ':/projector/projector_not_connected_error.png', - E_NOT_CONNECTED: ':/projector/projector_not_connected_error.png' -} - - class UiProjectorManager(object): """ UI part of the Projector Manager @@ -122,7 +101,7 @@ class UiProjectorManager(object): self.one_toolbar.add_toolbar_action('connect_projector', text=translate('OpenLP.ProjectorManager', 'Connect to selected projector.'), - icon=UiIcons().projector_connect, + icon=UiIcons().projector_select_connect, tooltip=translate('OpenLP.ProjectorManager', 'Connect to selected projector.'), triggers=self.on_connect_projector) @@ -136,7 +115,7 @@ class UiProjectorManager(object): self.one_toolbar.add_toolbar_action('disconnect_projector', text=translate('OpenLP.ProjectorManager', 'Disconnect from selected projectors'), - icon=UiIcons().projector_disconnect, + icon=UiIcons().projector_select_disconnect, tooltip=translate('OpenLP.ProjectorManager', 'Disconnect from selected projector.'), triggers=self.on_disconnect_projector) @@ -151,7 +130,7 @@ class UiProjectorManager(object): self.one_toolbar.add_toolbar_action('poweron_projector', text=translate('OpenLP.ProjectorManager', 'Power on selected projector'), - icon=UiIcons().projector_on, + icon=UiIcons().projector_power_on, tooltip=translate('OpenLP.ProjectorManager', 'Power on selected projector.'), triggers=self.on_poweron_projector) @@ -164,7 +143,7 @@ class UiProjectorManager(object): triggers=self.on_poweron_projector) self.one_toolbar.add_toolbar_action('poweroff_projector', text=translate('OpenLP.ProjectorManager', 'Standby selected projector'), - icon=UiIcons().projector_off, + icon=UiIcons().projector_power_off, tooltip=translate('OpenLP.ProjectorManager', 'Put selected projector in standby.'), triggers=self.on_poweroff_projector) @@ -309,7 +288,7 @@ class ProjectorManager(QtWidgets.QWidget, RegistryBase, UiProjectorManager, LogM S_INITIALIZE: UiIcons().projector_on, S_STANDBY: UiIcons().projector_off, S_WARMUP: UiIcons().projector_warmup, - S_ON: UiIcons().projector_off, + S_ON: UiIcons().projector_on, S_COOLDOWN: UiIcons().projector_cooldown, E_ERROR: UiIcons().projector_error, E_NETWORK: UiIcons().error, @@ -505,7 +484,8 @@ class ProjectorManager(QtWidgets.QWidget, RegistryBase, UiProjectorManager, LogM projector = list_item.data(QtCore.Qt.UserRole) try: projector.link.connect_to_host() - except Exception: + except Exception as e: + print(e) continue def on_delete_projector(self, opt=None): @@ -880,6 +860,7 @@ class ProjectorManager(QtWidgets.QWidget, RegistryBase, UiProjectorManager, LogM """ Update the icons when the selected projectors change """ + log.debug('update_icons(): Checking for selected projector items in list') count = len(self.projector_list_widget.selectedItems()) projector = None if count == 0: @@ -900,6 +881,7 @@ class ProjectorManager(QtWidgets.QWidget, RegistryBase, UiProjectorManager, LogM self.get_toolbar_item('blank_projector_multiple', hidden=True) self.get_toolbar_item('show_projector_multiple', hidden=True) elif count == 1: + log.debug('update_icons(): Found one item selected') projector = self.projector_list_widget.selectedItems()[0].data(QtCore.Qt.UserRole) connected = QSOCKET_STATE[projector.link.state()] == S_CONNECTED power = projector.link.power == S_ON @@ -910,12 +892,14 @@ class ProjectorManager(QtWidgets.QWidget, RegistryBase, UiProjectorManager, LogM self.get_toolbar_item('blank_projector_multiple', hidden=True) self.get_toolbar_item('show_projector_multiple', hidden=True) if connected: + log.debug('update_icons(): Updating icons for connected state') self.get_toolbar_item('view_projector', enabled=True) self.get_toolbar_item('source_view_projector', - enabled=connected and power and projector.link.source_available is not None) + enabled=projector.link.source_available is not None and connected and power) self.get_toolbar_item('edit_projector', hidden=True) self.get_toolbar_item('delete_projector', hidden=True) else: + log.debug('update_icons(): Updating for not connected state') self.get_toolbar_item('view_projector', hidden=True) self.get_toolbar_item('source_view_projector', hidden=True) self.get_toolbar_item('edit_projector', enabled=True) @@ -931,6 +915,7 @@ class ProjectorManager(QtWidgets.QWidget, RegistryBase, UiProjectorManager, LogM self.get_toolbar_item('blank_projector', enabled=False) self.get_toolbar_item('show_projector', enabled=False) else: + log.debug('update_icons(): Updating for multiple items selected') self.get_toolbar_item('edit_projector', enabled=False) self.get_toolbar_item('delete_projector', enabled=False) self.get_toolbar_item('view_projector', hidden=True) diff --git a/openlp/core/projectors/pjlink.py b/openlp/core/projectors/pjlink.py index 02d6c444b..524bc8c3c 100644 --- a/openlp/core/projectors/pjlink.py +++ b/openlp/core/projectors/pjlink.py @@ -528,8 +528,9 @@ class PJLinkCommands(object): sources.append(source) sources.sort() self.source_available = sources - log.debug('({ip}) Setting projector sources_available to "{data}"'.format(ip=self.entry.name, - data=self.source_available)) + log.debug('({ip}) Setting projector source_available to "{data}"'.format(ip=self.entry.name, + data=self.source_available)) + self.projectorUpdateIcons.emit() return def process_lamp(self, data): @@ -886,6 +887,9 @@ class PJLink(QtNetwork.QTcpSocket, PJLinkCommands): elif status >= S_NOT_CONNECTED and status in QSOCKET_STATE: # Socket connection status update self.status_connect = status + # Check if we need to update error state as well + if self.error_status != S_OK and status != S_NOT_CONNECTED: + self.error_status = S_OK elif status >= S_NOT_CONNECTED and status in PROJECTOR_STATE: # Only affects the projector status self.projector_status = status @@ -905,7 +909,14 @@ class PJLink(QtNetwork.QTcpSocket, PJLinkCommands): message=status_message if msg is None else msg)) # Now that we logged extra information for debugging, broadcast the original change/message - (code, message) = self._get_status(status) + # Check for connection errors first + if self.error_status != S_OK: + log.debug('({ip}) Signalling error code'.format(ip=self.entry.name)) + (code, message) = self._get_status(self.error_status) + status = self.error_status + else: + log.debug('({ip}) Signalling status code'.format(ip=self.entry.name)) + (code, message) = self._get_status(status) if msg is not None: message = msg elif message is None: @@ -953,7 +964,7 @@ class PJLink(QtNetwork.QTcpSocket, PJLinkCommands): log.error('({ip}) Invalid initial packet received - closing socket'.format(ip=self.entry.name)) return self.disconnect_from_host() # Convert the initial login prompt with the expected PJLink normal command format for processing - log.debug('({ip}) check_login(): Formatting initial connection prompt' + log.debug('({ip}) check_login(): Formatting initial connection prompt ' 'to PJLink packet'.format(ip=self.entry.name)) return self.get_data('{start}{clss}{data}'.format(start=PJLINK_PREFIX, clss='1', diff --git a/openlp/core/ui/icons.py b/openlp/core/ui/icons.py index 5aa157e9f..0e83a01d8 100644 --- a/openlp/core/ui/icons.py +++ b/openlp/core/ui/icons.py @@ -117,13 +117,17 @@ class UiIcons(object): 'presentation': {'icon': 'fa.bar-chart'}, 'preview': {'icon': 'fa.laptop'}, 'projector': {'icon': 'op.video'}, - 'projector_connect': {'icon': 'fa.plug'}, + 'projector_connect': {'icon': 'fa.plug'}, # Projector connect 'projector_cooldown': {'icon': 'fa.video-camera', 'attr': 'blue'}, - 'projector_disconnect': {'icon': 'fa.plug', 'attr': 'lightGray'}, + 'projector_disconnect': {'icon': 'fa.plug', 'attr': 'lightGray'}, # Projector disconnect 'projector_error': {'icon': 'fa.video-camera', 'attr': 'red'}, 'projector_hdmi': {'icon': 'op.hdmi'}, - 'projector_off': {'icon': 'fa.video-camera', 'attr': 'black'}, - 'projector_on': {'icon': 'fa.video-camera', 'attr': 'green'}, + 'projector_power_off': {'icon': 'fa.video-camera', 'attr': 'red'}, # Toolbar power off + 'projector_power_on': {'icon': 'fa.video-camera', 'attr': 'green'}, # Toolbar power on + 'projector_off': {'icon': 'fa.video-camera', 'attr': 'black'}, # Projector off + 'projector_on': {'icon': 'fa.video-camera', 'attr': 'green'}, # Projector on + 'projector_select_connect': {'icon': 'fa.plug', 'attr': 'green'}, # Toolbar connect + 'projector_select_disconnect': {'icon': 'fa.plug', 'attr': 'red'}, # Toolbar disconnect 'projector_warmup': {'icon': 'fa.video-camera', 'attr': 'yellow'}, 'picture': {'icon': 'fa.picture-o'}, 'print': {'icon': 'fa.print'}, diff --git a/setup.cfg b/setup.cfg index 71cd36460..5b443dcf7 100644 --- a/setup.cfg +++ b/setup.cfg @@ -9,6 +9,7 @@ ignore = E402,E722,W503,W504 [flake8] exclude=resources.py,vlc.py +max-line-length = 120 ignore = E402,W503,W504,D [pycodestyle] diff --git a/tests/functional/openlp_core/lib/test_image_manager.py b/tests/functional/openlp_core/lib/test_image_manager.py index 33207f69b..9cb77ece9 100644 --- a/tests/functional/openlp_core/lib/test_image_manager.py +++ b/tests/functional/openlp_core/lib/test_image_manager.py @@ -178,7 +178,7 @@ class TestImageManager(TestCase, TestMixin): # THEN a KeyError is thrown with self.assertRaises(KeyError) as context: self.image_manager.get_image(TEST_PATH, 'church1.jpg') - assert context.exception is not '', 'KeyError exception should have been thrown for missing image' + assert context.exception != '', 'KeyError exception should have been thrown for missing image' @patch('openlp.core.lib.imagemanager.run_thread') def test_different_dimension_image(self, mocked_run_thread): @@ -211,7 +211,7 @@ class TestImageManager(TestCase, TestMixin): # WHEN: calling with correct image, but wrong dimensions with self.assertRaises(KeyError) as context: self.image_manager.get_image(full_path, 'church.jpg', 120, 120) - assert context.exception is not '', 'KeyError exception should have been thrown for missing dimension' + assert context.exception != '', 'KeyError exception should have been thrown for missing dimension' @patch('openlp.core.lib.imagemanager.resize_image') @patch('openlp.core.lib.imagemanager.image_to_byte') diff --git a/tests/functional/openlp_plugins/media/test_mediaplugin.py b/tests/functional/openlp_plugins/media/test_mediaplugin.py index eabf35aa0..d5bfcac0b 100644 --- a/tests/functional/openlp_plugins/media/test_mediaplugin.py +++ b/tests/functional/openlp_plugins/media/test_mediaplugin.py @@ -57,4 +57,4 @@ class MediaPluginTest(TestCase, TestMixin): # THEN: about() should return a string object assert isinstance(MediaPlugin.about(), str) # THEN: about() should return a non-empty string - assert len(MediaPlugin.about()) is not 0 + assert len(MediaPlugin.about()) != 0 diff --git a/tests/functional/openlp_plugins/songs/test_lib.py b/tests/functional/openlp_plugins/songs/test_lib.py index eedbe85c7..e9c657df3 100644 --- a/tests/functional/openlp_plugins/songs/test_lib.py +++ b/tests/functional/openlp_plugins/songs/test_lib.py @@ -199,7 +199,7 @@ class TestLib(TestCase): result = _remove_typos(diff) # THEN: There should be no typos in the middle anymore. The remaining equals should have been merged. - assert len(result) is 1, 'The result should contain only one element.' + assert len(result) == 1, 'The result should contain only one element.' assert result[0][0] == 'equal', 'The result should contain an equal element.' assert result[0][1] == 0, 'The start indices should be kept.' assert result[0][2] == 22, 'The stop indices should be kept.' diff --git a/tests/functional/openlp_plugins/songusage/test_songusage.py b/tests/functional/openlp_plugins/songusage/test_songusage.py index 03847a601..e80c31c03 100644 --- a/tests/functional/openlp_plugins/songusage/test_songusage.py +++ b/tests/functional/openlp_plugins/songusage/test_songusage.py @@ -45,8 +45,8 @@ class TestSongUsage(TestCase): # THEN: about() should return a string object assert isinstance(SongUsagePlugin.about(), str) # THEN: about() should return a non-empty string - assert len(SongUsagePlugin.about()) is not 0 - assert len(SongUsagePlugin.about()) is not 0 + assert len(SongUsagePlugin.about()) != 0 + assert len(SongUsagePlugin.about()) != 0 @patch('openlp.plugins.songusage.songusageplugin.Manager') def test_song_usage_init(self, MockedManager): diff --git a/tests/openlp_core/projectors/test_projector_db.py b/tests/openlp_core/projectors/test_projector_db.py index ae25e011c..bc5899aeb 100644 --- a/tests/openlp_core/projectors/test_projector_db.py +++ b/tests/openlp_core/projectors/test_projector_db.py @@ -134,6 +134,7 @@ class TestProjectorDB(TestCase, TestMixin): """ Set up anything necessary for all tests """ + self.tmp_folder = mkdtemp(prefix='openlp_') # Create a test app to keep from segfaulting Registry.create() self.registry = Registry() @@ -153,11 +154,11 @@ class TestProjectorDB(TestCase, TestMixin): patch('openlp.core.ui.mainwindow.ThemeManager'), \ patch('openlp.core.ui.mainwindow.ProjectorManager'), \ patch('openlp.core.ui.mainwindow.websockets.WebSocketServer'), \ - patch('openlp.core.ui.mainwindow.server.HttpServer'): + patch('openlp.core.ui.mainwindow.server.HttpServer'), \ + patch('openlp.core.state.State.list_plugins') as mock_plugins: + mock_plugins.return_value = [] self.main_window = MainWindow() - # Create a temporary database directory and database - self.tmp_folder = mkdtemp(prefix='openlp_') tmpdb_url = 'sqlite:///{db}'.format(db=os.path.join(self.tmp_folder, TEST_DB)) mocked_init_url.return_value = tmpdb_url self.projector = ProjectorDB() diff --git a/tests/openlp_core/projectors/test_projector_pjlink_commands_01.py b/tests/openlp_core/projectors/test_projector_pjlink_commands_01.py index a03e84db5..361b5c4bb 100644 --- a/tests/openlp_core/projectors/test_projector_pjlink_commands_01.py +++ b/tests/openlp_core/projectors/test_projector_pjlink_commands_01.py @@ -452,12 +452,16 @@ class TestPJLinkCommands(TestCase): """ Test saving video source available information """ + # GIVEN: Test object with patch.object(openlp.core.projectors.pjlink, 'log') as mock_log: pjlink = PJLink(Projector(**TEST1_DATA), no_poll=True) pjlink.source_available = [] - log_debug_calls = [call('({ip}) Setting projector sources_available to ' + log_debug_calls = [call('({ip}) reset_information() connect status is ' + 'S_NOT_CONNECTED'.format(ip=pjlink.name)), + call('({ip}) Setting projector source_available to ' '"[\'11\', \'12\', \'21\', \'22\', \'31\', \'32\']"'.format(ip=pjlink.name))] + chk_data = '21 12 11 22 32 31' # Although they should already be sorted, use unsorted to verify method chk_test = ['11', '12', '21', '22', '31', '32']