From 2f780aab791e82763718154bda50eb69f4e24e73 Mon Sep 17 00:00:00 2001 From: tov101 Date: Fri, 8 Sep 2023 17:17:47 +0300 Subject: [PATCH 01/11] Fixes and tests. --- src/asammdf/gui/widgets/plot.py | 2 +- src/asammdf/gui/widgets/tree.py | 5 + src/asammdf/version.py | 2 +- test/asammdf/gui/test_base.py | 107 +- .../gui/widgets/test_BaseFileWidget.py | 5 + .../gui/widgets/test_BasePlotWidget.py | 107 +- ...dget.py => test_FileWidget_TabChannels.py} | 142 +-- .../test_FileWidget_TabModifyAndExport.py | 140 +++ .../widgets/test_PlotWidget_DoubleClick.py | 931 ++++++++++++++++++ ...dget.py => test_PlotWidget_DragAndDrop.py} | 708 +------------ .../widgets/test_PlotWidget_PushButtons.py | 338 +++++++ .../gui/widgets/test_PlotWidget_Shortcuts.py | 237 +++++ 12 files changed, 1774 insertions(+), 950 deletions(-) rename test/asammdf/gui/widgets/{test_FileWidget.py => test_FileWidget_TabChannels.py} (88%) create mode 100644 test/asammdf/gui/widgets/test_FileWidget_TabModifyAndExport.py create mode 100644 test/asammdf/gui/widgets/test_PlotWidget_DoubleClick.py rename test/asammdf/gui/widgets/{test_PlotWidget.py => test_PlotWidget_DragAndDrop.py} (50%) create mode 100644 test/asammdf/gui/widgets/test_PlotWidget_PushButtons.py create mode 100644 test/asammdf/gui/widgets/test_PlotWidget_Shortcuts.py diff --git a/src/asammdf/gui/widgets/plot.py b/src/asammdf/gui/widgets/plot.py index 715b5bcf3..d97b3c13e 100644 --- a/src/asammdf/gui/widgets/plot.py +++ b/src/asammdf/gui/widgets/plot.py @@ -2186,7 +2186,7 @@ def add_new_items(tree, root, items, items_pool): if info["enabled"] else QtCore.Qt.Unchecked, ) - if info["disabled"]: + if "disabled" in info and info["disabled"]: item.set_disabled(info["disabled"]) self.channel_selection.blockSignals(False) diff --git a/src/asammdf/gui/widgets/tree.py b/src/asammdf/gui/widgets/tree.py index aa5872772..cb09bbfea 100644 --- a/src/asammdf/gui/widgets/tree.py +++ b/src/asammdf/gui/widgets/tree.py @@ -886,6 +886,11 @@ def mousePressEvent(self, event) -> None: if self.context_menu is not None: self.context_menu.close() self.context_menu = None + + # If there was a click performed on disabled item, then clear selection + item = self.itemAt(event.pos()) + if item.isDisabled(): + self.clearSelection() super().mousePressEvent(event) def mouseDoubleClickEvent(self, event): diff --git a/src/asammdf/version.py b/src/asammdf/version.py index 83b6f6635..57149fdca 100644 --- a/src/asammdf/version.py +++ b/src/asammdf/version.py @@ -1,4 +1,4 @@ # -*- coding: utf-8 -*- """ asammdf version module """ -__version__ = "7.3.15.dev7" +__version__ = "7.3.15.dev8" diff --git a/test/asammdf/gui/test_base.py b/test/asammdf/gui/test_base.py index 35a1f59f5..acd0341c2 100644 --- a/test/asammdf/gui/test_base.py +++ b/test/asammdf/gui/test_base.py @@ -21,7 +21,7 @@ class DragAndDrop from unittest import mock import pyqtgraph -from PySide6 import QtCore, QtTest, QtWidgets +from PySide6 import QtCore, QtGui, QtTest, QtWidgets from asammdf.gui.utils import excepthook @@ -219,3 +219,108 @@ def __init__(self, source_widget, destination_widget, source_pos, destination_po # drag_thread.wait() move_thread.wait() move_thread.quit() + + +class Pixmap: + COLOR_BACKGROUND = "#000000" + COLOR_RANGE = "#000032" + COLOR_CURSOR = "#e69138" + + @staticmethod + def is_black(pixmap): + """ + Excepting cursor + """ + cursor_x = None + cursor_y = None + cursor_color = None + image = pixmap.toImage() + + for y in range(image.height()): + for x in range(image.width()): + color = QtGui.QColor(image.pixel(x, y)) + if color.name() != Pixmap.COLOR_BACKGROUND: + if not cursor_x and not cursor_y and not cursor_color: + cursor_x = x + cursor_y = y + 1 + cursor_color = color + continue + elif cursor_x == x and cursor_y == y and cursor_color == color: + cursor_y += 1 + continue + else: + return False + return True + + @staticmethod + def is_colored(pixmap, color_name, x, y, width=None, height=None): + image = pixmap.toImage() + + offset = 1 + y = y + offset + + if not width: + width = image.width() + if not height: + height = image.height() + + for _y in range(offset, image.height()): + for _x in range(image.width()): + color = QtGui.QColor(image.pixel(_x, _y)) + if _x < x or _y < y: + continue + # De unde 2? + elif (_x > width - x) or (_y > height - y - 2): + break + if color.name() != color_name: + print(x, y, width, height) + print(_x, _y, color.name()) + return False + return True + + @staticmethod + def has_color(pixmap, color_name): + image = pixmap.toImage() + + for y in range(image.height()): + for x in range(image.width()): + color = QtGui.QColor(image.pixel(x, y)) + if color.name() == color_name: + return True + return False + + @staticmethod + def color_names(pixmap): + color_names = set() + + image = pixmap.toImage() + for y in range(image.height()): + for x in range(image.width()): + color = QtGui.QColor(image.pixel(x, y)) + color_names.add(color.name()) + return color_names + + @staticmethod + def cursors_x(pixmap): + image = pixmap.toImage() + + cursors = [] + possible_cursor = None + + for x in range(image.width()): + count = 0 + for y in range(image.height()): + color = QtGui.QColor(image.pixel(x, y)) + # Skip Black + if color.name() == Pixmap.COLOR_BACKGROUND: + continue + if not possible_cursor: + possible_cursor = color.name() + if possible_cursor != color.name(): + break + count += 1 + else: + if count == image.height() - 2: + cursors.append(x) + + return cursors diff --git a/test/asammdf/gui/widgets/test_BaseFileWidget.py b/test/asammdf/gui/widgets/test_BaseFileWidget.py index 01cd34295..a59a453aa 100644 --- a/test/asammdf/gui/widgets/test_BaseFileWidget.py +++ b/test/asammdf/gui/widgets/test_BaseFileWidget.py @@ -1,4 +1,5 @@ from test.asammdf.gui.test_base import TestBase +from unittest import mock from asammdf.gui.widgets.file import FileWidget @@ -8,6 +9,10 @@ def setUp(self): super().setUp() self.widget = None + patcher = mock.patch("asammdf.gui.widgets.file.ErrorDialog") + self.mc_widget_ed = patcher.start() + self.addCleanup(patcher.stop) + def tearDown(self): if self.widget: self.widget.close() diff --git a/test/asammdf/gui/widgets/test_BasePlotWidget.py b/test/asammdf/gui/widgets/test_BasePlotWidget.py index ba3b4bce5..5e70d5223 100644 --- a/test/asammdf/gui/widgets/test_BasePlotWidget.py +++ b/test/asammdf/gui/widgets/test_BasePlotWidget.py @@ -3,112 +3,7 @@ from test.asammdf.gui.widgets.test_BaseFileWidget import TestFileWidget from unittest import mock -from PySide6 import QtCore, QtGui, QtTest, QtWidgets - - -class Pixmap: - COLOR_BACKGROUND = "#000000" - COLOR_RANGE = "#000032" - COLOR_CURSOR = "#e69138" - - @staticmethod - def is_black(pixmap): - """ - Excepting cursor - """ - cursor_x = None - cursor_y = None - cursor_color = None - image = pixmap.toImage() - - for y in range(image.height()): - for x in range(image.width()): - color = QtGui.QColor(image.pixel(x, y)) - if color.name() != Pixmap.COLOR_BACKGROUND: - if not cursor_x and not cursor_y and not cursor_color: - cursor_x = x - cursor_y = y + 1 - cursor_color = color - continue - elif cursor_x == x and cursor_y == y and cursor_color == color: - cursor_y += 1 - continue - else: - return False - return True - - @staticmethod - def is_colored(pixmap, color_name, x, y, width=None, height=None): - image = pixmap.toImage() - - offset = 1 - y = y + offset - - if not width: - width = image.width() - if not height: - height = image.height() - - for _y in range(offset, image.height()): - for _x in range(image.width()): - color = QtGui.QColor(image.pixel(_x, _y)) - if _x < x or _y < y: - continue - # De unde 2? - elif (_x > width - x) or (_y > height - y - 2): - break - if color.name() != color_name: - print(x, y, width, height) - print(_x, _y, color.name()) - return False - return True - - @staticmethod - def has_color(pixmap, color_name): - image = pixmap.toImage() - - for y in range(image.height()): - for x in range(image.width()): - color = QtGui.QColor(image.pixel(x, y)) - if color.name() == color_name: - return True - return False - - @staticmethod - def color_names(pixmap): - color_names = set() - - image = pixmap.toImage() - for y in range(image.height()): - for x in range(image.width()): - color = QtGui.QColor(image.pixel(x, y)) - color_names.add(color.name()) - return color_names - - @staticmethod - def cursors_x(pixmap): - image = pixmap.toImage() - - cursors = [] - possible_cursor = None - - for x in range(image.width()): - count = 0 - for y in range(image.height()): - color = QtGui.QColor(image.pixel(x, y)) - # Skip Black - if color.name() == Pixmap.COLOR_BACKGROUND: - continue - if not possible_cursor: - possible_cursor = color.name() - if possible_cursor != color.name(): - break - count += 1 - else: - if count == image.height() - 2: - cursors.append(x) - - return cursors +from PySide6 import QtCore, QtTest, QtWidgets class TestPlotWidget(TestFileWidget): diff --git a/test/asammdf/gui/widgets/test_FileWidget.py b/test/asammdf/gui/widgets/test_FileWidget_TabChannels.py similarity index 88% rename from test/asammdf/gui/widgets/test_FileWidget.py rename to test/asammdf/gui/widgets/test_FileWidget_TabChannels.py index 46b507404..bba7f83c8 100644 --- a/test/asammdf/gui/widgets/test_FileWidget.py +++ b/test/asammdf/gui/widgets/test_FileWidget_TabChannels.py @@ -1,21 +1,24 @@ #!/usr/bin/env python import pathlib -import shutil from test.asammdf.gui.test_base import DragAndDrop from test.asammdf.gui.widgets.test_BaseFileWidget import TestFileWidget -import time from unittest import mock -from PySide6 import QtCore, QtGui, QtTest, QtWidgets +from PySide6 import QtCore, QtTest, QtWidgets from asammdf.gui.dialogs.channel_group_info import ChannelGroupInfoDialog from asammdf.gui.dialogs.channel_info import ChannelInfoDialog -# Note: If it's possible and make sense use self.subTests -# to avoid initialize widgets multiple times and consume time. +# Note: If it's possible and make sense, use self.subTests +# to avoid initializing widgets multiple times and consume time. class TestTabChannels(TestFileWidget): + def tearDown(self): + self.mc_ErrorDialog.assert_not_called() + self.mc_widget_ed.assert_not_called() + super().tearDown() + def test_PushButton_LoadOfflineWindows_DSP(self): """ Events: @@ -971,132 +974,3 @@ def test_DoubleClick_Channel(self): self.assertTrue(child.isVisible()) child.close() self.assertFalse(child.isVisible()) - - -class TestTabModifyAndExport(TestFileWidget): - def test_PushButton_ScrambleTexts(self): - """ - Events: - - Open 'FileWidget' with valid measurement. - - Go to Tab: "Modify & Export": Index 1 - - Press PushButton "Scramble texts" - Evaluate: - - New file is created - - No channel from first file is found in 2nd file (scrambled file) - """ - # Setup - measurement_file = str(pathlib.Path(self.test_workspace, "ASAP2_Demo_V171.mf4")) - shutil.copy( - pathlib.Path(self.resource, "ASAP2_Demo_V171.mf4"), measurement_file - ) - # Event - self.setUpFileWidget(measurement_file=measurement_file, default=True) - # Go to Tab: "Modify & Export": Index 1 - self.widget.aspects.setCurrentIndex(1) - # Press PushButton ScrambleTexts - QtTest.QTest.mouseClick(self.widget.scramble_btn, QtCore.Qt.LeftButton) - - channels = self.widget.channels_db_items - - # Evaluate - scrambled_filepath = pathlib.Path( - self.test_workspace, "ASAP2_Demo_V171.scrambled.mf4" - ) - # Wait for Thread to finish - time.sleep(0.1) - # TearDown Current Widget. - self.widget.close() - self.widget.destroy() - self.widget.deleteLater() - - self.setUpFileWidget(measurement_file=scrambled_filepath, default=True) - scrambled_channels = self.widget.channels_db_items - result = filter(lambda c: c in scrambled_channels, channels) - self.assertFalse(any(result)) - - def test_ExportMDF(self): - """ - When QThreads are running, event-loops needs to be processed. - Events: - - Open 'FileWidget' with valid measurement. - - Go to Tab: "Modify & Export": Index 1 - - Set "channel_view" to "Natural sort" - - Select two channels - - Ensure that output format is MDF - - Case 0: - - Press PushButton Apply. - - Simulate that no valid path is provided. - - Case 1: - - Press PushButton Apply. - - Simulate that no valid path is provided. - Evaluate: - - Evaluate that file was created. - - Open File and check that there are only two channels. - """ - # Setup - measurement_file = str(pathlib.Path(self.resource, "ASAP2_Demo_V171.mf4")) - # Event - self.setUpFileWidget(measurement_file=measurement_file, default=True) - # Go to Tab: "Modify & Export": Index 1 - self.widget.aspects.setCurrentIndex(1) - self.widget.filter_view.setCurrentText("Natural sort") - - count = 2 - selected_channels = [] - iterator = QtWidgets.QTreeWidgetItemIterator(self.widget.filter_tree) - while iterator.value() and count: - item = iterator.value() - item.setCheckState(0, QtCore.Qt.Checked) - self.assertTrue(item.checkState(0)) - selected_channels.append(item.text(0)) - iterator += 1 - count -= 1 - # Evaluate that channels were added to "selected_filter_channels" - for index in range(self.widget.selected_filter_channels.count()): - item = self.widget.selected_filter_channels.item(index) - self.assertIn(item.text(), selected_channels) - - self.widget.output_format.setCurrentText("MDF") - - # Case 0: - self.processEvents() - with self.subTest("test_ExportMDF_0"): - with mock.patch( - "asammdf.gui.widgets.file.QtWidgets.QFileDialog.getSaveFileName" - ) as mc_getSaveFileName, mock.patch( - "asammdf.gui.widgets.file.setup_progress" - ) as mo_setup_progress: - mc_getSaveFileName.return_value = None, None - QtTest.QTest.mouseClick(self.widget.apply_btn, QtCore.Qt.LeftButton) - self.processEvents() - # Evaluate - # Progress is not created - mo_setup_progress.assert_not_called() - - # Case 1: - self.processEvents() - with self.subTest("test_ExportMDF_1"): - saved_file = pathlib.Path(self.test_workspace, f"{self.id()}.mf4") - with mock.patch( - "asammdf.gui.widgets.file.QtWidgets.QFileDialog.getSaveFileName" - ) as mc_getSaveFileName: - mc_getSaveFileName.return_value = str(saved_file), None - QtTest.QTest.mouseClick(self.widget.apply_btn, QtCore.Qt.LeftButton) - self.processEvents() - # Wait for thread to finish - self.processEvents(0.1) - - # Evaluate - self.assertTrue(saved_file.exists()) - - # TearDown Widget - self.widget.close() - self.widget.destroy() - self.widget.deleteLater() - self.processEvents() - - self.setUpFileWidget(measurement_file=saved_file, default=True) - - channels = self.widget.channels_db_items - selected_channels.append("time") - self.assertListEqual(selected_channels, list(channels)) diff --git a/test/asammdf/gui/widgets/test_FileWidget_TabModifyAndExport.py b/test/asammdf/gui/widgets/test_FileWidget_TabModifyAndExport.py new file mode 100644 index 000000000..7ce00d4f4 --- /dev/null +++ b/test/asammdf/gui/widgets/test_FileWidget_TabModifyAndExport.py @@ -0,0 +1,140 @@ +#!/usr/bin/env python +import pathlib +import shutil +from test.asammdf.gui.widgets.test_BaseFileWidget import TestFileWidget +import time +from unittest import mock + +from PySide6 import QtCore, QtTest, QtWidgets + +# Note: If it's possible and make sense, use self.subTests +# to avoid initializing widgets multiple times and consume time. + + +class TestTabModifyAndExport(TestFileWidget): + def test_PushButton_ScrambleTexts(self): + """ + Events: + - Open 'FileWidget' with valid measurement. + - Go to Tab: "Modify & Export": Index 1 + - Press PushButton "Scramble texts" + Evaluate: + - New file is created + - No channel from first file is found in 2nd file (scrambled file) + """ + # Setup + measurement_file = str(pathlib.Path(self.test_workspace, "ASAP2_Demo_V171.mf4")) + shutil.copy( + pathlib.Path(self.resource, "ASAP2_Demo_V171.mf4"), measurement_file + ) + # Event + self.setUpFileWidget(measurement_file=measurement_file, default=True) + # Go to Tab: "Modify & Export": Index 1 + self.widget.aspects.setCurrentIndex(1) + # Press PushButton ScrambleTexts + QtTest.QTest.mouseClick(self.widget.scramble_btn, QtCore.Qt.LeftButton) + + channels = self.widget.channels_db_items + + # Evaluate + scrambled_filepath = pathlib.Path( + self.test_workspace, "ASAP2_Demo_V171.scrambled.mf4" + ) + # Wait for Thread to finish + time.sleep(0.1) + # TearDown Current Widget. + self.widget.close() + self.widget.destroy() + self.widget.deleteLater() + + self.setUpFileWidget(measurement_file=scrambled_filepath, default=True) + scrambled_channels = self.widget.channels_db_items + result = filter(lambda c: c in scrambled_channels, channels) + self.assertFalse(any(result)) + + def test_ExportMDF(self): + """ + When QThreads are running, event-loops needs to be processed. + Events: + - Open 'FileWidget' with valid measurement. + - Go to Tab: "Modify & Export": Index 1 + - Set "channel_view" to "Natural sort" + - Select two channels + - Ensure that output format is MDF + - Case 0: + - Press PushButton Apply. + - Simulate that no valid path is provided. + - Case 1: + - Press PushButton Apply. + - Simulate that no valid path is provided. + Evaluate: + - Evaluate that file was created. + - Open File and check that there are only two channels. + """ + # Setup + measurement_file = str(pathlib.Path(self.resource, "ASAP2_Demo_V171.mf4")) + # Event + self.setUpFileWidget(measurement_file=measurement_file, default=True) + # Go to Tab: "Modify & Export": Index 1 + self.widget.aspects.setCurrentIndex(1) + self.widget.filter_view.setCurrentText("Natural sort") + + count = 2 + selected_channels = [] + iterator = QtWidgets.QTreeWidgetItemIterator(self.widget.filter_tree) + while iterator.value() and count: + item = iterator.value() + item.setCheckState(0, QtCore.Qt.Checked) + self.assertTrue(item.checkState(0)) + selected_channels.append(item.text(0)) + iterator += 1 + count -= 1 + # Evaluate that channels were added to "selected_filter_channels" + for index in range(self.widget.selected_filter_channels.count()): + item = self.widget.selected_filter_channels.item(index) + self.assertIn(item.text(), selected_channels) + + self.widget.output_format.setCurrentText("MDF") + + # Case 0: + self.processEvents() + with self.subTest("test_ExportMDF_0"): + with mock.patch( + "asammdf.gui.widgets.file.QtWidgets.QFileDialog.getSaveFileName" + ) as mc_getSaveFileName, mock.patch( + "asammdf.gui.widgets.file.setup_progress" + ) as mo_setup_progress: + mc_getSaveFileName.return_value = None, None + QtTest.QTest.mouseClick(self.widget.apply_btn, QtCore.Qt.LeftButton) + self.processEvents() + # Evaluate + # Progress is not created + mo_setup_progress.assert_not_called() + + # Case 1: + self.processEvents() + with self.subTest("test_ExportMDF_1"): + saved_file = pathlib.Path(self.test_workspace, f"{self.id()}.mf4") + with mock.patch( + "asammdf.gui.widgets.file.QtWidgets.QFileDialog.getSaveFileName" + ) as mc_getSaveFileName: + mc_getSaveFileName.return_value = str(saved_file), None + QtTest.QTest.mouseClick(self.widget.apply_btn, QtCore.Qt.LeftButton) + self.processEvents() + # Wait for thread to finish + self.processEvents(0.1) + + # Evaluate + self.assertTrue(saved_file.exists()) + + # TearDown Widget + self.widget.close() + self.widget.destroy() + self.widget.deleteLater() + self.processEvents() + + self.setUpFileWidget(measurement_file=saved_file, default=True) + + channels = self.widget.channels_db_items + selected_channels.append("time") + self.assertListEqual(selected_channels, list(channels)) diff --git a/test/asammdf/gui/widgets/test_PlotWidget_DoubleClick.py b/test/asammdf/gui/widgets/test_PlotWidget_DoubleClick.py new file mode 100644 index 000000000..02514d7e0 --- /dev/null +++ b/test/asammdf/gui/widgets/test_PlotWidget_DoubleClick.py @@ -0,0 +1,931 @@ +#!/usr/bin/env python +from test.asammdf.gui.test_base import DragAndDrop, Pixmap +from test.asammdf.gui.widgets.test_BasePlotWidget import TestPlotWidget +from unittest import mock + +from PySide6 import QtCore, QtGui, QtTest + + +class TestDoubleClick(TestPlotWidget): + # Note: Test Plot Widget through FileWidget. + + def test_ChannelSelection(self): + """ + Test Scope: Validate that doubleClick operation will activate deactivate channels. + Events: + - Open 'FileWidget' with valid measurement. + - Switch ComboBox to "Natural sort" + - Press PushButton "Create Window" + - Simulate that Plot window is selected as window type. + - Drag and Drop channel from FileWidget.channel_tree to Plot + - Press mouse double click on added channel + - Press mouse double click on added channel + Evaluate: + - Evaluate that channel checkbox is unchecked. + - Evaluate that channel checkbox is checked. + """ + # Event + # Open File Widget + self.setUpFileWidget(measurement_file=self.measurement_file, default=True) + # Switch ComboBox to "Natural sort" + self.widget.channel_view.setCurrentText("Natural sort") + # Create plot window + self.create_window(window_type="Plot") + self.assertEqual(len(self.widget.mdi_area.subWindowList()), 1) + # Drag and Drop channel from FileWidget.channel_tree to Plot + plot = self.widget.mdi_area.subWindowList()[0].widget() + plot_channel = self.add_channel_to_plot(plot=plot) + + # Pre-evaluation + self.assertEqual(QtCore.Qt.Checked, plot_channel.checkState(0)) + + # Press mouse double click on channel + self.mouseDClick_WidgetItem(plot_channel) + + # Evaluate + self.assertEqual(QtCore.Qt.Unchecked, plot_channel.checkState(0)) + + # Press mouse double click on channel + self.mouseDClick_WidgetItem(plot_channel) + self.assertEqual(QtCore.Qt.Checked, plot_channel.checkState(0)) + + def test_EnableDisable_Group(self): + """ + Test Scope: Validate that doubleClick operation will activate deactivate groups. + Events: + - Open 'FileWidget' with valid measurement. + - Switch ComboBox to "Natural sort" + - Press PushButton "Create Window" + - Simulate that Plot window is selected as window type. + - Drag and Drop channels from FileWidget.channel_tree to Plot + - Press 'Shift-Insert' in order to Insert Group + - Drag and Drop some channels to new Group + - Press mouse double click on added group + - Press key Down few times + - Press mouse double click on added group + - Press key Down few times + Evaluate: + - Evaluate that group is disabled (not selectable anymore). + - Evaluate that channel is enabled (selectable). + - Evaluate that channel is not present on plot when is disabled. + """ + # Event + # Open File Widget + self.setUpFileWidget(measurement_file=self.measurement_file, default=True) + # Switch ComboBox to "Natural sort" + self.widget.channel_view.setCurrentText("Natural sort") + # Create a plot window + self.create_window(window_type="Plot") + self.assertEqual(len(self.widget.mdi_area.subWindowList()), 1) + plot = self.widget.mdi_area.subWindowList()[0].widget() + # Press PushButton 'FocusMode' - disabled (easy for evaluation) + if not plot.focused_mode_btn.isFlat(): + QtTest.QTest.mouseClick(plot.focused_mode_btn, QtCore.Qt.LeftButton) + # Drag and Drop channel from FileWidget.channel_tree to Plot + plot_channel_0 = self.add_channel_to_plot(plot=plot, channel_index=10) + _ = self.add_channel_to_plot(plot=plot, channel_index=11) + plot_channel_2 = self.add_channel_to_plot(plot=plot, channel_index=12) + # Press 'Shift-Insert' in order to Insert Group + # Create Channel Group. Drag channels inside the group one by one + with mock.patch( + "asammdf.gui.widgets.tree.QtWidgets.QInputDialog.getText" + ) as mc_getText: + # Create Channel Group + mc_getText.return_value = "FirstGroup", True + QtTest.QTest.keySequence( + plot.channel_selection, QtGui.QKeySequence("Shift+Insert") + ) + self.processEvents() + # PreEvaluation: Check if there is one extra-item + self.assertEqual(4, plot.channel_selection.topLevelItemCount()) + # Get Group Position + for index in range(plot.channel_selection.topLevelItemCount()): + item = plot.channel_selection.topLevelItem(index) + if item.text(self.Column.NAME) == "FirstGroup": + first_group = item + break + else: + self.fail("FirstGroup is not present on Plot Channel Selection.") + first_group.setExpanded(True) + # Get the First Item that will be moved + drag_position = plot.channel_selection.visualItemRect( + plot_channel_0 + ).center() + drop_position = plot.channel_selection.visualItemRect(first_group).center() + # Get the Name of the first channel + first_channel = plot_channel_0.text(self.Column.NAME) + # PreEvaluation: Ensure that group has no child + self.assertEqual(0, first_group.childCount()) + DragAndDrop( + source_widget=plot.channel_selection, + destination_widget=plot.channel_selection.viewport(), + source_pos=drag_position, + destination_pos=drop_position, + ) + # PreEvaluate: Ensure that channel was added to group + self.assertEqual(1, first_group.childCount()) + self.assertEqual(first_channel, first_group.child(0).text(self.Column.NAME)) + self.assertEqual(3, plot.channel_selection.topLevelItemCount()) + + enabled_groups_pixmap = plot.plot.viewport().grab() + # Evaluate + self.assertTrue( + Pixmap.has_color( + pixmap=enabled_groups_pixmap, + color_name=plot_channel_0.color, + ) + ) + # Press mouse double click on channel + self.mouseDClick_WidgetItem(first_group) + disabled_groups_pixmap = plot.plot.viewport().grab() + + # Evaluate + self.assertFalse( + Pixmap.has_color( + pixmap=disabled_groups_pixmap, + color_name=plot_channel_0.color, + ) + ) + + for _ in range(4): + QtTest.QTest.keyClick(plot.channel_selection, QtCore.Qt.Key_Down) + self.processEvents() + + # Evaluate that item is still 2nd one because + selectedItems = plot.channel_selection.selectedItems() + self.assertEqual(1, len(selectedItems)) + selectedItem = selectedItems[0].text(self.Column.NAME) + self.assertEqual(plot_channel_2.text(self.Column.NAME), selectedItem) + + # Press mouse double click on channel + self.mouseDClick_WidgetItem(first_group) + self.processEvents() + + for _ in range(4): + QtTest.QTest.keyClick(plot.channel_selection, QtCore.Qt.Key_Down) + self.processEvents() + + # Evaluate that item is the one from the group + selectedItems = plot.channel_selection.selectedItems() + self.assertEqual(1, len(selectedItems)) + selectedItem = selectedItems[0].text(self.Column.NAME) + self.assertEqual(plot_channel_0.text(self.Column.NAME), selectedItem) + + # Evaluate + # After channels are enabled, they first flash a few times on plot. + # ProcessEvents few times for channels to be present + for _ in range(20): + self.processEvents() + + enabled_groups_pixmap = plot.plot.viewport().grab() + self.assertTrue( + Pixmap.has_color( + pixmap=enabled_groups_pixmap, + color_name=plot_channel_0.color, + ) + ) + + def test_EnableDisable_ParentGroup(self): + """ + Test Scope: + Validate that doubleClick operation will activate deactivate subgroups when parent is disabled. + Events: + - Open 'FileWidget' with valid measurement. + - Switch ComboBox to "Natural sort" + - Press PushButton "Create Window" + - Simulate that Plot window is selected as window type. + - Drag and Drop channels from FileWidget.channel_tree to Plot + - Press 'Shift-Insert' in order to Insert Group: A + - Press 'Shift-Insert' in order to Insert Group: B + - Press 'Shift-Insert' in order to Insert Group: C + - Drag and Drop some channels to new Group: A + - Drag and Drop some channels to new Group: B + - Drag and Drop some channels to new Group: C + - Move Group C inside Group B + - Move Group B inside Group A + - Press mouse double click on added group: A + - Press key Down few times + - Press mouse double click on added group: A + - Press key Down few times + Evaluate: + - Evaluate that subgroups are disabled (not selectable anymore). + - Evaluate that channels are enabled (selectable). + - Evaluate that channel is not present on plot when is disabled. + - Evaluate channel color is darkGray when it's disabled. + """ + # Event + # Open File Widget + self.setUpFileWidget(measurement_file=self.measurement_file, default=True) + # Switch ComboBox to "Natural sort" + self.widget.channel_view.setCurrentText("Natural sort") + # Create a plot window + self.create_window(window_type="Plot") + self.assertEqual(len(self.widget.mdi_area.subWindowList()), 1) + plot = self.widget.mdi_area.subWindowList()[0].widget() + # Press PushButton 'FocusMode' - disabled (easy for evaluation) + if not plot.focused_mode_btn.isFlat(): + QtTest.QTest.mouseClick(plot.focused_mode_btn, QtCore.Qt.LeftButton) + # Drag and Drop channel from FileWidget.channel_tree to Plot + plot_channel_a = self.add_channel_to_plot(plot=plot, channel_index=10) + plot_channel_b = self.add_channel_to_plot(plot=plot, channel_index=11) + plot_channel_c = self.add_channel_to_plot(plot=plot, channel_index=12) + plot_channel_d = self.add_channel_to_plot(plot=plot, channel_index=13) + # Press 'Shift-Insert' in order to Insert Group + # Create Channel Group. Drag channels inside the group one by one + groups = {} + with mock.patch( + "asammdf.gui.widgets.tree.QtWidgets.QInputDialog.getText" + ) as mc_getText: + for group_name in ("A", "B", "C"): + # Create Channel Group + mc_getText.return_value = group_name, True + QtTest.QTest.keySequence( + plot.channel_selection, QtGui.QKeySequence("Shift+Insert") + ) + self.processEvents() + + # Get Groups Position + for index in range(plot.channel_selection.topLevelItemCount()): + item = plot.channel_selection.topLevelItem(index) + group_name = item.text(self.Column.NAME) + if group_name in ("A", "B", "C"): + groups[group_name] = item + item.setExpanded(True) + + # Get the First Item that will be moved + for group_name in ("A", "B", "C"): + plot_channel = locals()[f"plot_channel_{group_name.lower()}"] + drag_position = plot.channel_selection.visualItemRect( + plot_channel + ).center() + drop_position = plot.channel_selection.visualItemRect( + groups[group_name] + ).center() + + # Get the Name of the first channel + first_channel = plot_channel.text(self.Column.NAME) + # PreEvaluation: Ensure that group has no child + self.assertEqual(0, groups[group_name].childCount()) + DragAndDrop( + source_widget=plot.channel_selection, + destination_widget=plot.channel_selection.viewport(), + source_pos=drag_position, + destination_pos=drop_position, + ) + self.assertEqual(1, groups[group_name].childCount()) + self.processEvents() + + # Move Group C inside Group B + drag_position = plot.channel_selection.visualItemRect(groups["C"]).center() + drop_position = plot.channel_selection.visualItemRect(groups["B"]).center() + DragAndDrop( + source_widget=plot.channel_selection, + destination_widget=plot.channel_selection.viewport(), + source_pos=drag_position, + destination_pos=drop_position, + ) + # Move Group B inside Group A + drag_position = plot.channel_selection.visualItemRect(groups["B"]).center() + drop_position = plot.channel_selection.visualItemRect(groups["A"]).center() + DragAndDrop( + source_widget=plot.channel_selection, + destination_widget=plot.channel_selection.viewport(), + source_pos=drag_position, + destination_pos=drop_position, + ) + + groups["A"].setExpanded(True) + groups["B"].setExpanded(True) + groups["C"].setExpanded(True) + + enabled_groups_pixmap = plot.plot.viewport().grab() + self.processEvents() + # Evaluate + for channel in (plot_channel_a, plot_channel_b, plot_channel_c): + self.assertTrue( + Pixmap.has_color( + pixmap=enabled_groups_pixmap, color_name=channel.color + ), + msg=f"Color of Channel: {channel.text(self.Column.NAME)} not present on 'plot'.", + ) + color_name = channel.foreground(self.Column.NAME).color().name() + self.assertNotEqual(color_name, "#808080") + # Press mouse double click on Group A + self.mouseDClick_WidgetItem(groups["A"]) + disabled_groups_pixmap = plot.plot.viewport().grab() + + # Evaluate + for channel in (plot_channel_a, plot_channel_b, plot_channel_c): + self.assertFalse( + Pixmap.has_color( + pixmap=disabled_groups_pixmap, + color_name=channel.color, + ), + msg=f"Color of Channel: {channel.text(self.Column.NAME)} present on 'plot'.", + ) + color_name = channel.foreground(self.Column.NAME).color().name() + self.assertEqual(color_name, "#808080") + + QtTest.QTest.keyClick(plot.channel_selection, QtCore.Qt.Key_Up) + for _ in range(4): + QtTest.QTest.keyClick(plot.channel_selection, QtCore.Qt.Key_Down) + self.processEvents() + + # Evaluate that item is still plot_channel_d + selectedItems = plot.channel_selection.selectedItems() + self.assertEqual(1, len(selectedItems)) + selectedItem = selectedItems[0].text(self.Column.NAME) + self.assertEqual(plot_channel_d.text(self.Column.NAME), selectedItem) + + # Press mouse double click on channel + self.mouseDClick_WidgetItem(groups["A"]) + self.processEvents() + + for _ in range(8): + QtTest.QTest.keyClick(plot.channel_selection, QtCore.Qt.Key_Down) + self.processEvents() + + # Evaluate that item is the one from the group C + selectedItems = plot.channel_selection.selectedItems() + self.assertEqual(1, len(selectedItems)) + selectedItem = selectedItems[0].text(self.Column.NAME) + self.assertEqual(plot_channel_c.text(self.Column.NAME), selectedItem) + + # Evaluate + # After channels are enabled, they first flash a few times on plot. + # ProcessEvents few times for channels to be present + for _ in range(20): + self.processEvents() + + enabled_groups_pixmap = plot.plot.viewport().grab() + for channel in ( + plot_channel_a, + plot_channel_b, + plot_channel_c, + plot_channel_d, + ): + self.assertTrue( + Pixmap.has_color( + pixmap=enabled_groups_pixmap, color_name=channel.color + ), + msg=f"Color for Channel: {channel.text(self.Column.NAME)} not present on 'plot'", + ) + color_name = channel.foreground(self.Column.NAME).color().name() + self.assertNotEqual(color_name, "#808080") + + def test_EnableDisable_Subgroup(self): + """ + Test Scope: + Validate that doubleClick operation will activate deactivate subgroups and keep parent enabled. + Events: + - Open 'FileWidget' with valid measurement. + - Switch ComboBox to "Natural sort" + - Press PushButton "Create Window" + - Simulate that Plot window is selected as window type. + - Drag and Drop channels from FileWidget.channel_tree to Plot + - Press 'Shift-Insert' in order to Insert Group: A + - Press 'Shift-Insert' in order to Insert Group: B + - Press 'Shift-Insert' in order to Insert Group: C + - Drag and Drop some channels to new Group: A + - Drag and Drop some channels to new Group: B + - Drag and Drop some channels to new Group: C + - Move Group C inside Group B + - Move Group B inside Group A + - Press mouse double click on added group: B + - Press key Down few times + - Press mouse double click on added group: B + - Press key Down few times + Evaluate: + - Evaluate that subgroups are disabled (not selectable anymore). + - Evaluate that channels are enabled (selectable). + - Evaluate that channel is not present on plot when is disabled. + """ + # Event + # Open File Widget + self.setUpFileWidget(measurement_file=self.measurement_file, default=True) + # Switch ComboBox to "Natural sort" + self.widget.channel_view.setCurrentText("Natural sort") + # Create a plot window + self.create_window(window_type="Plot") + self.assertEqual(len(self.widget.mdi_area.subWindowList()), 1) + plot = self.widget.mdi_area.subWindowList()[0].widget() + # Press PushButton 'FocusMode' - disabled (easy for evaluation) + if not plot.focused_mode_btn.isFlat(): + QtTest.QTest.mouseClick(plot.focused_mode_btn, QtCore.Qt.LeftButton) + # Drag and Drop channel from FileWidget.channel_tree to Plot + plot_channel_a = self.add_channel_to_plot(plot=plot, channel_index=10) + plot_channel_b = self.add_channel_to_plot(plot=plot, channel_index=11) + plot_channel_c = self.add_channel_to_plot(plot=plot, channel_index=12) + plot_channel_d = self.add_channel_to_plot(plot=plot, channel_index=13) + # Press 'Shift-Insert' in order to Insert Group + # Create Channel Group. Drag channels inside the group one by one + groups = {} + with mock.patch( + "asammdf.gui.widgets.tree.QtWidgets.QInputDialog.getText" + ) as mc_getText: + for group_name in ("A", "B", "C"): + # Create Channel Group + mc_getText.return_value = group_name, True + QtTest.QTest.keySequence( + plot.channel_selection, QtGui.QKeySequence("Shift+Insert") + ) + self.processEvents() + + # Get Groups Position + for index in range(plot.channel_selection.topLevelItemCount()): + item = plot.channel_selection.topLevelItem(index) + group_name = item.text(self.Column.NAME) + if group_name in ("A", "B", "C"): + groups[group_name] = item + item.setExpanded(True) + + # Get the First Item that will be moved + for group_name in ("A", "B", "C"): + plot_channel = locals()[f"plot_channel_{group_name.lower()}"] + drag_position = plot.channel_selection.visualItemRect( + plot_channel + ).center() + drop_position = plot.channel_selection.visualItemRect( + groups[group_name] + ).center() + + # Get the Name of the first channel + first_channel = plot_channel.text(self.Column.NAME) + # PreEvaluation: Ensure that group has no child + self.assertEqual(0, groups[group_name].childCount()) + DragAndDrop( + source_widget=plot.channel_selection, + destination_widget=plot.channel_selection.viewport(), + source_pos=drag_position, + destination_pos=drop_position, + ) + self.assertEqual(1, groups[group_name].childCount()) + self.processEvents() + + # Move Group C inside Group B + drag_position = plot.channel_selection.visualItemRect(groups["C"]).center() + drop_position = plot.channel_selection.visualItemRect(groups["B"]).center() + DragAndDrop( + source_widget=plot.channel_selection, + destination_widget=plot.channel_selection.viewport(), + source_pos=drag_position, + destination_pos=drop_position, + ) + # Move Group B inside Group A + drag_position = plot.channel_selection.visualItemRect(groups["B"]).center() + drop_position = plot.channel_selection.visualItemRect(groups["A"]).center() + DragAndDrop( + source_widget=plot.channel_selection, + destination_widget=plot.channel_selection.viewport(), + source_pos=drag_position, + destination_pos=drop_position, + ) + + groups["A"].setExpanded(True) + groups["B"].setExpanded(True) + groups["C"].setExpanded(True) + + enabled_groups_pixmap = plot.plot.viewport().grab() + self.processEvents() + # Evaluate + for channel in (plot_channel_a, plot_channel_b, plot_channel_c): + self.assertTrue( + Pixmap.has_color( + pixmap=enabled_groups_pixmap, color_name=channel.color + ), + msg=f"Color of Channel: {channel.text(self.Column.NAME)} not present on 'plot'.", + ) + # Press mouse double click on Group B + self.mouseDClick_WidgetItem(groups["B"]) + disabled_groups_pixmap = plot.plot.viewport().grab() + + # Evaluate + self.assertTrue( + Pixmap.has_color( + pixmap=enabled_groups_pixmap, color_name=plot_channel_a.color + ), + msg=f"Color of Channel: {plot_channel_a.text(self.Column.NAME)} not present on 'plot'.", + ) + for channel in (plot_channel_b, plot_channel_c): + self.assertFalse( + Pixmap.has_color( + pixmap=disabled_groups_pixmap, + color_name=channel.color, + ), + msg=f"Color of Channel: {channel.text(self.Column.NAME)} present on 'plot'.", + ) + + QtTest.QTest.keyClick(plot.channel_selection, QtCore.Qt.Key_Up) + for _ in range(4): + QtTest.QTest.keyClick(plot.channel_selection, QtCore.Qt.Key_Down) + self.processEvents() + + # Press mouse double click on group B + self.mouseDClick_WidgetItem(groups["B"]) + self.processEvents() + + for _ in range(8): + QtTest.QTest.keyClick(plot.channel_selection, QtCore.Qt.Key_Down) + self.processEvents() + + # Evaluate + # After channels are enabled, they first flash a few times on plot. + # ProcessEvents few times for channels to be present + for _ in range(20): + self.processEvents() + + enabled_groups_pixmap = plot.plot.viewport().grab() + for channel in ( + plot_channel_a, + plot_channel_b, + plot_channel_c, + plot_channel_d, + ): + self.assertTrue( + Pixmap.has_color( + pixmap=enabled_groups_pixmap, color_name=channel.color + ), + msg=f"Color for Channel: {channel.text(self.Column.NAME)} not present on 'plot'", + ) + + def test_EnableDisable_Preserve_Subgroup_State_0(self): + """ + Test Scope: + Validate that doubleClick operation will activate/deactivate subgroups and preserve state + when parent is disabled/enabled. + Events: + - Open 'FileWidget' with valid measurement. + - Switch ComboBox to "Natural sort" + - Press PushButton "Create Window" + - Simulate that Plot window is selected as window type. + - Drag and Drop channels from FileWidget.channel_tree to Plot + - Press 'Shift-Insert' in order to Insert Group: A + - Press 'Shift-Insert' in order to Insert Group: B + - Press 'Shift-Insert' in order to Insert Group: C + - Drag and Drop some channels to new Group: A + - Drag and Drop some channels to new Group: B + - Drag and Drop some channels to new Group: C + - Move Group C inside Group B + - Move Group B inside Group A + - Press mouse double click on added group: C + - Press mouse double click on added group: B + - Press key Down few times + - Press mouse double click on added group: B + - Press key Down few times + Evaluate: + - Evaluate that subgroups are disabled (not selectable anymore). + - Evaluate that channel is not present on plot when is disabled. + - Evaluate that subgroup C state is maintained after subgroup B is enabled. + """ + # Event + # Open File Widget + self.setUpFileWidget(measurement_file=self.measurement_file, default=True) + # Switch ComboBox to "Natural sort" + self.widget.channel_view.setCurrentText("Natural sort") + # Create a plot window + self.create_window(window_type="Plot") + self.assertEqual(len(self.widget.mdi_area.subWindowList()), 1) + plot = self.widget.mdi_area.subWindowList()[0].widget() + # Press PushButton 'FocusMode' - disabled (easy for evaluation) + if not plot.focused_mode_btn.isFlat(): + QtTest.QTest.mouseClick(plot.focused_mode_btn, QtCore.Qt.LeftButton) + # Drag and Drop channel from FileWidget.channel_tree to Plot + plot_channel_a = self.add_channel_to_plot(plot=plot, channel_index=10) + plot_channel_b = self.add_channel_to_plot(plot=plot, channel_index=11) + plot_channel_c = self.add_channel_to_plot(plot=plot, channel_index=12) + plot_channel_d = self.add_channel_to_plot(plot=plot, channel_index=13) + # Press 'Shift-Insert' in order to Insert Group + # Create Channel Group. Drag channels inside the group one by one + groups = {} + with mock.patch( + "asammdf.gui.widgets.tree.QtWidgets.QInputDialog.getText" + ) as mc_getText: + for group_name in ("A", "B", "C"): + # Create Channel Group + mc_getText.return_value = group_name, True + QtTest.QTest.keySequence( + plot.channel_selection, QtGui.QKeySequence("Shift+Insert") + ) + self.processEvents() + + # Get Groups Position + for index in range(plot.channel_selection.topLevelItemCount()): + item = plot.channel_selection.topLevelItem(index) + group_name = item.text(self.Column.NAME) + if group_name in ("A", "B", "C"): + groups[group_name] = item + item.setExpanded(True) + + # Get the First Item that will be moved + for group_name in ("A", "B", "C"): + plot_channel = locals()[f"plot_channel_{group_name.lower()}"] + drag_position = plot.channel_selection.visualItemRect( + plot_channel + ).center() + drop_position = plot.channel_selection.visualItemRect( + groups[group_name] + ).center() + + # Get the Name of the first channel + first_channel = plot_channel.text(self.Column.NAME) + # PreEvaluation: Ensure that group has no child + self.assertEqual(0, groups[group_name].childCount()) + DragAndDrop( + source_widget=plot.channel_selection, + destination_widget=plot.channel_selection.viewport(), + source_pos=drag_position, + destination_pos=drop_position, + ) + self.assertEqual(1, groups[group_name].childCount()) + self.processEvents() + + # Move Group C inside Group B + drag_position = plot.channel_selection.visualItemRect(groups["C"]).center() + drop_position = plot.channel_selection.visualItemRect(groups["B"]).center() + DragAndDrop( + source_widget=plot.channel_selection, + destination_widget=plot.channel_selection.viewport(), + source_pos=drag_position, + destination_pos=drop_position, + ) + # Move Group B inside Group A + drag_position = plot.channel_selection.visualItemRect(groups["B"]).center() + drop_position = plot.channel_selection.visualItemRect(groups["A"]).center() + DragAndDrop( + source_widget=plot.channel_selection, + destination_widget=plot.channel_selection.viewport(), + source_pos=drag_position, + destination_pos=drop_position, + ) + + groups["A"].setExpanded(True) + groups["B"].setExpanded(True) + groups["C"].setExpanded(True) + + enabled_groups_pixmap = plot.plot.viewport().grab() + self.processEvents() + # Evaluate + for channel in (plot_channel_a, plot_channel_b, plot_channel_c): + self.assertTrue( + Pixmap.has_color( + pixmap=enabled_groups_pixmap, color_name=channel.color + ), + msg=f"Color of Channel: {channel.text(self.Column.NAME)} not present on 'plot'.", + ) + # Press mouse double click on Group C + self.mouseDClick_WidgetItem(groups["C"]) + # Press mouse double click on Group B + self.mouseDClick_WidgetItem(groups["B"]) + disabled_groups_pixmap = plot.plot.viewport().grab() + + # Evaluate + self.assertTrue( + Pixmap.has_color( + pixmap=enabled_groups_pixmap, color_name=plot_channel_a.color + ), + msg=f"Color of Channel: {plot_channel_a.text(self.Column.NAME)} not present on 'plot'.", + ) + for channel in (plot_channel_b, plot_channel_c): + self.assertFalse( + Pixmap.has_color( + pixmap=disabled_groups_pixmap, + color_name=channel.color, + ), + msg=f"Color of Channel: {channel.text(self.Column.NAME)} present on 'plot'.", + ) + + QtTest.QTest.keyClick(plot.channel_selection, QtCore.Qt.Key_Up) + for _ in range(4): + QtTest.QTest.keyClick(plot.channel_selection, QtCore.Qt.Key_Down) + self.processEvents() + + # Press mouse double click on group B + self.mouseDClick_WidgetItem(groups["B"]) + self.processEvents() + + for _ in range(8): + QtTest.QTest.keyClick(plot.channel_selection, QtCore.Qt.Key_Down) + self.processEvents() + + # Evaluate + # After channels are enabled, they first flash a few times on plot. + # ProcessEvents few times for channels to be present + for _ in range(20): + self.processEvents() + + enabled_groups_pixmap = plot.plot.viewport().grab() + self.assertFalse( + Pixmap.has_color( + pixmap=enabled_groups_pixmap, color_name=plot_channel_c.color + ), + msg=f"Color for Channel: {plot_channel_c.text(self.Column.NAME)} present on 'plot'", + ) + for channel in (plot_channel_a, plot_channel_b, plot_channel_d): + self.assertTrue( + Pixmap.has_color( + pixmap=enabled_groups_pixmap, color_name=channel.color + ), + msg=f"Color for Channel: {channel.text(self.Column.NAME)} not present on 'plot'", + ) + + def test_EnableDisable_Preserve_Subgroup_State_1(self): + """ + Test Scope: + Validate that doubleClick operation will activate/deactivate subgroups and preserve state + when parent is disabled/enabled. + Events: + - Open 'FileWidget' with valid measurement. + - Switch ComboBox to "Natural sort" + - Press PushButton "Create Window" + - Simulate that Plot window is selected as window type. + - Drag and Drop channels from FileWidget.channel_tree to Plot + - Press 'Shift-Insert' in order to Insert Group: A + - Press 'Shift-Insert' in order to Insert Group: B + - Press 'Shift-Insert' in order to Insert Group: C + - Drag and Drop some channels to new Group: A + - Drag and Drop some channels to new Group: B + - Drag and Drop some channels to new Group: C + - Move Group C inside Group B + - Move Group B inside Group A + - Press mouse double click on added group: C + - Press mouse double click on added group: B + - Press key Down few times + - Press mouse double click on added group: B + - Press mouse click on group B: + - Use supposed to simulate Deactivate group from ContextMenu for group: C + but the bug is related to previous enabled group which remains selected. + - Press key Down few times + Evaluate: + - Evaluate that subgroups are disabled (not selectable anymore). + - Evaluate that channels are enabled (selectable). + - Evaluate that channel is not present on plot when is disabled. + """ + # Event + # Open File Widget + self.setUpFileWidget(measurement_file=self.measurement_file, default=True) + # Switch ComboBox to "Natural sort" + self.widget.channel_view.setCurrentText("Natural sort") + # Create a plot window + self.create_window(window_type="Plot") + self.assertEqual(len(self.widget.mdi_area.subWindowList()), 1) + plot = self.widget.mdi_area.subWindowList()[0].widget() + # Press PushButton 'FocusMode' - disabled (easy for evaluation) + if not plot.focused_mode_btn.isFlat(): + QtTest.QTest.mouseClick(plot.focused_mode_btn, QtCore.Qt.LeftButton) + # Drag and Drop channel from FileWidget.channel_tree to Plot + plot_channel_a = self.add_channel_to_plot(plot=plot, channel_index=10) + plot_channel_b = self.add_channel_to_plot(plot=plot, channel_index=11) + plot_channel_c = self.add_channel_to_plot(plot=plot, channel_index=12) + plot_channel_d = self.add_channel_to_plot(plot=plot, channel_index=13) + # Press 'Shift-Insert' in order to Insert Group + # Create Channel Group. Drag channels inside the group one by one + groups = {} + with mock.patch( + "asammdf.gui.widgets.tree.QtWidgets.QInputDialog.getText" + ) as mc_getText: + for group_name in ("A", "B", "C"): + # Create Channel Group + mc_getText.return_value = group_name, True + QtTest.QTest.keySequence( + plot.channel_selection, QtGui.QKeySequence("Shift+Insert") + ) + self.processEvents() + + # Get Groups Position + for index in range(plot.channel_selection.topLevelItemCount()): + item = plot.channel_selection.topLevelItem(index) + group_name = item.text(self.Column.NAME) + if group_name in ("A", "B", "C"): + groups[group_name] = item + item.setExpanded(True) + + # Get the First Item that will be moved + for group_name in ("A", "B", "C"): + plot_channel = locals()[f"plot_channel_{group_name.lower()}"] + drag_position = plot.channel_selection.visualItemRect( + plot_channel + ).center() + drop_position = plot.channel_selection.visualItemRect( + groups[group_name] + ).center() + + # Get the Name of the first channel + first_channel = plot_channel.text(self.Column.NAME) + # PreEvaluation: Ensure that group has no child + self.assertEqual(0, groups[group_name].childCount()) + DragAndDrop( + source_widget=plot.channel_selection, + destination_widget=plot.channel_selection.viewport(), + source_pos=drag_position, + destination_pos=drop_position, + ) + self.assertEqual(1, groups[group_name].childCount()) + self.processEvents() + + # Move Group C inside Group B + drag_position = plot.channel_selection.visualItemRect(groups["C"]).center() + drop_position = plot.channel_selection.visualItemRect(groups["B"]).center() + DragAndDrop( + source_widget=plot.channel_selection, + destination_widget=plot.channel_selection.viewport(), + source_pos=drag_position, + destination_pos=drop_position, + ) + # Move Group B inside Group A + drag_position = plot.channel_selection.visualItemRect(groups["B"]).center() + drop_position = plot.channel_selection.visualItemRect(groups["A"]).center() + DragAndDrop( + source_widget=plot.channel_selection, + destination_widget=plot.channel_selection.viewport(), + source_pos=drag_position, + destination_pos=drop_position, + ) + + groups["A"].setExpanded(True) + groups["B"].setExpanded(True) + groups["C"].setExpanded(True) + + enabled_groups_pixmap = plot.plot.viewport().grab() + self.processEvents() + # Evaluate + for channel in (plot_channel_a, plot_channel_b, plot_channel_c): + self.assertTrue( + Pixmap.has_color( + pixmap=enabled_groups_pixmap, color_name=channel.color + ), + msg=f"Color of Channel: {channel.text(self.Column.NAME)} not present on 'plot'.", + ) + # Press mouse double click on Group C + self.mouseDClick_WidgetItem(groups["C"]) + # Press mouse double click on Group B + self.mouseDClick_WidgetItem(groups["B"]) + disabled_groups_pixmap = plot.plot.viewport().grab() + + # Evaluate + self.assertTrue( + Pixmap.has_color( + pixmap=enabled_groups_pixmap, color_name=plot_channel_a.color + ), + msg=f"Color of Channel: {plot_channel_a.text(self.Column.NAME)} not present on 'plot'.", + ) + for channel in (plot_channel_b, plot_channel_c): + self.assertFalse( + Pixmap.has_color( + pixmap=disabled_groups_pixmap, + color_name=channel.color, + ), + msg=f"Color of Channel: {channel.text(self.Column.NAME)} present on 'plot'.", + ) + + QtTest.QTest.keyClick(plot.channel_selection, QtCore.Qt.Key_Up) + for _ in range(4): + QtTest.QTest.keyClick(plot.channel_selection, QtCore.Qt.Key_Down) + self.processEvents() + + # Press mouse double click on group B + self.mouseDClick_WidgetItem(groups["B"]) + self.mouseClick_WidgetItem(groups["B"]) + self.processEvents() + + # Evaluate selected items + selectedItems = plot.channel_selection.selectedItems() + self.assertEqual(1, len(selectedItems)) + self.assertEqual("B", selectedItems[0].text(self.Column.NAME)) + + # Disable group C from context-menu + # Disclaimer: Group C is already disabled + # Simple Click on group C is enough. The bug was that when you click disabled item, + # the previous selected item remains in selectedItems. + # Basically, the disabled item is not selectable and selection is kept. + # In case that previous item was a group, and 'Disable groups' is selected from the context-menu + # then, unintended parent and subgroups disable will happen. + self.mouseClick_WidgetItem(groups["C"]) + + # Evaluate that selection was changed. + selectedItems = plot.channel_selection.selectedItems() + self.assertEqual(0, len(selectedItems)) + + for _ in range(8): + QtTest.QTest.keyClick(plot.channel_selection, QtCore.Qt.Key_Down) + self.processEvents() + + # Evaluate + # After channels are enabled, they first flash a few times on plot. + # ProcessEvents few times for channels to be present + for _ in range(20): + self.processEvents() + + enabled_groups_pixmap = plot.plot.viewport().grab() + self.assertFalse( + Pixmap.has_color( + pixmap=enabled_groups_pixmap, color_name=plot_channel_c.color + ), + msg=f"Color for Channel: {plot_channel_c.text(self.Column.NAME)} present on 'plot'", + ) + for channel in (plot_channel_a, plot_channel_b, plot_channel_d): + self.assertTrue( + Pixmap.has_color( + pixmap=enabled_groups_pixmap, color_name=channel.color + ), + msg=f"Color for Channel: {channel.text(self.Column.NAME)} not present on 'plot'", + ) diff --git a/test/asammdf/gui/widgets/test_PlotWidget.py b/test/asammdf/gui/widgets/test_PlotWidget_DragAndDrop.py similarity index 50% rename from test/asammdf/gui/widgets/test_PlotWidget.py rename to test/asammdf/gui/widgets/test_PlotWidget_DragAndDrop.py index f79ecfb83..32cbc95e5 100644 --- a/test/asammdf/gui/widgets/test_PlotWidget.py +++ b/test/asammdf/gui/widgets/test_PlotWidget_DragAndDrop.py @@ -1,157 +1,13 @@ #!/usr/bin/env python import sys from test.asammdf.gui.test_base import DragAndDrop -from test.asammdf.gui.widgets.test_BasePlotWidget import Pixmap, TestPlotWidget +from test.asammdf.gui.widgets.test_BasePlotWidget import TestPlotWidget import unittest from unittest import mock from PySide6 import QtCore, QtGui, QtTest, QtWidgets -class TestDoubleClick(TestPlotWidget): - # Note: Test Plot Widget through FileWidget. - - def test_DoubleClick_ChannelSelection(self): - """ - Test Scope: Validate that doubleClick operation will activate de-activate channels. - Events: - - Open 'FileWidget' with valid measurement. - - Switch ComboBox to "Natural sort" - - Press PushButton "Create Window" - - Simulate that Plot window is selected as window type. - - Drag and Drop channel from FileWidget.channel_tree to Plot - - Press mouse double click on added channel - - Press mouse double click on added channel - Evaluate: - - Evaluate that channel checkbox is unchecked. - - Evaluate that channel checkbox is checked. - """ - # Event - # Open File Widget - self.setUpFileWidget(measurement_file=self.measurement_file, default=True) - # Switch ComboBox to "Natural sort" - self.widget.channel_view.setCurrentText("Natural sort") - # Create plot window - self.create_window(window_type="Plot") - self.assertEqual(len(self.widget.mdi_area.subWindowList()), 1) - # Drag and Drop channel from FileWidget.channel_tree to Plot - plot = self.widget.mdi_area.subWindowList()[0].widget() - plot_channel = self.add_channel_to_plot(plot=plot) - - # Pre-evaluation - self.assertEqual(QtCore.Qt.Checked, plot_channel.checkState(0)) - - # Press mouse double click on channel - self.mouseDClick_WidgetItem(plot_channel) - - # Evaluate - self.assertEqual(QtCore.Qt.Unchecked, plot_channel.checkState(0)) - - # Press mouse double click on channel - self.mouseDClick_WidgetItem(plot_channel) - self.assertEqual(QtCore.Qt.Checked, plot_channel.checkState(0)) - - def test_DoubleClick_Group(self): - """ - Test Scope: Validate that doubleClick operation will activate de-activate groups. - Events: - - Open 'FileWidget' with valid measurement. - - Switch ComboBox to "Natural sort" - - Press PushButton "Create Window" - - Simulate that Plot window is selected as window type. - - Drag and Drop channels from FileWidget.channel_tree to Plot - - Press 'Shift-Insert' in order to Insert Group - - Drag and Drop some channels to new Group - - Press mouse double click on added group - - Press key Down few times - - Press mouse double click on added group - - Press key Down few times - Evaluate: - - Evaluate that group is disabled (not selectable anymore). - - Evaluate that channel is enabled (selectable). - """ - # Event - # Open File Widget - self.setUpFileWidget(measurement_file=self.measurement_file, default=True) - # Switch ComboBox to "Natural sort" - self.widget.channel_view.setCurrentText("Natural sort") - # Create plot window - self.create_window(window_type="Plot") - self.assertEqual(len(self.widget.mdi_area.subWindowList()), 1) - # Drag and Drop channel from FileWidget.channel_tree to Plot - plot = self.widget.mdi_area.subWindowList()[0].widget() - plot_channel_0 = self.add_channel_to_plot(plot=plot, channel_index=10) - plot_channel_1 = self.add_channel_to_plot(plot=plot, channel_index=11) - plot_channel_2 = self.add_channel_to_plot(plot=plot, channel_index=12) - # Press 'Shift-Insert' in order to Insert Group - # Create Channel Group. Drag channels inside the group one by one - with mock.patch( - "asammdf.gui.widgets.tree.QtWidgets.QInputDialog.getText" - ) as mc_getText: - # Create Channel Group - mc_getText.return_value = "FirstGroup", True - QtTest.QTest.keySequence( - plot.channel_selection, QtGui.QKeySequence("Shift+Insert") - ) - # PreEvaluation: Check if there is one extra-item - self.assertEqual(4, plot.channel_selection.topLevelItemCount()) - # Get Group Position - for index in range(plot.channel_selection.topLevelItemCount()): - item = plot.channel_selection.topLevelItem(index) - if item.text(self.Column.NAME) == "FirstGroup": - first_group = item - break - else: - self.fail("FirstGroup is not present on Plot Channel Selection.") - first_group.setExpanded(True) - # Get First Item that will be moved - drag_position = plot.channel_selection.visualItemRect( - plot_channel_0 - ).center() - drop_position = plot.channel_selection.visualItemRect(first_group).center() - # Get Name of first channel - first_channel = plot_channel_0.text(self.Column.NAME) - # PreEvaluation: Ensure that group has no child - self.assertEqual(0, first_group.childCount()) - DragAndDrop( - source_widget=plot.channel_selection, - destination_widget=plot.channel_selection.viewport(), - source_pos=drag_position, - destination_pos=drop_position, - ) - # PreEvaluate: Ensure that channel was added to group - self.assertEqual(1, first_group.childCount()) - self.assertEqual(first_channel, first_group.child(0).text(self.Column.NAME)) - self.assertEqual(3, plot.channel_selection.topLevelItemCount()) - - # Press mouse double click on channel - self.mouseDClick_WidgetItem(first_group) - - for _ in range(4): - QtTest.QTest.keyClick(plot.channel_selection, QtCore.Qt.Key_Down) - self.processEvents() - - # Evaluate that item is still 2nd one because - selectedItems = plot.channel_selection.selectedItems() - self.assertEqual(1, len(selectedItems)) - selectedItem = selectedItems[0].text(self.Column.NAME) - self.assertEqual(plot_channel_2.text(self.Column.NAME), selectedItem) - - # Press mouse double click on channel - self.mouseDClick_WidgetItem(first_group) - self.processEvents() - - for _ in range(4): - QtTest.QTest.keyClick(plot.channel_selection, QtCore.Qt.Key_Down) - self.processEvents() - - # Evaluate that item is the one from the group - selectedItems = plot.channel_selection.selectedItems() - self.assertEqual(1, len(selectedItems)) - selectedItem = selectedItems[0].text(self.Column.NAME) - self.assertEqual(plot_channel_0.text(self.Column.NAME), selectedItem) - - class TestDragAndDrop(TestPlotWidget): # Note: Test Plot Widget through FileWidget. @@ -815,565 +671,3 @@ def test_Plot_ChannelSelection_DragAndDrop_fromNumeric_toPlot(self): plot_0_new_channel_name = plot_0_new_channel.text(self.Column.NAME) self.assertEqual(2, plot_0.channel_selection.topLevelItemCount()) self.assertEqual(numeric_channel, plot_0_new_channel_name) - - -class TestPushButtons(TestPlotWidget): - def setUp(self): - super().setUp() - - self.channel_0_name = "ASAM_[14].M.MATRIX_DIM_16.UBYTE.IDENTICAL" - self.channel_1_name = "ASAM_[15].M.MATRIX_DIM_16.UBYTE.IDENTICAL" - - # Event - self.setUpFileWidget(measurement_file=self.measurement_file, default=True) - # Switch ComboBox to "Natural sort" - self.widget.channel_view.setCurrentText("Natural sort") - # Press PushButton "Create Window" - self.create_window(window_type="Plot") - self.assertEqual(len(self.widget.mdi_area.subWindowList()), 1) - self.plot = self.widget.mdi_area.subWindowList()[0].widget() - - # Press PushButton "Hide axis" - if not self.plot.hide_axes_btn.isFlat(): - QtTest.QTest.mouseClick(self.plot.hide_axes_btn, QtCore.Qt.LeftButton) - - # Save PixMap of clear plot - clear_pixmap = self.plot.plot.viewport().grab() - self.assertTrue(Pixmap.is_black(clear_pixmap)) - - # Add Channels to Plot - self.plot_tree_channel_0 = self.add_channel_to_plot( - plot=self.plot, channel_name=self.channel_0_name - ) - self.assertEqual(1, self.plot.channel_selection.topLevelItemCount()) - self.plot_tree_channel_1 = self.add_channel_to_plot( - plot=self.plot, channel_name=self.channel_1_name - ) - self.assertEqual(2, self.plot.channel_selection.topLevelItemCount()) - - # Identify PlotSignal - self.plot_graph_channel_0, self.plot_graph_channel_1 = None, None - for channel in self.plot.plot.signals: - if channel.name == self.channel_0_name: - self.plot_graph_channel_0 = channel - elif channel.name == self.channel_1_name: - self.plot_graph_channel_1 = channel - - def test_Plot_ChannelSelection_PushButton_ValuePanel(self): - """ - Test Scope: - Check that Value Panel label is visible or hidden according to Push Button - Check that Value Panel label is updated according signal samples - Precondition: - - Open 'FileWidget' with valid measurement. - - Switch ComboBox to "Natural sort" - - Press PushButton "Create Window" - - Drag and Drop 2 channels from FileWidget.channels_tree to Plot.channels_selection - Events: - - Press PushButton "Show selected channel value panel" - - Press PushButton "Hide selected channel value panel" - - Press PushButton "Show selected channel value panel" - - Select one channel - - Use navigation keys to change values - - Select 2nd channel - - Use navigation keys to change values - Evaluate: - - Evaluate that label is visible when button "Show selected channel value panel" is pressed. - - Evaluate that label is hidden when button "Hide selected channel value panel" is pressed. - - Evaluate that value from label is equal with: Channel Value + Channel Unit - - Evaluate that value is updated according channel selected and current value - """ - # Event - if self.plot.selected_channel_value.isVisible(): - # Press PushButton "Hide selected channel value panel" - QtTest.QTest.mouseClick( - self.plot.selected_channel_value_btn, QtCore.Qt.LeftButton - ) - # Press PushButton "Show selected channel value panel" - QtTest.QTest.mouseClick( - self.plot.selected_channel_value_btn, QtCore.Qt.LeftButton - ) - self.assertTrue(self.plot.selected_channel_value.isVisible()) - - # Press PushButton "Hide selected channel value panel" - QtTest.QTest.mouseClick( - self.plot.selected_channel_value_btn, QtCore.Qt.LeftButton - ) - self.assertFalse(self.plot.selected_channel_value.isVisible()) - # Press PushButton "Show selected channel value panel" - QtTest.QTest.mouseClick( - self.plot.selected_channel_value_btn, QtCore.Qt.LeftButton - ) - self.assertTrue(self.plot.selected_channel_value.isVisible()) - - # Select Channel - self.mouseClick_WidgetItem(self.plot_tree_channel_0) - - # Evaluate - plot_channel_0_value = self.plot_tree_channel_0.text(self.Column.VALUE) - plot_channel_0_unit = self.plot_tree_channel_0.text(self.Column.UNIT) - self.assertEqual( - f"{plot_channel_0_value} {plot_channel_0_unit}", - self.plot.selected_channel_value.text(), - ) - - # Event - self.plot.plot.setFocus() - self.processEvents(0.1) - # Send Key strokes - for _ in range(6): - QtTest.QTest.keyClick(self.plot.plot, QtCore.Qt.Key_Right) - self.processEvents(0.1) - self.processEvents(0.1) - - # Evaluate - plot_channel_0_value = self.plot_tree_channel_0.text(self.Column.VALUE) - plot_channel_0_unit = self.plot_tree_channel_0.text(self.Column.UNIT) - self.assertEqual( - f"{plot_channel_0_value} {plot_channel_0_unit}", - self.plot.selected_channel_value.text(), - ) - - # Select 2nd Channel - self.mouseClick_WidgetItem(self.plot_tree_channel_1) - - # Evaluate - plot_channel_1_value = self.plot_tree_channel_1.text(self.Column.VALUE) - plot_channel_1_unit = self.plot_tree_channel_1.text(self.Column.UNIT) - self.assertEqual( - f"{plot_channel_1_value} {plot_channel_1_unit}", - self.plot.selected_channel_value.text(), - ) - - # Event - self.plot.plot.setFocus() - self.processEvents(0.1) - # Send Key strokes - for _ in range(6): - QtTest.QTest.keyClick(self.plot.plot, QtCore.Qt.Key_Right) - self.processEvents(0.1) - self.processEvents(0.1) - - # Evaluate - plot_channel_1_value = self.plot_tree_channel_1.text(self.Column.VALUE) - plot_channel_1_unit = self.plot_tree_channel_1.text(self.Column.UNIT) - self.assertEqual( - f"{plot_channel_1_value} {plot_channel_1_unit}", - self.plot.selected_channel_value.text(), - ) - - def test_Plot_ChannelSelection_PushButton_FocusedMode(self): - """ - Test Scope: - Check if Plot is cleared when no channel is selected. - Check if Plot is showing all channels when Focus Mode is disabled. - Check if Plot is showing only one channel when Focus Mode is enabled. - Precondition: - - Open 'FileWidget' with valid measurement. - - Switch ComboBox to "Natural sort" - - Press PushButton "Create Window" - - Press PushButton HideAxis (easy for evaluation) - - Drag and Drop channels from FileWidget.channels_tree to Plot.channels_selection: - # First - - ASAM_[15].M.MATRIX_DIM_16.UBYTE.IDENTICAL - # Second - - ASAM_[14].M.MATRIX_DIM_16.UBYTE.IDENTICAL - Events: - - Press PushButton FocusMode - - Press PushButton FocusMode - Evaluate: - - Evaluate that channels are displayed when FocusMode is disabled. - - Evaluate that selected channels is displayed when FocusMode is enabled. - """ - # Events - if not self.plot.focused_mode_btn.isFlat(): - QtTest.QTest.mouseClick(self.plot.focused_mode_btn, QtCore.Qt.LeftButton) - - channels_present_pixmap = self.plot.plot.viewport().grab() - self.assertFalse(Pixmap.is_black(pixmap=channels_present_pixmap)) - self.assertTrue( - Pixmap.has_color( - pixmap=channels_present_pixmap, - color_name=self.plot_graph_channel_0.color_name, - ) - ) - self.assertTrue( - Pixmap.has_color( - pixmap=channels_present_pixmap, - color_name=self.plot_graph_channel_1.color_name, - ) - ) - - # Press Button Focus Mode - QtTest.QTest.mouseClick(self.plot.focused_mode_btn, QtCore.Qt.LeftButton) - - # Evaluate - focus_mode_clear_pixmap = self.plot.plot.viewport().grab() - # No Channel is selected - self.assertTrue(Pixmap.is_black(pixmap=focus_mode_clear_pixmap)) - - # Select 2nd Channel - QtTest.QTest.mouseClick( - self.plot.channel_selection.viewport(), - QtCore.Qt.LeftButton, - QtCore.Qt.KeyboardModifiers(), - self.plot.channel_selection.visualItemRect( - self.plot_tree_channel_1 - ).center(), - ) - # Process flash until signal is present on plot. - for _ in range(10): - self.processEvents(timeout=0.01) - focus_mode_channel_1_pixmap = self.plot.plot.viewport().grab() - if Pixmap.has_color( - pixmap=focus_mode_channel_1_pixmap, - color_name=self.plot_graph_channel_1.color_name, - ): - break - - # Evaluate - focus_mode_channel_1_pixmap = self.plot.plot.viewport().grab() - self.assertFalse(Pixmap.is_black(pixmap=focus_mode_channel_1_pixmap)) - self.assertFalse( - Pixmap.has_color( - pixmap=focus_mode_channel_1_pixmap, - color_name=self.plot_graph_channel_0.color_name, - ) - ) - self.assertTrue( - Pixmap.has_color( - pixmap=focus_mode_channel_1_pixmap, - color_name=self.plot_graph_channel_1.color_name, - ) - ) - - def test_Plot_ChannelSelection_PushButton_RegionDelta(self): - """ - Test Scope: - Check if computation is done when Region is selected. - Events: - - Open 'FileWidget' with valid measurement. - - Switch ComboBox to "Natural sort" - - Press PushButton "Create Window" - - Press PushButton HideAxis (easy for evaluation) - - Drag and Drop channels from FileWidget.channels_tree to Plot.channels_selection: - # First - - ASAM_[15].M.MATRIX_DIM_16.UBYTE.IDENTICAL - # Second - - ASAM_[14].M.MATRIX_DIM_16.UBYTE.IDENTICAL - - Press PushButton Delta (range is not active) - - Press Key 'R' for range selection - - Press PushButton Delta (range is active) - - Move cursors - - Press Key 'R' for range selection - - Press PushButton Delta (range is not active) - Evaluate: - - Evaluate that 'delta' char is present on channel values when range selection is active - - Evaluate that 'delta' is correctly computed and result is updated on channel value - """ - channel_0 = "ASAM_[14].M.MATRIX_DIM_16.UBYTE.IDENTICAL" - channel_1 = "ASAM_[15].M.MATRIX_DIM_16.UBYTE.IDENTICAL" - - # Event - if not self.plot.delta_btn.isFlat(): - QtTest.QTest.mouseClick(self.plot.delta_btn, QtCore.Qt.LeftButton) - self.processEvents() - - # Ensure that delta char is not present on channel values - self.assertNotIn("Δ", self.plot_tree_channel_0.text(self.Column.VALUE)) - self.assertNotIn("Δ", self.plot_tree_channel_1.text(self.Column.VALUE)) - - # Press PushButton Delta (range is not active) - QtTest.QTest.mouseClick(self.plot.delta_btn, QtCore.Qt.LeftButton) - self.processEvents() - - # Ensure that delta char is not present on channel values even if button is pressed - self.assertNotIn("Δ", self.plot_tree_channel_0.text(self.Column.VALUE)) - self.assertNotIn("Δ", self.plot_tree_channel_1.text(self.Column.VALUE)) - - # Press Key 'R' for range selection - QtTest.QTest.keyClick(self.plot.plot, QtCore.Qt.Key_R) - self.processEvents(timeout=0.01) - - # Ensure that delta char is present on channel values even if button is pressed - self.assertIn("Δ", self.plot_tree_channel_0.text(self.Column.VALUE)) - self.assertIn("Δ", self.plot_tree_channel_1.text(self.Column.VALUE)) - - # Move cursor - # Select channel_1 - QtTest.QTest.mouseClick( - self.plot.channel_selection.viewport(), - QtCore.Qt.LeftButton, - QtCore.Qt.KeyboardModifiers(), - self.plot.channel_selection.visualItemRect( - self.plot_tree_channel_1 - ).center(), - ) - self.plot.plot.setFocus() - self.processEvents(0.1) - # Move a little bit in center of measurement - for _ in range(15): - QtTest.QTest.keyClick(self.plot.plot, QtCore.Qt.Key_Right) - self.processEvents(timeout=0.1) - - # Get current value: Ex: 'Δ = 8'. Get last number - old_channel_0_value = int( - self.plot_tree_channel_0.text(self.Column.VALUE).split(" ")[-1] - ) - old_channel_1_value = int( - self.plot_tree_channel_1.text(self.Column.VALUE).split(" ")[-1] - ) - for count in range(5): - QtTest.QTest.keyClick(self.plot.plot, QtCore.Qt.Key_Right) - self.processEvents(timeout=0.1) - # Evaluate - channel_0_value = int( - self.plot_tree_channel_0.text(self.Column.VALUE).split(" ")[-1] - ) - channel_1_value = int( - self.plot_tree_channel_1.text(self.Column.VALUE).split(" ")[-1] - ) - self.assertLess(old_channel_0_value, channel_0_value) - self.assertGreater(old_channel_1_value, channel_1_value) - old_channel_0_value = channel_0_value - old_channel_1_value = channel_1_value - - # Press Key 'R' for range selection - QtTest.QTest.keyClick(self.plot.plot, QtCore.Qt.Key_R) - self.processEvents(timeout=0.01) - - # Ensure that delta char is not present on channel values even if button is pressed - self.assertNotIn("Δ", self.plot_tree_channel_0.text(self.Column.VALUE)) - self.assertNotIn("Δ", self.plot_tree_channel_1.text(self.Column.VALUE)) - - -class TestShortcuts(TestPlotWidget): - def test_Plot_Plot_Shortcut_Key_LeftRight(self): - """ - Test Scope: - Check that Arrow Keys: Left & Right ensure navigation on channels evolution. - Ensure that navigation is working. - Events: - - Open 'FileWidget' with valid measurement. - - Switch ComboBox to "Natural sort" - - Press PushButton "Create Window" - - Drag and Drop channels from FileWidget.channels_tree to Plot.channels_selection: - # First - - ASAM_[15].M.MATRIX_DIM_16.UBYTE.IDENTICAL - # Second - - ASAM_[14].M.MATRIX_DIM_16.UBYTE.IDENTICAL - - Send KeyClick Right 5 times - - Send KeyClick Left 4 times - Evaluate: - - Evaluate values from `Value` column on Plot.channels_selection - - Evaluate timestamp label - """ - # Event - self.setUpFileWidget(measurement_file=self.measurement_file, default=True) - # Switch ComboBox to "Natural sort" - self.widget.channel_view.setCurrentText("Natural sort") - - self.create_window(window_type="Plot") - self.assertEqual(len(self.widget.mdi_area.subWindowList()), 1) - - plot = self.widget.mdi_area.subWindowList()[0].widget() - channel_selection = plot.channel_selection - channel_14 = self.add_channel_to_plot( - plot=plot, channel_name="ASAM_[14].M.MATRIX_DIM_16.UBYTE.IDENTICAL" - ) - channel_15 = self.add_channel_to_plot( - plot=plot, channel_name="ASAM_[15].M.MATRIX_DIM_16.UBYTE.IDENTICAL" - ) - self.assertEqual(2, plot.channel_selection.topLevelItemCount()) - - # Case 0: - with self.subTest("test_Plot_Plot_Shortcut_Key_LeftRight_0"): - # Select channel: ASAM_[15].M.MATRIX_DIM_16.UBYTE.IDENTICAL - self.mouseClick_WidgetItem(channel_15) - plot.plot.setFocus() - self.processEvents(0.1) - - self.assertEqual("25", channel_14.text(self.Column.VALUE)) - self.assertEqual("244", channel_15.text(self.Column.VALUE)) - - # Send Key strokes - for _ in range(6): - QtTest.QTest.keyClick(plot.plot, QtCore.Qt.Key_Right) - self.processEvents(0.1) - self.processEvents(0.1) - - # Evaluate - self.assertEqual("8", channel_14.text(self.Column.VALUE)) - self.assertEqual("6", channel_15.text(self.Column.VALUE)) - self.assertEqual("t = 0.082657s", plot.cursor_info.text()) - - # Send Key strokes - for _ in range(5): - QtTest.QTest.keyClick(plot.plot, QtCore.Qt.Key_Left) - self.processEvents(0.1) - self.processEvents(0.1) - - # Evaluate - self.assertEqual("21", channel_14.text(self.Column.VALUE)) - self.assertEqual("247", channel_15.text(self.Column.VALUE)) - self.assertEqual("t = 0.032657s", plot.cursor_info.text()) - - # Case 1: - with self.subTest("test_Plot_Plot_Shortcut_Key_LeftRight_1"): - # Select channel: ASAM_[14].M.MATRIX_DIM_16.UBYTE.IDENTICAL - self.mouseClick_WidgetItem(channel_15) - plot.plot.setFocus() - self.processEvents(0.1) - - # Send Key strokes - for _ in range(6): - QtTest.QTest.keyClick(plot.plot, QtCore.Qt.Key_Right) - self.processEvents(0.1) - self.processEvents(0.1) - - # Evaluate - self.assertEqual("5", channel_14.text(self.Column.VALUE)) - self.assertEqual("9", channel_15.text(self.Column.VALUE)) - self.assertEqual("t = 0.092657s", plot.cursor_info.text()) - - # Send Key strokes - for _ in range(5): - QtTest.QTest.keyClick(plot.plot, QtCore.Qt.Key_Left) - self.processEvents(0.1) - self.processEvents(0.1) - - # Evaluate - self.assertEqual("18", channel_14.text(self.Column.VALUE)) - self.assertEqual("250", channel_15.text(self.Column.VALUE)) - self.assertEqual("t = 0.042657s", plot.cursor_info.text()) - - def test_Plot_Plot_Shortcut_Key_R(self): - """ - Test Scope: - Check if Range Selection rectangle is painted over the plot. - Events: - - Open 'FileWidget' with valid measurement. - - Press PushButton "Create Window" - - Press PushButton HideAxis (easy for evaluation) - - Press Key R for range selection - - Move Cursors - - Press Key R for range selection - Evaluate: - - Evaluate that two cursors are available - - Evaluate that new rectangle with different color is present - - Evaluate that sum of rectangle areas is same with the one when plot is full black. - - Evaluate that range selection disappear. - """ - # Event - self.setUpFileWidget(measurement_file=self.measurement_file, default=True) - # Press PushButton "Create Window" - self.create_window(window_type="Plot") - self.assertEqual(len(self.widget.mdi_area.subWindowList()), 1) - plot = self.widget.mdi_area.subWindowList()[0].widget() - - # Press PushButton "Hide axis" - if not plot.hide_axes_btn.isFlat(): - QtTest.QTest.mouseClick(plot.hide_axes_btn, QtCore.Qt.LeftButton) - - # Save PixMap of clear plot - clear_pixmap = plot.plot.viewport().grab() - self.assertTrue(Pixmap.is_black(clear_pixmap)) - - # Get X position of Cursor - cursors = Pixmap.cursors_x(clear_pixmap) - # Evaluate that there is only one cursor - self.assertEqual(1, len(cursors)) - - # Press Key 'R' for range selection - QtTest.QTest.keyClick(plot.plot, QtCore.Qt.Key_R) - self.processEvents(timeout=0.01) - - # Save PixMap of Range plot - range_pixmap = plot.plot.viewport().grab() - self.assertFalse(Pixmap.is_black(range_pixmap)) - - # Get X position of Cursors - cursors = Pixmap.cursors_x(range_pixmap) - # Evaluate that two cursors are available - self.assertEqual(2, len(cursors)) - - # Evaluate that new rectangle with different color is present - self.assertTrue( - Pixmap.is_colored( - pixmap=range_pixmap, - color_name=Pixmap.COLOR_BACKGROUND, - x=0, - y=0, - width=min(cursors) - 1, - ) - ) - self.assertTrue( - Pixmap.is_colored( - pixmap=range_pixmap, - color_name=Pixmap.COLOR_RANGE, - x=min(cursors) + 1, - y=0, - width=max(cursors), - ) - ) - self.assertTrue( - Pixmap.is_colored( - pixmap=range_pixmap, - color_name=Pixmap.COLOR_BACKGROUND, - x=max(cursors) + 1, - y=0, - ) - ) - - # Move Cursors - QtTest.QTest.keyClick(plot.plot, QtCore.Qt.Key_Right) - self.processEvents(timeout=0.01) - QtTest.QTest.keySequence(plot.plot, QtGui.QKeySequence("Ctrl+Left")) - self.processEvents(timeout=0.01) - - # Save PixMap of Range plot - range_pixmap = plot.plot.viewport().grab() - self.assertFalse(Pixmap.is_black(range_pixmap)) - - # Get X position of Cursors - new_cursors = Pixmap.cursors_x(range_pixmap) - # Evaluate that two cursors are available - self.assertEqual(2, len(cursors)) - for c in cursors: - self.assertNotIn(c, new_cursors) - - # Evaluate that new rectangle with different color is present - self.assertTrue( - Pixmap.is_colored( - pixmap=range_pixmap, - color_name=Pixmap.COLOR_BACKGROUND, - x=0, - y=0, - width=min(new_cursors) - 1, - ) - ) - self.assertTrue( - Pixmap.is_colored( - pixmap=range_pixmap, - color_name=Pixmap.COLOR_RANGE, - x=min(new_cursors) + 1, - y=0, - width=max(new_cursors), - ) - ) - self.assertTrue( - Pixmap.is_colored( - pixmap=range_pixmap, - color_name=Pixmap.COLOR_BACKGROUND, - x=max(new_cursors) + 1, - y=0, - ) - ) - - # Press Key 'R' for range selection - QtTest.QTest.keyClick(plot.plot, QtCore.Qt.Key_R) - self.processEvents(timeout=0.01) - - # Save PixMap of clear plot - clear_pixmap = plot.plot.viewport().grab() - self.assertTrue(Pixmap.is_black(clear_pixmap)) diff --git a/test/asammdf/gui/widgets/test_PlotWidget_PushButtons.py b/test/asammdf/gui/widgets/test_PlotWidget_PushButtons.py new file mode 100644 index 000000000..b341d8772 --- /dev/null +++ b/test/asammdf/gui/widgets/test_PlotWidget_PushButtons.py @@ -0,0 +1,338 @@ +#!/usr/bin/env python +import sys +from test.asammdf.gui.test_base import DragAndDrop +from test.asammdf.gui.widgets.test_BasePlotWidget import Pixmap, TestPlotWidget +import unittest +from unittest import mock + +from PySide6 import QtCore, QtGui, QtTest, QtWidgets + + +class TestPushButtons(TestPlotWidget): + def setUp(self): + super().setUp() + + self.channel_0_name = "ASAM_[14].M.MATRIX_DIM_16.UBYTE.IDENTICAL" + self.channel_1_name = "ASAM_[15].M.MATRIX_DIM_16.UBYTE.IDENTICAL" + + # Event + self.setUpFileWidget(measurement_file=self.measurement_file, default=True) + # Switch ComboBox to "Natural sort" + self.widget.channel_view.setCurrentText("Natural sort") + # Press PushButton "Create Window" + self.create_window(window_type="Plot") + self.assertEqual(len(self.widget.mdi_area.subWindowList()), 1) + self.plot = self.widget.mdi_area.subWindowList()[0].widget() + + # Press PushButton "Hide axis" + if not self.plot.hide_axes_btn.isFlat(): + QtTest.QTest.mouseClick(self.plot.hide_axes_btn, QtCore.Qt.LeftButton) + + # Save PixMap of clear plot + clear_pixmap = self.plot.plot.viewport().grab() + self.assertTrue(Pixmap.is_black(clear_pixmap)) + + # Add Channels to Plot + self.plot_tree_channel_0 = self.add_channel_to_plot( + plot=self.plot, channel_name=self.channel_0_name + ) + self.assertEqual(1, self.plot.channel_selection.topLevelItemCount()) + self.plot_tree_channel_1 = self.add_channel_to_plot( + plot=self.plot, channel_name=self.channel_1_name + ) + self.assertEqual(2, self.plot.channel_selection.topLevelItemCount()) + + # Identify PlotSignal + self.plot_graph_channel_0, self.plot_graph_channel_1 = None, None + for channel in self.plot.plot.signals: + if channel.name == self.channel_0_name: + self.plot_graph_channel_0 = channel + elif channel.name == self.channel_1_name: + self.plot_graph_channel_1 = channel + + def test_Plot_ChannelSelection_PushButton_ValuePanel(self): + """ + Test Scope: + Check that Value Panel label is visible or hidden according to Push Button + Check that Value Panel label is updated according signal samples + Precondition: + - Open 'FileWidget' with valid measurement. + - Switch ComboBox to "Natural sort" + - Press PushButton "Create Window" + - Drag and Drop 2 channels from FileWidget.channels_tree to Plot.channels_selection + Events: + - Press PushButton "Show selected channel value panel" + - Press PushButton "Hide selected channel value panel" + - Press PushButton "Show selected channel value panel" + - Select one channel + - Use navigation keys to change values + - Select 2nd channel + - Use navigation keys to change values + Evaluate: + - Evaluate that label is visible when button "Show selected channel value panel" is pressed. + - Evaluate that label is hidden when button "Hide selected channel value panel" is pressed. + - Evaluate that value from label is equal with: Channel Value + Channel Unit + - Evaluate that value is updated according channel selected and current value + """ + # Event + if self.plot.selected_channel_value.isVisible(): + # Press PushButton "Hide selected channel value panel" + QtTest.QTest.mouseClick( + self.plot.selected_channel_value_btn, QtCore.Qt.LeftButton + ) + # Press PushButton "Show selected channel value panel" + QtTest.QTest.mouseClick( + self.plot.selected_channel_value_btn, QtCore.Qt.LeftButton + ) + self.assertTrue(self.plot.selected_channel_value.isVisible()) + + # Press PushButton "Hide selected channel value panel" + QtTest.QTest.mouseClick( + self.plot.selected_channel_value_btn, QtCore.Qt.LeftButton + ) + self.assertFalse(self.plot.selected_channel_value.isVisible()) + # Press PushButton "Show selected channel value panel" + QtTest.QTest.mouseClick( + self.plot.selected_channel_value_btn, QtCore.Qt.LeftButton + ) + self.assertTrue(self.plot.selected_channel_value.isVisible()) + + # Select Channel + self.mouseClick_WidgetItem(self.plot_tree_channel_0) + + # Evaluate + plot_channel_0_value = self.plot_tree_channel_0.text(self.Column.VALUE) + plot_channel_0_unit = self.plot_tree_channel_0.text(self.Column.UNIT) + self.assertEqual( + f"{plot_channel_0_value} {plot_channel_0_unit}", + self.plot.selected_channel_value.text(), + ) + + # Event + self.plot.plot.setFocus() + self.processEvents(0.1) + # Send Key strokes + for _ in range(6): + QtTest.QTest.keyClick(self.plot.plot, QtCore.Qt.Key_Right) + self.processEvents(0.1) + self.processEvents(0.1) + + # Evaluate + plot_channel_0_value = self.plot_tree_channel_0.text(self.Column.VALUE) + plot_channel_0_unit = self.plot_tree_channel_0.text(self.Column.UNIT) + self.assertEqual( + f"{plot_channel_0_value} {plot_channel_0_unit}", + self.plot.selected_channel_value.text(), + ) + + # Select 2nd Channel + self.mouseClick_WidgetItem(self.plot_tree_channel_1) + + # Evaluate + plot_channel_1_value = self.plot_tree_channel_1.text(self.Column.VALUE) + plot_channel_1_unit = self.plot_tree_channel_1.text(self.Column.UNIT) + self.assertEqual( + f"{plot_channel_1_value} {plot_channel_1_unit}", + self.plot.selected_channel_value.text(), + ) + + # Event + self.plot.plot.setFocus() + self.processEvents(0.1) + # Send Key strokes + for _ in range(6): + QtTest.QTest.keyClick(self.plot.plot, QtCore.Qt.Key_Right) + self.processEvents(0.1) + self.processEvents(0.1) + + # Evaluate + plot_channel_1_value = self.plot_tree_channel_1.text(self.Column.VALUE) + plot_channel_1_unit = self.plot_tree_channel_1.text(self.Column.UNIT) + self.assertEqual( + f"{plot_channel_1_value} {plot_channel_1_unit}", + self.plot.selected_channel_value.text(), + ) + + def test_Plot_ChannelSelection_PushButton_FocusedMode(self): + """ + Test Scope: + Check if Plot is cleared when no channel is selected. + Check if Plot is showing all channels when Focus Mode is disabled. + Check if Plot is showing only one channel when Focus Mode is enabled. + Precondition: + - Open 'FileWidget' with valid measurement. + - Switch ComboBox to "Natural sort" + - Press PushButton "Create Window" + - Press PushButton HideAxis (easy for evaluation) + - Drag and Drop channels from FileWidget.channels_tree to Plot.channels_selection: + # First + - ASAM_[15].M.MATRIX_DIM_16.UBYTE.IDENTICAL + # Second + - ASAM_[14].M.MATRIX_DIM_16.UBYTE.IDENTICAL + Events: + - Press PushButton FocusMode + - Press PushButton FocusMode + Evaluate: + - Evaluate that channels are displayed when FocusMode is disabled. + - Evaluate that selected channels is displayed when FocusMode is enabled. + """ + # Events + if not self.plot.focused_mode_btn.isFlat(): + QtTest.QTest.mouseClick(self.plot.focused_mode_btn, QtCore.Qt.LeftButton) + + channels_present_pixmap = self.plot.plot.viewport().grab() + self.assertFalse(Pixmap.is_black(pixmap=channels_present_pixmap)) + self.assertTrue( + Pixmap.has_color( + pixmap=channels_present_pixmap, + color_name=self.plot_graph_channel_0.color_name, + ) + ) + self.assertTrue( + Pixmap.has_color( + pixmap=channels_present_pixmap, + color_name=self.plot_graph_channel_1.color_name, + ) + ) + + # Press Button Focus Mode + QtTest.QTest.mouseClick(self.plot.focused_mode_btn, QtCore.Qt.LeftButton) + + # Evaluate + focus_mode_clear_pixmap = self.plot.plot.viewport().grab() + # No Channel is selected + self.assertTrue(Pixmap.is_black(pixmap=focus_mode_clear_pixmap)) + + # Select 2nd Channel + QtTest.QTest.mouseClick( + self.plot.channel_selection.viewport(), + QtCore.Qt.LeftButton, + QtCore.Qt.KeyboardModifiers(), + self.plot.channel_selection.visualItemRect( + self.plot_tree_channel_1 + ).center(), + ) + # Process flash until signal is present on plot. + for _ in range(10): + self.processEvents(timeout=0.01) + focus_mode_channel_1_pixmap = self.plot.plot.viewport().grab() + if Pixmap.has_color( + pixmap=focus_mode_channel_1_pixmap, + color_name=self.plot_graph_channel_1.color_name, + ): + break + + # Evaluate + focus_mode_channel_1_pixmap = self.plot.plot.viewport().grab() + self.assertFalse(Pixmap.is_black(pixmap=focus_mode_channel_1_pixmap)) + self.assertFalse( + Pixmap.has_color( + pixmap=focus_mode_channel_1_pixmap, + color_name=self.plot_graph_channel_0.color_name, + ) + ) + self.assertTrue( + Pixmap.has_color( + pixmap=focus_mode_channel_1_pixmap, + color_name=self.plot_graph_channel_1.color_name, + ) + ) + + def test_Plot_ChannelSelection_PushButton_RegionDelta(self): + """ + Test Scope: + Check if computation is done when Region is selected. + Events: + - Open 'FileWidget' with valid measurement. + - Switch ComboBox to "Natural sort" + - Press PushButton "Create Window" + - Press PushButton HideAxis (easy for evaluation) + - Drag and Drop channels from FileWidget.channels_tree to Plot.channels_selection: + # First + - ASAM_[15].M.MATRIX_DIM_16.UBYTE.IDENTICAL + # Second + - ASAM_[14].M.MATRIX_DIM_16.UBYTE.IDENTICAL + - Press PushButton Delta (range is not active) + - Press Key 'R' for range selection + - Press PushButton Delta (range is active) + - Move cursors + - Press Key 'R' for range selection + - Press PushButton Delta (range is not active) + Evaluate: + - Evaluate that 'delta' char is present on channel values when range selection is active + - Evaluate that 'delta' is correctly computed and result is updated on channel value + """ + channel_0 = "ASAM_[14].M.MATRIX_DIM_16.UBYTE.IDENTICAL" + channel_1 = "ASAM_[15].M.MATRIX_DIM_16.UBYTE.IDENTICAL" + + # Event + if not self.plot.delta_btn.isFlat(): + QtTest.QTest.mouseClick(self.plot.delta_btn, QtCore.Qt.LeftButton) + self.processEvents() + + # Ensure that delta char is not present on channel values + self.assertNotIn("Δ", self.plot_tree_channel_0.text(self.Column.VALUE)) + self.assertNotIn("Δ", self.plot_tree_channel_1.text(self.Column.VALUE)) + + # Press PushButton Delta (range is not active) + QtTest.QTest.mouseClick(self.plot.delta_btn, QtCore.Qt.LeftButton) + self.processEvents() + + # Ensure that delta char is not present on channel values even if button is pressed + self.assertNotIn("Δ", self.plot_tree_channel_0.text(self.Column.VALUE)) + self.assertNotIn("Δ", self.plot_tree_channel_1.text(self.Column.VALUE)) + + # Press Key 'R' for range selection + QtTest.QTest.keyClick(self.plot.plot, QtCore.Qt.Key_R) + self.processEvents(timeout=0.01) + + # Ensure that delta char is present on channel values even if button is pressed + self.assertIn("Δ", self.plot_tree_channel_0.text(self.Column.VALUE)) + self.assertIn("Δ", self.plot_tree_channel_1.text(self.Column.VALUE)) + + # Move cursor + # Select channel_1 + QtTest.QTest.mouseClick( + self.plot.channel_selection.viewport(), + QtCore.Qt.LeftButton, + QtCore.Qt.KeyboardModifiers(), + self.plot.channel_selection.visualItemRect( + self.plot_tree_channel_1 + ).center(), + ) + self.plot.plot.setFocus() + self.processEvents(0.1) + # Move a little bit in center of measurement + for _ in range(15): + QtTest.QTest.keyClick(self.plot.plot, QtCore.Qt.Key_Right) + self.processEvents(timeout=0.1) + + # Get current value: Ex: 'Δ = 8'. Get last number + old_channel_0_value = int( + self.plot_tree_channel_0.text(self.Column.VALUE).split(" ")[-1] + ) + old_channel_1_value = int( + self.plot_tree_channel_1.text(self.Column.VALUE).split(" ")[-1] + ) + for count in range(5): + QtTest.QTest.keyClick(self.plot.plot, QtCore.Qt.Key_Right) + self.processEvents(timeout=0.1) + # Evaluate + channel_0_value = int( + self.plot_tree_channel_0.text(self.Column.VALUE).split(" ")[-1] + ) + channel_1_value = int( + self.plot_tree_channel_1.text(self.Column.VALUE).split(" ")[-1] + ) + self.assertLess(old_channel_0_value, channel_0_value) + self.assertGreater(old_channel_1_value, channel_1_value) + old_channel_0_value = channel_0_value + old_channel_1_value = channel_1_value + + # Press Key 'R' for range selection + QtTest.QTest.keyClick(self.plot.plot, QtCore.Qt.Key_R) + self.processEvents(timeout=0.01) + + # Ensure that delta char is not present on channel values even if button is pressed + self.assertNotIn("Δ", self.plot_tree_channel_0.text(self.Column.VALUE)) + self.assertNotIn("Δ", self.plot_tree_channel_1.text(self.Column.VALUE)) diff --git a/test/asammdf/gui/widgets/test_PlotWidget_Shortcuts.py b/test/asammdf/gui/widgets/test_PlotWidget_Shortcuts.py new file mode 100644 index 000000000..4fa4e3d5c --- /dev/null +++ b/test/asammdf/gui/widgets/test_PlotWidget_Shortcuts.py @@ -0,0 +1,237 @@ +#!/usr/bin/env python +from test.asammdf.gui.test_base import Pixmap +from test.asammdf.gui.widgets.test_BasePlotWidget import TestPlotWidget + +from PySide6 import QtCore, QtGui, QtTest + + +class TestShortcuts(TestPlotWidget): + def test_Plot_Plot_Shortcut_Key_LeftRight(self): + """ + Test Scope: + Check that Arrow Keys: Left & Right ensure navigation on channels evolution. + Ensure that navigation is working. + Events: + - Open 'FileWidget' with valid measurement. + - Switch ComboBox to "Natural sort" + - Press PushButton "Create Window" + - Drag and Drop channels from FileWidget.channels_tree to Plot.channels_selection: + # First + - ASAM_[15].M.MATRIX_DIM_16.UBYTE.IDENTICAL + # Second + - ASAM_[14].M.MATRIX_DIM_16.UBYTE.IDENTICAL + - Send KeyClick Right 5 times + - Send KeyClick Left 4 times + Evaluate: + - Evaluate values from `Value` column on Plot.channels_selection + - Evaluate timestamp label + """ + # Event + self.setUpFileWidget(measurement_file=self.measurement_file, default=True) + # Switch ComboBox to "Natural sort" + self.widget.channel_view.setCurrentText("Natural sort") + + self.create_window(window_type="Plot") + self.assertEqual(len(self.widget.mdi_area.subWindowList()), 1) + + plot = self.widget.mdi_area.subWindowList()[0].widget() + channel_selection = plot.channel_selection + channel_14 = self.add_channel_to_plot( + plot=plot, channel_name="ASAM_[14].M.MATRIX_DIM_16.UBYTE.IDENTICAL" + ) + channel_15 = self.add_channel_to_plot( + plot=plot, channel_name="ASAM_[15].M.MATRIX_DIM_16.UBYTE.IDENTICAL" + ) + self.assertEqual(2, plot.channel_selection.topLevelItemCount()) + + # Case 0: + with self.subTest("test_Plot_Plot_Shortcut_Key_LeftRight_0"): + # Select channel: ASAM_[15].M.MATRIX_DIM_16.UBYTE.IDENTICAL + self.mouseClick_WidgetItem(channel_15) + plot.plot.setFocus() + self.processEvents(0.1) + + self.assertEqual("25", channel_14.text(self.Column.VALUE)) + self.assertEqual("244", channel_15.text(self.Column.VALUE)) + + # Send Key strokes + for _ in range(6): + QtTest.QTest.keyClick(plot.plot, QtCore.Qt.Key_Right) + self.processEvents(0.1) + self.processEvents(0.1) + + # Evaluate + self.assertEqual("8", channel_14.text(self.Column.VALUE)) + self.assertEqual("6", channel_15.text(self.Column.VALUE)) + self.assertEqual("t = 0.082657s", plot.cursor_info.text()) + + # Send Key strokes + for _ in range(5): + QtTest.QTest.keyClick(plot.plot, QtCore.Qt.Key_Left) + self.processEvents(0.1) + self.processEvents(0.1) + + # Evaluate + self.assertEqual("21", channel_14.text(self.Column.VALUE)) + self.assertEqual("247", channel_15.text(self.Column.VALUE)) + self.assertEqual("t = 0.032657s", plot.cursor_info.text()) + + # Case 1: + with self.subTest("test_Plot_Plot_Shortcut_Key_LeftRight_1"): + # Select channel: ASAM_[14].M.MATRIX_DIM_16.UBYTE.IDENTICAL + self.mouseClick_WidgetItem(channel_15) + plot.plot.setFocus() + self.processEvents(0.1) + + # Send Key strokes + for _ in range(6): + QtTest.QTest.keyClick(plot.plot, QtCore.Qt.Key_Right) + self.processEvents(0.1) + self.processEvents(0.1) + + # Evaluate + self.assertEqual("5", channel_14.text(self.Column.VALUE)) + self.assertEqual("9", channel_15.text(self.Column.VALUE)) + self.assertEqual("t = 0.092657s", plot.cursor_info.text()) + + # Send Key strokes + for _ in range(5): + QtTest.QTest.keyClick(plot.plot, QtCore.Qt.Key_Left) + self.processEvents(0.1) + self.processEvents(0.1) + + # Evaluate + self.assertEqual("18", channel_14.text(self.Column.VALUE)) + self.assertEqual("250", channel_15.text(self.Column.VALUE)) + self.assertEqual("t = 0.042657s", plot.cursor_info.text()) + + def test_Plot_Plot_Shortcut_Key_R(self): + """ + Test Scope: + Check if Range Selection rectangle is painted over the plot. + Events: + - Open 'FileWidget' with valid measurement. + - Press PushButton "Create Window" + - Press PushButton HideAxis (easy for evaluation) + - Press Key R for range selection + - Move Cursors + - Press Key R for range selection + Evaluate: + - Evaluate that two cursors are available + - Evaluate that new rectangle with different color is present + - Evaluate that sum of rectangle areas is same with the one when plot is full black. + - Evaluate that range selection disappear. + """ + # Event + self.setUpFileWidget(measurement_file=self.measurement_file, default=True) + # Press PushButton "Create Window" + self.create_window(window_type="Plot") + self.assertEqual(len(self.widget.mdi_area.subWindowList()), 1) + plot = self.widget.mdi_area.subWindowList()[0].widget() + + # Press PushButton "Hide axis" + if not plot.hide_axes_btn.isFlat(): + QtTest.QTest.mouseClick(plot.hide_axes_btn, QtCore.Qt.LeftButton) + + # Save PixMap of clear plot + clear_pixmap = plot.plot.viewport().grab() + self.assertTrue(Pixmap.is_black(clear_pixmap)) + + # Get X position of Cursor + cursors = Pixmap.cursors_x(clear_pixmap) + # Evaluate that there is only one cursor + self.assertEqual(1, len(cursors)) + + # Press Key 'R' for range selection + QtTest.QTest.keyClick(plot.plot, QtCore.Qt.Key_R) + self.processEvents(timeout=0.01) + + # Save PixMap of Range plot + range_pixmap = plot.plot.viewport().grab() + self.assertFalse(Pixmap.is_black(range_pixmap)) + + # Get X position of Cursors + cursors = Pixmap.cursors_x(range_pixmap) + # Evaluate that two cursors are available + self.assertEqual(2, len(cursors)) + + # Evaluate that new rectangle with different color is present + self.assertTrue( + Pixmap.is_colored( + pixmap=range_pixmap, + color_name=Pixmap.COLOR_BACKGROUND, + x=0, + y=0, + width=min(cursors) - 1, + ) + ) + self.assertTrue( + Pixmap.is_colored( + pixmap=range_pixmap, + color_name=Pixmap.COLOR_RANGE, + x=min(cursors) + 1, + y=0, + width=max(cursors), + ) + ) + self.assertTrue( + Pixmap.is_colored( + pixmap=range_pixmap, + color_name=Pixmap.COLOR_BACKGROUND, + x=max(cursors) + 1, + y=0, + ) + ) + + # Move Cursors + QtTest.QTest.keyClick(plot.plot, QtCore.Qt.Key_Right) + self.processEvents(timeout=0.01) + QtTest.QTest.keySequence(plot.plot, QtGui.QKeySequence("Ctrl+Left")) + self.processEvents(timeout=0.01) + + # Save PixMap of Range plot + range_pixmap = plot.plot.viewport().grab() + self.assertFalse(Pixmap.is_black(range_pixmap)) + + # Get X position of Cursors + new_cursors = Pixmap.cursors_x(range_pixmap) + # Evaluate that two cursors are available + self.assertEqual(2, len(cursors)) + for c in cursors: + self.assertNotIn(c, new_cursors) + + # Evaluate that new rectangle with different color is present + self.assertTrue( + Pixmap.is_colored( + pixmap=range_pixmap, + color_name=Pixmap.COLOR_BACKGROUND, + x=0, + y=0, + width=min(new_cursors) - 1, + ) + ) + self.assertTrue( + Pixmap.is_colored( + pixmap=range_pixmap, + color_name=Pixmap.COLOR_RANGE, + x=min(new_cursors) + 1, + y=0, + width=max(new_cursors), + ) + ) + self.assertTrue( + Pixmap.is_colored( + pixmap=range_pixmap, + color_name=Pixmap.COLOR_BACKGROUND, + x=max(new_cursors) + 1, + y=0, + ) + ) + + # Press Key 'R' for range selection + QtTest.QTest.keyClick(plot.plot, QtCore.Qt.Key_R) + self.processEvents(timeout=0.01) + + # Save PixMap of clear plot + clear_pixmap = plot.plot.viewport().grab() + self.assertTrue(Pixmap.is_black(clear_pixmap)) From 7e63eb5580acf4c256e722111694cc1858c0b589 Mon Sep 17 00:00:00 2001 From: tov101 Date: Fri, 8 Sep 2023 17:19:44 +0300 Subject: [PATCH 02/11] .. --- src/asammdf/gui/widgets/tree.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/asammdf/gui/widgets/tree.py b/src/asammdf/gui/widgets/tree.py index cb09bbfea..39d8711fd 100644 --- a/src/asammdf/gui/widgets/tree.py +++ b/src/asammdf/gui/widgets/tree.py @@ -889,7 +889,7 @@ def mousePressEvent(self, event) -> None: # If there was a click performed on disabled item, then clear selection item = self.itemAt(event.pos()) - if item.isDisabled(): + if item and item.isDisabled(): self.clearSelection() super().mousePressEvent(event) From 5ead3b8c835dad89dba1f75fd13613b956dbf9a3 Mon Sep 17 00:00:00 2001 From: tov101 Date: Fri, 8 Sep 2023 17:38:31 +0300 Subject: [PATCH 03/11] fix imports. --- test/asammdf/gui/widgets/test_PlotWidget_PushButtons.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/asammdf/gui/widgets/test_PlotWidget_PushButtons.py b/test/asammdf/gui/widgets/test_PlotWidget_PushButtons.py index b341d8772..ad0a97ee5 100644 --- a/test/asammdf/gui/widgets/test_PlotWidget_PushButtons.py +++ b/test/asammdf/gui/widgets/test_PlotWidget_PushButtons.py @@ -1,7 +1,7 @@ #!/usr/bin/env python import sys -from test.asammdf.gui.test_base import DragAndDrop -from test.asammdf.gui.widgets.test_BasePlotWidget import Pixmap, TestPlotWidget +from test.asammdf.gui.test_base import DragAndDrop, Pixmap +from test.asammdf.gui.widgets.test_BasePlotWidget import TestPlotWidget import unittest from unittest import mock From e5404795d3d1c819eb7e496ed90da91039d69d71 Mon Sep 17 00:00:00 2001 From: tov101 Date: Mon, 11 Sep 2023 07:53:46 +0300 Subject: [PATCH 04/11] .. --- .../gui/widgets/test_BasePlotWidget.py | 1 + .../widgets/test_PlotWidget_DoubleClick.py | 33 ++++++++++--------- .../widgets/test_PlotWidget_PushButtons.py | 13 +++----- 3 files changed, 23 insertions(+), 24 deletions(-) diff --git a/test/asammdf/gui/widgets/test_BasePlotWidget.py b/test/asammdf/gui/widgets/test_BasePlotWidget.py index 5e70d5223..d6fc6a6be 100644 --- a/test/asammdf/gui/widgets/test_BasePlotWidget.py +++ b/test/asammdf/gui/widgets/test_BasePlotWidget.py @@ -55,6 +55,7 @@ def add_channel_to_plot(self, plot, channel_name=None, channel_index=None): plot_channel = item iterator += 1 + self.processEvents() return plot_channel def create_window(self, window_type): diff --git a/test/asammdf/gui/widgets/test_PlotWidget_DoubleClick.py b/test/asammdf/gui/widgets/test_PlotWidget_DoubleClick.py index 02514d7e0..7d76a1d22 100644 --- a/test/asammdf/gui/widgets/test_PlotWidget_DoubleClick.py +++ b/test/asammdf/gui/widgets/test_PlotWidget_DoubleClick.py @@ -1,10 +1,11 @@ #!/usr/bin/env python -from test.asammdf.gui.test_base import DragAndDrop, Pixmap -from test.asammdf.gui.widgets.test_BasePlotWidget import TestPlotWidget from unittest import mock from PySide6 import QtCore, QtGui, QtTest +from test.asammdf.gui.test_base import DragAndDrop, Pixmap +from test.asammdf.gui.widgets.test_BasePlotWidget import TestPlotWidget + class TestDoubleClick(TestPlotWidget): # Note: Test Plot Widget through FileWidget. @@ -29,7 +30,7 @@ def test_ChannelSelection(self): self.setUpFileWidget(measurement_file=self.measurement_file, default=True) # Switch ComboBox to "Natural sort" self.widget.channel_view.setCurrentText("Natural sort") - # Create plot window + # Create a plot window self.create_window(window_type="Plot") self.assertEqual(len(self.widget.mdi_area.subWindowList()), 1) # Drag and Drop channel from FileWidget.channel_tree to Plot @@ -88,7 +89,7 @@ def test_EnableDisable_Group(self): # Press 'Shift-Insert' in order to Insert Group # Create Channel Group. Drag channels inside the group one by one with mock.patch( - "asammdf.gui.widgets.tree.QtWidgets.QInputDialog.getText" + "asammdf.gui.widgets.tree.QtWidgets.QInputDialog.getText" ) as mc_getText: # Create Channel Group mc_getText.return_value = "FirstGroup", True @@ -234,7 +235,7 @@ def test_EnableDisable_ParentGroup(self): # Create Channel Group. Drag channels inside the group one by one groups = {} with mock.patch( - "asammdf.gui.widgets.tree.QtWidgets.QInputDialog.getText" + "asammdf.gui.widgets.tree.QtWidgets.QInputDialog.getText" ) as mc_getText: for group_name in ("A", "B", "C"): # Create Channel Group @@ -359,10 +360,10 @@ def test_EnableDisable_ParentGroup(self): enabled_groups_pixmap = plot.plot.viewport().grab() for channel in ( - plot_channel_a, - plot_channel_b, - plot_channel_c, - plot_channel_d, + plot_channel_a, + plot_channel_b, + plot_channel_c, + plot_channel_d, ): self.assertTrue( Pixmap.has_color( @@ -421,7 +422,7 @@ def test_EnableDisable_Subgroup(self): # Create Channel Group. Drag channels inside the group one by one groups = {} with mock.patch( - "asammdf.gui.widgets.tree.QtWidgets.QInputDialog.getText" + "asammdf.gui.widgets.tree.QtWidgets.QInputDialog.getText" ) as mc_getText: for group_name in ("A", "B", "C"): # Create Channel Group @@ -536,10 +537,10 @@ def test_EnableDisable_Subgroup(self): enabled_groups_pixmap = plot.plot.viewport().grab() for channel in ( - plot_channel_a, - plot_channel_b, - plot_channel_c, - plot_channel_d, + plot_channel_a, + plot_channel_b, + plot_channel_c, + plot_channel_d, ): self.assertTrue( Pixmap.has_color( @@ -598,7 +599,7 @@ def test_EnableDisable_Preserve_Subgroup_State_0(self): # Create Channel Group. Drag channels inside the group one by one groups = {} with mock.patch( - "asammdf.gui.widgets.tree.QtWidgets.QInputDialog.getText" + "asammdf.gui.widgets.tree.QtWidgets.QInputDialog.getText" ) as mc_getText: for group_name in ("A", "B", "C"): # Create Channel Group @@ -781,7 +782,7 @@ def test_EnableDisable_Preserve_Subgroup_State_1(self): # Create Channel Group. Drag channels inside the group one by one groups = {} with mock.patch( - "asammdf.gui.widgets.tree.QtWidgets.QInputDialog.getText" + "asammdf.gui.widgets.tree.QtWidgets.QInputDialog.getText" ) as mc_getText: for group_name in ("A", "B", "C"): # Create Channel Group diff --git a/test/asammdf/gui/widgets/test_PlotWidget_PushButtons.py b/test/asammdf/gui/widgets/test_PlotWidget_PushButtons.py index ad0a97ee5..73f37c7d3 100644 --- a/test/asammdf/gui/widgets/test_PlotWidget_PushButtons.py +++ b/test/asammdf/gui/widgets/test_PlotWidget_PushButtons.py @@ -1,11 +1,8 @@ #!/usr/bin/env python -import sys -from test.asammdf.gui.test_base import DragAndDrop, Pixmap -from test.asammdf.gui.widgets.test_BasePlotWidget import TestPlotWidget -import unittest -from unittest import mock +from PySide6 import QtCore, QtTest -from PySide6 import QtCore, QtGui, QtTest, QtWidgets +from test.asammdf.gui.test_base import Pixmap +from test.asammdf.gui.widgets.test_BasePlotWidget import TestPlotWidget class TestPushButtons(TestPlotWidget): @@ -217,8 +214,8 @@ def test_Plot_ChannelSelection_PushButton_FocusedMode(self): self.processEvents(timeout=0.01) focus_mode_channel_1_pixmap = self.plot.plot.viewport().grab() if Pixmap.has_color( - pixmap=focus_mode_channel_1_pixmap, - color_name=self.plot_graph_channel_1.color_name, + pixmap=focus_mode_channel_1_pixmap, + color_name=self.plot_graph_channel_1.color_name, ): break From 06e5440bd2daaebdf5861df212a7321d6e398cbf Mon Sep 17 00:00:00 2001 From: tov101 Date: Mon, 11 Sep 2023 07:54:27 +0300 Subject: [PATCH 05/11] .. --- .../widgets/test_PlotWidget_DoubleClick.py | 31 +++++++++---------- .../widgets/test_PlotWidget_PushButtons.py | 8 ++--- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/test/asammdf/gui/widgets/test_PlotWidget_DoubleClick.py b/test/asammdf/gui/widgets/test_PlotWidget_DoubleClick.py index 7d76a1d22..269cb1d19 100644 --- a/test/asammdf/gui/widgets/test_PlotWidget_DoubleClick.py +++ b/test/asammdf/gui/widgets/test_PlotWidget_DoubleClick.py @@ -1,11 +1,10 @@ #!/usr/bin/env python +from test.asammdf.gui.test_base import DragAndDrop, Pixmap +from test.asammdf.gui.widgets.test_BasePlotWidget import TestPlotWidget from unittest import mock from PySide6 import QtCore, QtGui, QtTest -from test.asammdf.gui.test_base import DragAndDrop, Pixmap -from test.asammdf.gui.widgets.test_BasePlotWidget import TestPlotWidget - class TestDoubleClick(TestPlotWidget): # Note: Test Plot Widget through FileWidget. @@ -89,7 +88,7 @@ def test_EnableDisable_Group(self): # Press 'Shift-Insert' in order to Insert Group # Create Channel Group. Drag channels inside the group one by one with mock.patch( - "asammdf.gui.widgets.tree.QtWidgets.QInputDialog.getText" + "asammdf.gui.widgets.tree.QtWidgets.QInputDialog.getText" ) as mc_getText: # Create Channel Group mc_getText.return_value = "FirstGroup", True @@ -235,7 +234,7 @@ def test_EnableDisable_ParentGroup(self): # Create Channel Group. Drag channels inside the group one by one groups = {} with mock.patch( - "asammdf.gui.widgets.tree.QtWidgets.QInputDialog.getText" + "asammdf.gui.widgets.tree.QtWidgets.QInputDialog.getText" ) as mc_getText: for group_name in ("A", "B", "C"): # Create Channel Group @@ -360,10 +359,10 @@ def test_EnableDisable_ParentGroup(self): enabled_groups_pixmap = plot.plot.viewport().grab() for channel in ( - plot_channel_a, - plot_channel_b, - plot_channel_c, - plot_channel_d, + plot_channel_a, + plot_channel_b, + plot_channel_c, + plot_channel_d, ): self.assertTrue( Pixmap.has_color( @@ -422,7 +421,7 @@ def test_EnableDisable_Subgroup(self): # Create Channel Group. Drag channels inside the group one by one groups = {} with mock.patch( - "asammdf.gui.widgets.tree.QtWidgets.QInputDialog.getText" + "asammdf.gui.widgets.tree.QtWidgets.QInputDialog.getText" ) as mc_getText: for group_name in ("A", "B", "C"): # Create Channel Group @@ -537,10 +536,10 @@ def test_EnableDisable_Subgroup(self): enabled_groups_pixmap = plot.plot.viewport().grab() for channel in ( - plot_channel_a, - plot_channel_b, - plot_channel_c, - plot_channel_d, + plot_channel_a, + plot_channel_b, + plot_channel_c, + plot_channel_d, ): self.assertTrue( Pixmap.has_color( @@ -599,7 +598,7 @@ def test_EnableDisable_Preserve_Subgroup_State_0(self): # Create Channel Group. Drag channels inside the group one by one groups = {} with mock.patch( - "asammdf.gui.widgets.tree.QtWidgets.QInputDialog.getText" + "asammdf.gui.widgets.tree.QtWidgets.QInputDialog.getText" ) as mc_getText: for group_name in ("A", "B", "C"): # Create Channel Group @@ -782,7 +781,7 @@ def test_EnableDisable_Preserve_Subgroup_State_1(self): # Create Channel Group. Drag channels inside the group one by one groups = {} with mock.patch( - "asammdf.gui.widgets.tree.QtWidgets.QInputDialog.getText" + "asammdf.gui.widgets.tree.QtWidgets.QInputDialog.getText" ) as mc_getText: for group_name in ("A", "B", "C"): # Create Channel Group diff --git a/test/asammdf/gui/widgets/test_PlotWidget_PushButtons.py b/test/asammdf/gui/widgets/test_PlotWidget_PushButtons.py index 73f37c7d3..994a22af1 100644 --- a/test/asammdf/gui/widgets/test_PlotWidget_PushButtons.py +++ b/test/asammdf/gui/widgets/test_PlotWidget_PushButtons.py @@ -1,9 +1,9 @@ #!/usr/bin/env python -from PySide6 import QtCore, QtTest - from test.asammdf.gui.test_base import Pixmap from test.asammdf.gui.widgets.test_BasePlotWidget import TestPlotWidget +from PySide6 import QtCore, QtTest + class TestPushButtons(TestPlotWidget): def setUp(self): @@ -214,8 +214,8 @@ def test_Plot_ChannelSelection_PushButton_FocusedMode(self): self.processEvents(timeout=0.01) focus_mode_channel_1_pixmap = self.plot.plot.viewport().grab() if Pixmap.has_color( - pixmap=focus_mode_channel_1_pixmap, - color_name=self.plot_graph_channel_1.color_name, + pixmap=focus_mode_channel_1_pixmap, + color_name=self.plot_graph_channel_1.color_name, ): break From 6fb935d73f14c197d272287ab9f57c8383aa732c Mon Sep 17 00:00:00 2001 From: tov101 Date: Mon, 11 Sep 2023 08:03:42 +0300 Subject: [PATCH 06/11] .. --- test/asammdf/gui/widgets/test_PlotWidget_DoubleClick.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/asammdf/gui/widgets/test_PlotWidget_DoubleClick.py b/test/asammdf/gui/widgets/test_PlotWidget_DoubleClick.py index 269cb1d19..38a51eb1c 100644 --- a/test/asammdf/gui/widgets/test_PlotWidget_DoubleClick.py +++ b/test/asammdf/gui/widgets/test_PlotWidget_DoubleClick.py @@ -177,6 +177,7 @@ def test_EnableDisable_Group(self): for _ in range(20): self.processEvents() + self.processEvents(0.1) enabled_groups_pixmap = plot.plot.viewport().grab() self.assertTrue( Pixmap.has_color( @@ -298,8 +299,8 @@ def test_EnableDisable_ParentGroup(self): groups["B"].setExpanded(True) groups["C"].setExpanded(True) - enabled_groups_pixmap = plot.plot.viewport().grab() self.processEvents() + enabled_groups_pixmap = plot.plot.viewport().grab() # Evaluate for channel in (plot_channel_a, plot_channel_b, plot_channel_c): self.assertTrue( @@ -312,6 +313,7 @@ def test_EnableDisable_ParentGroup(self): self.assertNotEqual(color_name, "#808080") # Press mouse double click on Group A self.mouseDClick_WidgetItem(groups["A"]) + self.processEvents() disabled_groups_pixmap = plot.plot.viewport().grab() # Evaluate From 546bacd6c20697614bacbed3c4b76d378d020d19 Mon Sep 17 00:00:00 2001 From: tov101 Date: Mon, 11 Sep 2023 09:44:27 +0300 Subject: [PATCH 07/11] Fix tests. --- benchmarks/bench.py | 184 +-- benchmarks/gen_images.py | 12 +- ci/support.py | 3 +- doc/conf.py | 4 +- examples/mf4_demo.py | 4 +- examples/working with Signal class.py | 4 +- pyproject.toml | 1 + setup.py | 4 +- src/asammdf/blocks/bus_logging_utils.py | 25 +- src/asammdf/blocks/conversion_utils.py | 68 +- src/asammdf/blocks/mdf_common.py | 15 +- src/asammdf/blocks/mdf_v2.py | 4 +- src/asammdf/blocks/mdf_v3.py | 243 +--- src/asammdf/blocks/mdf_v4.py | 1092 +++++------------ src/asammdf/blocks/source_utils.py | 4 +- src/asammdf/blocks/utils.py | 145 +-- src/asammdf/blocks/v2_v3_blocks.py | 206 +--- src/asammdf/blocks/v4_blocks.py | 386 ++---- src/asammdf/blocks/v4_constants.py | 8 +- src/asammdf/gui/dialogs/advanced_search.py | 75 +- .../gui/dialogs/bus_database_manager.py | 4 +- src/asammdf/gui/dialogs/conversion_editor.py | 36 +- src/asammdf/gui/dialogs/define_channel.py | 29 +- src/asammdf/gui/dialogs/dependencies_dlg.py | 4 +- src/asammdf/gui/dialogs/error_dialog.py | 16 +- src/asammdf/gui/dialogs/functions_manager.py | 8 +- src/asammdf/gui/dialogs/messagebox.py | 3 +- src/asammdf/gui/dialogs/multi_search.py | 16 +- src/asammdf/gui/dialogs/range_editor.py | 6 +- src/asammdf/gui/utils.py | 74 +- src/asammdf/gui/widgets/attachment.py | 4 +- src/asammdf/gui/widgets/bar.py | 21 +- src/asammdf/gui/widgets/batch.py | 262 +--- .../gui/widgets/bus_database_manager.py | 12 +- src/asammdf/gui/widgets/can_bus_trace.py | 4 +- .../gui/widgets/channel_bar_display.py | 35 +- src/asammdf/gui/widgets/channel_group_info.py | 18 +- src/asammdf/gui/widgets/channel_stats.py | 8 +- src/asammdf/gui/widgets/collapsiblebox.py | 32 +- src/asammdf/gui/widgets/cursor.py | 40 +- src/asammdf/gui/widgets/database_item.py | 4 +- src/asammdf/gui/widgets/dict_to_tree.py | 6 +- src/asammdf/gui/widgets/fft_window.py | 4 +- src/asammdf/gui/widgets/file.py | 341 ++--- src/asammdf/gui/widgets/flexray_bus_trace.py | 4 +- src/asammdf/gui/widgets/formated_axis.py | 86 +- src/asammdf/gui/widgets/functions_manager.py | 30 +- src/asammdf/gui/widgets/gps.py | 10 +- src/asammdf/gui/widgets/lin_bus_trace.py | 4 +- src/asammdf/gui/widgets/list.py | 54 +- src/asammdf/gui/widgets/main.py | 257 +--- src/asammdf/gui/widgets/mdi_area.py | 597 +++------ src/asammdf/gui/widgets/numeric.py | 257 +--- src/asammdf/gui/widgets/plot.py | 668 +++------- src/asammdf/gui/widgets/plot_standalone.py | 66 +- src/asammdf/gui/widgets/python_highlighter.py | 12 +- src/asammdf/gui/widgets/range_widget.py | 16 +- src/asammdf/gui/widgets/tabular.py | 30 +- src/asammdf/gui/widgets/tabular_base.py | 364 ++---- src/asammdf/gui/widgets/tree.py | 187 +-- src/asammdf/gui/widgets/tree_numeric.py | 5 +- src/asammdf/gui/widgets/viewbox.py | 17 +- src/asammdf/gui/widgets/vtt_widget.py | 4 +- src/asammdf/mdf.py | 711 +++-------- src/asammdf/signal.py | 161 +-- src/asammdf/types.py | 12 +- .../dialogs/test_FunctionsManagerDialog.py | 144 +-- test/asammdf/gui/test_base.py | 20 +- test/asammdf/gui/test_util.py | 12 +- .../gui/widgets/test_BaseFileWidget.py | 2 + .../gui/widgets/test_BasePlotWidget.py | 13 +- .../widgets/test_FileWidget_TabChannels.py | 200 +-- .../test_FileWidget_TabModifyAndExport.py | 16 +- .../widgets/test_PlotWidget_DoubleClick.py | 484 +++----- .../widgets/test_PlotWidget_DragAndDrop.py | 120 +- .../widgets/test_PlotWidget_PushButtons.py | 48 +- .../gui/widgets/test_PlotWidget_Shortcuts.py | 8 +- test/run_all.py | 4 +- test/test_CAN_bus_loogging.py | 60 +- test/test_endianess.py | 156 +-- test/test_mdf.py | 325 ++--- test/test_mdf4.py | 8 +- test/test_signal.py | 76 +- test/test_v4_blocks/test_atblock.py | 8 +- test/utils.py | 24 +- 85 files changed, 2200 insertions(+), 6554 deletions(-) diff --git a/benchmarks/bench.py b/benchmarks/bench.py index 110d985ba..71136bb13 100644 --- a/benchmarks/bench.py +++ b/benchmarks/bench.py @@ -91,22 +91,16 @@ def __exit__(self, type_, value, tracebackobj): traceback.print_tb(tracebackobj, None, info) info.seek(0) info = info.read() - self.error = "{} : {}\n{}\t \n{}{}".format( - self.topic, self.message, type_, value, info - ) + self.error = "{} : {}\n{}\t \n{}{}".format(self.topic, self.message, type_, value, info) if self.fmt == "rst": self.output = "{:<50} {:>9} {:>8}".format(self.message, "0*", "0*") elif self.fmt == "md": self.output = "|{:<50}|{:>9}|{:>8}|".format(self.message, "0*", "0*") else: if self.fmt == "rst": - self.output = "{:<50} {:>9} {:>8}".format( - self.message, elapsed_time, ram_usage - ) + self.output = "{:<50} {:>9} {:>8}".format(self.message, elapsed_time, ram_usage) elif self.fmt == "md": - self.output = "|{:<50}|{:>9}|{:>8}|".format( - self.message, elapsed_time, ram_usage - ) + self.output = "|{:<50}|{:>9}|{:>8}|".format(self.message, elapsed_time, ram_usage) return True @@ -147,9 +141,7 @@ def generate_test_files(version="4.10"): sigs = [] for i in range(channels_count): conversion = { - "conversion_type": v4c.CONVERSION_TYPE_LIN - if version >= "4.00" - else v3c.CONVERSION_TYPE_LINEAR, + "conversion_type": v4c.CONVERSION_TYPE_LIN if version >= "4.00" else v3c.CONVERSION_TYPE_LINEAR, "a": float(i), "b": -0.5, } @@ -169,9 +161,7 @@ def generate_test_files(version="4.10"): sigs = [] for i in range(channels_count): conversion = { - "conversion_type": v4c.CONVERSION_TYPE_ALG - if version >= "4.00" - else v3c.CONVERSION_TYPE_FORMULA, + "conversion_type": v4c.CONVERSION_TYPE_ALG if version >= "4.00" else v3c.CONVERSION_TYPE_FORMULA, "formula": "{} * sin(X)".format(i), } sig = Signal( @@ -190,9 +180,7 @@ def generate_test_files(version="4.10"): sigs = [] for i in range(channels_count): conversion = { - "conversion_type": v4c.CONVERSION_TYPE_RAT - if version >= "4.00" - else v3c.CONVERSION_TYPE_RAT, + "conversion_type": v4c.CONVERSION_TYPE_RAT if version >= "4.00" else v3c.CONVERSION_TYPE_RAT, "P1": 0, "P2": i, "P3": -0.5, @@ -215,9 +203,7 @@ def generate_test_files(version="4.10"): # string sigs = [] for i in range(channels_count): - sig = [ - "Channel {} sample {}".format(i, j).encode("ascii") for j in range(cycles) - ] + sig = ["Channel {} sample {}".format(i, j).encode("ascii") for j in range(cycles)] sig = Signal( np.array(sig), t, @@ -251,17 +237,13 @@ def generate_test_files(version="4.10"): conversion = { "raw": np.arange(255, dtype=np.float64), "phys": np.array(["Value {}".format(i).encode("ascii") for i in range(255)]), - "conversion_type": v4c.CONVERSION_TYPE_TABX - if version >= "4.00" - else v3c.CONVERSION_TYPE_TABX, + "conversion_type": v4c.CONVERSION_TYPE_TABX if version >= "4.00" else v3c.CONVERSION_TYPE_TABX, "links_nr": 260, "ref_param_nr": 255, } for i in range(255): - conversion["val_{}".format(i)] = conversion[ - "param_val_{}".format(i) - ] = conversion["raw"][i] + conversion["val_{}".format(i)] = conversion["param_val_{}".format(i)] = conversion["raw"][i] conversion["text_{}".format(i)] = conversion["phys"][i] conversion["text_{}".format(255)] = "Default" @@ -351,9 +333,7 @@ def get_all_mdf4(output, fmt): def get_all_mdf4_column(output, fmt): x = MDF(r"test_column.mf4") - with Timer( - "Get all channels", f"asammdf {asammdf_version} column mdfv4", fmt - ) as timer: + with Timer("Get all channels", f"asammdf {asammdf_version} column mdfv4", fmt) as timer: t = perf_counter() counter = 0 to_break = False @@ -380,9 +360,7 @@ def convert_v3_v4(output, fmt): def convert_v4_v410(output, fmt): with MDF(r"test.mf4") as x: - with Timer( - "Convert file", f"asammdf {asammdf_version} v4 to v410", fmt - ) as timer: + with Timer("Convert file", f"asammdf {asammdf_version} v4 to v410", fmt) as timer: y = x.convert("4.10") y.close() output.send([timer.output, timer.error]) @@ -390,9 +368,7 @@ def convert_v4_v410(output, fmt): def convert_v4_v420(output, fmt): with MDF(r"test.mf4") as x: - with Timer( - "Convert file", f"asammdf {asammdf_version} v4 to v420", fmt - ) as timer: + with Timer("Convert file", f"asammdf {asammdf_version} v4 to v420", fmt) as timer: y = x.convert("4.20") y.close() output.send([timer.output, timer.error]) @@ -419,79 +395,59 @@ def merge_v4(output, fmt): def open_reader3(output, fmt): - with Timer( - "Open file", "mdfreader {} mdfv3".format(mdfreader_version), fmt - ) as timer: + with Timer("Open file", "mdfreader {} mdfv3".format(mdfreader_version), fmt) as timer: MDFreader(r"test.mdf") output.send([timer.output, timer.error]) def open_reader3_nodata(output, fmt): - with Timer( - "Open file", "mdfreader {} no_data_loading mdfv3".format(mdfreader_version), fmt - ) as timer: + with Timer("Open file", "mdfreader {} no_data_loading mdfv3".format(mdfreader_version), fmt) as timer: MDFreader(r"test.mdf", no_data_loading=True) output.send([timer.output, timer.error]) def open_reader3_compression(output, fmt): - with Timer( - "Open file", "mdfreader {} compress mdfv3".format(mdfreader_version), fmt - ) as timer: + with Timer("Open file", "mdfreader {} compress mdfv3".format(mdfreader_version), fmt) as timer: MDFreader(r"test.mdf", compression="blosc") output.send([timer.output, timer.error]) def open_reader4(output, fmt): - with Timer( - "Open file", "mdfreader {} mdfv4".format(mdfreader_version), fmt - ) as timer: + with Timer("Open file", "mdfreader {} mdfv4".format(mdfreader_version), fmt) as timer: MDFreader(r"test.mf4") output.send([timer.output, timer.error]) def open_reader4_nodata(output, fmt): - with Timer( - "Open file", "mdfreader {} no_data_loading mdfv4".format(mdfreader_version), fmt - ) as timer: + with Timer("Open file", "mdfreader {} no_data_loading mdfv4".format(mdfreader_version), fmt) as timer: MDFreader(r"test.mf4", no_data_loading=True) output.send([timer.output, timer.error]) def open_reader4_compression(output, fmt): - with Timer( - "Open file", "mdfreader {} compress mdfv4".format(mdfreader_version), fmt - ) as timer: + with Timer("Open file", "mdfreader {} compress mdfv4".format(mdfreader_version), fmt) as timer: MDFreader(r"test.mf4", compression="blosc") output.send([timer.output, timer.error]) def save_reader3(output, fmt): x = MDFreader(r"test.mdf") - with Timer( - "Save file", "mdfreader {} mdfv3".format(mdfreader_version), fmt - ) as timer: + with Timer("Save file", "mdfreader {} mdfv3".format(mdfreader_version), fmt) as timer: x.write(r"x.mdf") output.send([timer.output, timer.error]) def save_reader3_nodata(output, fmt): x = MDFreader(r"test.mdf", no_data_loading=True) - with Timer( - "Save file", "mdfreader {} no_data_loading mdfv3".format(mdfreader_version), fmt - ) as timer: + with Timer("Save file", "mdfreader {} no_data_loading mdfv3".format(mdfreader_version), fmt) as timer: x.write(r"x.mdf") output.send([timer.output, timer.error]) def save_reader3_compression(output, fmt): - with Timer( - "Save file", "mdfreader {} compress mdfv3".format(mdfreader_version), fmt - ) as outer_timer: + with Timer("Save file", "mdfreader {} compress mdfv3".format(mdfreader_version), fmt) as outer_timer: x = MDFreader(r"test.mdf", compression="blosc") - with Timer( - "Save file", "mdfreader {} compress mdfv3".format(mdfreader_version), fmt - ) as timer: + with Timer("Save file", "mdfreader {} compress mdfv3".format(mdfreader_version), fmt) as timer: x.write(r"x.mdf") output.send([timer.output, timer.error]) if outer_timer.error: @@ -500,36 +456,28 @@ def save_reader3_compression(output, fmt): def save_reader4(output, fmt): x = MDFreader(r"test.mf4") - with Timer( - "Save file", "mdfreader {} mdfv4".format(mdfreader_version), fmt - ) as timer: + with Timer("Save file", "mdfreader {} mdfv4".format(mdfreader_version), fmt) as timer: x.write(r"x.mf4") output.send([timer.output, timer.error]) def save_reader4_nodata(output, fmt): x = MDFreader(r"test.mf4", no_data_loading=True) - with Timer( - "Save file", "mdfreader {} no_data_loading mdfv4".format(mdfreader_version), fmt - ) as timer: + with Timer("Save file", "mdfreader {} no_data_loading mdfv4".format(mdfreader_version), fmt) as timer: x.write(r"x.mf4") output.send([timer.output, timer.error]) def save_reader4_compression(output, fmt): x = MDFreader(r"test.mf4", compression="blosc") - with Timer( - "Save file", "mdfreader {} compress mdfv4".format(mdfreader_version), fmt - ) as timer: + with Timer("Save file", "mdfreader {} compress mdfv4".format(mdfreader_version), fmt) as timer: x.write(r"x.mf4") output.send([timer.output, timer.error]) def get_all_reader3(output, fmt): x = MDFreader(r"test.mdf") - with Timer( - "Get all channels", "mdfreader {} mdfv3".format(mdfreader_version), fmt - ) as timer: + with Timer("Get all channels", "mdfreader {} mdfv3".format(mdfreader_version), fmt) as timer: for s in x: x.get_channel_data(s) output.send([timer.output, timer.error]) @@ -537,9 +485,7 @@ def get_all_reader3(output, fmt): def get_all_reader3_nodata(output, fmt): x = MDFreader(r"test.mdf", no_data_loading=True) - with Timer( - "Get all channels", "mdfreader {} nodata mdfv3".format(mdfreader_version), fmt - ) as timer: + with Timer("Get all channels", "mdfreader {} nodata mdfv3".format(mdfreader_version), fmt) as timer: for s in x: x.get_channel_data(s) output.send([timer.output, timer.error]) @@ -547,9 +493,7 @@ def get_all_reader3_nodata(output, fmt): def get_all_reader3_compression(output, fmt): x = MDFreader(r"test.mdf", compression="blosc") - with Timer( - "Get all channels", "mdfreader {} compress mdfv3".format(mdfreader_version), fmt - ) as timer: + with Timer("Get all channels", "mdfreader {} compress mdfv3".format(mdfreader_version), fmt) as timer: for s in x: x.get_channel_data(s) @@ -560,9 +504,7 @@ def get_all_reader3_compression(output, fmt): def get_all_reader4(output, fmt): x = MDFreader(r"test.mf4") - with Timer( - "Get all channels", "mdfreader {} mdfv4".format(mdfreader_version), fmt - ) as timer: + with Timer("Get all channels", "mdfreader {} mdfv4".format(mdfreader_version), fmt) as timer: t = perf_counter() counter = 0 to_break = False @@ -579,9 +521,7 @@ def get_all_reader4(output, fmt): def get_all_reader4_nodata(output, fmt): x = MDFreader(r"test.mf4", no_data_loading=True) - with Timer( - "Get all channels", "mdfreader {} nodata mdfv4".format(mdfreader_version), fmt - ) as timer: + with Timer("Get all channels", "mdfreader {} nodata mdfv4".format(mdfreader_version), fmt) as timer: t = perf_counter() counter = 0 to_break = False @@ -598,9 +538,7 @@ def get_all_reader4_nodata(output, fmt): def get_all_reader4_compression(output, fmt): x = MDFreader(r"test.mf4", compression="blosc") - with Timer( - "Get all channels", "mdfreader {} compress mdfv4".format(mdfreader_version), fmt - ) as timer: + with Timer("Get all channels", "mdfreader {} compress mdfv4".format(mdfreader_version), fmt) as timer: t = perf_counter() counter = 0 to_break = False @@ -617,9 +555,7 @@ def get_all_reader4_compression(output, fmt): def merge_reader_v3(output, fmt): files = [r"test.mdf"] * 3 - with Timer( - "Merge 3 files", "mdfreader {} v3".format(mdfreader_version), fmt - ) as timer: + with Timer("Merge 3 files", "mdfreader {} v3".format(mdfreader_version), fmt) as timer: x1 = MDFreader(files[0]) x1.resample(0.01) x2 = MDFreader(files[1]) @@ -633,9 +569,7 @@ def merge_reader_v3(output, fmt): def merge_reader_v3_compress(output, fmt): files = [r"test.mdf"] * 3 - with Timer( - "Merge 3 files", "mdfreader {} compress v3".format(mdfreader_version), fmt - ) as timer: + with Timer("Merge 3 files", "mdfreader {} compress v3".format(mdfreader_version), fmt) as timer: x1 = MDFreader(files[0], compression="blosc") x1.resample(0.01) x2 = MDFreader(files[1], compression="blosc") @@ -649,9 +583,7 @@ def merge_reader_v3_compress(output, fmt): def merge_reader_v3_nodata(output, fmt): files = [r"test.mdf"] * 3 - with Timer( - "Merge 3 files", "mdfreader {} nodata v3".format(mdfreader_version), fmt - ) as timer: + with Timer("Merge 3 files", "mdfreader {} nodata v3".format(mdfreader_version), fmt) as timer: x1 = MDFreader(files[0], no_data_loading=True) x1.resample(0.01) x2 = MDFreader(files[1], no_data_loading=True) @@ -666,9 +598,7 @@ def merge_reader_v3_nodata(output, fmt): def merge_reader_v4(output, fmt): files = [r"test.mf4"] * 3 - with Timer( - "Merge 3 files", "mdfreader {} v4".format(mdfreader_version), fmt - ) as timer: + with Timer("Merge 3 files", "mdfreader {} v4".format(mdfreader_version), fmt) as timer: x1 = MDFreader(files[0]) x1.resample(0.01) x2 = MDFreader(files[1]) @@ -683,9 +613,7 @@ def merge_reader_v4(output, fmt): def merge_reader_v4_compress(output, fmt): files = [r"test.mf4"] * 3 - with Timer( - "Merge 3 files", "mdfreader {} compress v4".format(mdfreader_version), fmt - ) as timer: + with Timer("Merge 3 files", "mdfreader {} compress v4".format(mdfreader_version), fmt) as timer: x1 = MDFreader(files[0], compression="blosc") x1.resample(0.01) x2 = MDFreader(files[1], compression="blosc") @@ -700,9 +628,7 @@ def merge_reader_v4_compress(output, fmt): def merge_reader_v4_nodata(output, fmt): files = [r"test.mf4"] * 3 - with Timer( - "Merge 3 files", "mdfreader {} nodata v4".format(mdfreader_version), fmt - ) as timer: + with Timer("Merge 3 files", "mdfreader {} nodata v4".format(mdfreader_version), fmt) as timer: x1 = MDFreader(files[0], no_data_loading=True) x1.resample(0.01) x2 = MDFreader(files[1], no_data_loading=True) @@ -722,9 +648,7 @@ def merge_reader_v4_nodata(output, fmt): def filter_asam(output, fmt): with Timer("Filter file", f"asammdf {asammdf_version} mdfv4", fmt) as timer: - x = MDF(r"test.mf4").filter( - [(None, i, int(f"{j}5")) for i in range(10, 20) for j in range(1, 20)] - ) + x = MDF(r"test.mf4").filter([(None, i, int(f"{j}5")) for i in range(10, 20) for j in range(1, 20)]) t = perf_counter() counter = 0 to_break = False @@ -743,9 +667,7 @@ def filter_asam(output, fmt): def filter_reader4(output, fmt): - with Timer( - "Filter file", "mdfreader {} mdfv4".format(mdfreader_version), fmt - ) as timer: + with Timer("Filter file", "mdfreader {} mdfv4".format(mdfreader_version), fmt) as timer: x = MDFreader( r"test.mf4", channel_list=[f"Channel_{i}_{j}5" for i in range(10) for j in range(1, 20)], @@ -763,9 +685,7 @@ def filter_reader4(output, fmt): def filter_reader4_compression(output, fmt): - with Timer( - "Filter file", "mdfreader {} compression mdfv4".format(mdfreader_version), fmt - ) as timer: + with Timer("Filter file", "mdfreader {} compression mdfv4".format(mdfreader_version), fmt) as timer: x = MDFreader( r"test.mf4", compression="blosc", @@ -784,9 +704,7 @@ def filter_reader4_compression(output, fmt): def filter_reader4_nodata(output, fmt): - with Timer( - "Filter file", "mdfreader {} nodata mdfv4".format(mdfreader_version), fmt - ) as timer: + with Timer("Filter file", "mdfreader {} nodata mdfv4".format(mdfreader_version), fmt) as timer: x = MDFreader( r"test.mf4", no_data_loading=True, @@ -818,9 +736,7 @@ def cut_reader4(output, fmt): x = MDFreader(r"test.mf4") t = x.get_channel_data(list(x.masterChannelList)[0]) begin, end = 0.2 * (t[-1] - t[0]) + t[0], 0.8 * (t[-1] - t[0]) + t[0] - with Timer( - "Cut file", "mdfreader {} mdfv4".format(mdfreader_version), fmt - ) as timer: + with Timer("Cut file", "mdfreader {} mdfv4".format(mdfreader_version), fmt) as timer: x.cut(begin=begin, end=end) output.send([timer.output, timer.error]) @@ -829,9 +745,7 @@ def cut_reader4_compression(output, fmt): x = MDFreader(r"test.mf4", compression="blosc") t = x.get_channel_data(list(x.masterChannelList)[0]) begin, end = 0.2 * (t[-1] - t[0]) + t[0], 0.8 * (t[-1] - t[0]) + t[0] - with Timer( - "Cut file", "mdfreader {} compression mdfv4".format(mdfreader_version), fmt - ) as timer: + with Timer("Cut file", "mdfreader {} compression mdfv4".format(mdfreader_version), fmt) as timer: x.cut(begin=begin, end=end) output.send([timer.output, timer.error]) @@ -840,9 +754,7 @@ def cut_reader4_nodata(output, fmt): x = MDFreader(r"test.mf4", no_data_loading=True) t = x.get_channel_data(list(x.masterChannelList)[0]) begin, end = 0.2 * (t[-1] - t[0]) + t[0], 0.8 * (t[-1] - t[0]) + t[0] - with Timer( - "Cut file", "mdfreader {} nodata mdfv4".format(mdfreader_version), fmt - ) as timer: + with Timer("Cut file", "mdfreader {} nodata mdfv4".format(mdfreader_version), fmt) as timer: x.cut(begin=begin, end=end) output.send([timer.output, timer.error]) @@ -904,9 +816,7 @@ def main(text_output, fmt): output.append("* numpy {}".format(np.__version__)) output.append("* {}GB installed RAM\n".format(installed_ram)) output.append("Notations used in the results\n") - output.append( - ("* compress = mdfreader mdf object created with " "compression=blosc") - ) + output.append(("* compress = mdfreader mdf object created with " "compression=blosc")) output.append(("* nodata = mdfreader mdf object read with " "no_data_loading=True")) output.append("\nFiles used for benchmark:\n") output.append("* mdf version {}".format(v3_version)) @@ -1070,9 +980,7 @@ def main(text_output, fmt): if text_output: arch = "x86" if platform.architecture()[0] == "32bit" else "x64" - file = "{}_asammdf_{}_mdfreader_{}.{}".format( - arch, asammdf_version, mdfreader_version, fmt - ) + file = "{}_asammdf_{}_mdfreader_{}.{}".format(arch, asammdf_version, mdfreader_version, fmt) with open(file, "w") as out: out.write("\n".join(output)) diff --git a/benchmarks/gen_images.py b/benchmarks/gen_images.py index a8d3ca38f..0da9d6f75 100644 --- a/benchmarks/gen_images.py +++ b/benchmarks/gen_images.py @@ -67,17 +67,9 @@ def generate_graphs(result, topic, aspect, for_doc=False): ax.invert_yaxis() ax.set_xlabel("Time [ms]" if aspect == "time" else "RAM [MB]") if topic == "Get": - ax.set_title( - "Get all channels (36424 calls) - {}".format( - "time" if aspect == "time" else "ram usage" - ) - ) + ax.set_title("Get all channels (36424 calls) - {}".format("time" if aspect == "time" else "ram usage")) else: - ax.set_title( - "{} test file - {}".format( - topic, "time" if aspect == "time" else "ram usage" - ) - ) + ax.set_title("{} test file - {}".format(topic, "time" if aspect == "time" else "ram usage")) ax.xaxis.grid() fig.subplots_adjust( diff --git a/ci/support.py b/ci/support.py index 47a62c1bd..3e691fa87 100644 --- a/ci/support.py +++ b/ci/support.py @@ -50,8 +50,7 @@ def __str__(self): verdict_details = "" for data in datas: verdict_table_entry = ( - f"|{data.classname}|[{data.name}](#user-content-{data.name.lower()})|" - f"{data.time}|\n" + f"|{data.classname}|[{data.name}](#user-content-{data.name.lower()})|" f"{data.time}|\n" ) verdict_data_entry = ( f"
\n" diff --git a/doc/conf.py b/doc/conf.py index a0d5dfab5..15e2b79bf 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -154,9 +154,7 @@ # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). -latex_documents = [ - (master_doc, "asammdf.tex", "asammdf Documentation", "Daniel Hrisca", "manual") -] +latex_documents = [(master_doc, "asammdf.tex", "asammdf Documentation", "Daniel Hrisca", "manual")] # -- Options for manual page output --------------------------------------- diff --git a/examples/mf4_demo.py b/examples/mf4_demo.py index c4a69be04..ea9525a22 100644 --- a/examples/mf4_demo.py +++ b/examples/mf4_demo.py @@ -90,9 +90,7 @@ # value to text vals = 20 conversion = {"val_{}".format(i): i for i in range(vals)} -conversion.update( - {"text_{}".format(i): "key_{}".format(i).encode("ascii") for i in range(vals)} -) +conversion.update({"text_{}".format(i): "key_{}".format(i).encode("ascii") for i in range(vals)}) conversion["default"] = b"default key" sig = Signal( np.arange(cycles, dtype=np.uint32) % 30, diff --git a/examples/working with Signal class.py b/examples/working with Signal class.py index 92c7978a4..e3a86a22f 100644 --- a/examples/working with Signal class.py +++ b/examples/working with Signal class.py @@ -48,9 +48,7 @@ timestamps = np.arange(0, 2, 0.02) -s_map = Signal( - samples=samples, timestamps=timestamps, name="Variable Map Signal", unit="dB" -) +s_map = Signal(samples=samples, timestamps=timestamps, name="Variable Map Signal", unit="dB") s_map.plot() diff --git a/pyproject.toml b/pyproject.toml index 8ab4ccb15..dd43972b2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,6 +3,7 @@ requires = ["numpy", "setuptools", "wheel"] build-backend = "setuptools.build_meta" [tool.black] +line-length = 120 target-version = ['py38'] extend-exclude = ''' ^/src/asammdf/gui/ui diff --git a/setup.py b/setup.py index 46219cfee..8f2ab8e09 100644 --- a/setup.py +++ b/setup.py @@ -134,8 +134,6 @@ def _get_ext_modules(): # To provide executable scripts, use entry points in preference to the # "scripts" keyword. Entry points provide cross-platform support and allow # pip to create the appropriate form of executable for the target platform. - entry_points={ - "console_scripts": ["asammdf = asammdf.gui.asammdfgui:main [gui,export,decode]"] - }, + entry_points={"console_scripts": ["asammdf = asammdf.gui.asammdfgui:main [gui,export,decode]"]}, ext_modules=_get_ext_modules(), ) diff --git a/src/asammdf/blocks/bus_logging_utils.py b/src/asammdf/blocks/bus_logging_utils.py index 601228947..f417e0523 100644 --- a/src/asammdf/blocks/bus_logging_utils.py +++ b/src/asammdf/blocks/bus_logging_utils.py @@ -34,9 +34,7 @@ def defined_j1939_bit_count(signal): return size -def apply_conversion( - vals: NDArray[Any], signal: Signal, ignore_value2text_conversion: bool -) -> NDArray[Any]: +def apply_conversion(vals: NDArray[Any], signal: Signal, ignore_value2text_conversion: bool) -> NDArray[Any]: a, b = float(signal.factor), float(signal.offset) if signal.values: @@ -99,13 +97,9 @@ def extract_signal( if is_float: if bit_offset: - raise MdfException( - f"Cannot extract float signal '{signal}' because it is not byte aligned" - ) + raise MdfException(f"Cannot extract float signal '{signal}' because it is not byte aligned") if bit_count not in (16, 32, 64): - raise MdfException( - f"Cannot extract float signal '{signal}' because it does not have a standard byte size" - ) + raise MdfException(f"Cannot extract float signal '{signal}' because it does not have a standard byte size") if big_endian: byte_pos = start_byte + 1 @@ -329,10 +323,7 @@ def extract_mux( multiplexor_name = sig.name break for sig in message: - if ( - sig.multiplex not in (None, "Multiplexor") - and sig.muxer_for_signal is None - ): + if sig.multiplex not in (None, "Multiplexor") and sig.muxer_for_signal is None: sig.muxer_for_signal = multiplexor_name sig.mux_val_min = sig.mux_val_max = int(sig.multiplex) sig.mux_val_grp.insert(0, (int(sig.multiplex), int(sig.multiplex))) @@ -386,17 +377,13 @@ def extract_mux( "name": sig_name, "comment": sig.comment or "", "unit": sig.unit or "", - "samples": samples - if raw - else apply_conversion(samples, sig, ignore_value2text_conversion), + "samples": samples if raw else apply_conversion(samples, sig, ignore_value2text_conversion), "t": t_, "invalidation_bits": None, } if is_j1939: - signals[sig_name]["invalidation_bits"] = ( - samples > MAX_VALID_J1939[defined_j1939_bit_count(sig)] - ) + signals[sig_name]["invalidation_bits"] = samples > MAX_VALID_J1939[defined_j1939_bit_count(sig)] except: print(format_exc()) diff --git a/src/asammdf/blocks/conversion_utils.py b/src/asammdf/blocks/conversion_utils.py index ada3b2f43..58886d981 100644 --- a/src/asammdf/blocks/conversion_utils.py +++ b/src/asammdf/blocks/conversion_utils.py @@ -50,9 +50,7 @@ def conversion_transfer( unit = conversion.unit.strip(" \r\n\t\0").encode("latin-1") if conversion_type == v4c.CONVERSION_TYPE_NON: - conversion = v3b.ChannelConversion( - unit=unit, conversion_type=v3c.CONVERSION_TYPE_NONE - ) + conversion = v3b.ChannelConversion(unit=unit, conversion_type=v3c.CONVERSION_TYPE_NONE) elif conversion_type == v4c.CONVERSION_TYPE_LIN: conversion = v3b.ChannelConversion( @@ -141,22 +139,16 @@ def conversion_transfer( conversion.referenced_blocks[f"text_{i}"], v4b.ChannelConversion, ): - kargs[f"text_{i}"] = conversion.referenced_blocks[ - f"text_{i}" - ].name.encode("latin-1") + kargs[f"text_{i}"] = conversion.referenced_blocks[f"text_{i}"].name.encode("latin-1") else: - kargs[f"text_{i}"] = conversion.referenced_blocks[ - f"text_{i}" - ] + kargs[f"text_{i}"] = conversion.referenced_blocks[f"text_{i}"] new_conversion = v3b.ChannelConversion(**kargs) if isinstance( conversion.referenced_blocks["default_addr"], v4b.ChannelConversion, ): - default_addr = conversion.referenced_blocks[ - f"default_addr" - ].name.encode("latin-1") + default_addr = conversion.referenced_blocks[f"default_addr"].name.encode("latin-1") else: default_addr = conversion.referenced_blocks["default_addr"] new_conversion.referenced_blocks["default_addr"] = default_addr @@ -177,22 +169,16 @@ def conversion_transfer( conversion.referenced_blocks[f"text_{i}"], v4b.ChannelConversion, ): - kargs[f"text_{i}"] = conversion.referenced_blocks[ - f"text_{i}" - ].name.encode("latin-1") + kargs[f"text_{i}"] = conversion.referenced_blocks[f"text_{i}"].name.encode("latin-1") else: - kargs[f"text_{i}"] = conversion.referenced_blocks[ - f"text_{i}" - ] + kargs[f"text_{i}"] = conversion.referenced_blocks[f"text_{i}"] new_conversion = v3b.ChannelConversion(**kargs) if isinstance( conversion.referenced_blocks["default_addr"], v4b.ChannelConversion, ): - default_addr = conversion.referenced_blocks[ - f"default_addr" - ].name.encode("latin-1") + default_addr = conversion.referenced_blocks[f"default_addr"].name.encode("latin-1") else: default_addr = conversion.referenced_blocks["default_addr"] new_conversion.referenced_blocks["default_addr"] = default_addr @@ -208,9 +194,7 @@ def conversion_transfer( unit = conversion.unit_field.decode("latin-1").strip(" \r\n\t\0") if conversion_type == v3c.CONVERSION_TYPE_NONE: - conversion = v4b.ChannelConversion( - conversion_type=v4c.CONVERSION_TYPE_NON - ) + conversion = v4b.ChannelConversion(conversion_type=v4c.CONVERSION_TYPE_NON) elif conversion_type == v3c.CONVERSION_TYPE_LINEAR: conversion = v4b.ChannelConversion( @@ -232,9 +216,7 @@ def conversion_transfer( elif conversion_type == v3c.CONVERSION_TYPE_FORMULA: formula = conversion.formula - conversion = v4b.ChannelConversion( - conversion_type=v4c.CONVERSION_TYPE_ALG, formula=formula - ) + conversion = v4b.ChannelConversion(conversion_type=v4c.CONVERSION_TYPE_ALG, formula=formula) elif conversion_type == v3c.CONVERSION_TYPE_TAB: conversion_ = {} @@ -243,9 +225,7 @@ def conversion_transfer( conversion_[f"raw_{i}"] = conversion[f"raw_{i}"] conversion_[f"phys_{i}"] = conversion[f"phys_{i}"] - conversion = v4b.ChannelConversion( - conversion_type=v4c.CONVERSION_TYPE_TAB, **conversion_ - ) + conversion = v4b.ChannelConversion(conversion_type=v4c.CONVERSION_TYPE_TAB, **conversion_) elif conversion_type == v3c.CONVERSION_TYPE_TABI: conversion_ = {} @@ -254,9 +234,7 @@ def conversion_transfer( conversion_[f"raw_{i}"] = conversion[f"raw_{i}"] conversion_[f"phys_{i}"] = conversion[f"phys_{i}"] - conversion = v4b.ChannelConversion( - conversion_type=v4c.CONVERSION_TYPE_TABI, **conversion_ - ) + conversion = v4b.ChannelConversion(conversion_type=v4c.CONVERSION_TYPE_TABI, **conversion_) elif conversion_type == v3c.CONVERSION_TYPE_TABX: nr = conversion["ref_param_nr"] @@ -426,32 +404,20 @@ def to_dict(conversion: ChannelConversionType) -> Union[dict, None]: conversion_dict["conversion_type"] = conversion_type elif conversion_type == v4c.CONVERSION_TYPE_RAT: - conversion_dict.update( - {key: conversion[key] for key in [f"P{i}" for i in range(1, 7)]} - ) + conversion_dict.update({key: conversion[key] for key in [f"P{i}" for i in range(1, 7)]}) conversion_dict["conversion_type"] = conversion_type elif conversion_type in (v4c.CONVERSION_TYPE_TAB, v4c.CONVERSION_TYPE_TABI): params = conversion["val_param_nr"] // 2 - conversion_dict.update( - {key: conversion[key] for key in [f"phys_{nr}" for nr in range(params)]} - ) - conversion_dict.update( - {key: conversion[key] for key in [f"raw_{nr}" for nr in range(params)]} - ) + conversion_dict.update({key: conversion[key] for key in [f"phys_{nr}" for nr in range(params)]}) + conversion_dict.update({key: conversion[key] for key in [f"raw_{nr}" for nr in range(params)]}) conversion_dict["conversion_type"] = conversion_type elif conversion_type == v4c.CONVERSION_TYPE_RTAB: params = (conversion["val_param_nr"] - 1) // 3 - conversion_dict.update( - {key: conversion[key] for key in [f"lower_{nr}" for nr in range(params)]} - ) - conversion_dict.update( - {key: conversion[key] for key in [f"upper_{nr}" for nr in range(params)]} - ) - conversion_dict.update( - {key: conversion[key] for key in [f"phys_{nr}" for nr in range(params)]} - ) + conversion_dict.update({key: conversion[key] for key in [f"lower_{nr}" for nr in range(params)]}) + conversion_dict.update({key: conversion[key] for key in [f"upper_{nr}" for nr in range(params)]}) + conversion_dict.update({key: conversion[key] for key in [f"phys_{nr}" for nr in range(params)]}) conversion_dict["conversion_type"] = conversion_type conversion_dict["default"] = conversion.default diff --git a/src/asammdf/blocks/mdf_common.py b/src/asammdf/blocks/mdf_common.py index 521e6df40..3d9d185ec 100644 --- a/src/asammdf/blocks/mdf_common.py +++ b/src/asammdf/blocks/mdf_common.py @@ -63,10 +63,7 @@ def _validate_channel_selection( if name is None: if group is None or index is None: - message = ( - "Invalid arguments for channel selection: " - 'must give "name" or, "group" and "index"' - ) + message = "Invalid arguments for channel selection: " 'must give "name" or, "group" and "index"' raise MdfException(message) else: gp_nr, ch_nr = group, index @@ -79,9 +76,7 @@ def _validate_channel_selection( try: grp.channels[ch_nr] except IndexError: - raise MdfException( - f"Channel index out of range: {(name, group, index)}" - ) + raise MdfException(f"Channel index out of range: {(name, group, index)}") else: if name not in self.channels_db: raise MdfException(f'Channel "{name}" not found') @@ -114,11 +109,7 @@ def _validate_channel_selection( ch_nr = index else: if index is None: - entries = tuple( - (gp_nr, ch_nr) - for gp_nr, ch_nr in self.channels_db[name] - if gp_nr == group - ) + entries = tuple((gp_nr, ch_nr) for gp_nr, ch_nr in self.channels_db[name] if gp_nr == group) count = len(entries) if count == 1: diff --git a/src/asammdf/blocks/mdf_v2.py b/src/asammdf/blocks/mdf_v2.py index 34a3763e7..6f4b8d7bd 100644 --- a/src/asammdf/blocks/mdf_v2.py +++ b/src/asammdf/blocks/mdf_v2.py @@ -26,9 +26,7 @@ def __init__( version = validate_version_argument(version, hint=2) if not kwargs.get("__internal__", False): - raise MdfException( - "Always use the MDF class; do not use the class MDF2 directly" - ) + raise MdfException("Always use the MDF class; do not use the class MDF2 directly") super().__init__(name, version, **kwargs) diff --git a/src/asammdf/blocks/mdf_v3.py b/src/asammdf/blocks/mdf_v3.py index ac63e6477..062fd571f 100644 --- a/src/asammdf/blocks/mdf_v3.py +++ b/src/asammdf/blocks/mdf_v3.py @@ -176,9 +176,7 @@ def __init__( **kwargs, ) -> None: if not kwargs.get("__internal__", False): - raise MdfException( - "Always use the MDF class; do not use the class MDF3 directly" - ) + raise MdfException("Always use the MDF class; do not use the class MDF3 directly") self._kwargs = kwargs self._password = kwargs.get("password", None) @@ -190,9 +188,7 @@ def __init__( self.load_filter = set(channels) self.use_load_filter = True - self.temporary_folder = kwargs.get( - "temporary_folder", get_global_option("temporary_folder") - ) + self.temporary_folder = kwargs.get("temporary_folder", get_global_option("temporary_folder")) self.groups = [] self.header = None @@ -208,9 +204,7 @@ def __init__( self._tempfile.write(b"\0") self._file = None - self._remove_source_from_channel_names = kwargs.get( - "remove_source_from_channel_names", False - ) + self._remove_source_from_channel_names = kwargs.get("remove_source_from_channel_names", False) self._read_fragment_size = get_global_option("read_fragment_size") self._write_fragment_size = get_global_option("write_fragment_size") @@ -221,9 +215,7 @@ def __init__( "raise_on_multiple_occurrences", get_global_option("raise_on_multiple_occurrences"), ) - self._use_display_names = kwargs.get( - "use_display_names", get_global_option("use_display_names") - ) + self._use_display_names = kwargs.get("use_display_names", get_global_option("use_display_names")) self._fill_0_for_missing_computation_channels = kwargs.get( "fill_0_for_missing_computation_channels", get_global_option("fill_0_for_missing_computation_channels"), @@ -261,9 +253,7 @@ def __init__( else: self.name = Path(name) self._mapped_file = open(self.name, "rb") - self._file = mmap.mmap( - self._mapped_file.fileno(), 0, access=mmap.ACCESS_READ - ) + self._file = mmap.mmap(self._mapped_file.fileno(), 0, access=mmap.ACCESS_READ) self._from_filelike = False self._read(mapped=True, progress=progress) else: @@ -375,11 +365,7 @@ def _load_data( while size >= split_size - cur_size: stream.seek(current_address) if data: - data.append( - stream.read( - min(record_count, split_size - cur_size) - ) - ) + data.append(stream.read(min(record_count, split_size - cur_size))) bts = b"".join(data)[:record_count] record_count -= len(bts) @@ -392,9 +378,7 @@ def _load_data( finished = True break else: - bts = stream.read(min(split_size, record_count))[ - :record_count - ] + bts = stream.read(min(split_size, record_count))[:record_count] record_count -= len(bts) __count = len(bts) // samples_size yield bts, offset // samples_size, __count @@ -565,9 +549,7 @@ def _prepare_record(self, group: Group) -> list: bit_offset += 16 - bit_size if not new_ch.dtype_fmt: - new_ch.dtype_fmt = dtype( - get_fmt_v3(data_type, size, byte_order) - ) + new_ch.dtype_fmt = dtype(get_fmt_v3(data_type, size, byte_order)) record.append( ( @@ -584,9 +566,7 @@ def _prepare_record(self, group: Group) -> list: return record - def _get_not_byte_aligned_data( - self, data: bytes, group: Group, ch_nr: int - ) -> NDArray[Any]: + def _get_not_byte_aligned_data(self, data: bytes, group: Group, ch_nr: int) -> NDArray[Any]: big_endian_types = ( v23c.DATA_TYPE_UNSIGNED_MOTOROLA, v23c.DATA_TYPE_FLOAT_MOTOROLA, @@ -631,9 +611,7 @@ def _get_not_byte_aligned_data( if extra_bytes: if big_endian: - vals = column_stack( - [vals, zeros(len(vals), dtype=f"<({extra_bytes},)u1")] - ) + vals = column_stack([vals, zeros(len(vals), dtype=f"<({extra_bytes},)u1")]) try: vals = vals.view(f">u{std_size}").ravel() except: @@ -643,9 +621,7 @@ def _get_not_byte_aligned_data( vals &= (1 << bit_count) - 1 else: - vals = column_stack( - [vals, zeros(len(vals), dtype=f"<({extra_bytes},)u1")] - ) + vals = column_stack([vals, zeros(len(vals), dtype=f"<({extra_bytes},)u1")]) try: vals = vals.view(f" None: self.identification = FileIdentificationBlock(stream=stream) self.header = HeaderBlock(stream=stream) - self.version = self.identification.version_str.decode("latin-1").strip( - " \n\t\0" - ) + self.version = self.identification.version_str.decode("latin-1").strip(" \n\t\0") # this will hold mapping from channel address to Channel object # needed for linking dependency blocks to referenced channels after @@ -717,9 +689,7 @@ def _read(self, mapped: bool = False, progress=None) -> None: # read each data group sequentially while dg_addr: if dg_addr > self.file_limit: - logger.warning( - f"Data group address {dg_addr:X} is outside the file size {self.file_limit}" - ) + logger.warning(f"Data group address {dg_addr:X} is outside the file size {self.file_limit}") break data_group = DataGroup(address=dg_addr, stream=stream, mapped=mapped) record_id_nr = data_group.record_id_len @@ -731,9 +701,7 @@ def _read(self, mapped: bool = False, progress=None) -> None: trigger_addr = data_group.trigger_addr if trigger_addr: if trigger_addr > self.file_limit: - logger.warning( - f"Trigger address {trigger_addr:X} is outside the file size {self.file_limit}" - ) + logger.warning(f"Trigger address {trigger_addr:X} is outside the file size {self.file_limit}") trigger = None else: trigger = TriggerBlock(address=trigger_addr, stream=stream) @@ -765,9 +733,7 @@ def _read(self, mapped: bool = False, progress=None) -> None: # read each channel group sequentially if cg_addr > self.file_limit: - logger.warning( - f"Channel group address {cg_addr:X} is outside the file size {self.file_limit}" - ) + logger.warning(f"Channel group address {cg_addr:X} is outside the file size {self.file_limit}") break grp.channel_group = ChannelGroup(address=cg_addr, stream=stream) @@ -778,9 +744,7 @@ def _read(self, mapped: bool = False, progress=None) -> None: while ch_addr: if ch_addr > self.file_limit: - logger.warning( - f"Channel address {ch_addr:X} is outside the file size {self.file_limit}" - ) + logger.warning(f"Channel address {ch_addr:X} is outside the file size {self.file_limit}") break if filter_channels: @@ -795,22 +759,14 @@ def _read(self, mapped: bool = False, progress=None) -> None: ) = v23c.CHANNEL_FILTER_uf(stream, ch_addr) name = name.decode("latin-1").strip(" \t\n\r\0") if block_len >= v23c.CN_LONGNAME_BLOCK_SIZE: - tx_address = v23c.UINT32_uf( - stream, ch_addr + v23c.CN_SHORT_BLOCK_SIZE - )[0] + tx_address = v23c.UINT32_uf(stream, ch_addr + v23c.CN_SHORT_BLOCK_SIZE)[0] if tx_address: - name = get_text_v3( - tx_address, stream, mapped=mapped - ) + name = get_text_v3(tx_address, stream, mapped=mapped) if block_len == v23c.CN_DISPLAYNAME_BLOCK_SIZE: - tx_address = v23c.UINT32_uf( - stream, ch_addr + v23c.CN_LONGNAME_BLOCK_SIZE - )[0] + tx_address = v23c.UINT32_uf(stream, ch_addr + v23c.CN_LONGNAME_BLOCK_SIZE)[0] if tx_address: display_names = { - get_text_v3( - tx_address, stream, mapped=mapped - ): "display_name", + get_text_v3(tx_address, stream, mapped=mapped): "display_name", } else: @@ -821,49 +777,34 @@ def _read(self, mapped: bool = False, progress=None) -> None: next_ch_addr, channel_type, name, - ) = v23c.CHANNEL_FILTER_u( - stream.read(v23c.CHANNEL_FILTER_SIZE) - ) + ) = v23c.CHANNEL_FILTER_u(stream.read(v23c.CHANNEL_FILTER_SIZE)) name = name.decode("latin-1").strip(" \t\n\r\0") if block_len >= v23c.CN_LONGNAME_BLOCK_SIZE: stream.seek(ch_addr + v23c.CN_SHORT_BLOCK_SIZE) tx_address = v23c.UINT32_u(stream.read(4))[0] if tx_address: - name = get_text_v3( - tx_address, stream, mapped=mapped - ) + name = get_text_v3(tx_address, stream, mapped=mapped) if block_len == v23c.CN_DISPLAYNAME_BLOCK_SIZE: stream.seek(ch_addr + v23c.CN_LONGNAME_BLOCK_SIZE) tx_address = v23c.UINT32_u(stream.read(4))[0] if tx_address: display_names = { - get_text_v3( - tx_address, stream, mapped=mapped - ): "display_name", + get_text_v3(tx_address, stream, mapped=mapped): "display_name", } if id_ != b"CN": - message = ( - f'Expected "CN" block @{hex(ch_addr)} but found "{id_}"' - ) + message = f'Expected "CN" block @{hex(ch_addr)} but found "{id_}"' raise MdfException(message) if self._remove_source_from_channel_names: name = name.split("\\", 1)[0] - display_names = { - _name.split("\\", 1)[0]: val - for _name, val in display_names.items() - } + display_names = {_name.split("\\", 1)[0]: val for _name, val in display_names.items()} if ( channel_type == v23c.CHANNEL_TYPE_MASTER or name in self.load_filter - or ( - any( - _name in self.load_filter for _name in display_names - ) - ) + or (any(_name in self.load_filter for _name in display_names)) ): new_ch = Channel( address=ch_addr, @@ -894,15 +835,12 @@ def _read(self, mapped: bool = False, progress=None) -> None: if self._remove_source_from_channel_names: new_ch.name = new_ch.name.split("\\", 1)[0] new_ch.display_names = { - _name.split("\\", 1)[0]: val - for _name, val in new_ch.display_names.items() + _name.split("\\", 1)[0]: val for _name, val in new_ch.display_names.items() } # check if it has channel dependencies if new_ch.component_addr: - dep = ChannelDependency( - address=new_ch.component_addr, stream=stream - ) + dep = ChannelDependency(address=new_ch.component_addr, stream=stream) grp.channel_dependencies.append(dep) else: grp.channel_dependencies.append(None) @@ -1363,9 +1301,7 @@ def append( start_bit_offset = offset additional_byte_offset = 0 - s_type, s_size = fmt_to_datatype_v3( - signal.samples.dtype, signal.samples.shape - ) + s_type, s_size = fmt_to_datatype_v3(signal.samples.dtype, signal.samples.shape) name = signal.name display_names = signal.display_names @@ -1397,9 +1333,7 @@ def append( gp_channels.append(channel) if len(signal.samples.shape) > 1: - channel.dtype_fmt = dtype( - (signal.samples.dtype, signal.samples.shape[1:]) - ) + channel.dtype_fmt = dtype((signal.samples.dtype, signal.samples.shape[1:])) else: channel.dtype_fmt = signal.samples.dtype @@ -1428,9 +1362,7 @@ def append( if s_type != v23c.DATA_TYPE_BYTEARRAY: types.append((field_name, signal.samples.dtype)) else: - types.append( - (field_name, signal.samples.dtype, signal.samples.shape[1:]) - ) + types.append((field_name, signal.samples.dtype, signal.samples.shape[1:])) ch_cntr += 1 @@ -1573,9 +1505,7 @@ def append( # compute additional byte offset for large records size if new_offset > v23c.MAX_UINT16: - additional_byte_offset = ceil( - (new_offset - v23c.MAX_UINT16) / 8 - ) + additional_byte_offset = ceil((new_offset - v23c.MAX_UINT16) / 8) start_bit_offset = new_offset - additional_byte_offset * 8 else: start_bit_offset = new_offset @@ -1762,9 +1692,7 @@ def append( new_ch_cntr += 1 - for i, (name, samples) in enumerate( - zip(component_names, component_samples) - ): + for i, (name, samples) in enumerate(zip(component_names, component_samples)): if i < sd_nr: dep_pair = new_dg_cntr, new_ch_cntr parent_dep.referenced_channels.append(dep_pair) @@ -1798,9 +1726,7 @@ def append( # compute additional byte offset for large records size if new_offset > v23c.MAX_UINT16: - additional_byte_offset = ceil( - (new_offset - v23c.MAX_UINT16) / 8 - ) + additional_byte_offset = ceil((new_offset - v23c.MAX_UINT16) / 8) start_bit_offset = new_offset - additional_byte_offset * 8 else: start_bit_offset = new_offset @@ -1901,9 +1827,7 @@ def append( s_type, s_size = fmt_to_datatype_v3(samples.dtype, ()) # compute additional byte offset for large records size if new_offset > v23c.MAX_UINT16: - additional_byte_offset = ceil( - (new_offset - v23c.MAX_UINT16) / 8 - ) + additional_byte_offset = ceil((new_offset - v23c.MAX_UINT16) / 8) start_bit_offset = new_offset - additional_byte_offset * 8 else: start_bit_offset = new_offset @@ -1934,9 +1858,7 @@ def append( new_ch_cntr += 1 - for i, (name, samples) in enumerate( - zip(component_names, component_samples) - ): + for i, (name, samples) in enumerate(zip(component_names, component_samples)): if i < sd_nr: dep_pair = new_dg_cntr, new_ch_cntr parent_dep.referenced_channels.append(dep_pair) @@ -1971,9 +1893,7 @@ def append( # compute additional byte offset for large records size if new_offset > v23c.MAX_UINT16: - additional_byte_offset = ceil( - (new_offset - v23c.MAX_UINT16) / 8 - ) + additional_byte_offset = ceil((new_offset - v23c.MAX_UINT16) / 8) start_bit_offset = new_offset - additional_byte_offset * 8 else: start_bit_offset = new_offset @@ -2504,9 +2424,7 @@ def extend(self, index: int, signals: list[tuple[NDArray[Any], None]]) -> None: cycles_nr = len(signals[0][0]) string_counter = 0 - for k_i, ((signal, invalidation_bits), sig_type) in enumerate( - zip(signals, gp.signal_types) - ): + for k_i, ((signal, invalidation_bits), sig_type) in enumerate(zip(signals, gp.signal_types)): sig = signal names = sig.dtype.names @@ -2977,9 +2895,7 @@ def get( # get data group record if data is None: - data = self._load_data( - grp, record_offset=record_offset, record_count=record_count - ) + data = self._load_data(grp, record_offset=record_offset, record_count=record_count) else: data = (data,) @@ -3099,9 +3015,7 @@ def get( kind_ = dtype_.kind if data_type in v23c.INT_TYPES: - dtype_fmt = get_fmt_v3( - data_type, bits, self.identification.byte_order - ) + dtype_fmt = get_fmt_v3(data_type, bits, self.identification.byte_order) channel_dtype = dtype(dtype_fmt.split(")")[-1]) if channel_dtype.byteorder == "=" and data_type in ( @@ -3128,9 +3042,7 @@ def get( vals = vals.view(view) else: if bits != size * 8: - vals = self._get_not_byte_aligned_data( - data_bytes, grp, ch_nr - ) + vals = self._get_not_byte_aligned_data(data_bytes, grp, ch_nr) else: vals = self._get_not_byte_aligned_data(data_bytes, grp, ch_nr) @@ -3265,8 +3177,7 @@ def get_master( if raster is not None: PendingDeprecationWarning( - "the argument raster is deprecated since version 5.13.0 " - "and will be removed in a future release" + "the argument raster is deprecated since version 5.13.0 " "and will be removed in a future release" ) fragment = data @@ -3301,9 +3212,7 @@ def get_master( else: # get data group record if data is None: - data = self._load_data( - group, record_offset=record_offset, record_count=record_count - ) + data = self._load_data(group, record_offset=record_offset, record_count=record_count) _count = record_count else: data = (data,) @@ -3312,9 +3221,7 @@ def get_master( count = 0 for fragment in data: data_bytes, offset, _count = fragment - dtype_, byte_size, byte_offset, bit_offset = group.record[ - time_ch_nr - ] + dtype_, byte_size, byte_offset, bit_offset = group.record[time_ch_nr] buffer = get_channel_raw_bytes( data_bytes, @@ -3522,8 +3429,7 @@ def save( else: cntr += 1 message = ( - f'Destination file "{dst}" already exists ' - f'and "overwrite" is False. Saving MDF file as "{name}"' + f'Destination file "{dst}" already exists ' f'and "overwrite" is False. Saving MDF file as "{name}"' ) logger.warning(message) dst = name @@ -3583,9 +3489,7 @@ def save( # restore he original data block address gp_rec_ids = [] - original_data_block_addrs = [ - group.data_group.data_block_addr for group in self.groups - ] + original_data_block_addrs = [group.data_group.data_block_addr for group in self.groups] for idx, gp in enumerate(self.groups): dg = gp.data_group @@ -3636,9 +3540,7 @@ def save( address += dep.block_len else: channel.component_addr = 0 - address = channel.to_blocks( - address, blocks, defined_texts, cc_map, si_map - ) + address = channel.to_blocks(address, blocks, defined_texts, cc_map, si_map) count = len(gp.channels) if count: @@ -3716,9 +3618,7 @@ def save( for block in blocks: write(bytes(block)) - for gp, rec_id, original_address in zip( - self.groups, gp_rec_ids, original_data_block_addrs - ): + for gp, rec_id, original_address in zip(self.groups, gp_rec_ids, original_data_block_addrs): gp.data_group.record_id_len = rec_id gp.data_group.data_block_addr = original_address @@ -3875,9 +3775,7 @@ def included_channels( for group_index, channels in gps.items(): group = self.groups[group_index] - channel_dependencies = [ - group.channel_dependencies[ch_nr] for ch_nr in channels - ] + channel_dependencies = [group.channel_dependencies[ch_nr] for ch_nr in channels] if minimal: for dep in channel_dependencies: @@ -3891,12 +3789,7 @@ def included_channels( pass gp_master = self.masters_db.get(group_index, None) - if ( - skip_master - and gp_master is not None - and gp_master in channels - and len(channels) > 1 - ): + if skip_master and gp_master is not None and gp_master in channels and len(channels) > 1: channels.remove(gp_master) result[group_index] = {group_index: sorted(channels)} @@ -3925,11 +3818,7 @@ def _yield_selected_signals( self._set_temporary_master(None) - for idx, fragment in enumerate( - self._load_data( - group, record_offset=record_offset, record_count=record_count - ) - ): + for idx, fragment in enumerate(self._load_data(group, record_offset=record_offset, record_count=record_count)): self._set_temporary_master(self.get_master(index, data=fragment)) self._prepare_record(group) @@ -3978,18 +3867,10 @@ def _yield_selected_signals( del strsig if sig.encoding != "latin-1": if sig.encoding == "utf-16-le": - sig.samples = ( - sig.samples.view(uint16) - .byteswap() - .view(sig.samples.dtype) - ) - sig.samples = encode( - decode(sig.samples, "utf-16-be"), "latin-1" - ) + sig.samples = sig.samples.view(uint16).byteswap().view(sig.samples.dtype) + sig.samples = encode(decode(sig.samples, "utf-16-be"), "latin-1") else: - sig.samples = encode( - decode(sig.samples, sig.encoding), "latin-1" - ) + sig.samples = encode(decode(sig.samples, sig.encoding), "latin-1") else: encodings.append(None) else: @@ -3998,18 +3879,10 @@ def _yield_selected_signals( samples = sig[0] if encoding != "latin-1": if encoding == "utf-16-le": - samples = ( - samples.view(uint16) - .byteswap() - .view(samples.dtype) - ) - samples = encode( - decode(samples, "utf-16-be"), "latin-1" - ) + samples = samples.view(uint16).byteswap().view(samples.dtype) + samples = encode(decode(samples, "utf-16-be"), "latin-1") else: - samples = encode( - decode(samples, encoding), "latin-1" - ) + samples = encode(decode(samples, encoding), "latin-1") signals[i] = (samples, sig[1]) self._set_temporary_master(None) diff --git a/src/asammdf/blocks/mdf_v4.py b/src/asammdf/blocks/mdf_v4.py index 065ae9706..9108409ca 100644 --- a/src/asammdf/blocks/mdf_v4.py +++ b/src/asammdf/blocks/mdf_v4.py @@ -273,9 +273,7 @@ def __init__( **kwargs, ) -> None: if not kwargs.get("__internal__", False): - raise MdfException( - "Always use the MDF class; do not use the class MDF4 directly" - ) + raise MdfException("Always use the MDF class; do not use the class MDF4 directly") self._kwargs = kwargs self.original_name = kwargs["original_name"] @@ -328,30 +326,22 @@ def __init__( "raise_on_multiple_occurrences", get_global_option("raise_on_multiple_occurrences"), ) - self._use_display_names = kwargs.get( - "use_display_names", get_global_option("use_display_names") - ) + self._use_display_names = kwargs.get("use_display_names", get_global_option("use_display_names")) self._fill_0_for_missing_computation_channels = kwargs.get( "fill_0_for_missing_computation_channels", get_global_option("fill_0_for_missing_computation_channels"), ) - self._remove_source_from_channel_names = kwargs.get( - "remove_source_from_channel_names", False - ) + self._remove_source_from_channel_names = kwargs.get("remove_source_from_channel_names", False) self._password = kwargs.get("password", None) - self._force_attachment_encryption = kwargs.get( - "force_attachment_encryption", False - ) + self._force_attachment_encryption = kwargs.get("force_attachment_encryption", False) self.copy_on_get = kwargs.get("copy_on_get", True) self.compact_vlsd = kwargs.get("compact_vlsd", False) self.virtual_groups = {} # master group 2 referencing groups self.virtual_groups_map = {} # group index 2 master group - self.vlsd_max_length = ( - {} - ) # hint about the maximum vlsd length for group_index, name pairs + self.vlsd_max_length = {} # hint about the maximum vlsd length for group_index, name pairs self._master = None @@ -395,9 +385,7 @@ def __init__( else: self.name = Path(name) self._mapped_file = open(self.name, "rb") - self._file = mmap.mmap( - self._mapped_file.fileno(), 0, access=mmap.ACCESS_READ - ) + self._file = mmap.mmap(self._mapped_file.fileno(), 0, access=mmap.ACCESS_READ) self._from_filelike = False self._read(mapped=True, progress=progress) @@ -423,10 +411,7 @@ def _check_finalised(self) -> int: flags = self.identification["unfinalized_standard_flags"] if flags & 1: - message = ( - f"Unfinalised file {self.name}:" - " Update of cycle counters for CG/CA blocks required" - ) + message = f"Unfinalised file {self.name}:" " Update of cycle counters for CG/CA blocks required" logger.info(message) if flags & 1 << 1: @@ -507,9 +492,7 @@ def _read(self, mapped: bool = False, progress=None) -> None: fh_addr = self.header["file_history_addr"] while fh_addr: if (fh_addr + v4c.FH_BLOCK_SIZE) > self.file_limit: - logger.warning( - f"File history address {fh_addr:X} is outside the file size {self.file_limit}" - ) + logger.warning(f"File history address {fh_addr:X} is outside the file size {self.file_limit}") break history_block = FileHistory(address=fh_addr, stream=stream, mapped=mapped) self.file_history.append(history_block) @@ -520,9 +503,7 @@ def _read(self, mapped: bool = False, progress=None) -> None: index = 0 while at_addr: if (at_addr + v4c.AT_COMMON_SIZE) > self.file_limit: - logger.warning( - f"Attachment address {at_addr:X} is outside the file size {self.file_limit}" - ) + logger.warning(f"Attachment address {at_addr:X} is outside the file size {self.file_limit}") break at_block = AttachmentBlock(address=at_addr, stream=stream, mapped=mapped) self._attachments_map[at_addr] = index @@ -535,9 +516,7 @@ def _read(self, mapped: bool = False, progress=None) -> None: while dg_addr: if (dg_addr + v4c.DG_BLOCK_SIZE) > self.file_limit: - logger.warning( - f"Data group address {dg_addr:X} is outside the file size {self.file_limit}" - ) + logger.warning(f"Data group address {dg_addr:X} is outside the file size {self.file_limit}") break new_groups = [] group = DataGroup(address=dg_addr, stream=stream, mapped=mapped) @@ -552,9 +531,7 @@ def _read(self, mapped: bool = False, progress=None) -> None: while cg_addr: if (cg_addr + v4c.CG_BLOCK_SIZE) > self.file_limit: - logger.warning( - f"Channel group address {cg_addr:X} is outside the file size {self.file_limit}" - ) + logger.warning(f"Channel group address {cg_addr:X} is outside the file size {self.file_limit}") break cg_nr += 1 @@ -604,9 +581,7 @@ def _read(self, mapped: bool = False, progress=None) -> None: # Read channels by walking recursively in the channel group # starting from the first channel - self._read_channels( - ch_addr, grp, stream, dg_cntr, ch_cntr, mapped=mapped - ) + self._read_channels(ch_addr, grp, stream, dg_cntr, ch_cntr, mapped=mapped) cg_addr = channel_group.next_cg_addr @@ -633,29 +608,18 @@ def _read(self, mapped: bool = False, progress=None) -> None: channel_group = new_group.channel_group if channel_group.flags & v4c.FLAG_CG_REMOTE_MASTER: block_type = b"##DV" - total_size += ( - channel_group.samples_byte_nr * channel_group.cycles_nr - ) - inval_total_size += ( - channel_group.invalidation_bytes_nr * channel_group.cycles_nr - ) + total_size += channel_group.samples_byte_nr * channel_group.cycles_nr + inval_total_size += channel_group.invalidation_bytes_nr * channel_group.cycles_nr record_size = channel_group.samples_byte_nr else: block_type = b"##DT" total_size += ( - channel_group.samples_byte_nr - + channel_group.invalidation_bytes_nr + channel_group.samples_byte_nr + channel_group.invalidation_bytes_nr ) * channel_group.cycles_nr - record_size = ( - channel_group.samples_byte_nr - + channel_group.invalidation_bytes_nr - ) + record_size = channel_group.samples_byte_nr + channel_group.invalidation_bytes_nr - if ( - self.identification["unfinalized_standard_flags"] - & v4c.FLAG_UNFIN_UPDATE_CG_COUNTER - ): + if self.identification["unfinalized_standard_flags"] & v4c.FLAG_UNFIN_UPDATE_CG_COUNTER: total_size = int(10**12) inval_total_size = int(10**12) @@ -690,13 +654,8 @@ def _read(self, mapped: bool = False, progress=None) -> None: # all channels have been loaded so now we can link the # channel dependencies and load the signal data for VLSD channels for gp_index, grp in enumerate(self.groups): - if ( - self.version >= "4.20" - and grp.channel_group.flags & v4c.FLAG_CG_REMOTE_MASTER - ): - grp.channel_group.cg_master_index = self._cg_map[ - grp.channel_group.cg_master_addr - ] + if self.version >= "4.20" and grp.channel_group.flags & v4c.FLAG_CG_REMOTE_MASTER: + grp.channel_group.cg_master_index = self._cg_map[grp.channel_group.cg_master_addr] index = grp.channel_group.cg_master_index else: @@ -709,8 +668,7 @@ def _read(self, mapped: bool = False, progress=None) -> None: virtual_channel_group = self.virtual_groups[index] virtual_channel_group.groups.append(gp_index) virtual_channel_group.record_size += ( - grp.channel_group.samples_byte_nr - + grp.channel_group.invalidation_bytes_nr + grp.channel_group.samples_byte_nr + grp.channel_group.invalidation_bytes_nr ) virtual_channel_group.cycles_nr = grp.channel_group.cycles_nr @@ -768,9 +726,7 @@ def _read(self, mapped: bool = False, progress=None) -> None: else: dep.axis_conversions.append(None) - if (dep.flags & v4c.FLAG_CA_AXIS) and not ( - dep.flags & v4c.FLAG_CA_FIXED_AXIS - ): + if (dep.flags & v4c.FLAG_CA_AXIS) and not (dep.flags & v4c.FLAG_CA_FIXED_AXIS): for i in range(dep.dims): ch_addr = dep[f"scale_axis_{i}_ch_addr"] if ch_addr: @@ -792,10 +748,7 @@ def _read(self, mapped: bool = False, progress=None) -> None: for grp in self.groups: channels = grp.channels - if ( - len(channels) == 1 - and channels[0].dtype_fmt.itemsize == grp.channel_group.samples_byte_nr - ): + if len(channels) == 1 and channels[0].dtype_fmt.itemsize == grp.channel_group.samples_byte_nr: grp.single_channel_dtype = channels[0].dtype_fmt self._process_bus_logging() @@ -806,9 +759,7 @@ def _read(self, mapped: bool = False, progress=None) -> None: event_index = 0 while addr: if (addr + v4c.COMMON_SIZE) > self.file_limit: - logger.warning( - f"Event address {addr:X} is outside the file size {self.file_limit}" - ) + logger.warning(f"Event address {addr:X} is outside the file size {self.file_limit}") break event = EventBlock(address=addr, stream=stream, mapped=mapped) event.update_references(self._ch_map, self._cg_map) @@ -844,9 +795,7 @@ def _read(self, mapped: bool = False, progress=None) -> None: if progress is not None: if callable(progress): - progress( - progress_steps, progress_steps - ) # last step, we've completely loaded the file for sure + progress(progress_steps, progress_steps) # last step, we've completely loaded the file for sure self.progress = cg_count, cg_count @@ -882,9 +831,7 @@ def _read_channels( # read channel block and create channel object if (ch_addr + v4c.COMMON_SIZE) > self.file_limit: - logger.warning( - f"Channel address {ch_addr:X} is outside the file size {self.file_limit}" - ) + logger.warning(f"Channel address {ch_addr:X} is outside the file size {self.file_limit}") break if filter_channels: @@ -933,21 +880,13 @@ def _read_channels( if self._remove_source_from_channel_names: name = name.split(path_separator, 1)[0] - display_names = { - _name.split(path_separator, 1)[0]: val - for _name, val in display_names.items() - } + display_names = {_name.split(path_separator, 1)[0]: val for _name, val in display_names.items()} if ( channel_composition or channel_type in v4c.MASTER_TYPES or name in self.load_filter - or ( - use_display_names - and any( - dsp_name in self.load_filter for dsp_name in display_names - ) - ) + or (use_display_names and any(dsp_name in self.load_filter for dsp_name in display_names)) ): if comment is None: comment = get_text_v4(comment_addr, stream, mapped=mapped) @@ -1021,8 +960,7 @@ def _read_channels( if self._remove_source_from_channel_names: channel.name = channel.name.split(path_separator, 1)[0] channel.display_names = { - _name.split(path_separator, 1)[0]: val - for _name, val in channel.display_names.items() + _name.split(path_separator, 1)[0]: val for _name, val in channel.display_names.items() } entry = (dg_cntr, ch_cntr) @@ -1040,9 +978,7 @@ def _read_channels( # signal data cn_data_addr = channel.data_block_addr if cn_data_addr: - grp.signal_data.append( - ([], self._get_signal_data_blocks_info(cn_data_addr, stream)) - ) + grp.signal_data.append(([], self._get_signal_data_blocks_info(cn_data_addr, stream))) else: grp.signal_data.append(None) @@ -1088,9 +1024,7 @@ def _read_channels( else: # only channel arrays with storage=CN_TEMPLATE are # supported so far - first_dep = ca_block = ChannelArrayBlock( - address=component_addr, stream=stream, mapped=mapped - ) + first_dep = ca_block = ChannelArrayBlock(address=component_addr, stream=stream, mapped=mapped) if ca_block.storage != v4c.CA_STORAGE_TYPE_CN_TEMPLATE: logger.warning("Only CN template arrays are supported") ca_list = [ca_block] @@ -1106,10 +1040,7 @@ def _read_channels( ) ca_list.append(ca_block) else: - logger.warning( - "skipping CN block; CN block within CA block" - " is not implemented yet" - ) + logger.warning("skipping CN block; CN block within CA block" " is not implemented yet") break dependencies.append(ca_list) @@ -1139,10 +1070,7 @@ def _read_channels( if channel_composition: composition_channels.sort() composition_dtype = dtype( - [ - (unique_names.get_unique_name(channel.name), channel.dtype_fmt) - for channel in composition_channels - ] + [(unique_names.get_unique_name(channel.name), channel.dtype_fmt) for channel in composition_channels] ) else: @@ -1258,17 +1186,8 @@ def _load_signal_data( if current_offset + original_size > end_offset: start_index = max(0, start_offset - current_offset) - (last_sample_size,) = UINT32_uf( - new_data, end_offset - current_offset - ) - data.append( - new_data[ - start_index : end_offset - - current_offset - + last_sample_size - + 4 - ] - ) + (last_sample_size,) = UINT32_uf(new_data, end_offset - current_offset) + data.append(new_data[start_index : end_offset - current_offset + last_sample_size + 4]) break @@ -1320,9 +1239,7 @@ def _load_data( rm = True else: rm = False - samples_size = ( - channel_group.samples_byte_nr + channel_group.invalidation_bytes_nr - ) + samples_size = channel_group.samples_byte_nr + channel_group.invalidation_bytes_nr invalidation_size = channel_group.invalidation_bytes_nr record_offset *= samples_size @@ -1480,18 +1397,11 @@ def _load_data( cols = invalidation_info.param lines = invalidation_info.original_size // cols - nd = frombuffer( - new_invalidation_data[: lines * cols], dtype=uint8 - ) + nd = frombuffer(new_invalidation_data[: lines * cols], dtype=uint8) nd = nd.reshape((cols, lines)) - new_invalidation_data = ( - nd.T.ravel().tobytes() - + new_invalidation_data[lines * cols :] - ) + new_invalidation_data = nd.T.ravel().tobytes() + new_invalidation_data[lines * cols :] if invalidation_info.block_limit is not None: - new_invalidation_data = new_invalidation_data[ - : invalidation_info.block_limit - ] + new_invalidation_data = new_invalidation_data[: invalidation_info.block_limit] inv_size = len(new_invalidation_data) @@ -1515,9 +1425,7 @@ def _load_data( if rm and invalidation_size: invalidation_data.append( - new_invalidation_data[ - : invalidation_split_size - cur_invalidation_size - ] + new_invalidation_data[: invalidation_split_size - cur_invalidation_size] ) new_invalidation_data = new_invalidation_data[ invalidation_split_size - cur_invalidation_size : @@ -1558,18 +1466,12 @@ def _load_data( new_data[split_size:], ) if rm and invalidation_size: - invalidation_data_ = new_invalidation_data[ - :invalidation_split_size - ] - new_invalidation_data = new_invalidation_data[ - invalidation_split_size: - ] + invalidation_data_ = new_invalidation_data[:invalidation_split_size] + new_invalidation_data = new_invalidation_data[invalidation_split_size:] if record_count is not None: if rm and invalidation_size: - yield data_[ - :record_count - ], offset // samples_size, _count, invalidation_data_[ + yield data_[:record_count], offset // samples_size, _count, invalidation_data_[ :invalidation_record_count ] invalidation_record_count -= len(invalidation_data_) @@ -1625,9 +1527,7 @@ def _load_data( if rm and invalidation_size: __data = data_[:record_count] _count = len(__data) // samples_size - yield __data, offset // samples_size, _count, invalidation_data_[ - :invalidation_record_count - ] + yield __data, offset // samples_size, _count, invalidation_data_[:invalidation_record_count] invalidation_record_count -= len(invalidation_data_) else: __data = data_[:record_count] @@ -1704,12 +1604,7 @@ def _prepare_record(self, group: Group) -> list: if not new_ch.dtype_fmt: new_ch.dtype_fmt = dtype(get_fmt_v4(data_type, size, ch_type)) - if ( - bit_offset - or new_ch.dtype_fmt.kind in "ui" - and size < 64 - and size not in (8, 16, 32) - ): + if bit_offset or new_ch.dtype_fmt.kind in "ui" and size < 64 and size not in (8, 16, 32): new_ch.standard_C_size = False record.append( @@ -1843,9 +1738,7 @@ def _get_data_blocks_info( param, original_size, zip_size, - ) = v4c.DZ_COMMON_INFO_uf( - stream, address + v4c.DZ_INFO_COMMON_OFFSET - ) + ) = v4c.DZ_COMMON_INFO_uf(stream, address + v4c.DZ_INFO_COMMON_OFFSET) if original_size: if zip_type == v4c.FLAG_DZ_DEFLATE: @@ -1921,9 +1814,7 @@ def _get_data_blocks_info( param, original_size, zip_size, - ) = v4c.DZ_COMMON_INFO_uf( - stream, addr + v4c.DZ_INFO_COMMON_OFFSET - ) + ) = v4c.DZ_COMMON_INFO_uf(stream, addr + v4c.DZ_INFO_COMMON_OFFSET) if original_size: if zip_type == v4c.FLAG_DZ_DEFLATE: @@ -1981,9 +1872,7 @@ def _get_data_blocks_info( param, original_size, zip_size, - ) = v4c.DZ_COMMON_INFO_uf( - stream, addr + v4c.DZ_INFO_COMMON_OFFSET - ) + ) = v4c.DZ_COMMON_INFO_uf(stream, addr + v4c.DZ_INFO_COMMON_OFFSET) if original_size: if zip_type == v4c.FLAG_DZ_DEFLATE: @@ -2008,9 +1897,7 @@ def _get_data_blocks_info( if has_invalidation: inval_addr = ld[f"invalidation_bits_addr_{i}"] if inval_addr: - id_string, block_len = COMMON_SHORT_uf( - stream, inval_addr - ) + id_string, block_len = COMMON_SHORT_uf(stream, inval_addr) if id_string == b"##DI": size = block_len - 24 if size: @@ -2019,15 +1906,13 @@ def _get_data_blocks_info( else: block_limit = None inval_total_size -= size - data_info.invalidation_block = ( - InvalidationBlockInfo( - address=inval_addr + COMMON_SIZE, - block_type=v4c.DT_BLOCK, - original_size=size, - compressed_size=size, - param=0, - block_limit=block_limit, - ) + data_info.invalidation_block = InvalidationBlockInfo( + address=inval_addr + COMMON_SIZE, + block_type=v4c.DT_BLOCK, + original_size=size, + compressed_size=size, + param=0, + block_limit=block_limit, ) else: ( @@ -2051,27 +1936,22 @@ def _get_data_blocks_info( else: block_limit = None inval_total_size -= original_size - data_info.invalidation_block = ( - InvalidationBlockInfo( - address=inval_addr - + v4c.DZ_COMMON_SIZE, - block_type=block_type_, - original_size=original_size, - compressed_size=zip_size, - param=param, - block_limit=block_limit, - ) + data_info.invalidation_block = InvalidationBlockInfo( + address=inval_addr + v4c.DZ_COMMON_SIZE, + block_type=block_type_, + original_size=original_size, + compressed_size=zip_size, + param=param, + block_limit=block_limit, ) else: - data_info.invalidation_block = ( - InvalidationBlockInfo( - address=0, - block_type=v4c.DT_BLOCK, - original_size=None, - compressed_size=None, - param=None, - all_valid=True, - ) + data_info.invalidation_block = InvalidationBlockInfo( + address=0, + block_type=v4c.DT_BLOCK, + original_size=None, + compressed_size=None, + param=None, + all_valid=True, ) yield data_info @@ -2172,9 +2052,7 @@ def _get_data_blocks_info( addr = dl[f"data_block_addr{i}"] stream.seek(addr) - id_string, block_len = COMMON_SHORT_u( - stream.read(COMMON_SHORT_SIZE) - ) + id_string, block_len = COMMON_SHORT_u(stream.read(COMMON_SHORT_SIZE)) # can be a DataBlock if id_string == block_type: @@ -2223,9 +2101,7 @@ def _get_data_blocks_info( param, original_size, zip_size, - ) = v4c.DZ_COMMON_INFO_u( - stream.read(v4c.DZ_COMMON_INFO_SIZE) - ) + ) = v4c.DZ_COMMON_INFO_u(stream.read(v4c.DZ_COMMON_INFO_SIZE)) if original_size: if zip_type == v4c.FLAG_DZ_DEFLATE: @@ -2259,9 +2135,7 @@ def _get_data_blocks_info( addr = ld[f"data_block_addr{i}"] stream.seek(addr) - id_string, block_len = COMMON_SHORT_u( - stream.read(COMMON_SHORT_SIZE) - ) + id_string, block_len = COMMON_SHORT_u(stream.read(COMMON_SHORT_SIZE)) # can be a DataBlock if id_string == b"##DV": size = block_len - 24 @@ -2288,9 +2162,7 @@ def _get_data_blocks_info( param, original_size, zip_size, - ) = v4c.DZ_COMMON_INFO_u( - stream.read(v4c.DZ_COMMON_INFO_SIZE) - ) + ) = v4c.DZ_COMMON_INFO_u(stream.read(v4c.DZ_COMMON_INFO_SIZE)) if original_size: if zip_type == v4c.FLAG_DZ_DEFLATE: @@ -2316,9 +2188,7 @@ def _get_data_blocks_info( inval_addr = ld[f"invalidation_bits_addr_{i}"] if inval_addr: stream.seek(inval_addr) - id_string, block_len = COMMON_SHORT_u( - stream.read(COMMON_SHORT_SIZE) - ) + id_string, block_len = COMMON_SHORT_u(stream.read(COMMON_SHORT_SIZE)) if id_string == b"##DI": size = block_len - 24 if size: @@ -2327,28 +2197,22 @@ def _get_data_blocks_info( else: block_limit = None inval_total_size -= size - data_info.invalidation_block = ( - InvalidationBlockInfo( - address=inval_addr + COMMON_SIZE, - block_type=v4c.DT_BLOCK, - original_size=size, - compressed_size=size, - param=0, - block_limit=block_limit, - ) + data_info.invalidation_block = InvalidationBlockInfo( + address=inval_addr + COMMON_SIZE, + block_type=v4c.DT_BLOCK, + original_size=size, + compressed_size=size, + param=0, + block_limit=block_limit, ) else: - stream.seek( - inval_addr + v4c.DZ_INFO_COMMON_OFFSET - ) + stream.seek(inval_addr + v4c.DZ_INFO_COMMON_OFFSET) ( zip_type, param, original_size, zip_size, - ) = v4c.DZ_COMMON_INFO_u( - stream.read(v4c.DZ_COMMON_INFO_SIZE) - ) + ) = v4c.DZ_COMMON_INFO_u(stream.read(v4c.DZ_COMMON_INFO_SIZE)) if original_size: if zip_type == v4c.FLAG_DZ_DEFLATE: @@ -2361,27 +2225,22 @@ def _get_data_blocks_info( else: block_limit = None inval_total_size -= original_size - data_info.invalidation_block = ( - InvalidationBlockInfo( - address=inval_addr - + v4c.DZ_COMMON_SIZE, - block_type=block_type_, - original_size=original_size, - compressed_size=zip_size, - param=param, - block_limit=block_limit, - ) + data_info.invalidation_block = InvalidationBlockInfo( + address=inval_addr + v4c.DZ_COMMON_SIZE, + block_type=block_type_, + original_size=original_size, + compressed_size=zip_size, + param=param, + block_limit=block_limit, ) else: - data_info.invalidation_block = ( - InvalidationBlockInfo( - address=0, - block_type=v4c.DT_BLOCK, - original_size=0, - compressed_size=0, - param=0, - all_valid=True, - ) + data_info.invalidation_block = InvalidationBlockInfo( + address=0, + block_type=v4c.DT_BLOCK, + original_size=0, + compressed_size=0, + param=0, + all_valid=True, ) yield data_info @@ -2408,9 +2267,7 @@ def _get_signal_data_blocks_info( stream: ReadableBufferType, ) -> Iterator[SignalDataBlockInfo]: if not address: - raise MdfException( - f"Expected non-zero SDBLOCK address but got 0x{address:X}" - ) + raise MdfException(f"Expected non-zero SDBLOCK address but got 0x{address:X}") stream.seek(address) id_string, block_len = COMMON_SHORT_u(stream.read(COMMON_SHORT_SIZE)) @@ -2459,9 +2316,7 @@ def _get_signal_data_blocks_info( addr = dl[f"data_block_addr{i}"] stream.seek(addr) - id_string, block_len = COMMON_SHORT_u( - stream.read(COMMON_SHORT_SIZE) - ) + id_string, block_len = COMMON_SHORT_u(stream.read(COMMON_SHORT_SIZE)) # can be a DataBlock if id_string == b"##SD": @@ -2593,8 +2448,7 @@ def get_invalidation_bits( invalidation_bytes = get_channel_raw_bytes( data_bytes, - group.channel_group.samples_byte_nr - + group.channel_group.invalidation_bytes_nr, + group.channel_group.samples_byte_nr + group.channel_group.invalidation_bytes_nr, group.channel_group.samples_byte_nr, size, ) @@ -2675,11 +2529,7 @@ def append( >>> mdf2.append(df, units=units) """ - source_block = ( - SourceInformation.from_common_source(acq_source) - if acq_source - else acq_source - ) + source_block = SourceInformation.from_common_source(acq_source) if acq_source else acq_source if isinstance(signals, Signal): signals = [signals] @@ -2727,9 +2577,7 @@ def append( t = [] if self.version >= "4.20" and (self._column_storage or 1): - return self._append_column_oriented( - signals, acq_name=acq_name, acq_source=source_block, comment=comment - ) + return self._append_column_oriented(signals, acq_name=acq_name, acq_source=source_block, comment=comment) dg_cntr = len(self.groups) @@ -2943,9 +2791,7 @@ def append( if source in si_map: ch.source = si_map[source] else: - new_source = SourceInformation( - source_type=source.source_type, bus_type=source.bus_type - ) + new_source = SourceInformation(source_type=source.source_type, bus_type=source.bus_type) new_source.name = source.name new_source.path = source.path new_source.comment = source.comment @@ -3047,9 +2893,7 @@ def append( # conversions for channel if signal.raw: - ch.conversion = conversion_transfer( - signal.conversion, version=4 - ) + ch.conversion = conversion_transfer(signal.conversion, version=4) # source for channel @@ -3058,9 +2902,7 @@ def append( if source in si_map: ch.source = si_map[source] else: - new_source = SourceInformation( - source_type=source.source_type, bus_type=source.bus_type - ) + new_source = SourceInformation(source_type=source.source_type, bus_type=source.bus_type) new_source.name = source.name new_source.path = source.path new_source.comment = source.comment @@ -3126,15 +2968,9 @@ def append( vals = [] for field in ("ms", "min", "hour", "day", "month", "year"): if field == "hour": - vals.append( - signal.samples[field] - + (signal.samples["summer_time"] << 7) - ) + vals.append(signal.samples[field] + (signal.samples["summer_time"] << 7)) elif field == "day": - vals.append( - signal.samples[field] - + (signal.samples["day_of_week"] << 4) - ) + vals.append(signal.samples[field] + (signal.samples["day_of_week"] << 4)) else: vals.append(signal.samples[field]) vals = fromarrays(vals).tobytes() @@ -3177,9 +3013,7 @@ def append( if source in si_map: ch.source = si_map[source] else: - new_source = SourceInformation( - source_type=source.source_type, bus_type=source.bus_type - ) + new_source = SourceInformation(source_type=source.source_type, bus_type=source.bus_type) new_source.name = source.name new_source.path = source.path new_source.comment = source.comment @@ -3319,9 +3153,7 @@ def append( if source in si_map: ch.source = si_map[source] else: - new_source = SourceInformation( - source_type=source.source_type, bus_type=source.bus_type - ) + new_source = SourceInformation(source_type=source.source_type, bus_type=source.bus_type) new_source.name = source.name new_source.path = source.path new_source.comment = source.comment @@ -3477,9 +3309,7 @@ def append( ) ) else: - offsets = arange(len(samples), dtype=uint64) * ( - signal.samples.itemsize + 4 - ) + offsets = arange(len(samples), dtype=uint64) * (signal.samples.itemsize + 4) values = [ full(len(samples), samples.itemsize, dtype=uint32), @@ -3552,9 +3382,7 @@ def append( if source in si_map: ch.source = si_map[source] else: - new_source = SourceInformation( - source_type=source.source_type, bus_type=source.bus_type - ) + new_source = SourceInformation(source_type=source.source_type, bus_type=source.bus_type) new_source.name = source.name new_source.path = source.path new_source.comment = source.comment @@ -3599,11 +3427,7 @@ def append( gp.channel_group.invalidation_bytes_nr = invalidation_bytes_nr - inval_bits = fliplr( - packbits(array(inval_bits).T).reshape( - (cycles_nr, invalidation_bytes_nr) - ) - ) + inval_bits = fliplr(packbits(array(inval_bits).T).reshape((cycles_nr, invalidation_bytes_nr))) if self.version < "4.20": fields.append((inval_bits.tobytes(), invalidation_bytes_nr)) @@ -3934,9 +3758,7 @@ def _append_column_oriented( channel_type = v4c.CHANNEL_TYPE_SYNC if signal.attachment: at_data, at_name, hash_sum = signal.attachment - attachment_addr = self.attach( - at_data, at_name, hash_sum, mime="video/avi", embedded=False - ) + attachment_addr = self.attach(at_data, at_name, hash_sum, mime="video/avi", embedded=False) data_block_addr = attachment_addr else: data_block_addr = 0 @@ -3981,9 +3803,7 @@ def _append_column_oriented( if source in si_map: ch.source = si_map[source] else: - new_source = SourceInformation( - source_type=source.source_type, bus_type=source.bus_type - ) + new_source = SourceInformation(source_type=source.source_type, bus_type=source.bus_type) new_source.name = source.name new_source.path = source.path new_source.comment = source.comment @@ -4046,15 +3866,9 @@ def _append_column_oriented( vals = [] for field in ("ms", "min", "hour", "day", "month", "year"): if field == "hour": - vals.append( - signal.samples[field] - + (signal.samples["summer_time"] << 7) - ) + vals.append(signal.samples[field] + (signal.samples["summer_time"] << 7)) elif field == "day": - vals.append( - signal.samples[field] - + (signal.samples["day_of_week"] << 4) - ) + vals.append(signal.samples[field] + (signal.samples["day_of_week"] << 4)) else: vals.append(signal.samples[field]) samples = fromarrays(vals) @@ -4098,9 +3912,7 @@ def _append_column_oriented( if source in si_map: ch.source = si_map[source] else: - new_source = SourceInformation( - source_type=source.source_type, bus_type=source.bus_type - ) + new_source = SourceInformation(source_type=source.source_type, bus_type=source.bus_type) new_source.name = source.name new_source.path = source.path new_source.comment = source.comment @@ -4252,9 +4064,7 @@ def _append_column_oriented( if source in si_map: ch.source = si_map[source] else: - new_source = SourceInformation( - source_type=source.source_type, bus_type=source.bus_type - ) + new_source = SourceInformation(source_type=source.source_type, bus_type=source.bus_type) new_source.name = source.name new_source.path = source.path new_source.comment = source.comment @@ -4365,9 +4175,7 @@ def _append_column_oriented( else: raise MdfException(f'wrong encoding "{encoding}" for string signal') - offsets = arange(len(samples), dtype=uint64) * ( - signal.samples.itemsize + 4 - ) + offsets = arange(len(samples), dtype=uint64) * (signal.samples.itemsize + 4) values = [full(len(samples), samples.itemsize, dtype=uint32), samples] @@ -4436,9 +4244,7 @@ def _append_column_oriented( if source in si_map: ch.source = si_map[source] else: - new_source = SourceInformation( - source_type=source.source_type, bus_type=source.bus_type - ) + new_source = SourceInformation(source_type=source.source_type, bus_type=source.bus_type) new_source.name = source.name new_source.path = source.path new_source.comment = source.comment @@ -4837,15 +4643,7 @@ def _append_structure_composition( invalidation_bytes_nr: int, inval_bits: list[NDArray[Any]], inval_cntr: int, - ) -> tuple[ - int, - int, - int, - tuple[int, int], - list[NDArray[Any]], - list[tuple[str, dtype[Any], tuple[int, ...]]], - int, - ]: + ) -> tuple[int, int, int, tuple[int, int], list[NDArray[Any]], list[tuple[str, dtype[Any], tuple[int, ...]]], int,]: si_map = self._si_map fields = [] @@ -4875,9 +4673,7 @@ def _append_structure_composition( mime = "applciation/A2L" else: mime = f"application/x-{suffix}" - attachment_index = self.attach( - at_data, at_name, hash_sum=hash_sum, mime=mime - ) + attachment_index = self.attach(at_data, at_name, hash_sum=hash_sum, mime=mime) attachment = attachment_index else: attachment = None @@ -4900,9 +4696,7 @@ def _append_structure_composition( if source_bus: kwargs["flags"] = v4c.FLAG_CN_BUS_EVENT flags_ = v4c.FLAG_CN_BUS_EVENT - grp.channel_group.flags |= ( - v4c.FLAG_CG_BUS_EVENT | v4c.FLAG_CG_PLAIN_BUS_EVENT - ) + grp.channel_group.flags |= v4c.FLAG_CG_BUS_EVENT | v4c.FLAG_CG_PLAIN_BUS_EVENT else: kwargs["flags"] = 0 flags_ = 0 @@ -4924,9 +4718,7 @@ def _append_structure_composition( record.append((ch.dtype_fmt, ch.dtype_fmt.itemsize, offset, 0)) if source_bus and grp.channel_group.acq_source is None: - grp.channel_group.acq_source = SourceInformation.from_common_source( - signal.source - ) + grp.channel_group.acq_source = SourceInformation.from_common_source(signal.source) if signal.source.bus_type == v4c.BUS_TYPE_CAN: grp.channel_group.path_separator = 46 @@ -4953,9 +4745,7 @@ def _append_structure_composition( if source in si_map: ch.source = si_map[source] else: - new_source = SourceInformation( - source_type=source.source_type, bus_type=source.bus_type - ) + new_source = SourceInformation(source_type=source.source_type, bus_type=source.bus_type) new_source.name = source.name new_source.path = source.path new_source.comment = source.comment @@ -5142,9 +4932,7 @@ def _append_structure_composition( if source in si_map: ch.source = si_map[source] else: - new_source = SourceInformation( - source_type=source.source_type, bus_type=source.bus_type - ) + new_source = SourceInformation(source_type=source.source_type, bus_type=source.bus_type) new_source.name = source.name new_source.path = source.path new_source.comment = source.comment @@ -5274,14 +5062,7 @@ def _append_structure_composition_column_oriented( dg_cntr: int, ch_cntr: int, defined_texts: dict[str, int], - ) -> tuple[ - int, - int, - int, - tuple[int, int], - list[NDArray[Any]], - list[tuple[str, dtype[Any], tuple[int, ...]]], - ]: + ) -> tuple[int, int, int, tuple[int, int], list[NDArray[Any]], list[tuple[str, dtype[Any], tuple[int, ...]]],]: si_map = self._si_map fields = [] @@ -5310,9 +5091,7 @@ def _append_structure_composition_column_oriented( suffix = Path(at_name).suffix.strip(".") else: suffix = "dbc" - attachment_index = self.attach( - at_data, at_name, hash_sum=hash_sum, mime=f"application/x-{suffix}" - ) + attachment_index = self.attach(at_data, at_name, hash_sum=hash_sum, mime=f"application/x-{suffix}") attachment = attachment_index else: attachment = None @@ -5353,9 +5132,7 @@ def _append_structure_composition_column_oriented( ch.dtype_fmt = signal.samples.dtype if source_bus: - grp.channel_group.acq_source = SourceInformation.from_common_source( - signal.source - ) + grp.channel_group.acq_source = SourceInformation.from_common_source(signal.source) if signal.source.bus_type == v4c.BUS_TYPE_CAN: grp.channel_group.path_separator = 46 @@ -5373,9 +5150,7 @@ def _append_structure_composition_column_oriented( if source in si_map: ch.source = si_map[source] else: - new_source = SourceInformation( - source_type=source.source_type, bus_type=source.bus_type - ) + new_source = SourceInformation(source_type=source.source_type, bus_type=source.bus_type) new_source.name = source.name new_source.path = source.path new_source.comment = source.comment @@ -5568,9 +5343,7 @@ def _append_structure_composition_column_oriented( if source in si_map: ch.source = si_map[source] else: - new_source = SourceInformation( - source_type=source.source_type, bus_type=source.bus_type - ) + new_source = SourceInformation(source_type=source.source_type, bus_type=source.bus_type) new_source.name = source.name new_source.path = source.path new_source.comment = source.comment @@ -5687,9 +5460,7 @@ def _append_structure_composition_column_oriented( return offset, dg_cntr, ch_cntr, struct_self, fields, types - def extend( - self, index: int, signals: list[tuple[NDArray[Any], NDArray[Any] | None]] - ) -> None: + def extend(self, index: int, signals: list[tuple[NDArray[Any], NDArray[Any] | None]]) -> None: """ Extend a group with new samples. *signals* contains (values, invalidation_bits) pairs for each extended signal. The first pair is the master channel's pair, and the @@ -5740,9 +5511,7 @@ def extend( added_cycles = len(signals[0][0]) invalidation_bytes_nr = gp.channel_group.invalidation_bytes_nr - for i, ((signal, invalidation_bits), sig_type) in enumerate( - zip(signals, gp.signal_types) - ): + for i, ((signal, invalidation_bits), sig_type) in enumerate(zip(signals, gp.signal_types)): # first add the signals in the simple signal list if sig_type == v4c.SIGNAL_TYPE_SCALAR: s_type, s_size = fmt_to_datatype_v4(signal.dtype, signal.shape) @@ -5809,9 +5578,7 @@ def extend( else: if self.compact_vlsd: - cur_offset = sum( - blk.original_size for blk in gp.get_signal_data_blocks(i) - ) + cur_offset = sum(blk.original_size for blk in gp.get_signal_data_blocks(i)) data = [] offsets = [] @@ -5854,9 +5621,7 @@ def extend( fields.append((offsets.tobytes(), 8)) else: - cur_offset = sum( - blk.original_size for blk in gp.get_signal_data_blocks(i) - ) + cur_offset = sum(blk.original_size for blk in gp.get_signal_data_blocks(i)) offsets = arange(len(signal), dtype=uint64) * (signal.itemsize + 4) @@ -5898,11 +5663,7 @@ def extend( gp.channel_group.invalidation_bytes_nr = invalidation_bytes_nr - inval_bits = fliplr( - packbits(array(inval_bits).T).reshape( - (cycles_nr, invalidation_bytes_nr) - ) - ) + inval_bits = fliplr(packbits(array(inval_bits).T).reshape((cycles_nr, invalidation_bytes_nr))) if self.version < "4.20": fields.append((inval_bits.tobytes(), invalidation_bytes_nr)) @@ -5974,9 +5735,7 @@ def extend( ) ) - def _extend_column_oriented( - self, index: int, signals: list[tuple[NDArray[Any], NDArray[Any] | None]] - ) -> None: + def _extend_column_oriented(self, index: int, signals: list[tuple[NDArray[Any], NDArray[Any] | None]]) -> None: """ Extend a group with new samples. *signals* contains (values, invalidation_bits) pairs for each extended signal. The first pair is the master channel's pair, and the @@ -6053,9 +5812,7 @@ def _extend_column_oriented( samples = signal else: - cur_offset = sum( - blk.original_size for blk in gp.get_signal_data_blocks(0) - ) + cur_offset = sum(blk.original_size for blk in gp.get_signal_data_blocks(0)) offsets = arange(len(signal), dtype=uint64) * (signal.itemsize + 4) @@ -6165,9 +5922,7 @@ def attach( password = password or self._password if password and not CRYPTOGRAPHY_AVAILABLE: - raise MdfException( - "cryptography must be installed for attachment encryption" - ) + raise MdfException("cryptography must be installed for attachment encryption") if hash_sum is None: worker = md5() @@ -6378,9 +6133,7 @@ def extract_attachment( encryption_info = extract_encryption_information(attachment.comment) if encryption_info.get("encrypted", False): if not password: - raise MdfException( - "the password must be provided for encrypted attachments" - ) + raise MdfException("the password must be provided for encrypted attachments") if isinstance(password, str): password = password.encode("utf-8") @@ -6644,10 +6397,7 @@ def get( vals = None all_invalid = False - if ( - channel.byte_offset + (channel.bit_offset + channel.bit_count) / 8 - > grp.channel_group.samples_byte_nr - ): + if channel.byte_offset + (channel.bit_offset + channel.bit_count) / 8 > grp.channel_group.samples_byte_nr: all_invalid = True logger.warning( "\n\t".join( @@ -6663,9 +6413,7 @@ def get( ) ) - if ( - channel.bit_offset + channel.bit_count - ) / 8 > grp.channel_group.samples_byte_nr: + if (channel.bit_offset + channel.bit_count) / 8 > grp.channel_group.samples_byte_nr: vals, timestamps, invalidation_bits, encoding = [], [], None, None else: channel = deepcopy(channel) @@ -6820,17 +6568,13 @@ def _get_structure( # get group data if data is None: - data = self._load_data( - grp, record_offset=record_offset, record_count=record_count - ) + data = self._load_data(grp, record_offset=record_offset, record_count=record_count) else: data = (data,) groups = self.groups - channel_invalidation_present = channel.flags & ( - v4c.FLAG_CN_ALL_INVALID | v4c.FLAG_CN_INVALIDATION_PRESENT - ) + channel_invalidation_present = channel.flags & (v4c.FLAG_CN_ALL_INVALID | v4c.FLAG_CN_INVALIDATION_PRESENT) _dtype = dtype(channel.dtype_fmt) conditions = [ @@ -6847,36 +6591,26 @@ def _get_structure( invalidation_bits = [] byte_offset = channel.byte_offset - record_size = ( - grp.channel_group.samples_byte_nr - + grp.channel_group.invalidation_bytes_nr - ) + record_size = grp.channel_group.samples_byte_nr + grp.channel_group.invalidation_bytes_nr count = 0 for fragment in data: bts = fragment[0] - buffer = get_channel_raw_bytes( - bts, record_size, byte_offset, _dtype.itemsize - ) + buffer = get_channel_raw_bytes(bts, record_size, byte_offset, _dtype.itemsize) channel_values.append(frombuffer(buffer, dtype=_dtype)) if master_is_required: timestamps.append(self.get_master(gp_nr, fragment, one_piece=True)) if channel_invalidation_present: - invalidation_bits.append( - self.get_invalidation_bits(gp_nr, channel, fragment) - ) + invalidation_bits.append(self.get_invalidation_bits(gp_nr, channel, fragment)) count += 1 else: unique_names = UniqueDB() fast_path = False - names = [ - unique_names.get_unique_name(grp.channels[ch_nr].name) - for _, ch_nr in dependency_list - ] + names = [unique_names.get_unique_name(grp.channels[ch_nr].name) for _, ch_nr in dependency_list] channel_values = [[] for _ in dependency_list] timestamps = [] @@ -6899,9 +6633,7 @@ def _get_structure( if master_is_required: timestamps.append(self.get_master(gp_nr, fragment, one_piece=True)) if channel_invalidation_present: - invalidation_bits.append( - self.get_invalidation_bits(gp_nr, channel, fragment) - ) + invalidation_bits.append(self.get_invalidation_bits(gp_nr, channel, fragment)) count += 1 @@ -6961,16 +6693,12 @@ def _get_structure( arrays.append( concatenate( lst, - out=empty( - (total_size,) + lst[0].shape[1:], dtype=lst[0].dtype - ), + out=empty((total_size,) + lst[0].shape[1:], dtype=lst[0].dtype), ) ) else: arrays = [lst[0] for lst in channel_values] - types = [ - (name_, arr.dtype, arr.shape[1:]) for name_, arr in zip(names, arrays) - ] + types = [(name_, arr.dtype, arr.shape[1:]) for name_, arr in zip(names, arrays)] types = dtype(types) vals = fromarrays(arrays, dtype=types) @@ -7001,9 +6729,7 @@ def _get_structure( if raster and len(timestamps) > 1: t = arange(timestamps[0], timestamps[-1], raster) - vals = Signal( - vals, timestamps, name="_", invalidation_bits=invalidation_bits - ).interp( + vals = Signal(vals, timestamps, name="_", invalidation_bits=invalidation_bits).interp( t, integer_interpolation_mode=self._integer_interpolation, float_interpolation_mode=self._float_interpolation, @@ -7039,9 +6765,7 @@ def _get_array( # get group data if data is None: - data = self._load_data( - grp, record_offset=record_offset, record_count=record_count - ) + data = self._load_data(grp, record_offset=record_offset, record_count=record_count) else: data = (data,) @@ -7060,10 +6784,7 @@ def _get_array( if group.uses_ld: record_size = group.channel_group.samples_byte_nr else: - record_size = ( - group.channel_group.samples_byte_nr - + group.channel_group.invalidation_bytes_nr - ) + record_size = group.channel_group.samples_byte_nr + group.channel_group.invalidation_bytes_nr channel_dtype = get_fmt_v4( channel.data_type, @@ -7081,14 +6802,10 @@ def _get_array( dtype_fmt = dtype(types) - channel_invalidation_present = channel.flags & ( - v4c.FLAG_CN_ALL_INVALID | v4c.FLAG_CN_INVALIDATION_PRESENT - ) + channel_invalidation_present = channel.flags & (v4c.FLAG_CN_ALL_INVALID | v4c.FLAG_CN_INVALIDATION_PRESENT) channel_group = grp.channel_group - samples_size = ( - channel_group.samples_byte_nr + channel_group.invalidation_bytes_nr - ) + samples_size = channel_group.samples_byte_nr + channel_group.invalidation_bytes_nr channel_values = [] timestamps = [] @@ -7161,9 +6878,7 @@ def _get_array( debug_channel(self, grp, channel, dependency_list) raise - axisname = ( - self.groups[ref_dg_nr].channels[ref_ch_nr].name - ) + axisname = self.groups[ref_dg_nr].channels[ref_ch_nr].name if ref_dg_nr == gp_nr: axis_values = self.get( @@ -7218,9 +6933,7 @@ def _get_array( key = f"axis_{i}_value_{j}" axis.append(ca_block[key]) - axis = array( - [axis for _ in range(cycles_nr)], dtype=f"{shape}f8" - ) + axis = array([axis for _ in range(cycles_nr)], dtype=f"{shape}f8") arrays.append(axis) types.append((f"axis_{i}", axis.dtype, shape)) else: @@ -7230,9 +6943,7 @@ def _get_array( if axis is None: axisname = f"axis_{i}" - axis_values = array( - [arange(shape[0])] * cycles, dtype=f"({shape[0]},)f8" - ) + axis_values = array([arange(shape[0])] * cycles, dtype=f"({shape[0]},)f8") else: try: @@ -7283,9 +6994,7 @@ def _get_array( if master_is_required: timestamps.append(self.get_master(gp_nr, fragment, one_piece=True)) if channel_invalidation_present: - invalidation_bits.append( - self.get_invalidation_bits(gp_nr, channel, fragment) - ) + invalidation_bits.append(self.get_invalidation_bits(gp_nr, channel, fragment)) channel_values.append(vals) count += 1 @@ -7328,9 +7037,7 @@ def _get_array( if raster and len(timestamps) > 1: t = arange(timestamps[0], timestamps[-1], raster) - vals = Signal( - vals, timestamps, name="_", invalidation_bits=invalidation_bits - ).interp( + vals = Signal(vals, timestamps, name="_", invalidation_bits=invalidation_bits).interp( t, integer_interpolation_mode=self._integer_interpolation, float_interpolation_mode=self._float_interpolation, @@ -7365,16 +7072,12 @@ def _get_scalar( # get group data if data is None: - data = self._load_data( - grp, record_offset=record_offset, record_count=record_count - ) + data = self._load_data(grp, record_offset=record_offset, record_count=record_count) one_piece = False else: one_piece = True - channel_invalidation_present = channel.flags & ( - v4c.FLAG_CN_ALL_INVALID | v4c.FLAG_CN_INVALIDATION_PRESENT - ) + channel_invalidation_present = channel.flags & (v4c.FLAG_CN_ALL_INVALID | v4c.FLAG_CN_INVALIDATION_PRESENT) data_type = channel.data_type channel_type = channel.channel_type @@ -7424,9 +7127,7 @@ def _get_scalar( ) ) if channel_invalidation_present: - invalidation_bits.append( - self.get_invalidation_bits(gp_nr, channel, fragment) - ) + invalidation_bits.append(self.get_invalidation_bits(gp_nr, channel, fragment)) channel_values.append(vals) count += 1 @@ -7471,9 +7172,7 @@ def _get_scalar( else: t = arange(timestamps[0], timestamps[-1], raster) - vals = Signal( - vals, timestamps, name="_", invalidation_bits=invalidation_bits - ).interp( + vals = Signal(vals, timestamps, name="_", invalidation_bits=invalidation_bits).interp( t, integer_interpolation_mode=self._integer_interpolation, float_interpolation_mode=self._float_interpolation, @@ -7501,11 +7200,7 @@ def _get_scalar( if info is not None: dtype_, byte_size, byte_offset, bit_offset = info - if ( - ch_nr == 0 - and len(grp.channels) == 1 - and channel.dtype_fmt.itemsize == record_size - ): + if ch_nr == 0 and len(grp.channels) == 1 and channel.dtype_fmt.itemsize == record_size: buffer = bytearray(data_bytes) else: buffer = get_channel_raw_bytes( @@ -7557,9 +7252,7 @@ def _get_scalar( timestamps = None if channel_invalidation_present: - invalidation_bits = self.get_invalidation_bits( - gp_nr, channel, fragment - ) + invalidation_bits = self.get_invalidation_bits(gp_nr, channel, fragment) if not ignore_invalidation_bits: vals = vals[nonzero(~invalidation_bits)[0]] @@ -7585,13 +7278,9 @@ def _get_scalar( vals = array(vals, dtype=bool) if master_is_required: - timestamps.append( - self.get_master(gp_nr, fragment, one_piece=True) - ) + timestamps.append(self.get_master(gp_nr, fragment, one_piece=True)) if channel_invalidation_present: - invalidation_bits.append( - self.get_invalidation_bits(gp_nr, channel, fragment) - ) + invalidation_bits.append(self.get_invalidation_bits(gp_nr, channel, fragment)) channel_values.append(vals) vals = concatenate(channel_values) @@ -7604,11 +7293,7 @@ def _get_scalar( for count, fragment in enumerate(data, 1): data_bytes = fragment[0] - if ( - ch_nr == 0 - and len(grp.channels) == 1 - and channel.dtype_fmt.itemsize == record_size - ): + if ch_nr == 0 and len(grp.channels) == 1 and channel.dtype_fmt.itemsize == record_size: buffer.append(data_bytes) else: buffer.append( @@ -7621,13 +7306,9 @@ def _get_scalar( ) if master_is_required: - timestamps.append( - self.get_master(gp_nr, fragment, one_piece=True) - ) + timestamps.append(self.get_master(gp_nr, fragment, one_piece=True)) if channel_invalidation_present: - invalidation_bits.append( - self.get_invalidation_bits(gp_nr, channel, fragment) - ) + invalidation_bits.append(self.get_invalidation_bits(gp_nr, channel, fragment)) if count > 1: buffer = bytearray().join(buffer) @@ -7703,9 +7384,7 @@ def _get_scalar( else: t = arange(timestamps[0], timestamps[-1], raster) - vals = Signal( - vals, timestamps, name="_", invalidation_bits=invalidation_bits - ).interp( + vals = Signal(vals, timestamps, name="_", invalidation_bits=invalidation_bits).interp( t, integer_interpolation_mode=self._integer_interpolation, float_interpolation_mode=self._float_interpolation, @@ -7721,15 +7400,11 @@ def _get_scalar( count_ = len(vals) if count_: - signal_data = self._load_signal_data( - group=grp, index=ch_nr, start_offset=vals[0], end_offset=vals[-1] - ) + signal_data = self._load_signal_data(group=grp, index=ch_nr, start_offset=vals[0], end_offset=vals[-1]) else: signal_data = b"" - max_vlsd_size = self.determine_max_vlsd_sample_size( - group_index, channel_index - ) + max_vlsd_size = self.determine_max_vlsd_sample_size(group_index, channel_index) if signal_data: if data_type in ( @@ -7784,9 +7459,7 @@ def _get_scalar( ) else: - raise MdfException( - f'wrong data type "{data_type}" for vlsd channel "{channel.name}"' - ) + raise MdfException(f'wrong data type "{data_type}" for vlsd channel "{channel.name}"') vals = vals.astype(f"S{max_vlsd_size}") else: @@ -7811,16 +7484,12 @@ def _get_scalar( encoding = "latin-1" else: - raise MdfException( - f'wrong data type "{data_type}" for vlsd channel "{channel.name}"' - ) + raise MdfException(f'wrong data type "{data_type}" for vlsd channel "{channel.name}"') else: vals = array([], dtype=f"({max_vlsd_size},)u1") - elif ( - v4c.DATA_TYPE_STRING_LATIN_1 <= data_type <= v4c.DATA_TYPE_STRING_UTF_16_BE - ): + elif v4c.DATA_TYPE_STRING_LATIN_1 <= data_type <= v4c.DATA_TYPE_STRING_UTF_16_BE: if channel_type in (v4c.CHANNEL_TYPE_VALUE, v4c.CHANNEL_TYPE_MLSD): if data_type == v4c.DATA_TYPE_STRING_UTF_16_BE: encoding = "utf-16-be" @@ -7835,9 +7504,7 @@ def _get_scalar( encoding = "latin-1" else: - raise MdfException( - f'wrong data type "{data_type}" for string channel' - ) + raise MdfException(f'wrong data type "{data_type}" for string channel') elif data_type in (v4c.DATA_TYPE_CANOPEN_TIME, v4c.DATA_TYPE_CANOPEN_DATE): # CANopen date @@ -7890,9 +7557,7 @@ def _get_scalar( return vals, timestamps, invalidation_bits, encoding - def _get_not_byte_aligned_data( - self, data: bytes, group: Group, ch_nr: int - ) -> NDArray[Any]: + def _get_not_byte_aligned_data(self, data: bytes, group: Group, ch_nr: int) -> NDArray[Any]: big_endian_types = ( v4c.DATA_TYPE_UNSIGNED_MOTOROLA, v4c.DATA_TYPE_REAL_MOTOROLA, @@ -7902,10 +7567,7 @@ def _get_not_byte_aligned_data( if group.uses_ld: record_size = group.channel_group.samples_byte_nr else: - record_size = ( - group.channel_group.samples_byte_nr - + group.channel_group.invalidation_bytes_nr - ) + record_size = group.channel_group.samples_byte_nr + group.channel_group.invalidation_bytes_nr channel = group.channels[ch_nr] @@ -7961,9 +7623,7 @@ def _get_not_byte_aligned_data( if extra_bytes: if big_endian: - vals = column_stack( - [vals, zeros(len(vals), dtype=f"<({extra_bytes},)u1")] - ) + vals = column_stack([vals, zeros(len(vals), dtype=f"<({extra_bytes},)u1")]) try: vals = vals.view(f">u{std_size}").ravel() except: @@ -7973,9 +7633,7 @@ def _get_not_byte_aligned_data( vals &= (1 << bit_count) - 1 else: - vals = column_stack( - [vals, zeros(len(vals), dtype=f"<({extra_bytes},)u1")] - ) + vals = column_stack([vals, zeros(len(vals), dtype=f"<({extra_bytes},)u1")]) try: vals = vals.view(f" dict[str, Any]: """ info = { "version": self.version, - "program": self.identification.program_identification.decode("utf-8").strip( - " \0\n\r\t" - ), + "program": self.identification.program_identification.decode("utf-8").strip(" \0\n\r\t"), "comment": self.header.comment, } info["groups"] = len(self.groups) @@ -9290,16 +8890,12 @@ def save( address = tell() total_size = ( - gp.channel_group.samples_byte_nr - + gp.channel_group.invalidation_bytes_nr + gp.channel_group.samples_byte_nr + gp.channel_group.invalidation_bytes_nr ) * gp.channel_group.cycles_nr if total_size: if self._write_fragment_size: - samples_size = ( - gp.channel_group.samples_byte_nr - + gp.channel_group.invalidation_bytes_nr - ) + samples_size = gp.channel_group.samples_byte_nr + gp.channel_group.invalidation_bytes_nr if samples_size: split_size = self._write_fragment_size // samples_size split_size *= samples_size @@ -9396,10 +8992,7 @@ def save( if compression == 1: param = 0 else: - param = ( - gp.channel_group.samples_byte_nr - + gp.channel_group.invalidation_bytes_nr - ) + param = gp.channel_group.samples_byte_nr + gp.channel_group.invalidation_bytes_nr kwargs = { "data": data_, "zip_type": zip_type, @@ -9452,9 +9045,7 @@ def save( if compression == 1: param = 0 else: - param = ( - gp.channel_group.invalidation_bytes_nr - ) + param = gp.channel_group.invalidation_bytes_nr kwargs = { "data": inval_, "zip_type": zip_type, @@ -9476,8 +9067,7 @@ def save( kwargs = { "flags": v4c.FLAG_LD_EQUAL_LENGHT, "data_block_nr": len(dv_addr), - "data_block_len": block_size - // gp.channel_group.samples_byte_nr, + "data_block_len": block_size // gp.channel_group.samples_byte_nr, } for i, addr in enumerate(dv_addr): kwargs[f"data_block_addr_{i}"] = addr @@ -9526,8 +9116,7 @@ def save( param = 0 else: param = ( - gp.channel_group.samples_byte_nr - + gp.channel_group.invalidation_bytes_nr + gp.channel_group.samples_byte_nr + gp.channel_group.invalidation_bytes_nr ) kwargs = { "data": data_, @@ -9606,21 +9195,15 @@ def save( for j, channel in enumerate(channels): if channel.attachment is not None: - channel.attachment_addr = self.attachments[ - channel.attachment - ].address + channel.attachment_addr = self.attachments[channel.attachment].address elif channel.attachment_nr: channel.attachment_addr = 0 - address = channel.to_blocks( - address, blocks, defined_texts, cc_map, si_map - ) + address = channel.to_blocks(address, blocks, defined_texts, cc_map, si_map) if channel.channel_type == v4c.CHANNEL_TYPE_SYNC: if channel.attachment is not None: - channel.data_block_addr = self.attachments[ - channel.attachment - ].address + channel.data_block_addr = self.attachments[channel.attachment].address else: sdata = self._load_signal_data(group=gp, index=j) if sdata: @@ -9764,9 +9347,7 @@ def save( gp.channel_group.first_ch_addr = 0 gp.channel_group.next_cg_addr = 0 - address = gp.channel_group.to_blocks( - address, blocks, defined_texts, si_map - ) + address = gp.channel_group.to_blocks(address, blocks, defined_texts, si_map) gp.data_group.first_cg_addr = gp.channel_group.address cg_map[i] = gp.channel_group.address @@ -9785,37 +9366,23 @@ def save( if dep_list: if all(isinstance(dep, ChannelArrayBlock) for dep in dep_list): for dep in dep_list: - for i, (gp_nr, ch_nr) in enumerate( - dep.dynamic_size_channels - ): + for i, (gp_nr, ch_nr) in enumerate(dep.dynamic_size_channels): grp = self.groups[gp_nr] ch = grp.channels[ch_nr] - dep[ - f"dynamic_size_{i}_dg_addr" - ] = grp.data_group.address - dep[ - f"dynamic_size_{i}_cg_addr" - ] = grp.channel_group.address + dep[f"dynamic_size_{i}_dg_addr"] = grp.data_group.address + dep[f"dynamic_size_{i}_cg_addr"] = grp.channel_group.address dep[f"dynamic_size_{i}_ch_addr"] = ch.address - for i, (gp_nr, ch_nr) in enumerate( - dep.input_quantity_channels - ): + for i, (gp_nr, ch_nr) in enumerate(dep.input_quantity_channels): grp = self.groups[gp_nr] ch = grp.channels[ch_nr] - dep[ - f"input_quantity_{i}_dg_addr" - ] = grp.data_group.address - dep[ - f"input_quantity_{i}_cg_addr" - ] = grp.channel_group.address + dep[f"input_quantity_{i}_dg_addr"] = grp.data_group.address + dep[f"input_quantity_{i}_cg_addr"] = grp.channel_group.address dep[f"input_quantity_{i}_ch_addr"] = ch.address for i, conversion in enumerate(dep.axis_conversions): if conversion: - address = conversion.to_blocks( - address, blocks, defined_texts, cc_map - ) + address = conversion.to_blocks(address, blocks, defined_texts, cc_map) dep[f"axis_conversion_{i}"] = conversion.address else: dep[f"axis_conversion_{i}"] = 0 @@ -9824,35 +9391,23 @@ def save( gp_nr, ch_nr = dep.output_quantity_channel grp = self.groups[gp_nr] ch = grp.channels[ch_nr] - dep[ - f"output_quantity_dg_addr" - ] = grp.data_group.address - dep[ - f"output_quantity_cg_addr" - ] = grp.channel_group.address + dep[f"output_quantity_dg_addr"] = grp.data_group.address + dep[f"output_quantity_cg_addr"] = grp.channel_group.address dep[f"output_quantity_ch_addr"] = ch.address if dep.comparison_quantity_channel: gp_nr, ch_nr = dep.comparison_quantity_channel grp = self.groups[gp_nr] ch = grp.channels[ch_nr] - dep[ - f"comparison_quantity_dg_addr" - ] = grp.data_group.address - dep[ - f"comparison_quantity_cg_addr" - ] = grp.channel_group.address + dep[f"comparison_quantity_dg_addr"] = grp.data_group.address + dep[f"comparison_quantity_cg_addr"] = grp.channel_group.address dep[f"comparison_quantity_ch_addr"] = ch.address for i, (gp_nr, ch_nr) in enumerate(dep.axis_channels): grp = self.groups[gp_nr] ch = grp.channels[ch_nr] - dep[ - f"scale_axis_{i}_dg_addr" - ] = grp.data_group.address - dep[ - f"scale_axis_{i}_cg_addr" - ] = grp.channel_group.address + dep[f"scale_axis_{i}_dg_addr"] = grp.data_group.address + dep[f"scale_axis_{i}_cg_addr"] = grp.channel_group.address dep[f"scale_axis_{i}_ch_addr"] = ch.address position = tell() @@ -9875,14 +9430,10 @@ def save( for i, ref in enumerate(event.scopes): try: dg_cntr, ch_cntr = ref - event[f"scope_{i}_addr"] = ( - self.groups[dg_cntr].channels[ch_cntr].address - ) + event[f"scope_{i}_addr"] = self.groups[dg_cntr].channels[ch_cntr].address except TypeError: dg_cntr = ref - event[f"scope_{i}_addr"] = self.groups[ - dg_cntr - ].channel_group.address + event[f"scope_{i}_addr"] = self.groups[dg_cntr].channel_group.address blocks.append(event) ev_map.append(address) @@ -9955,19 +9506,12 @@ def save( for i, gp in enumerate(self.groups): for j, channel in enumerate(gp.channels): if channel.attachment is not None: - channel.attachment_addr = self.attachments[ - channel.attachment - ].address + channel.attachment_addr = self.attachments[channel.attachment].address elif channel.attachment_nr: channel.attachment_addr = 0 - if ( - channel.channel_type == v4c.CHANNEL_TYPE_SYNC - and channel.attachment is not None - ): - channel.data_block_addr = self.attachments[ - channel.attachment - ].address + if channel.channel_type == v4c.CHANNEL_TYPE_SYNC and channel.attachment is not None: + channel.data_block_addr = self.attachments[channel.attachment].address if progress is not None: blocks_nr = len(blocks) @@ -10247,9 +9791,7 @@ def _finalize(self) -> None: break starting_address = dl.address - next_block_position = bisect.bisect_right( - addresses, starting_address - ) + next_block_position = bisect.bisect_right(addresses, starting_address) # search for data blocks after the DLBLOCK for j in range(i, count): if next_block_position >= len(addresses): @@ -10269,24 +9811,12 @@ def _finalize(self) -> None: param, original_size, zip_size, - ) = v4c.DZ_COMMON_INFO_uf( - stream.read(v4c.DZ_COMMON_INFO_SIZE) - ) + ) = v4c.DZ_COMMON_INFO_uf(stream.read(v4c.DZ_COMMON_INFO_SIZE)) - exceeded = ( - limit - - ( - next_block_address - + v4c.DZ_COMMON_SIZE - + zip_size - ) - < 0 - ) + exceeded = limit - (next_block_address + v4c.DZ_COMMON_SIZE + zip_size) < 0 else: - id_string, block_len = COMMON_SHORT_uf( - stream.read(v4c.COMMON_SIZE) - ) + id_string, block_len = COMMON_SHORT_uf(stream.read(v4c.COMMON_SIZE)) original_size = block_len - 24 exceeded = limit - (next_block_address + block_len) < 0 @@ -10314,9 +9844,7 @@ def _finalize(self) -> None: stream.seek(data_addr) stream.write(bytes(DataList(**kwargs))) - self.identification[ - "unfinalized_standard_flags" - ] -= v4c.FLAG_UNFIN_UPDATE_LAST_DL + self.identification["unfinalized_standard_flags"] -= v4c.FLAG_UNFIN_UPDATE_LAST_DL if flags & v4c.FLAG_UNFIN_UPDATE_LAST_DT_LENGTH: try: @@ -10332,9 +9860,7 @@ def _finalize(self) -> None: blk = DataBlock(address=data_addr, stream=stream, mapped=mapped) elif blk_id == b"##DL": while True: - dl = DataList( - address=data_addr, stream=stream, mapped=mapped - ) + dl = DataList(address=data_addr, stream=stream, mapped=mapped) if not dl.next_dl_addr: break @@ -10346,9 +9872,7 @@ def _finalize(self) -> None: data_addr = hl.first_dl_addr while True: - dl = DataList( - address=data_addr, stream=stream, mapped=mapped - ) + dl = DataList(address=data_addr, stream=stream, mapped=mapped) if not dl.next_dl_addr: break @@ -10368,9 +9892,7 @@ def _finalize(self) -> None: print(format_exc()) raise - self.identification.unfinalized_standard_flags -= ( - v4c.FLAG_UNFIN_UPDATE_LAST_DT_LENGTH - ) + self.identification.unfinalized_standard_flags -= v4c.FLAG_UNFIN_UPDATE_LAST_DT_LENGTH self.identification.file_identification = b"MDF " def _sort( @@ -10405,9 +9927,7 @@ def _sort( write = self._tempfile.write for address, groups in common.items(): - cg_map = { - rec_id: self.groups[index_].channel_group for index_, rec_id in groups - } + cg_map = {rec_id: self.groups[index_].channel_group for index_, rec_id in groups} final_records = {id_: [] for (_, id_) in groups} @@ -10456,11 +9976,7 @@ def _sort( # and there's a tick update (at least 1 integer between the last update and the current index) # then we can notify about the callback progress - if ( - callable(progress) - and max_progress_count - and floor(previous) < floor(index) - ): + if callable(progress) and max_progress_count and floor(previous) < floor(index): progress(floor(index), max_progress_count) previous = index @@ -10523,9 +10039,7 @@ def _sort( block_type=v4c.DZ_BLOCK_LZ, location=v4c.LOCATION_TEMPORARY_FILE, ) - self.groups[dg_cntr].signal_data[ch_cntr][ - 0 - ].append(info) + self.groups[dg_cntr].signal_data[ch_cntr][0].append(info) else: block_info = DataBlockInfo( @@ -10547,9 +10061,7 @@ def _sort( block_type=v4c.DT_BLOCK, location=v4c.LOCATION_TEMPORARY_FILE, ) - self.groups[dg_cntr].signal_data[ch_cntr][ - 0 - ].append(info) + self.groups[dg_cntr].signal_data[ch_cntr][0].append(info) else: block_info = DataBlockInfo( @@ -10585,9 +10097,7 @@ def _sort( channel_group = cg_map[rec_id] if channel_group.address in self._cn_data_map: - dg_cntr, ch_cntr = self._cn_data_map[ - channel_group.address - ] + dg_cntr, ch_cntr = self._cn_data_map[channel_group.address] else: dg_cntr, ch_cntr = None, None @@ -10611,9 +10121,7 @@ def _sort( block_type=v4c.DZ_BLOCK_LZ, location=v4c.LOCATION_TEMPORARY_FILE, ) - self.groups[dg_cntr].signal_data[ch_cntr][ - 0 - ].append(info) + self.groups[dg_cntr].signal_data[ch_cntr][0].append(info) else: block_info = DataBlockInfo( @@ -10636,9 +10144,7 @@ def _sort( block_type=v4c.DT_BLOCK, location=v4c.LOCATION_TEMPORARY_FILE, ) - self.groups[dg_cntr].signal_data[ch_cntr][ - 0 - ].append(info) + self.groups[dg_cntr].signal_data[ch_cntr][0].append(info) else: block_info = DataBlockInfo( @@ -10667,10 +10173,7 @@ def _sort( if channel_group.flags & v4c.FLAG_CG_VLSD: continue - if ( - self.version >= "4.20" - and channel_group.flags & v4c.FLAG_CG_REMOTE_MASTER - ): + if self.version >= "4.20" and channel_group.flags & v4c.FLAG_CG_REMOTE_MASTER: index = channel_group.cg_master_index else: index = i @@ -10678,10 +10181,7 @@ def _sort( if group.uses_ld: samples_size = channel_group.samples_byte_nr else: - samples_size = ( - channel_group.samples_byte_nr - + channel_group.invalidation_bytes_nr - ) + samples_size = channel_group.samples_byte_nr + channel_group.invalidation_bytes_nr total_size = sum(blk.original_size for blk in group.get_data_blocks()) @@ -10690,20 +10190,10 @@ def _sort( virtual_channel_group.cycles_nr = cycles_nr channel_group.cycles_nr = cycles_nr - if ( - self.identification["unfinalized_standard_flags"] - & v4c.FLAG_UNFIN_UPDATE_CG_COUNTER - ): - self.identification[ - "unfinalized_standard_flags" - ] -= v4c.FLAG_UNFIN_UPDATE_CG_COUNTER - if ( - self.identification["unfinalized_standard_flags"] - & v4c.FLAG_UNFIN_UPDATE_VLSD_BYTES - ): - self.identification[ - "unfinalized_standard_flags" - ] -= v4c.FLAG_UNFIN_UPDATE_VLSD_BYTES + if self.identification["unfinalized_standard_flags"] & v4c.FLAG_UNFIN_UPDATE_CG_COUNTER: + self.identification["unfinalized_standard_flags"] -= v4c.FLAG_UNFIN_UPDATE_CG_COUNTER + if self.identification["unfinalized_standard_flags"] & v4c.FLAG_UNFIN_UPDATE_VLSD_BYTES: + self.identification["unfinalized_standard_flags"] -= v4c.FLAG_UNFIN_UPDATE_VLSD_BYTES def _process_bus_logging(self) -> None: groups_count = len(self.groups) @@ -10776,7 +10266,9 @@ def _process_can_logging(self, group_index: int, grp: Group) -> None: group=group_index, data=fragment, samples_only=True, - )[0].astype(" None: group=group_index, data=fragment, samples_only=True, - )[0].astype(" None: group=group_index, data=fragment, samples_only=True, - )[0].astype(" None: group=group_index, data=fragment, samples_only=True, - )[0].astype(" None: group=group_index, data=fragment, samples_only=True, - )[0].astype("> 8 @@ -10915,9 +10410,7 @@ def _process_can_logging(self, group_index: int, grp: Group) -> None: payload = bus_data_bytes[idx] t = bus_t[idx] - extracted_signals = bus_logging_utils.extract_mux( - payload, message, msg_id, bus, t - ) + extracted_signals = bus_logging_utils.extract_mux(payload, message, msg_id, bus, t) for entry, signals in extracted_signals.items(): if len(next(iter(signals.values()))["samples"]) == 0: @@ -10950,9 +10443,7 @@ def _process_can_logging(self, group_index: int, grp: Group) -> None: msg_map[entry] = cg_nr - for ch_index, ch in enumerate( - self.groups[cg_nr].channels - ): + for ch_index, ch in enumerate(self.groups[cg_nr].channels): if ch_index == 0: continue @@ -10976,9 +10467,7 @@ def _process_can_logging(self, group_index: int, grp: Group) -> None: sigs = [] for name_, signal in signals.items(): - sigs.append( - (signal["samples"], signal["invalidation_bits"]) - ) + sigs.append((signal["samples"], signal["invalidation_bits"])) t = signal["t"] @@ -11002,15 +10491,15 @@ def _process_lin_logging(self, group_index: int, grp: Group) -> None: index=attachment_addr, ) if at_name.suffix.lower() not in (".arxml", ".dbc", ".ldf"): - message = f'Expected .dbc, .arxml or .ldf file as LIN channel attachment but got "{at_name}"' + message = ( + f'Expected .dbc, .arxml or .ldf file as LIN channel attachment but got "{at_name}"' + ) logger.warning(message) elif not attachment: message = f'Attachment "{at_name}" not found' logger.warning(message) else: - contents = ( - None if at_name.suffix.lower() == ".ldf" else attachment - ) + contents = None if at_name.suffix.lower() == ".ldf" else attachment dbc = load_can_database(at_name, contents=contents) if dbc: self._dbc_cache[attachment_addr] = dbc @@ -11032,7 +10521,9 @@ def _process_lin_logging(self, group_index: int, grp: Group) -> None: group=group_index, data=fragment, samples_only=True, - )[0].astype(" None: self._set_temporary_master(None) self._set_temporary_master(self.get_master(group_index, data=fragment)) - msg_ids = ( - self.get("LIN_Frame.ID", group=group_index, data=fragment).astype( - " None: payload = bus_data_bytes[idx] t = bus_t[idx] - extracted_signals = bus_logging_utils.extract_mux( - payload, message, msg_id, 0, t - ) + extracted_signals = bus_logging_utils.extract_mux(payload, message, msg_id, 0, t) for entry, signals in extracted_signals.items(): if len(next(iter(signals.values()))["samples"]) == 0: @@ -11151,9 +10635,7 @@ def _process_lin_logging(self, group_index: int, grp: Group) -> None: sigs = [] for name_, signal in signals.items(): - sigs.append( - (signal["samples"], signal["invalidation_bits"]) - ) + sigs.append((signal["samples"], signal["invalidation_bits"])) t = signal["t"] diff --git a/src/asammdf/blocks/source_utils.py b/src/asammdf/blocks/source_utils.py index dd837328f..5bc8bdc14 100644 --- a/src/asammdf/blocks/source_utils.py +++ b/src/asammdf/blocks/source_utils.py @@ -34,9 +34,7 @@ class Source: BUS_TYPE_ETHERNET = v4c.BUS_TYPE_ETHERNET BUS_TYPE_USB = v4c.BUS_TYPE_USB - def __init__( - self, name: str, path: str, comment: str, source_type: int, bus_type: int - ) -> None: + def __init__(self, name: str, path: str, comment: str, source_type: int, bus_type: int) -> None: """Commons reprezentation for source information Attributes diff --git a/src/asammdf/blocks/utils.py b/src/asammdf/blocks/utils.py index 942c035ef..31e692acf 100644 --- a/src/asammdf/blocks/utils.py +++ b/src/asammdf/blocks/utils.py @@ -257,9 +257,7 @@ def get_text_v3( ... -def get_text_v3( - address: int, stream: ReadableBufferType, mapped: bool = False, decode: bool = True -) -> str | bytes: +def get_text_v3(address: int, stream: ReadableBufferType, mapped: bool = False, decode: bool = True) -> str | bytes: """faster way to extract strings from mdf versions 2 and 3 TextBlock Parameters @@ -284,9 +282,7 @@ def get_text_v3( if block_id != b"TX": return "" if decode else b"" (size,) = UINT16_uf(stream, address + 2) - text_bytes = ( - stream[address + 4 : address + size].split(b"\0", 1)[0].strip(b" \r\t\n") - ) + text_bytes = stream[address + 4 : address + size].split(b"\0", 1)[0].strip(b" \r\t\n") else: stream.seek(address) block_id = stream.read(2) @@ -329,9 +325,7 @@ def get_text_v4( ... -def get_text_v4( - address: int, stream: ReadableBufferType, mapped: bool = False, decode: bool = True -) -> str | bytes: +def get_text_v4(address: int, stream: ReadableBufferType, mapped: bool = False, decode: bool = True) -> str | bytes: """faster way to extract strings from mdf version 4 TextBlock Parameters @@ -355,9 +349,7 @@ def get_text_v4( block_id, size = BLK_COMMON_uf(stream, address) if block_id not in (b"##TX", b"##MD"): return "" if decode else b"" - text_bytes = ( - stream[address + 24 : address + size].split(b"\0", 1)[0].strip(b" \r\t\n") - ) + text_bytes = stream[address + 24 : address + size].split(b"\0", 1)[0].strip(b" \r\t\n") else: stream.seek(address) block_id, size = BLK_COMMON_u(stream.read(24)) @@ -443,9 +435,7 @@ def extract_ev_tool(comment: str) -> str: @lru_cache(maxsize=1024) -def get_fmt_v3( - data_type: int, size: int, byte_order: int = v3c.BYTE_ORDER_INTEL -) -> str: +def get_fmt_v3(data_type: int, size: int, byte_order: int = v3c.BYTE_ORDER_INTEL) -> str: """convert mdf versions 2 and 3 channel data type to numpy dtype format string @@ -532,9 +522,7 @@ def get_fmt_v3( @lru_cache(maxsize=1024) -def get_fmt_v4( - data_type: int, size: int, channel_type: int = v4c.CHANNEL_TYPE_VALUE -) -> str: +def get_fmt_v4(data_type: int, size: int, channel_type: int = v4c.CHANNEL_TYPE_VALUE) -> str: """convert mdf version 4 channel data type to numpy dtype format string Parameters @@ -646,9 +634,7 @@ def get_fmt_v4( @lru_cache(maxsize=1024) -def fmt_to_datatype_v3( - fmt: dtype[Any], shape: tuple[int, ...], array: bool = False -) -> tuple[int, int]: +def fmt_to_datatype_v3(fmt: dtype[Any], shape: tuple[int, ...], array: bool = False) -> tuple[int, int]: """convert numpy dtype format string to mdf versions 2 and 3 channel data type and size @@ -745,9 +731,7 @@ def info_to_datatype_v4(signed: bool, little_endian: bool) -> int: @lru_cache(maxsize=1024) -def fmt_to_datatype_v4( - fmt: dtype[Any], shape: tuple[int, ...], array: bool = False -) -> tuple[int, int]: +def fmt_to_datatype_v4(fmt: dtype[Any], shape: tuple[int, ...], array: bool = False) -> tuple[int, int]: """convert numpy dtype format string to mdf version 4 channel data type and size @@ -811,9 +795,7 @@ def fmt_to_datatype_v4( return data_type, size -def as_non_byte_sized_signed_int( - integer_array: NDArray[Any], bit_length: int -) -> NDArray[Any]: +def as_non_byte_sized_signed_int(integer_array: NDArray[Any], bit_length: int) -> NDArray[Any]: """ The MDF spec allows values to be encoded as integers that aren't byte-sized. Numpy only knows how to do two's complement on byte-sized @@ -839,14 +821,10 @@ def as_non_byte_sized_signed_int( integer_array &= (1 << bit_length) - 1 # Zero out the unwanted bits truncated_integers = integer_array else: - truncated_integers = integer_array & ( - (1 << bit_length) - 1 - ) # Zero out the unwanted bits + truncated_integers = integer_array & ((1 << bit_length) - 1) # Zero out the unwanted bits return where( - truncated_integers - >> bit_length - 1, # sign bit as a truth series (True when negative) - (2**bit_length - truncated_integers) - * -1, # when negative, do two's complement + truncated_integers >> bit_length - 1, # sign bit as a truth series (True when negative) + (2**bit_length - truncated_integers) * -1, # when negative, do two's complement truncated_integers, # when positive, return the truncated int ) @@ -953,21 +931,15 @@ def count_channel_groups( ch_count += 1 ch_addr = UINT64_uf(stream, ch_addr + 24)[0] if ch_addr >= file_limit: - raise MdfException( - f"File is a corrupted MDF file - Invalid CH block address" - ) + raise MdfException(f"File is a corrupted MDF file - Invalid CH block address") cg_addr = UINT64_uf(stream, cg_addr + 24)[0] if cg_addr >= file_limit: - raise MdfException( - f"File is a corrupted MDF file - Invalid CG block address" - ) + raise MdfException(f"File is a corrupted MDF file - Invalid CG block address") dg_addr = UINT64_uf(stream, dg_addr + 24)[0] if dg_addr >= file_limit: - raise MdfException( - f"File is a corrupted MDF file - Invalid DG block address" - ) + raise MdfException(f"File is a corrupted MDF file - Invalid DG block address") else: stream.seek(88, 0) dg_addr = UINT64_u(stream.read(8))[0] @@ -984,24 +956,18 @@ def count_channel_groups( stream.seek(ch_addr + 24) ch_addr = UINT64_u(stream.read(8))[0] if ch_addr >= file_limit: - raise MdfException( - f"File is a corrupted MDF file - Invalid CH block address" - ) + raise MdfException(f"File is a corrupted MDF file - Invalid CH block address") stream.seek(cg_addr + 24) cg_addr = UINT64_u(stream.read(8))[0] if cg_addr >= file_limit: - raise MdfException( - f"File is a corrupted MDF file - Invalid CG block address" - ) + raise MdfException(f"File is a corrupted MDF file - Invalid CG block address") stream.seek(dg_addr + 24) dg_addr = UINT64_u(stream.read(8))[0] if dg_addr >= file_limit: - raise MdfException( - f"File is a corrupted MDF file - Invalid DG block address" - ) + raise MdfException(f"File is a corrupted MDF file - Invalid DG block address") else: stream.seek(68, 0) @@ -1019,24 +985,18 @@ def count_channel_groups( stream.seek(ch_addr + 4) ch_addr = UINT32_u(stream.read(4))[0] if ch_addr >= file_limit: - raise MdfException( - f"File is a corrupted MDF file - Invalid CH block address" - ) + raise MdfException(f"File is a corrupted MDF file - Invalid CH block address") stream.seek(cg_addr + 4) cg_addr = UINT32_u(stream.read(4))[0] if cg_addr >= file_limit: - raise MdfException( - f"File is a corrupted MDF file - Invalid CG block address" - ) + raise MdfException(f"File is a corrupted MDF file - Invalid CG block address") stream.seek(dg_addr + 4) dg_addr = UINT32_u(stream.read(4))[0] if dg_addr >= file_limit: - raise MdfException( - f"File is a corrupted MDF file - Invalid DG block address" - ) + raise MdfException(f"File is a corrupted MDF file - Invalid DG block address") return count, ch_count @@ -1065,11 +1025,7 @@ def validate_version_argument(version: str, hint: int = 4) -> str: valid_version = "3.30" else: valid_version = "4.10" - message = ( - 'Unknown mdf version "{}".' - " The available versions are {};" - ' automatically using version "{}"' - ) + message = 'Unknown mdf version "{}".' " The available versions are {};" ' automatically using version "{}"' message = message.format(version, SUPPORTED_VERSIONS, valid_version) logger.warning(message) else: @@ -1493,9 +1449,7 @@ def components( if not only_basenames: name_ = unique_names.get_unique_name( - f"{prefix}.{channel_name}.{name}" - if prefix - else f"{channel_name}.{name}" + f"{prefix}.{channel_name}.{name}" if prefix else f"{channel_name}.{name}" ) else: name_ = unique_names.get_unique_name(name) @@ -1567,9 +1521,7 @@ def __init__( all_valid: bool = False, block_limit: int | None = None, ) -> None: - super().__init__( - address, block_type, original_size, compressed_size, param, block_limit - ) + super().__init__(address, block_type, original_size, compressed_size, param, block_limit) self.all_valid = all_valid def __repr__(self) -> str: @@ -1663,9 +1615,7 @@ def downcast(array: NDArray[Any]) -> NDArray[Any]: return array -def master_using_raster( - mdf: MDF_v2_v3_v4, raster: RasterType, endpoint: bool = False -) -> NDArray[Any]: +def master_using_raster(mdf: MDF_v2_v3_v4, raster: RasterType, endpoint: bool = False) -> NDArray[Any]: """get single master based on the raster Parameters @@ -1692,14 +1642,10 @@ def master_using_raster( group = mdf.groups[group_index] cycles_nr = group.channel_group.cycles_nr if cycles_nr: - master_min = mdf.get_master( - group_index, record_offset=0, record_count=1 - ) + master_min = mdf.get_master(group_index, record_offset=0, record_count=1) if len(master_min): t_min.append(master_min[0]) - master_max = mdf.get_master( - group_index, record_offset=cycles_nr - 1, record_count=1 - ) + master_max = mdf.get_master(group_index, record_offset=cycles_nr - 1, record_count=1) if len(master_max): t_max.append(master_max[0]) @@ -1800,9 +1746,7 @@ def pandas_query_compatible(name: str) -> str: return name -def load_can_database( - path: StrPathType, contents: bytes | str | None = None, **kwargs -) -> CanMatrix | None: +def load_can_database(path: StrPathType, contents: bytes | str | None = None, **kwargs) -> CanMatrix | None: """ @@ -1950,9 +1894,9 @@ def plausible_timestamps( """ exps = np.log10(t) - idx = (~np.isnan(t)) & (~np.isinf(t)) & (t >= minimum) & (t <= maximum) & ( - t == 0 - ) | ((exps >= exp_min) & (exps <= exp_max)) + idx = (~np.isnan(t)) & (~np.isinf(t)) & (t >= minimum) & (t <= maximum) & (t == 0) | ( + (exps >= exp_min) & (exps <= exp_max) + ) if not np.all(idx): all_ok = False return all_ok, idx @@ -1989,9 +1933,7 @@ def fix_comparison_name(data, disable_new_channels=None): else: if disable_new_channels is not None: item["enabled"] = not disable_new_channels - fix_comparison_name( - item["channels"], disable_new_channels=disable_new_channels - ) + fix_comparison_name(item["channels"], disable_new_channels=disable_new_channels) names = [] if data.hasFormat("application/octet-stream-asammdf"): @@ -2300,9 +2242,7 @@ def parse_c_functions(display): functions = {} virtual_channels = [] - for i, ch in enumerate( - parse_virtual_channels(dsp.find("VIRTUAL_CHANNEL")).values() - ): + for i, ch in enumerate(parse_virtual_channels(dsp.find("VIRTUAL_CHANNEL")).values()): virtual_channels.append( { "color": COLORS[i % len(COLORS)], @@ -2318,9 +2258,7 @@ def parse_c_functions(display): "triggering": "triggering_on_all", "triggering_value": "all", }, - "flags": int( - SignalFlags.computed | SignalFlags.user_defined_conversion - ), + "flags": int(SignalFlags.computed | SignalFlags.user_defined_conversion), "enabled": True, "fmt": "{}", "individual_axis": False, @@ -2336,9 +2274,7 @@ def parse_c_functions(display): } ) - functions[ - f"f_{ch['name']}" - ] = f"def f_{ch['name']}(arg1=0, t=0):\n return arg1" + functions[f"f_{ch['name']}"] = f"def f_{ch['name']}(arg1=0, t=0):\n return arg1" if virtual_channels: channels.append( @@ -2407,9 +2343,7 @@ def load_channel_names_from_file(file_name, lab_section=""): if window["type"] == "Plot": channels.extend(flatten_dsp(window["configuration"]["channels"])) elif window["type"] == "Numeric": - channels.extend( - [item["name"] for item in window["configuration"]["channels"]] - ) + channels.extend([item["name"] for item in window["configuration"]["channels"]]) elif window["type"] == "Tabular": channels.extend(window["configuration"]["channels"]) @@ -2457,12 +2391,7 @@ def load_lab(file): if "s" in locals(): s.append(line) - return { - name: channels - for name, channels in sections.items() - if channels - if name != "SETTINGS" - } + return {name: channels for name, channels in sections.items() if channels if name != "SETTINGS"} class SignalFlags(IntFlag): diff --git a/src/asammdf/blocks/v2_v3_blocks.py b/src/asammdf/blocks/v2_v3_blocks.py index 47902c3c5..0f76a6fbb 100644 --- a/src/asammdf/blocks/v2_v3_blocks.py +++ b/src/asammdf/blocks/v2_v3_blocks.py @@ -225,20 +225,14 @@ def __init__(self, **kwargs) -> None: if parsed_strings is None: addr = self.long_name_addr if addr: - self.name = get_text_v3( - address=addr, stream=stream, mapped=mapped - ) + self.name = get_text_v3(address=addr, stream=stream, mapped=mapped) else: - self.name = self.short_name.decode("latin-1").strip( - " \t\n\r\0" - ) + self.name = self.short_name.decode("latin-1").strip(" \t\n\r\0") addr = self.display_name_addr if addr: self.display_names = { - get_text_v3( - address=addr, stream=stream, mapped=mapped - ): "display_name", + get_text_v3(address=addr, stream=stream, mapped=mapped): "display_name", } else: @@ -271,13 +265,9 @@ def __init__(self, **kwargs) -> None: if parsed_strings is None: addr = self.long_name_addr if addr: - self.name = get_text_v3( - address=addr, stream=stream, mapped=mapped - ) + self.name = get_text_v3(address=addr, stream=stream, mapped=mapped) else: - self.name = self.short_name.decode("latin-1").strip( - " \t\n\r\0" - ) + self.name = self.short_name.decode("latin-1").strip(" \t\n\r\0") else: self.name, self.display_names = parsed_strings @@ -360,9 +350,7 @@ def __init__(self, **kwargs) -> None: self.source = source - self.comment = get_text_v3( - address=self.comment_addr, stream=stream, mapped=mapped - ) + self.comment = get_text_v3(address=self.comment_addr, stream=stream, mapped=mapped) else: stream.seek(address + 2) (size,) = UINT16_u(stream.read(2)) @@ -398,20 +386,14 @@ def __init__(self, **kwargs) -> None: if parsed_strings is None: addr = self.long_name_addr if addr: - self.name = get_text_v3( - address=addr, stream=stream, mapped=mapped - ) + self.name = get_text_v3(address=addr, stream=stream, mapped=mapped) else: - self.name = self.short_name.decode("latin-1").strip( - " \t\n\r\0" - ) + self.name = self.short_name.decode("latin-1").strip(" \t\n\r\0") addr = self.display_name_addr if addr: self.display_names = { - get_text_v3( - address=addr, stream=stream, mapped=mapped - ): "display_name", + get_text_v3(address=addr, stream=stream, mapped=mapped): "display_name", } else: @@ -444,13 +426,9 @@ def __init__(self, **kwargs) -> None: if parsed_strings is None: addr = self.long_name_addr if addr: - self.name = get_text_v3( - address=addr, stream=stream, mapped=mapped - ) + self.name = get_text_v3(address=addr, stream=stream, mapped=mapped) else: - self.name = self.short_name.decode("latin-1").strip( - " \t\n\r\0" - ) + self.name = self.short_name.decode("latin-1").strip(" \t\n\r\0") else: self.name, self.display_names = parsed_strings @@ -536,9 +514,7 @@ def __init__(self, **kwargs) -> None: source = None self.source = source - self.comment = get_text_v3( - address=self.comment_addr, stream=stream, mapped=mapped - ) + self.comment = get_text_v3(address=self.comment_addr, stream=stream, mapped=mapped) if self.id != b"CN": message = f'Expected "CN" block @{hex(address)} but found "{self.id}"' @@ -1013,9 +989,7 @@ def __init__(self, **kwargs) -> None: self.CANapeHiddenExtra = block[v23c.CC_LIN_BLOCK_SIZE - 4 :] size = len(self.CANapeHiddenExtra) nr = size // 40 - values = unpack_from( - "<" + "d32s" * nr, block, v23c.CC_COMMON_SHORT_SIZE - ) + values = unpack_from("<" + "d32s" * nr, block, v23c.CC_COMMON_SHORT_SIZE) for i in range(nr): (self[f"param_val_{i}"], self[f"text_{i}"]) = ( @@ -1028,11 +1002,7 @@ def __init__(self, **kwargs) -> None: elif conv_type == v23c.CONVERSION_TYPE_FORMULA: self.formula_field = block[v23c.CC_COMMON_SHORT_SIZE :] - self.formula = ( - self.formula_field.decode("latin-1") - .strip(" \t\r\n\0") - .replace("x", "X") - ) + self.formula = self.formula_field.decode("latin-1").strip(" \t\r\n\0").replace("x", "X") if "X1" not in self.formula: self.formula = self.formula.replace("X", "X1") @@ -1044,9 +1014,7 @@ def __init__(self, **kwargs) -> None: if block_size == v23c.MAX_UINT16: stream.seek(address) raw_bytes = stream.read(size) - conversion = ChannelConversion( - raw_bytes=raw_bytes, stream=stream, address=address - ) + conversion = ChannelConversion(raw_bytes=raw_bytes, stream=stream, address=address) conversion.block_len = size self.update(conversion) @@ -1084,9 +1052,7 @@ def __init__(self, **kwargs) -> None: if block_size == v23c.MAX_UINT16: stream.seek(address) raw_bytes = stream.read(size) - conversion = ChannelConversion( - raw_bytes=raw_bytes, stream=stream, address=address - ) + conversion = ChannelConversion(raw_bytes=raw_bytes, stream=stream, address=address) conversion.block_len = size for attr in get_fields(conversion): @@ -1095,9 +1061,7 @@ def __init__(self, **kwargs) -> None: self.referenced_blocks = conversion.referenced_blocks else: - values = unpack_from( - "<" + "d32s" * nr, block, v23c.CC_COMMON_SHORT_SIZE - ) + values = unpack_from("<" + "d32s" * nr, block, v23c.CC_COMMON_SHORT_SIZE) for i in range(nr): (self[f"param_val_{i}"], self[f"text_{i}"]) = ( @@ -1113,9 +1077,7 @@ def __init__(self, **kwargs) -> None: if block_size == v23c.MAX_UINT16: stream.seek(address) raw_bytes = stream.read(size) - conversion = ChannelConversion( - raw_bytes=raw_bytes, stream=stream, address=address - ) + conversion = ChannelConversion(raw_bytes=raw_bytes, stream=stream, address=address) conversion.block_len = size for attr in get_fields(conversion): @@ -1139,9 +1101,7 @@ def __init__(self, **kwargs) -> None: else: self.referenced_blocks["default_addr"] = b"" - values = unpack_from( - "<" + "2dI" * nr, block, v23c.CC_COMMON_SHORT_SIZE + 20 - ) + values = unpack_from("<" + "2dI" * nr, block, v23c.CC_COMMON_SHORT_SIZE + 20) for i in range(nr): (self[f"lower_{i}"], self[f"upper_{i}"], self[f"text_{i}"]) = ( @@ -1305,9 +1265,7 @@ def __init__(self, **kwargs) -> None: self[key] = 0 self.referenced_blocks[key] = kwargs[key] else: - message = ( - f'Conversion type "{kwargs["conversion_type"]}" not implemented' - ) + message = f'Conversion type "{kwargs["conversion_type"]}" not implemented' logger.exception(message) raise MdfException(message) @@ -1424,9 +1382,7 @@ def metadata(self, indent: str = "") -> str: lines.append(template.format(key, val)) if key == "conversion_type": - lines[ - -1 - ] += f" [{v23c.CONVERSION_TYPE_TO_STRING[self.conversion_type]}]" + lines[-1] += f" [{v23c.CONVERSION_TYPE_TO_STRING[self.conversion_type]}]" elif self.referenced_blocks and key in self.referenced_blocks: val = self.referenced_blocks[key] if isinstance(val, bytes): @@ -1451,9 +1407,7 @@ def metadata(self, indent: str = "") -> str: if not line: metadata.append(line) else: - for wrapped_line in wrap( - line, initial_indent=indent, subsequent_indent=indent, width=120 - ): + for wrapped_line in wrap(line, initial_indent=indent, subsequent_indent=indent, width=120): metadata.append(wrapped_line) return "\n".join(metadata) @@ -1492,9 +1446,7 @@ def convert(self, values, as_object=False, as_bytes=False): inds2 = inds - 1 inds2[inds2 < 0] = 0 - cond = np.abs(values - raw_vals[inds]) >= np.abs( - values - raw_vals[inds2] - ) + cond = np.abs(values - raw_vals[inds]) >= np.abs(values - raw_vals[inds2]) values = np.where(cond, phys[inds2], phys[inds]) @@ -1516,9 +1468,7 @@ def convert(self, values, as_object=False, as_bytes=False): idx = np.argwhere(idx1 != idx2).flatten() - new_values = np.zeros( - len(values), dtype=max(phys.dtype, np.array([default]).dtype) - ) + new_values = np.zeros(len(values), dtype=max(phys.dtype, np.array([default]).dtype)) new_values[idx] = default idx = np.argwhere(idx1 == idx2).flatten() @@ -1568,9 +1518,7 @@ def convert(self, values, as_object=False, as_bytes=False): else: if len(idx): - new_values = np.zeros( - len(values), dtype=max(phys.dtype, np.array([default]).dtype) - ) + new_values = np.zeros(len(values), dtype=max(phys.dtype, np.array([default]).dtype)) new_values[idx] = default idx = np.argwhere(idx1 == idx2).flatten() @@ -1679,9 +1627,7 @@ def __bytes__(self) -> bytes: if conv == v23c.CONVERSION_TYPE_NONE: fmt = v23c.FMT_CONVERSION_COMMON elif conv == v23c.CONVERSION_TYPE_FORMULA: - fmt = v23c.FMT_CONVERSION_FORMULA.format( - self.block_len - v23c.CC_COMMON_BLOCK_SIZE - ) + fmt = v23c.FMT_CONVERSION_FORMULA.format(self.block_len - v23c.CC_COMMON_BLOCK_SIZE) elif conv == v23c.CONVERSION_TYPE_LINEAR: fmt = v23c.FMT_CONVERSION_LINEAR if not self.block_len == v23c.CC_LIN_BLOCK_SIZE: @@ -1797,9 +1743,7 @@ def __init__(self, **kwargs) -> None: self.address = address = kwargs["address"] stream.seek(address) - (self.id, self.block_len, self.dependency_type, self.sd_nr) = unpack( - "<2s3H", stream.read(8) - ) + (self.id, self.block_len, self.dependency_type, self.sd_nr) = unpack("<2s3H", stream.read(8)) links_size = 3 * 4 * self.sd_nr links = unpack("<{}I".format(3 * self.sd_nr), stream.read(links_size)) @@ -1811,9 +1755,7 @@ def __init__(self, **kwargs) -> None: optional_dims_nr = (self.block_len - 8 - links_size) // 2 if optional_dims_nr: - dims = unpack( - f"<{optional_dims_nr}H", stream.read(optional_dims_nr * 2) - ) + dims = unpack(f"<{optional_dims_nr}H", stream.read(optional_dims_nr * 2)) for i, dim in enumerate(dims): self[f"dim_{i}"] = dim @@ -1936,9 +1878,7 @@ def __init__(self, **kwargs) -> None: if "stream" in kwargs: stream = kwargs["stream"] try: - (self.id, self.block_len, self.type) = SOURCE_COMMON_uf( - kwargs["raw_bytes"] - ) + (self.id, self.block_len, self.type) = SOURCE_COMMON_uf(kwargs["raw_bytes"]) if self.type == v23c.SOURCE_ECU: ( self.module_nr, @@ -1961,9 +1901,7 @@ def __init__(self, **kwargs) -> None: if kwargs.get("mapped", False): self.address = address = kwargs["address"] - (self.id, self.block_len, self.type) = SOURCE_COMMON_uf( - stream, address - ) + (self.id, self.block_len, self.type) = SOURCE_COMMON_uf(stream, address) if self.type == v23c.SOURCE_ECU: ( @@ -2031,15 +1969,11 @@ def __init__(self, **kwargs) -> None: if self.type == v23c.SOURCE_ECU: self.path = self.ECU_identification.decode("latin-1").strip(" \t\n\r\0") self.name = self.description.decode("latin-1").strip(" \t\n\r\0") - self.comment = ( - f"Module number={self.module_nr} @ address={self.module_address}" - ) + self.comment = f"Module number={self.module_nr} @ address={self.module_address}" else: self.path = self.sender_name.decode("latin-1").strip(" \t\n\r\0") self.name = self.message_name.decode("latin-1").strip(" \t\n\r\0") - self.comment = ( - f"Message ID={hex(self.CAN_id)} on CAN bus {self.CAN_ch_index}" - ) + self.comment = f"Message ID={hex(self.CAN_id)} on CAN bus {self.CAN_ch_index}" def to_blocks( self, @@ -2281,9 +2215,7 @@ def __init__(self, **kwargs) -> None: raise MdfException(message.format(self.id)) if self.comment_addr: - self.comment = get_text_v3( - address=self.comment_addr, stream=stream, mapped=mapped - ) + self.comment = get_text_v3(address=self.comment_addr, stream=stream, mapped=mapped) except KeyError: self.address = 0 self.id = b"CG" @@ -2523,9 +2455,7 @@ def __init__(self, **kwargs) -> None: if self.block_len == v23c.DG_POST_320_BLOCK_SIZE: self.reserved0 = stream[ - address - + v23c.DG_PRE_320_BLOCK_SIZE : address - + v23c.DG_POST_320_BLOCK_SIZE + address + v23c.DG_PRE_320_BLOCK_SIZE : address + v23c.DG_POST_320_BLOCK_SIZE ] else: stream.seek(address) @@ -2652,14 +2582,8 @@ def __init__(self, **kwargs) -> None: version = kwargs["version"] self.file_identification = "MDF ".encode("latin-1") self.version_str = version.encode("latin-1") + b"\0" * 4 - self.program_identification = "amdf{}".format( - __version__.replace(".", "") - ).encode("latin-1") - self.byte_order = ( - v23c.BYTE_ORDER_INTEL - if sys.byteorder == "little" - else v23c.BYTE_ORDER_MOTOROLA - ) + self.program_identification = "amdf{}".format(__version__.replace(".", "")).encode("latin-1") + self.byte_order = v23c.BYTE_ORDER_INTEL if sys.byteorder == "little" else v23c.BYTE_ORDER_MOTOROLA self.float_format = 0 self.mdf_version = int(version.replace(".", "")) self.code_page = 0 @@ -2766,9 +2690,7 @@ def __init__(self, **kwargs) -> None: ) if self.id != b"HD": - message = ( - f'Expected "HD" block @{hex(self.address)} but found "{self.id}"' - ) + message = f'Expected "HD" block @{hex(self.address)} but found "{self.id}"' message = message.format(hex(64), self.id) logger.exception(message) raise MdfException(message) @@ -2797,9 +2719,7 @@ def __init__(self, **kwargs) -> None: if self.block_len > v23c.HEADER_COMMON_SIZE: self.time_quality = 0 - self.timer_identification = "{:\0<32}".format( - "Local PC Reference Time" - ).encode("latin-1") + self.timer_identification = "{:\0<32}".format("Local PC Reference Time").encode("latin-1") self.start_time = datetime(1980, 1, 1, tzinfo=timezone.utc) @@ -2835,9 +2755,7 @@ def comment(self, string): if string.startswith(" datetime: try: timestamp = datetime.fromtimestamp(timestamp, tz) except OverflowError: - timestamp = datetime.fromtimestamp(0, tz) + timedelta( - seconds=timestamp - ) + timestamp = datetime.fromtimestamp(0, tz) + timedelta(seconds=timestamp) except OSError: timestamp = datetime.now(tz) else: - timestamp = "{} {}".format( - self.date.decode("ascii"), self.time.decode("ascii") - ) + timestamp = "{} {}".format(self.date.decode("ascii"), self.time.decode("ascii")) - timestamp = datetime.strptime( - timestamp, "%d:%m:%Y %H:%M:%S" - ).astimezone(timezone.utc) + timestamp = datetime.strptime(timestamp, "%d:%m:%Y %H:%M:%S").astimezone(timezone.utc) else: - timestamp = "{} {}".format( - self.date.decode("ascii"), self.time.decode("ascii") - ) + timestamp = "{} {}".format(self.date.decode("ascii"), self.time.decode("ascii")) - timestamp = datetime.strptime( - timestamp, "%d:%m:%Y %H:%M:%S" - ).astimezone(timezone.utc) + timestamp = datetime.strptime(timestamp, "%d:%m:%Y %H:%M:%S").astimezone(timezone.utc) except: return datetime.now().astimezone(timezone.utc) @@ -2998,9 +2906,7 @@ def start_time(self, timestamp: datetime) -> None: self.date = timestamp.strftime("%d:%m:%Y").encode("ascii") self.time = timestamp.strftime("%H:%M:%S").encode("ascii") if self.block_len > v23c.HEADER_COMMON_SIZE: - self.tz_offset = int( - timestamp.tzinfo.utcoffset(timestamp).total_seconds() / 3600 - ) + self.tz_offset = int(timestamp.tzinfo.utcoffset(timestamp).total_seconds() / 3600) timestamp = int(timestamp.timestamp() * 10**9) self.abs_time = timestamp @@ -3024,9 +2930,7 @@ def start_time_string(self): if self.block_len > v23c.HEADER_COMMON_SIZE: if self.abs_time: tz_offset_sign = "-" if self.tz_offset < 0 else "+" - tz_information = ( - f"[GMT{tz_offset_sign}{abs(self.tz_offset):.2f} DST+{0:.2f}h]" - ) + tz_information = f"[GMT{tz_offset_sign}{abs(self.tz_offset):.2f} DST+{0:.2f}h]" start_time = f'local time = {self.start_time.strftime("%d-%b-%Y %H:%M:%S + %fu")} {tz_information}' return start_time @@ -3148,9 +3052,7 @@ def __init__(self, **kwargs) -> None: if mapped: (self.id, self.block_len) = COMMON_uf(stream, address) if self.id != b"TX": - message = ( - f'Expected "TX" block @{hex(address)} but found "{self.id}"' - ) + message = f'Expected "TX" block @{hex(address)} but found "{self.id}"' logger.exception(message) raise MdfException(message) @@ -3159,9 +3061,7 @@ def __init__(self, **kwargs) -> None: stream.seek(address) (self.id, self.block_len) = COMMON_u(stream.read(4)) if self.id != b"TX": - message = ( - f'Expected "TX" block @{hex(address)} but found "{self.id}"' - ) + message = f'Expected "TX" block @{hex(address)} but found "{self.id}"' logger.exception(message) raise MdfException(message) @@ -3195,11 +3095,7 @@ def __bytes__(self) -> bytes: return v23c.COMMON_p(self.id, self.block_len) + self.text def __repr__(self) -> str: - return ( - f"TextBlock(id={self.id}," - f"block_len={self.block_len}, " - f"text={self.text})" - ) + return f"TextBlock(id={self.id}," f"block_len={self.block_len}, " f"text={self.text})" class TriggerBlock: @@ -3247,9 +3143,7 @@ def __init__(self, **kwargs) -> None: stream.seek(address) block = stream.read(size) - (self.id, self.block_len, self.text_addr, self.trigger_events_nr) = unpack( - "<2sHIH", block[:10] - ) + (self.id, self.block_len, self.text_addr, self.trigger_events_nr) = unpack("<2sHIH", block[:10]) nr = self.trigger_events_nr if nr: diff --git a/src/asammdf/blocks/v4_blocks.py b/src/asammdf/blocks/v4_blocks.py index 78da1ff61..de43ec44a 100644 --- a/src/asammdf/blocks/v4_blocks.py +++ b/src/asammdf/blocks/v4_blocks.py @@ -295,9 +295,7 @@ def extract(self) -> bytes: else: logger.warning("external attachments not supported") - def to_blocks( - self, address: int, blocks: list[Any], defined_texts: dict[str, int] - ) -> int: + def to_blocks(self, address: int, blocks: list[Any], defined_texts: dict[str, int]) -> int: text = self.file_name if text: if text in defined_texts: @@ -512,14 +510,10 @@ def __init__(self, **kwargs) -> None: mapped = kwargs["mapped"] if mapped: - (self.id, self.reserved0, self.block_len, self.links_nr) = COMMON_uf( - stream, address - ) + (self.id, self.reserved0, self.block_len, self.links_nr) = COMMON_uf(stream, address) if self.id != b"##CN": - message = ( - f'Expected "##CN" block @{hex(address)} but found "{self.id}"' - ) + message = f'Expected "##CN" block @{hex(address)} but found "{self.id}"' logger.exception(message) raise MdfException(message) @@ -580,9 +574,7 @@ def __init__(self, **kwargs) -> None: self.upper_limit, self.lower_ext_limit, self.upper_ext_limit, - ) = SINGLE_ATTACHMENT_CHANNEL_PARAMS_uf( - stream, address + COMMON_SIZE - ) + ) = SINGLE_ATTACHMENT_CHANNEL_PARAMS_uf(stream, address + COMMON_SIZE) self.attachment = kwargs["at_map"].get(self.attachment_addr, 0) @@ -736,14 +728,10 @@ def __init__(self, **kwargs) -> None: block = stream.read(CN_SINGLE_ATTACHMENT_BLOCK_SIZE) - (self.id, self.reserved0, self.block_len, self.links_nr) = COMMON_uf( - block - ) + (self.id, self.reserved0, self.block_len, self.links_nr) = COMMON_uf(block) if self.id != b"##CN": - message = ( - f'Expected "##CN" block @{hex(address)} but found "{self.id}"' - ) + message = f'Expected "##CN" block @{hex(address)} but found "{self.id}"' logger.exception(message) raise MdfException(message) @@ -1095,17 +1083,13 @@ def to_blocks( elif display_names_tags and comment: if not comment.startswith(" None: mapped = kwargs.get("mapped", False) or not is_file_like(stream) if mapped: - (self.id, self.reserved0, self.block_len, self.links_nr) = COMMON_uf( - stream, address - ) + (self.id, self.reserved0, self.block_len, self.links_nr) = COMMON_uf(stream, address) if self.id != b"##CA": - message = ( - f'Expected "##CA" block @{hex(address)} but found "{self.id}"' - ) + message = f'Expected "##CA" block @{hex(address)} but found "{self.id}"' logger.exception(message) raise MdfException(message) @@ -1518,9 +1498,7 @@ def __init__(self, **kwargs) -> None: self[f"axis_conversion_{i}"] = links[i] links = links[dims_nr:] - if (self.flags & v4c.FLAG_CA_AXIS) and not ( - self.flags & v4c.FLAG_CA_FIXED_AXIS - ): + if (self.flags & v4c.FLAG_CA_AXIS) and not (self.flags & v4c.FLAG_CA_FIXED_AXIS): for i in range(dims_nr): self[f"scale_axis_{i}_dg_addr"] = links[3 * i] self[f"scale_axis_{i}_cg_addr"] = links[3 * i + 1] @@ -1536,14 +1514,10 @@ def __init__(self, **kwargs) -> None: else: stream.seek(address) - (self.id, self.reserved0, self.block_len, self.links_nr) = unpack( - "<4sI2Q", stream.read(24) - ) + (self.id, self.reserved0, self.block_len, self.links_nr) = unpack("<4sI2Q", stream.read(24)) if self.id != b"##CA": - message = ( - f'Expected "##CA" block @{hex(address)} but found "{self.id}"' - ) + message = f'Expected "##CA" block @{hex(address)} but found "{self.id}"' logger.exception(message) raise MdfException(message) @@ -1609,9 +1583,7 @@ def __init__(self, **kwargs) -> None: self[f"axis_conversion_{i}"] = links[i] links = links[dims_nr:] - if (self.flags & v4c.FLAG_CA_AXIS) and not ( - self.flags & v4c.FLAG_CA_FIXED_AXIS - ): + if (self.flags & v4c.FLAG_CA_AXIS) and not (self.flags & v4c.FLAG_CA_FIXED_AXIS): for i in range(dims_nr): self[f"scale_axis_{i}_dg_addr"] = links[3 * i] self[f"scale_axis_{i}_cg_addr"] = links[3 * i + 1] @@ -1676,9 +1648,7 @@ def __init__(self, **kwargs) -> None: self[f"dim_size_{i}"] = kwargs[f"dim_size_{i}"] for i in range(dims_nr): for j in range(self[f"dim_size_{i}"]): - self[f"axis_{i}_value_{j}"] = kwargs.get( - f"axis_{i}_value_{j}", j - ) + self[f"axis_{i}_value_{j}"] = kwargs.get(f"axis_{i}_value_{j}", j) else: self.block_len = 48 + dims_nr * 5 * 8 self.links_nr = 1 + dims_nr * 4 @@ -1787,22 +1757,14 @@ def __bytes__(self) -> bytes: keys += tuple(f"dim_size_{i}" for i in range(dims_nr)) if flags & v4c.FLAG_CA_FIXED_AXIS: - keys += tuple( - f"axis_{i}_value_{j}" - for i in range(dims_nr) - for j in range(self[f"dim_size_{i}"]) - ) + keys += tuple(f"axis_{i}_value_{j}" for i in range(dims_nr) for j in range(self[f"dim_size_{i}"])) - dim_sizes = [ - 1 for i in range(dims_nr) for j in range(self[f"dim_size_{i}"]) - ] + dim_sizes = [1 for i in range(dims_nr) for j in range(self[f"dim_size_{i}"])] if self.storage: keys += tuple(f"cycle_count_{i}" for i in range(data_links_nr)) - fmt = "<4sI{}Q2BHIiI{}Q{}d{}Q".format( - self.links_nr + 2, dims_nr, sum(dim_sizes), data_links_nr - ) + fmt = "<4sI{}Q2BHIiI{}Q{}d{}Q".format(self.links_nr + 2, dims_nr, sum(dim_sizes), data_links_nr) result = pack(fmt, *[getattr(self, key) for key in keys]) return result @@ -1885,9 +1847,7 @@ def __init__(self, **kwargs) -> None: mapped = kwargs.get("mapped", False) or not is_file_like(stream) if mapped: - (self.id, self.reserved0, self.block_len, self.links_nr) = COMMON_uf( - stream, address - ) + (self.id, self.reserved0, self.block_len, self.links_nr) = COMMON_uf(stream, address) if self.block_len == v4c.CG_BLOCK_SIZE: ( @@ -1949,9 +1909,7 @@ def __init__(self, **kwargs) -> None: self.reserved1, self.samples_byte_nr, self.invalidation_bytes_nr, - ) = v4c.CHANNEL_GROUP_SHORT_u( - stream.read(v4c.CG_BLOCK_SIZE - COMMON_SIZE) - ) + ) = v4c.CHANNEL_GROUP_SHORT_u(stream.read(v4c.CG_BLOCK_SIZE - COMMON_SIZE)) else: ( @@ -1969,9 +1927,7 @@ def __init__(self, **kwargs) -> None: self.reserved1, self.samples_byte_nr, self.invalidation_bytes_nr, - ) = v4c.CHANNEL_GROUP_RM_SHORT_u( - stream.read(v4c.CG_RM_BLOCK_SIZE - COMMON_SIZE) - ) + ) = v4c.CHANNEL_GROUP_RM_SHORT_u(stream.read(v4c.CG_RM_BLOCK_SIZE - COMMON_SIZE)) if self.id != b"##CG": message = f'Expected "##CG" block @{hex(address)} but found "{self.id}"' @@ -2015,9 +1971,7 @@ def __init__(self, **kwargs) -> None: self.first_ch_addr = kwargs.get("first_ch_addr", 0) self.acq_name_addr = kwargs.get("acq_name_addr", 0) self.acq_source_addr = kwargs.get("acq_source_addr", 0) - self.first_sample_reduction_addr = kwargs.get( - "first_sample_reduction_addr", 0 - ) + self.first_sample_reduction_addr = kwargs.get("first_sample_reduction_addr", 0) self.comment_addr = kwargs.get("comment_addr", 0) self.record_id = kwargs.get("record_id", 1) self.cycles_nr = kwargs.get("cycles_nr", 0) @@ -2354,14 +2308,10 @@ def __init__(self, **kwargs) -> None: try: self.address = address = kwargs["address"] block = kwargs["raw_bytes"] - (self.id, self.reserved0, self.block_len, self.links_nr) = COMMON_uf( - block - ) + (self.id, self.reserved0, self.block_len, self.links_nr) = COMMON_uf(block) if self.id != b"##CC": - message = ( - f'Expected "##CC" block @{hex(address)} but found "{self.id}"' - ) + message = f'Expected "##CC" block @{hex(address)} but found "{self.id}"' logger.exception(message) raise MdfException(message) @@ -2371,14 +2321,10 @@ def __init__(self, **kwargs) -> None: self.address = address = kwargs["address"] stream.seek(address) - (self.id, self.reserved0, self.block_len, self.links_nr) = COMMON_u( - stream.read(COMMON_SIZE) - ) + (self.id, self.reserved0, self.block_len, self.links_nr) = COMMON_u(stream.read(COMMON_SIZE)) if self.id != b"##CC": - message = ( - f'Expected "##CC" block @{hex(address)} but found "{self.id}"' - ) + message = f'Expected "##CC" block @{hex(address)} but found "{self.id}"' logger.exception(message) raise MdfException(message) @@ -2556,9 +2502,7 @@ def __init__(self, **kwargs) -> None: self.max_phy_value, ) = unpack_from("<2B3H2d", block, 32 + links_nr * 8) - values = unpack_from( - f"<{self.val_param_nr}d", block, 32 + links_nr * 8 + 24 - ) + values = unpack_from(f"<{self.val_param_nr}d", block, 32 + links_nr * 8 + 24) self.default_lower = self.default_upper = 0 for i in range(self.val_param_nr // 2): j = 2 * i @@ -2589,9 +2533,7 @@ def __init__(self, **kwargs) -> None: self.max_phy_value, ) = unpack_from("<2B3H2d", block, 32 + links_nr * 8) - values = unpack_from( - f"<{self.val_param_nr}d", block, 32 + links_nr * 8 + 24 - ) + values = unpack_from(f"<{self.val_param_nr}d", block, 32 + links_nr * 8 + 24) for i, val in enumerate(values[:-1]): self[f"val_{i}"] = val self.val_default = values[-1] @@ -2648,9 +2590,7 @@ def __init__(self, **kwargs) -> None: self.max_phy_value, ) = unpack_from("<2B3H2d", block, 32 + links_nr * 8) - values = unpack_from( - f"<{self.val_param_nr}Q", block, 32 + links_nr * 8 + 24 - ) + values = unpack_from(f"<{self.val_param_nr}Q", block, 32 + links_nr * 8 + 24) for i, val in enumerate(values): self[f"mask_{i}"] = val @@ -2685,9 +2625,7 @@ def __init__(self, **kwargs) -> None: conv_type = conv if conv_type == v4c.CONVERSION_TYPE_ALG: - self.formula = get_text_v4( - self.formula_addr, stream, mapped=mapped - ).replace("x", "X") + self.formula = get_text_v4(self.formula_addr, stream, mapped=mapped).replace("x", "X") else: self.formula = "" @@ -2989,12 +2927,8 @@ def __init__(self, **kwargs) -> None: else: default = kwargs.get("default", b"") if isinstance(default, bytes) and b"{X}" in default: - default = ( - default.decode("latin-1").replace("{X}", "X").split('"')[1] - ) - default = ChannelConversion( - conversion_type=v4c.CONVERSION_TYPE_ALG, formula=default - ) + default = default.decode("latin-1").replace("{X}", "X").split('"')[1] + default = ChannelConversion(conversion_type=v4c.CONVERSION_TYPE_ALG, formula=default) self.referenced_blocks["default_addr"] = default else: self.referenced_blocks["default_addr"] = default @@ -3147,9 +3081,7 @@ def to_blocks( for key, block in self.referenced_blocks.items(): if block: if isinstance(block, ChannelConversion): - address = block.to_blocks( - address, blocks, defined_texts, cc_map - ) + address = block.to_blocks(address, blocks, defined_texts, cc_map) self[key] = block.address else: text = block @@ -3201,10 +3133,7 @@ def convert(self, values, as_object=False, as_bytes=False): values = np.core.records.fromarrays( [vals] + [values[name] for name in names[1:]], dtype=[(name, vals.dtype, vals.shape[1:])] - + [ - (name, values[name].dtype, values[name].shape[1:]) - for name in names[1:] - ], + + [(name, values[name].dtype, values[name].shape[1:]) for name in names[1:]], ) else: @@ -3246,10 +3175,7 @@ def convert(self, values, as_object=False, as_bytes=False): values = np.core.records.fromarrays( [vals] + [values[name] for name in names[1:]], dtype=[(name, vals.dtype, vals.shape[1:])] - + [ - (name, values[name].dtype, values[name].shape[1:]) - for name in names[1:] - ], + + [(name, values[name].dtype, values[name].shape[1:]) for name in names[1:]], ) else: @@ -3268,9 +3194,7 @@ def convert(self, values, as_object=False, as_bytes=False): try: values = evaluate(v4c.CONV_RAT_TEXT) except TypeError: - values = (P1 * X**2 + P2 * X + P3) / ( - P4 * X**2 + P5 * X + P6 - ) + values = (P1 * X**2 + P2 * X + P3) / (P4 * X**2 + P5 * X + P6) elif conversion_type == v4c.CONVERSION_TYPE_ALG: X = values @@ -3296,9 +3220,7 @@ def convert(self, values, as_object=False, as_bytes=False): inds2 = inds - 1 inds2[inds2 < 0] = 0 - cond = np.abs(values - raw_vals[inds]) >= np.abs( - values - raw_vals[inds2] - ) + cond = np.abs(values - raw_vals[inds]) >= np.abs(values - raw_vals[inds2]) values = np.where(cond, phys[inds2], phys[inds]) @@ -3391,12 +3313,7 @@ def convert(self, values, as_object=False, as_bytes=False): if as_bytes: ret = ret.astype(bytes) elif not as_object: - ret = np.array( - [ - np.nan if isinstance(v, bytes) else v - for v in ret.tolist() - ] - ) + ret = np.array([np.nan if isinstance(v, bytes) else v for v in ret.tolist()]) else: ret = ret.astype(bytes) @@ -3405,10 +3322,7 @@ def convert(self, values, as_object=False, as_bytes=False): values = np.core.records.fromarrays( [ret] + [values[name] for name in names[1:]], dtype=[(name, ret.dtype, ret.shape[1:])] - + [ - (name, values[name].dtype, values[name].shape[1:]) - for name in names[1:] - ], + + [(name, values[name].dtype, values[name].shape[1:]) for name in names[1:]], ) else: ret = np.full(values.size, None, "O") @@ -3473,12 +3387,7 @@ def convert(self, values, as_object=False, as_bytes=False): if as_bytes: ret = ret.astype(bytes) elif not as_object: - ret = np.array( - [ - np.nan if isinstance(v, bytes) else v - for v in ret.tolist() - ] - ) + ret = np.array([np.nan if isinstance(v, bytes) else v for v in ret.tolist()]) else: ret = ret.astype(bytes) @@ -3543,9 +3452,7 @@ def convert(self, values, as_object=False, as_bytes=False): if as_bytes: ret = ret.astype(bytes) elif not as_object: - ret = np.array( - [np.nan if isinstance(v, bytes) else v for v in ret] - ) + ret = np.array([np.nan if isinstance(v, bytes) else v for v in ret]) else: ret = np.array(ret, dtype=bytes) @@ -3554,10 +3461,7 @@ def convert(self, values, as_object=False, as_bytes=False): values = np.core.records.fromarrays( [ret] + [values[name] for name in names[1:]], dtype=[(name, ret.dtype, ret.shape[1:])] - + [ - (name, values[name].dtype, values[name].shape[1:]) - for name in names[1:] - ], + + [(name, values[name].dtype, values[name].shape[1:]) for name in names[1:]], ) else: ret = [] @@ -3593,12 +3497,7 @@ def convert(self, values, as_object=False, as_bytes=False): if as_bytes: ret = ret.astype(bytes) elif not as_object: - ret = np.array( - [ - np.nan if isinstance(v, bytes) else v - for v in ret.tolist() - ] - ) + ret = np.array([np.nan if isinstance(v, bytes) else v for v in ret.tolist()]) else: ret = np.array(ret, dtype=bytes) @@ -3673,12 +3572,7 @@ def convert(self, values, as_object=False, as_bytes=False): if as_bytes: ret = ret.astype(bytes) elif not as_object: - ret = np.array( - [ - np.nan if isinstance(v, bytes) else v - for v in ret.tolist() - ] - ) + ret = np.array([np.nan if isinstance(v, bytes) else v for v in ret.tolist()]) else: ret = ret.astype(bytes) @@ -3768,12 +3662,7 @@ def convert(self, values, as_object=False, as_bytes=False): if as_bytes: ret = ret.astype(bytes) elif not as_object: - ret = np.array( - [ - np.nan if isinstance(v, bytes) else v - for v in ret.tolist() - ] - ) + ret = np.array([np.nan if isinstance(v, bytes) else v for v in ret.tolist()]) else: ret = np.array(ret, dtype=bytes) @@ -3823,11 +3712,7 @@ def convert(self, values, as_object=False, as_bytes=False): phys = [ conv if isinstance(conv, bytes) - else ( - (f"{conv.name}=".encode("utf-8"), conv) - if conv.name - else (b"", conv) - ) + else ((f"{conv.name}=".encode("utf-8"), conv) if conv.name else (b"", conv)) for conv in phys ] @@ -4050,9 +3935,7 @@ def metadata(self, indent: str = "") -> str: if not line: metadata.append(line) else: - for wrapped_line in wrap( - line, initial_indent=indent, subsequent_indent=indent, width=120 - ): + for wrapped_line in wrap(line, initial_indent=indent, subsequent_indent=indent, width=120): metadata.append(wrapped_line) return "\n".join(metadata) @@ -4346,12 +4229,12 @@ def __init__(self, **kwargs) -> None: mapped = kwargs.get("mapped", False) or not is_file_like(stream) if mapped: - (self.id, self.reserved0, self.block_len, self.links_nr) = COMMON_uf( - stream, address - ) + (self.id, self.reserved0, self.block_len, self.links_nr) = COMMON_uf(stream, address) if self.id not in (b"##DT", b"##RD", b"##SD", b"##DV", b"##DI"): - message = f'Expected "##DT", "##DV", "##DI", "##RD" or "##SD" block @{hex(address)} but found "{self.id}"' + message = ( + f'Expected "##DT", "##DV", "##DI", "##RD" or "##SD" block @{hex(address)} but found "{self.id}"' + ) logger.exception(message) raise MdfException(message) @@ -4359,12 +4242,12 @@ def __init__(self, **kwargs) -> None: else: stream.seek(address) - (self.id, self.reserved0, self.block_len, self.links_nr) = COMMON_u( - stream.read(COMMON_SIZE) - ) + (self.id, self.reserved0, self.block_len, self.links_nr) = COMMON_u(stream.read(COMMON_SIZE)) if self.id not in (b"##DT", b"##RD", b"##SD", b"##DV", b"##DI"): - message = f'Expected "##DT", "##DV", "##DI", "##RD" or "##SD" block @{hex(address)} but found "{self.id}"' + message = ( + f'Expected "##DT", "##DV", "##DI", "##RD" or "##SD" block @{hex(address)} but found "{self.id}"' + ) logger.exception(message) raise MdfException(message) @@ -4389,10 +4272,7 @@ def __setitem__(self, item: str, value: Any) -> None: self.__setattr__(item, value) def __bytes__(self) -> bytes: - return ( - v4c.COMMON_p(self.id, self.reserved0, self.block_len, self.links_nr) - + self.data - ) + return v4c.COMMON_p(self.id, self.reserved0, self.block_len, self.links_nr) + self.data class DataZippedBlock(object): @@ -4517,19 +4397,11 @@ def __setattr__(self, item: str, value: Any) -> None: if lines * cols < original_size: data = memoryview(data) data = ( - np.frombuffer(data[: lines * cols], dtype="B") - .reshape((lines, cols)) - .T.ravel() - .tobytes() + np.frombuffer(data[: lines * cols], dtype="B").reshape((lines, cols)).T.ravel().tobytes() ) + data[lines * cols :] else: - data = ( - np.frombuffer(data, dtype=np.uint8) - .reshape((lines, cols)) - .T.ravel() - .tobytes() - ) + data = np.frombuffer(data, dtype=np.uint8).reshape((lines, cols)).T.ravel().tobytes() data = compress(data, COMPRESSION_LEVEL) zipped_size = len(data) @@ -4560,12 +4432,7 @@ def __getattribute__(self, item: str) -> Any: .tobytes() ) + data[lines * cols :] else: - data = ( - np.frombuffer(data, dtype=np.uint8) - .reshape((cols, lines)) - .T.ravel() - .tobytes() - ) + data = np.frombuffer(data, dtype=np.uint8).reshape((cols, lines)).T.ravel().tobytes() else: data = DataZippedBlock.__dict__[item].__get__(self) value = data @@ -4723,9 +4590,7 @@ def copy(self) -> DataGroup: return dg - def to_blocks( - self, address: int, blocks: list[Any], defined_texts: dict[str, int] - ) -> int: + def to_blocks(self, address: int, blocks: list[Any], defined_texts: dict[str, int]) -> int: text = self.comment if text: if text in defined_texts: @@ -4825,14 +4690,10 @@ def __init__(self, **kwargs) -> None: mapped = kwargs.get("mapped", False) or not is_file_like(stream) if mapped: - (self.id, self.reserved0, self.block_len, self.links_nr) = COMMON_uf( - stream, address - ) + (self.id, self.reserved0, self.block_len, self.links_nr) = COMMON_uf(stream, address) if self.id != b"##DL": - message = ( - f'Expected "##DL" block @{hex(address)} but found "{self.id}"' - ) + message = f'Expected "##DL" block @{hex(address)} but found "{self.id}"' logger.exception(message) raise MdfException(message) @@ -4850,13 +4711,9 @@ def __init__(self, **kwargs) -> None: self.flags = stream.read(1)[0] if self.flags & v4c.FLAG_DL_EQUAL_LENGHT: - (self.reserved1, self.data_block_nr, self.data_block_len) = unpack( - "<3sIQ", stream.read(15) - ) + (self.reserved1, self.data_block_nr, self.data_block_len) = unpack("<3sIQ", stream.read(15)) else: - (self.reserved1, self.data_block_nr) = unpack( - "<3sI", stream.read(7) - ) + (self.reserved1, self.data_block_nr) = unpack("<3sI", stream.read(7)) offsets = unpack( "<{}Q".format(self.links_nr - 1), stream.read((self.links_nr - 1) * 8), @@ -4866,14 +4723,10 @@ def __init__(self, **kwargs) -> None: else: stream.seek(address) - (self.id, self.reserved0, self.block_len, self.links_nr) = COMMON_u( - stream.read(COMMON_SIZE) - ) + (self.id, self.reserved0, self.block_len, self.links_nr) = COMMON_u(stream.read(COMMON_SIZE)) if self.id != b"##DL": - message = ( - f'Expected "##DL" block @{hex(address)} but found "{self.id}"' - ) + message = f'Expected "##DL" block @{hex(address)} but found "{self.id}"' logger.exception(message) raise MdfException(message) @@ -4887,13 +4740,9 @@ def __init__(self, **kwargs) -> None: self.flags = stream.read(1)[0] if self.flags & v4c.FLAG_DL_EQUAL_LENGHT: - (self.reserved1, self.data_block_nr, self.data_block_len) = unpack( - "<3sIQ", stream.read(15) - ) + (self.reserved1, self.data_block_nr, self.data_block_len) = unpack("<3sIQ", stream.read(15)) else: - (self.reserved1, self.data_block_nr) = unpack( - "<3sI", stream.read(7) - ) + (self.reserved1, self.data_block_nr) = unpack("<3sI", stream.read(7)) offsets = unpack( "<{}Q".format(self.links_nr - 1), stream.read((self.links_nr - 1) * 8), @@ -4918,9 +4767,7 @@ def __init__(self, **kwargs) -> None: if self.flags & v4c.FLAG_DL_EQUAL_LENGHT: self.data_block_len = kwargs["data_block_len"] else: - self.block_len = ( - 40 + 8 * kwargs.get("links_nr", 2) - 8 + 8 * self.data_block_nr - ) + self.block_len = 40 + 8 * kwargs.get("links_nr", 2) - 8 + 8 * self.data_block_nr for i in range(self.data_block_nr): self[f"offset_{i}"] = kwargs[f"offset_{i}"] @@ -5039,9 +4886,7 @@ def __init__(self, **kwargs) -> None: stream = kwargs["stream"] stream.seek(address) - (self.id, self.reserved0, self.block_len, self.links_nr) = COMMON_u( - stream.read(COMMON_SIZE) - ) + (self.id, self.reserved0, self.block_len, self.links_nr) = COMMON_u(stream.read(COMMON_SIZE)) block = stream.read(self.block_len - COMMON_SIZE) @@ -5138,10 +4983,7 @@ def update_references(self, ch_map, cg_map): elif addr in cg_map: self.scopes.append(cg_map[addr]) else: - message = ( - "{} is not a valid CNBLOCK or CGBLOCK " - "address for the event scope" - ) + message = "{} is not a valid CNBLOCK or CGBLOCK " "address for the event scope" message = message.format(hex(addr)) logger.exception(message) raise MdfException(message) @@ -5295,17 +5137,13 @@ def __init__(self, **kwargs) -> None: self.reserved1, self.unfinalized_standard_flags, self.unfinalized_custom_flags, - ) = unpack( - v4c.FMT_IDENTIFICATION_BLOCK, stream.read(v4c.IDENTIFICATION_BLOCK_SIZE) - ) + ) = unpack(v4c.FMT_IDENTIFICATION_BLOCK, stream.read(v4c.IDENTIFICATION_BLOCK_SIZE)) except KeyError: version = kwargs.get("version", "4.00") self.file_identification = "MDF ".encode("utf-8") self.version_str = "{} ".format(version).encode("utf-8") - self.program_identification = "amdf{}".format( - __version__.replace(".", "") - ).encode("utf-8") + self.program_identification = "amdf{}".format(__version__.replace(".", "")).encode("utf-8") self.reserved0 = b"\0" * 4 self.mdf_version = int(version.replace(".", "")) self.reserved1 = b"\0" * 30 @@ -5417,9 +5255,7 @@ def __init__(self, **kwargs) -> None: localtz = dateutil.tz.tzlocal() self.time_stamp = datetime.fromtimestamp(time.time(), tz=localtz) - def to_blocks( - self, address: int, blocks: list[Any], defined_texts: dict[str, int] - ) -> int: + def to_blocks(self, address: int, blocks: list[Any], defined_texts: dict[str, int]) -> int: text = self.comment if text: if text in defined_texts: @@ -5448,9 +5284,7 @@ def __setitem__(self, item: str, value: Any) -> None: self.__setattr__(item, value) def __bytes__(self) -> bytes: - result = pack( - v4c.FMT_FILE_HISTORY, *[self[key] for key in v4c.KEYS_FILE_HISTORY] - ) + result = pack(v4c.FMT_FILE_HISTORY, *[self[key] for key in v4c.KEYS_FILE_HISTORY]) return result @property @@ -5669,11 +5503,7 @@ def parse_common_properties(root): if string.startswith(" int: return address def __bytes__(self) -> bytes: - result = pack( - v4c.FMT_HEADER_BLOCK, *[self[key] for key in v4c.KEYS_HEADER_BLOCK] - ) + result = pack(v4c.FMT_HEADER_BLOCK, *[self[key] for key in v4c.KEYS_HEADER_BLOCK]) return result @@ -5990,14 +5816,10 @@ def __init__(self, **kwargs) -> None: mapped = kwargs.get("mapped", False) or not is_file_like(stream) if mapped: - (self.id, self.reserved0, self.block_len, self.links_nr) = COMMON_uf( - stream, address - ) + (self.id, self.reserved0, self.block_len, self.links_nr) = COMMON_uf(stream, address) if self.id != b"##LD": - message = ( - f'Expected "##LD" block @{hex(address)} but found "{self.id}"' - ) + message = f'Expected "##LD" block @{hex(address)} but found "{self.id}"' logger.exception(message) raise MdfException(message) @@ -6044,20 +5866,14 @@ def __init__(self, **kwargs) -> None: if self.flags & v4c.FLAG_LD_INVALIDATION_PRESENT: for i in range(self.data_block_nr): - self[f"invalidation_bits_addr_{i}"] = links[ - self.data_block_nr + 1 + i - ] + self[f"invalidation_bits_addr_{i}"] = links[self.data_block_nr + 1 + i] else: stream.seek(address) - (self.id, self.reserved0, self.block_len, self.links_nr) = COMMON_u( - stream.read(COMMON_SIZE) - ) + (self.id, self.reserved0, self.block_len, self.links_nr) = COMMON_u(stream.read(COMMON_SIZE)) if self.id != b"##LD": - message = ( - f'Expected "##LD" block @{hex(address)} but found "{self.id}"' - ) + message = f'Expected "##LD" block @{hex(address)} but found "{self.id}"' logger.exception(message) raise MdfException(message) @@ -6069,9 +5885,7 @@ def __init__(self, **kwargs) -> None: if self.flags & v4c.FLAG_LD_EQUAL_LENGHT: (self.data_block_len,) = UINT64_u(stream.read(8)) else: - offsets = unpack( - f"<{self.data_block_nr}Q", stream.read(self.data_block_nr * 8) - ) + offsets = unpack(f"<{self.data_block_nr}Q", stream.read(self.data_block_nr * 8)) for i, offset in enumerate(offsets): self[f"offset_{i}"] = offset @@ -6125,9 +5939,7 @@ def __init__(self, **kwargs) -> None: self.links_nr = 2 * self.data_block_nr + 1 for i in range(self.data_block_nr): - self[f"invalidation_bits_addr_{i}"] = kwargs[ - f"invalidation_bits_addr_{i}" - ] + self[f"invalidation_bits_addr_{i}"] = kwargs[f"invalidation_bits_addr_{i}"] else: self.links_nr = self.data_block_nr + 1 @@ -6154,9 +5966,7 @@ def __bytes__(self) -> bytes: if self.flags & v4c.FLAG_LD_INVALIDATION_PRESENT: fmt += f"{self.data_block_nr}Q" - keys += tuple( - f"invalidation_bits_addr_{i}" for i in range(self.data_block_nr) - ) + keys += tuple(f"invalidation_bits_addr_{i}" for i in range(self.data_block_nr)) fmt += "2I" keys += ("flags", "data_block_nr") @@ -6272,27 +6082,21 @@ def __init__(self, **kwargs) -> None: if address in tx_map: self.name = tx_map[address] else: - self.name = get_text_v4( - address=self.name_addr, stream=stream, mapped=mapped - ) + self.name = get_text_v4(address=self.name_addr, stream=stream, mapped=mapped) tx_map[address] = self.name address = self.path_addr if address in tx_map: self.path = tx_map[address] else: - self.path = get_text_v4( - address=self.path_addr, stream=stream, mapped=mapped - ) + self.path = get_text_v4(address=self.path_addr, stream=stream, mapped=mapped) tx_map[address] = self.path address = self.comment_addr if address in tx_map: self.comment = tx_map[address] else: - self.comment = get_text_v4( - address=self.comment_addr, stream=stream, mapped=mapped - ) + self.comment = get_text_v4(address=self.comment_addr, stream=stream, mapped=mapped) tx_map[address] = self.comment else: @@ -6530,9 +6334,7 @@ def __init__(self, **kwargs) -> None: self.address = address = kwargs["address"] if mapped: - (self.id, self.reserved0, self.block_len, self.links_nr) = COMMON_uf( - stream, address - ) + (self.id, self.reserved0, self.block_len, self.links_nr) = COMMON_uf(stream, address) size = self.block_len - COMMON_SIZE @@ -6541,15 +6343,11 @@ def __init__(self, **kwargs) -> None: logger.exception(message) raise MdfException(message) - self.text = text = stream[ - address + COMMON_SIZE : address + self.block_len - ] + self.text = text = stream[address + COMMON_SIZE : address + self.block_len] else: stream.seek(address) - (self.id, self.reserved0, self.block_len, self.links_nr) = COMMON_u( - stream.read(COMMON_SIZE) - ) + (self.id, self.reserved0, self.block_len, self.links_nr) = COMMON_u(stream.read(COMMON_SIZE)) size = self.block_len - COMMON_SIZE diff --git a/src/asammdf/blocks/v4_constants.py b/src/asammdf/blocks/v4_constants.py index 3b8b11788..bb970586d 100644 --- a/src/asammdf/blocks/v4_constants.py +++ b/src/asammdf/blocks/v4_constants.py @@ -472,12 +472,8 @@ FMT_SINGLE_ATTACHMENT_CHANNEL = "<4sI11Q4B4I2BH6d" SINGLE_ATTACHMENT_CHANNEL_PACK = struct.Struct(FMT_SINGLE_ATTACHMENT_CHANNEL).pack FMT_SINGLE_ATTACHMENT_CHANNEL_PARAMS = "<9Q4B4I2BH6d" -SINGLE_ATTACHMENT_CHANNEL_PARAMS_uf = struct.Struct( - FMT_SINGLE_ATTACHMENT_CHANNEL_PARAMS -).unpack_from -SINGLE_ATTACHMENT_CHANNEL_PARAMS_u = struct.Struct( - FMT_SINGLE_ATTACHMENT_CHANNEL_PARAMS -).unpack +SINGLE_ATTACHMENT_CHANNEL_PARAMS_uf = struct.Struct(FMT_SINGLE_ATTACHMENT_CHANNEL_PARAMS).unpack_from +SINGLE_ATTACHMENT_CHANNEL_PARAMS_u = struct.Struct(FMT_SINGLE_ATTACHMENT_CHANNEL_PARAMS).unpack FMT_TEXT_BLOCK = "<4sIQQ{}s" KEYS_TEXT_BLOCK = ("id", "reserved0", "block_len", "links_nr", "text") diff --git a/src/asammdf/gui/dialogs/advanced_search.py b/src/asammdf/gui/dialogs/advanced_search.py index 2262d5161..e04f6eebe 100644 --- a/src/asammdf/gui/dialogs/advanced_search.py +++ b/src/asammdf/gui/dialogs/advanced_search.py @@ -103,9 +103,7 @@ def __init__( self.case_sensitivity_pattern.setCurrentText("Case sensitive") else: self.case_sensitivity_pattern.setCurrentText("Case insensitive") - self.raw.setCheckState( - QtCore.Qt.Checked if pattern["raw"] else QtCore.Qt.Unchecked - ) + self.raw.setCheckState(QtCore.Qt.Checked if pattern["raw"] else QtCore.Qt.Unchecked) self.name.setText(pattern["name"]) self.ranges = pattern["ranges"] self.integer_format.setCurrentText(pattern.get("integer_format", "phys")) @@ -190,19 +188,14 @@ def search_text_changed(self): # check channel group source name if cg_source and ( - pattern.fullmatch(cg_source.name or "") - or pattern.fullmatch(cg_source.path or "") + pattern.fullmatch(cg_source.name or "") or pattern.fullmatch(cg_source.path or "") ): matches.update( { (group_index, channel_index): { "names": [ch.name], - "comment": extract_xml_comment( - ch.comment - ).strip(), - "unit": ch.conversion - and ch.conversion.unit - or ch.unit, + "comment": extract_xml_comment(ch.comment).strip(), + "unit": ch.conversion and ch.conversion.unit or ch.unit, "source_name": cg_source.name, "source_path": cg_source.path, } @@ -225,18 +218,10 @@ def search_text_changed(self): if entry not in matches: matches[entry] = { "names": [target], - "comment": extract_xml_comment( - ch.comment - ).strip(), - "unit": ch.conversion - and ch.conversion.unit - or ch.unit, - "source_name": source.name - if source - else "", - "source_path": source.path - if source - else "", + "comment": extract_xml_comment(ch.comment).strip(), + "unit": ch.conversion and ch.conversion.unit or ch.unit, + "source_name": source.name if source else "", + "source_path": source.path if source else "", } else: matches[entry]["name"].append(target) @@ -251,34 +236,22 @@ def search_text_changed(self): if pattern.fullmatch(target): matches[entry] = { "names": [ch.name], - "comment": extract_xml_comment( - ch.comment - ).strip(), - "unit": ch.conversion - and ch.conversion.unit - or ch.unit, - "source_name": source.name - if source - else "", - "source_path": source.path - if source - else "", + "comment": extract_xml_comment(ch.comment).strip(), + "unit": ch.conversion and ch.conversion.unit or ch.unit, + "source_name": source.name if source else "", + "source_path": source.path if source else "", } break else: - found_names = [ - name for name in self.channels_db if pattern.fullmatch(name) - ] + found_names = [name for name in self.channels_db if pattern.fullmatch(name)] matches = {} for name in found_names: for entry in self.channels_db[name]: if entry not in matches: (group_index, channel_index) = entry - ch = self.mdf.groups[group_index].channels[ - channel_index - ] + ch = self.mdf.groups[group_index].channels[channel_index] cg = self.mdf.groups[group_index].channel_group source = ch.source or getattr(cg, "acq_source", None) @@ -286,9 +259,7 @@ def search_text_changed(self): matches[entry] = { "names": [], "comment": extract_xml_comment(ch.comment).strip(), - "unit": ch.conversion - and ch.conversion.unit - or ch.unit, + "unit": ch.conversion and ch.conversion.unit or ch.unit, "source_name": source.name if source else "", "source_path": source.path if source else "", } @@ -300,10 +271,7 @@ def search_text_changed(self): else: info["names"].append(name) - matches = [ - (group_index, channel_index, info) - for (group_index, channel_index), info in matches.items() - ] + matches = [(group_index, channel_index, info) for (group_index, channel_index), info in matches.items()] matches.sort(key=lambda x: x[-1]["names"][0]) self.matches.clear() @@ -402,9 +370,7 @@ def _apply(self, event=None): if item is None: break - entry = int(item.text(self.GroupColumn)), int( - item.text(self.ChannelColumn) - ) + entry = int(item.text(self.GroupColumn)), int(item.text(self.ChannelColumn)) name = item.text(self.NameColumn) self.result[entry] = name iterator += 1 @@ -415,8 +381,7 @@ def _apply_pattern(self, event): self.result = { "pattern": self.pattern.text().strip(), "match_type": self.pattern_match_type.currentText(), - "case_sensitive": self.case_sensitivity_pattern.currentText() - == "Case sensitive", + "case_sensitive": self.case_sensitivity_pattern.currentText() == "Case sensitive", "filter_type": self.filter_type.currentText(), "filter_value": self.filter_value.value(), "raw": self.raw.checkState() == QtCore.Qt.Checked, @@ -426,9 +391,7 @@ def _apply_pattern(self, event): } if not self.result["pattern"]: - MessageBox.warning( - self, "Cannot apply pattern", "The pattern cannot be empty" - ) + MessageBox.warning(self, "Cannot apply pattern", "The pattern cannot be empty") return if not self.result["name"]: diff --git a/src/asammdf/gui/dialogs/bus_database_manager.py b/src/asammdf/gui/dialogs/bus_database_manager.py index b7283b7b3..815de77ed 100644 --- a/src/asammdf/gui/dialogs/bus_database_manager.py +++ b/src/asammdf/gui/dialogs/bus_database_manager.py @@ -40,9 +40,7 @@ def __init__( self.horLayout = QtWidgets.QHBoxLayout(self) - spacer = QtWidgets.QSpacerItem( - 40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum - ) + spacer = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) self.apply_btn = QtWidgets.QPushButton("Apply") self.cancel_btn = QtWidgets.QPushButton("Cancel") self.horLayout.addSpacerItem(spacer) diff --git a/src/asammdf/gui/dialogs/conversion_editor.py b/src/asammdf/gui/dialogs/conversion_editor.py index 18a83bcec..895422e46 100644 --- a/src/asammdf/gui/dialogs/conversion_editor.py +++ b/src/asammdf/gui/dialogs/conversion_editor.py @@ -27,9 +27,7 @@ def __init__(self, channel_name="", conversion=None, *args, **kwargs): self.vrtt_default_conversion = None self.vtt_default_mode.currentIndexChanged.connect(self.vtt_mode.setCurrentIndex) - self.vrtt_default_mode.currentIndexChanged.connect( - self.vrtt_mode.setCurrentIndex - ) + self.vrtt_default_mode.currentIndexChanged.connect(self.vrtt_mode.setCurrentIndex) self.vtt_default_btn.clicked.connect(self.edit_vtt_default_conversion) self.vrtt_default_btn.clicked.connect(self.edit_vrtt_default_conversion) @@ -81,25 +79,19 @@ def __init__(self, channel_name="", conversion=None, *args, **kwargs): self.vtt_default_mode.setCurrentIndex(0) self.vtt_default.setText( - conversion.referenced_blocks["default_addr"].decode( - "utf-8", errors="replace" - ) + conversion.referenced_blocks["default_addr"].decode("utf-8", errors="replace") ) else: self.vtt_default_mode.setCurrentIndex(1) - self.vtt_default_conversion = conversion.referenced_blocks[ - "default_addr" - ] + self.vtt_default_conversion = conversion.referenced_blocks["default_addr"] for i in range(conversion.ref_param_nr - 1): if isinstance(conversion.referenced_blocks[f"text_{i}"], bytes): widget = VTTWidget( mode="text", value=conversion[f"val_{i}"], - text=conversion.referenced_blocks[f"text_{i}"].decode( - "utf-8", errors="replace" - ), + text=conversion.referenced_blocks[f"text_{i}"].decode("utf-8", errors="replace"), ) else: @@ -122,16 +114,12 @@ def __init__(self, channel_name="", conversion=None, *args, **kwargs): self.vrtt_default_mode.setCurrentIndex(0) self.vrtt_default.setText( - conversion.referenced_blocks["default_addr"].decode( - "utf-8", errors="replace" - ) + conversion.referenced_blocks["default_addr"].decode("utf-8", errors="replace") ) else: self.vrtt_default_mode.setCurrentIndex(1) - self.vrtt_default_conversion = conversion.referenced_blocks[ - "default_addr" - ] + self.vrtt_default_conversion = conversion.referenced_blocks["default_addr"] for i in range(conversion.ref_param_nr - 1): if isinstance(conversion.referenced_blocks[f"text_{i}"], bytes): @@ -139,9 +127,7 @@ def __init__(self, channel_name="", conversion=None, *args, **kwargs): mode="text", lower=conversion[f"lower_{i}"], upper=conversion[f"upper_{i}"], - text=conversion.referenced_blocks[f"text_{i}"].decode( - "utf-8", errors="replace" - ), + text=conversion.referenced_blocks[f"text_{i}"].decode("utf-8", errors="replace"), ) else: @@ -291,9 +277,7 @@ def conversion(self): } if self.vtt_default_mode.currentIndex() == 0: - conversion["default"] = ( - self.vtt_default.text().strip().encode("utf-8") - ) + conversion["default"] = self.vtt_default.text().strip().encode("utf-8") else: conversion["default"] = self.vtt_default_conversion @@ -320,9 +304,7 @@ def conversion(self): } if self.vrtt_default_mode.currentIndex() == 0: - conversion["default"] = ( - self.vrtt_default.text().strip().encode("utf-8") - ) + conversion["default"] = self.vrtt_default.text().strip().encode("utf-8") else: conversion["default"] = self.vrtt_default_conversion diff --git a/src/asammdf/gui/dialogs/define_channel.py b/src/asammdf/gui/dialogs/define_channel.py index 9c847fb9d..865dabdbf 100644 --- a/src/asammdf/gui/dialogs/define_channel.py +++ b/src/asammdf/gui/dialogs/define_channel.py @@ -39,9 +39,7 @@ def __init__( self.origin_uuid = origin_uuid or (mdf.uuid if mdf else os.urandom(6).hex()) self.arg_widgets = [] - spacer = QtWidgets.QSpacerItem( - 20, 20, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding - ) + spacer = QtWidgets.QSpacerItem(20, 20, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding) self.arg_layout.addItem(spacer, len(self.arg_widgets) + 2, 0) self.arg_widgets.append(spacer) @@ -70,9 +68,7 @@ def __init__( if computation: computation = computation_to_python_function(computation) - self.name.setText( - computation.get("channel_name", computation.get("channel", "")) - ) + self.name.setText(computation.get("channel_name", computation.get("channel", ""))) self.unit.setText(computation.get("channel_unit", "")) self.comment.setPlainText(computation.get("channel_comment", "")) @@ -93,10 +89,7 @@ def __init__( for i, names in enumerate(computation["args"].values()): self.arg_widgets[i][1].insertPlainText("\n".join(names)) - if ( - computation.get("computation_mode", "sample_by_sample") - == "sample_by_sample" - ): + if computation.get("computation_mode", "sample_by_sample") == "sample_by_sample": self.sample_by_sample.setChecked(True) else: self.complete_signal.setChecked(True) @@ -154,9 +147,7 @@ def apply(self): "channel_comment": self.comment.toPlainText().strip(), "triggering": triggering, "triggering_value": triggering_value, - "computation_mode": "sample_by_sample" - if self.sample_by_sample.isChecked() - else "complete_signal", + "computation_mode": "sample_by_sample" if self.sample_by_sample.isChecked() else "complete_signal", }, } @@ -184,9 +175,7 @@ def function_changed(self, *args): func = locals()[name] icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/search.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/search.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) parameters = list(inspect.signature(func).parameters)[:-1] for i, arg_name in enumerate(parameters, 2): @@ -201,9 +190,7 @@ def function_changed(self, *args): self.arg_widgets.append((label, text_edit, button)) - spacer = QtWidgets.QSpacerItem( - 20, 20, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding - ) + spacer = QtWidgets.QSpacerItem(20, 20, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding) self.arg_layout.addItem(spacer, len(self.arg_widgets) + 2, 0) self.arg_widgets.append(spacer) @@ -265,9 +252,7 @@ def show_definition(self, *args): info.setPalette(p) icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/info.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/info.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) info.setWindowIcon(icon) info.show() diff --git a/src/asammdf/gui/dialogs/dependencies_dlg.py b/src/asammdf/gui/dialogs/dependencies_dlg.py index c738b7864..36f810c4b 100644 --- a/src/asammdf/gui/dialogs/dependencies_dlg.py +++ b/src/asammdf/gui/dialogs/dependencies_dlg.py @@ -88,9 +88,7 @@ def get_root_node(name: Optional[str] = None) -> QTreeWidgetItem: parent = get_root_node() if req.marker is not None: - match = re.search( - r"extra\s*==\s*['\"](?P\S+)['\"]", str(req.marker) - ) + match = re.search(r"extra\s*==\s*['\"](?P\S+)['\"]", str(req.marker)) if match: parent = get_root_node(match["extra"]) diff --git a/src/asammdf/gui/dialogs/error_dialog.py b/src/asammdf/gui/dialogs/error_dialog.py index 013b8c5b8..19852c6c4 100644 --- a/src/asammdf/gui/dialogs/error_dialog.py +++ b/src/asammdf/gui/dialogs/error_dialog.py @@ -45,9 +45,7 @@ def __init__(self, title, message, trace, *args, **kwargs): self.trace.setReadOnly(True) icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/error.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/error.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.setWindowIcon(icon) @@ -68,23 +66,17 @@ def __init__(self, title, message, trace, *args, **kwargs): self.timer.timeout.connect(self.count_down) if timeout > 0: - self.status.setText( - f"This window will be closed in {self._timeout}s\nAbort the countdown - [F1]" - ) + self.status.setText(f"This window will be closed in {self._timeout}s\nAbort the countdown - [F1]") self.timer.start(1000) def copy_to_clipboard(self, event): - text = ( - f"Error: {self.error_message.text()}\n\nDetails: {self.trace.toPlainText()}" - ) + text = f"Error: {self.error_message.text()}\n\nDetails: {self.trace.toPlainText()}" QtWidgets.QApplication.instance().clipboard().setText(text) def count_down(self): if self._timeout > 0: self._timeout -= 1 - self.status.setText( - f"This window will be closed in {self._timeout}s\nAbort the countdown - [F1]" - ) + self.status.setText(f"This window will be closed in {self._timeout}s\nAbort the countdown - [F1]") else: self.close() diff --git a/src/asammdf/gui/dialogs/functions_manager.py b/src/asammdf/gui/dialogs/functions_manager.py index 3be999665..0b3f47900 100644 --- a/src/asammdf/gui/dialogs/functions_manager.py +++ b/src/asammdf/gui/dialogs/functions_manager.py @@ -43,17 +43,13 @@ def __init__( self.setSizeGripEnabled(True) self.setWindowFlags(QtCore.Qt.Window) self.verticalLayout = QtWidgets.QVBoxLayout(self) - self.widget = FunctionsManager( - deepcopy(definitions), channels, selected_definition - ) + self.widget = FunctionsManager(deepcopy(definitions), channels, selected_definition) self.verticalLayout.addWidget(self.widget) self.horLayout = QtWidgets.QHBoxLayout(self) - spacer = QtWidgets.QSpacerItem( - 40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum - ) + spacer = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) self.apply_btn = QtWidgets.QPushButton("Apply") self.cancel_btn = QtWidgets.QPushButton("Cancel") self.horLayout.addSpacerItem(spacer) diff --git a/src/asammdf/gui/dialogs/messagebox.py b/src/asammdf/gui/dialogs/messagebox.py index 382fcc8e3..96119d5b6 100644 --- a/src/asammdf/gui/dialogs/messagebox.py +++ b/src/asammdf/gui/dialogs/messagebox.py @@ -26,8 +26,7 @@ def __init__(self, *args, **kwargs): ) else: self.setText( - f"{self.original_text}\n\nThis message will be closed in {self.timeout}s\n" - "Abort the countdown - [F1]" + f"{self.original_text}\n\nThis message will be closed in {self.timeout}s\n" "Abort the countdown - [F1]" ) if informative_text: diff --git a/src/asammdf/gui/dialogs/multi_search.py b/src/asammdf/gui/dialogs/multi_search.py index c6062bf3f..4325fe446 100644 --- a/src/asammdf/gui/dialogs/multi_search.py +++ b/src/asammdf/gui/dialogs/multi_search.py @@ -16,11 +16,7 @@ class MultiSearch(Ui_MultiSearchDialog, QtWidgets.QDialog): def __init__(self, channels_dbs, measurements, *args, **kwargs): super().__init__(*args, **kwargs) self.setupUi(self) - self.setWindowFlags( - self.windowFlags() - | QtCore.Qt.WindowSystemMenuHint - | QtCore.Qt.WindowMinMaxButtonsHint - ) + self.setWindowFlags(self.windowFlags() | QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowMinMaxButtonsHint) for widget in ( self.apply_btn, @@ -69,11 +65,7 @@ def search_text_changed(self): else: pattern = re.compile(f"(?i){pattern}") for i, channels_db in enumerate(self.channels_dbs, 1): - match_results = [ - f"{i:> 2}: {name}" - for name in channels_db - if pattern.fullmatch(name) - ] + match_results = [f"{i:> 2}: {name}" for name in channels_db if pattern.fullmatch(name)] results.extend(match_results) except Exception as err: @@ -123,6 +115,4 @@ def show_measurement_list(self, event): for i, name in enumerate(self.measurements, 1): info.extend(wrap(f"{i:> 2}: {name}", 120)) - MessageBox.information( - self, "Measurement files used for comparison", "\n".join(info) - ) + MessageBox.information(self, "Measurement files used for comparison", "\n".join(info)) diff --git a/src/asammdf/gui/dialogs/range_editor.py b/src/asammdf/gui/dialogs/range_editor.py index c33e3fee6..79f4b6c10 100644 --- a/src/asammdf/gui/dialogs/range_editor.py +++ b/src/asammdf/gui/dialogs/range_editor.py @@ -12,11 +12,7 @@ class RangeEditor(Ui_RangeDialog, QtWidgets.QDialog): def __init__(self, name, unit="", ranges=None, brush=False, *args, **kwargs): super().__init__(*args, **kwargs) self.setupUi(self) - self.setWindowFlags( - self.windowFlags() - | QtCore.Qt.WindowSystemMenuHint - | QtCore.Qt.WindowMinMaxButtonsHint - ) + self.setWindowFlags(self.windowFlags() | QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowMinMaxButtonsHint) self.name = name self.unit = unit diff --git a/src/asammdf/gui/utils.py b/src/asammdf/gui/utils.py index 6ddf2fa94..c2c42481c 100644 --- a/src/asammdf/gui/utils.py +++ b/src/asammdf/gui/utils.py @@ -174,14 +174,10 @@ def excepthook(exc_type, exc_value, tracebackobj): print("".join(traceback.format_tb(tracebackobj))) print("{0}: {1}".format(exc_type, exc_value)) - ErrorDialog( - message=errmsg, trace=msg, title="The following error was triggered" - ).exec_() + ErrorDialog(message=errmsg, trace=msg, title="The following error was triggered").exec_() -def run_thread_with_progress( - widget, target, kwargs, factor=100, offset=0, progress=None -): +def run_thread_with_progress(widget, target, kwargs, factor=100, offset=0, progress=None): termination_request = False thr = WorkerThread(target=target, kwargs=kwargs) @@ -195,9 +191,7 @@ def run_thread_with_progress( if progress and not progress.wasCanceled(): if widget.progress is not None: if widget.progress != (0, 0): - progress.setValue( - int(widget.progress[0] / widget.progress[1] * factor) + offset - ) + progress.setValue(int(widget.progress[0] / widget.progress[1] * factor) + offset) else: progress.setRange(0, 0) QtCore.QCoreApplication.processEvents() @@ -322,10 +316,7 @@ def close(self): self.destroy() def keyPressEvent(self, event): - if ( - event.key() == QtCore.Qt.Key_Escape - and event.modifiers() == QtCore.Qt.NoModifier - ): + if event.key() == QtCore.Qt.Key_Escape and event.modifiers() == QtCore.Qt.NoModifier: self.close() else: super().keyPressEvent(event) @@ -339,9 +330,7 @@ def setup_progress(parent, title="", message="", icon_name="", autoclose=False): progress.setAutoClose(autoclose) progress.setWindowTitle(title) icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(f":/{icon_name}.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(f":/{icon_name}.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) progress.setWindowIcon(icon) progress.setMinimumWidth(600) @@ -476,22 +465,14 @@ def compute_signal( signals = [sig.interp(common_timebase) for sig in signals] - if ( - description.get("computation_mode", "sample_by_sample") - == "sample_by_sample" - ): + if description.get("computation_mode", "sample_by_sample") == "sample_by_sample": signals = [sig.samples.tolist() for sig in signals] signals.append(common_timebase) samples = [] for values in zip(*signals): try: - current_sample = func( - **{ - arg_name: arg_val - for arg_name, arg_val in zip(names, values) - } - ) + current_sample = func(**{arg_name: arg_val for arg_name, arg_val in zip(names, values)}) except: current_sample = COMPUTED_FUNCTION_ERROR_VALUE samples.append(current_sample) @@ -508,11 +489,7 @@ def compute_signal( signals.append(common_timebase) - not_found = [ - arg_name - for arg_name in description["args"] - if arg_name not in names - ] + not_found = [arg_name for arg_name in description["args"] if arg_name not in names] not_found_signals = [] @@ -522,19 +499,12 @@ def compute_signal( if arg_name in names: continue else: - not_found_signals.append( - np.ones(len(common_timebase), dtype="u1") * arg.default - ) + not_found_signals.append(np.ones(len(common_timebase), dtype="u1") * arg.default) names.extend(not_found) signals.extend(not_found_signals) - samples = func( - **{ - arg_name: arg_signal - for arg_name, arg_signal in zip(names, signals) - } - ) + samples = func(**{arg_name: arg_signal for arg_name, arg_signal in zip(names, signals)}) if len(samples) != len(common_timebase): common_timebase = common_timebase[-len(samples) :] @@ -731,9 +701,7 @@ def computation_to_python_function(description): "channel_comment": description["channel_comment"], "channel_name": description["channel_name"], "channel_unit": description["channel_unit"], - "computation_mode": description.get( - "computation_mode", "sample_by_sample" - ), + "computation_mode": description.get("computation_mode", "sample_by_sample"), "definition": definition, "type": "python_function", "triggering": "triggering_on_all", @@ -742,9 +710,7 @@ def computation_to_python_function(description): } else: new_description = description - new_description["computation_mode"] = description.get( - "computation_mode", "sample_by_sample" - ) + new_description["computation_mode"] = description.get("computation_mode", "sample_by_sample") return new_description @@ -755,9 +721,7 @@ def replace_computation_dependency(computation, old_name, new_name): if isinstance(val, str) and old_name in val: new_computation[key] = val.replace(old_name, new_name) elif isinstance(val, dict): - new_computation[key] = replace_computation_dependency( - val, old_name, new_name - ) + new_computation[key] = replace_computation_dependency(val, old_name, new_name) else: new_computation[key] = val @@ -828,9 +792,7 @@ def compare(r): ) ranges = [] - for value1, value2, op1, op2, bk_color, ft_color in sorted( - new_ranges, key=compare - ): + for value1, value2, op1, op2, bk_color, ft_color in sorted(new_ranges, key=compare): if bk_color[0] == 0: ranges.append( { @@ -857,9 +819,7 @@ def compare(r): return ranges -def get_colors_using_ranges( - value, ranges, default_background_color, default_font_color -): +def get_colors_using_ranges(value, ranges, default_background_color, default_font_color): new_background_color = default_background_color new_font_color = default_font_color @@ -1085,9 +1045,7 @@ def draw_color_icon(color): return QtGui.QIcon(pix) -def generate_python_function( - definition: str, in_globals: Union[Dict, None] = None -) -> tuple: +def generate_python_function(definition: str, in_globals: Union[Dict, None] = None) -> tuple: trace = None func = None diff --git a/src/asammdf/gui/widgets/attachment.py b/src/asammdf/gui/widgets/attachment.py index c30a54be0..043be4fd1 100644 --- a/src/asammdf/gui/widgets/attachment.py +++ b/src/asammdf/gui/widgets/attachment.py @@ -31,9 +31,7 @@ def extract(self, event=None): if ok and text: password = text - data, file_path, md5_sum = self.mdf.extract_attachment( - self.index, password=password - ) + data, file_path, md5_sum = self.mdf.extract_attachment(self.index, password=password) file_name, _ = QtWidgets.QFileDialog.getSaveFileName( self, diff --git a/src/asammdf/gui/widgets/bar.py b/src/asammdf/gui/widgets/bar.py index 849825569..3c1776099 100644 --- a/src/asammdf/gui/widgets/bar.py +++ b/src/asammdf/gui/widgets/bar.py @@ -114,9 +114,7 @@ def add_new_channels(self, channels): invalid_indexes = invalid_indexes[:10] + 1 idx = invalid_indexes[0] ts = channel.timestamps[idx - 1 : idx + 2] - invalid.append( - f"{channel.name} @ index {invalid_indexes[:10] - 1} with first time stamp error: {ts}" - ) + invalid.append(f"{channel.name} @ index {invalid_indexes[:10] - 1} with first time stamp error: {ts}") if invalid: errors = "\n".join(invalid) @@ -200,10 +198,7 @@ def keyPressEvent(self, event): key = event.key() modifier = event.modifiers() - if ( - key in (QtCore.Qt.Key_H, QtCore.Qt.Key_B, QtCore.Qt.Key_P) - and modifier == QtCore.Qt.ControlModifier - ): + if key in (QtCore.Qt.Key_H, QtCore.Qt.Key_B, QtCore.Qt.Key_P) and modifier == QtCore.Qt.ControlModifier: if key == QtCore.Qt.Key_H: self.format_selection.setCurrentText("hex") elif key == QtCore.Qt.Key_B: @@ -237,11 +232,7 @@ def to_config(self): return config def search_forward(self): - if ( - self.op.currentIndex() < 0 - or not self.target.text().strip() - or not self.pattern_match.text().strip() - ): + if self.op.currentIndex() < 0 or not self.target.text().strip() or not self.pattern_match.text().strip(): self.match.setText("invalid input values") return @@ -297,11 +288,7 @@ def search_forward(self): self.match.setText("condition not found") def search_backward(self): - if ( - self.op.currentIndex() < 0 - or not self.target.text().strip() - or not self.pattern_match.text().strip() - ): + if self.op.currentIndex() < 0 or not self.target.text().strip() or not self.pattern_match.text().strip(): self.match.setText("invalid input values") return diff --git a/src/asammdf/gui/widgets/batch.py b/src/asammdf/gui/widgets/batch.py index e7b235a58..5dbcb655a 100644 --- a/src/asammdf/gui/widgets/batch.py +++ b/src/asammdf/gui/widgets/batch.py @@ -104,9 +104,7 @@ def __init__( self.filter_view.setCurrentIndex(-1) self.filter_view.currentIndexChanged.connect(self.update_channel_tree) self.filter_view.currentTextChanged.connect(self.update_channel_tree) - self.filter_view.setCurrentText( - self._settings.value("filter_view", "Internal file structure") - ) + self.filter_view.setCurrentText(self._settings.value("filter_view", "Internal file structure")) self.filter_tree.itemChanged.connect(self.filter_changed) @@ -210,17 +208,13 @@ def scramble_thread(self, source_files, progress): count = len(source_files) icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/scramble.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/scramble.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) progress.signals.setWindowIcon.emit(icon) progress.signals.setWindowTitle.emit("Scrambling measurements") # scrambling self.mdf for i, source_file in enumerate(source_files): - progress.signals.setLabelText.emit( - f"Scrambling file {i+1} of {count}\n{source_file}" - ) + progress.signals.setLabelText.emit(f"Scrambling file {i+1} of {count}\n{source_file}") result = MDF.scramble(name=source_file, progress=progress) if result is TERMINATED: @@ -266,9 +260,7 @@ def extract_bus_logging(self, event): for i in range(count1): item = self.can_database_list.item(i) widget = self.can_database_list.itemWidget(item) - database_files["CAN"].append( - (widget.database.text(), widget.bus.currentIndex()) - ) + database_files["CAN"].append((widget.database.text(), widget.bus.currentIndex())) count2 = self.lin_database_list.count() if count2: @@ -276,9 +268,7 @@ def extract_bus_logging(self, event): for i in range(count2): item = self.lin_database_list.item(i) widget = self.lin_database_list.itemWidget(item) - database_files["LIN"].append( - (widget.database.text(), widget.bus.currentIndex()) - ) + database_files["LIN"].append((widget.database.text(), widget.bus.currentIndex())) compression = self.extract_bus_compression.currentIndex() @@ -298,16 +288,12 @@ def extract_bus_logging(self, event): kwargs={}, ) - def extract_bus_logging_thread( - self, source_files, database_files, count, compression, version, progress - ): + def extract_bus_logging_thread(self, source_files, database_files, count, compression, version, progress): icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap(":/down.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) progress.signals.setWindowIcon.emit(icon) progress.signals.setWindowTitle.emit("Extract Bus logging from measurements") - progress.signals.setLabelText.emit( - f'Extracting Bus logging from "{count}" files' - ) + progress.signals.setLabelText.emit(f'Extracting Bus logging from "{count}" files') files = self._prepare_files(list(source_files), progress) @@ -317,9 +303,7 @@ def extract_bus_logging_thread( progress.signals.setMaximum.emit(count) for i, (file, source_file) in enumerate(zip(files, source_files)): - progress.signals.setLabelText.emit( - f"Extracting Bus logging from file {i+1} of {count}\n{source_file}" - ) + progress.signals.setLabelText.emit(f"Extracting Bus logging from file {i+1} of {count}\n{source_file}") if not isinstance(file, MDF): mdf = MDF(file) @@ -354,9 +338,7 @@ def extract_bus_logging_thread( f'- {found_id_count} of {len(call_info["total_unique_ids"])} IDs in the MDF4 file were matched in the DBC and converted', ] if call_info["unknown_id_count"]: - message.append( - f'- {call_info["unknown_id_count"]} unknown IDs in the MDF4 file' - ) + message.append(f'- {call_info["unknown_id_count"]} unknown IDs in the MDF4 file') else: message.append("- no unknown IDs inf the MDF4 file") @@ -369,39 +351,27 @@ def extract_bus_logging_thread( for dbc_name, found_ids in call_info["found_ids"].items(): for msg_id, msg_name in sorted(found_ids): try: - message.append( - f"- 0x{msg_id:X} --> {msg_name} in <{dbc_name}>" - ) + message.append(f"- 0x{msg_id:X} --> {msg_name} in <{dbc_name}>") except: pgn, sa = msg_id - message.append( - f"- PGN=0x{pgn:X} SA=0x{sa:X} --> {msg_name} in <{dbc_name}>" - ) + message.append(f"- PGN=0x{pgn:X} SA=0x{sa:X} --> {msg_name} in <{dbc_name}>") message += [ "", "The following Bus IDs were in the MDF log file, but not matched in the DBC:", ] - unknown_standard_can = sorted( - [e for e in call_info["unknown_ids"] if isinstance(e, int)] - ) - unknown_j1939 = sorted( - [e for e in call_info["unknown_ids"] if not isinstance(e, int)] - ) + unknown_standard_can = sorted([e for e in call_info["unknown_ids"] if isinstance(e, int)]) + unknown_j1939 = sorted([e for e in call_info["unknown_ids"] if not isinstance(e, int)]) for msg_id in unknown_standard_can: message.append(f"- 0x{msg_id:X}") for pgn, sa in unknown_j1939: message.append(f"- PGN=0x{pgn:X} SA=0x{sa:X}") - file_name = source_file.with_suffix( - ".bus_logging.mdf" if version < "4.00" else ".bus_logging.mf4" - ) + file_name = source_file.with_suffix(".bus_logging.mdf" if version < "4.00" else ".bus_logging.mf4") # then save it - progress.signals.setLabelText.emit( - f'Saving extracted Bus logging file {i+1} to "{file_name}"' - ) + progress.signals.setLabelText.emit(f'Saving extracted Bus logging file {i+1} to "{file_name}"') result = mdf_.save( dst=file_name, @@ -435,9 +405,7 @@ def extract_bus_csv_logging(self, event): for i in range(count1): item = self.can_database_list.item(i) widget = self.can_database_list.itemWidget(item) - database_files["CAN"].append( - (widget.database.text(), widget.bus.currentIndex()) - ) + database_files["CAN"].append((widget.database.text(), widget.bus.currentIndex())) count2 = self.lin_database_list.count() if count2: @@ -445,9 +413,7 @@ def extract_bus_csv_logging(self, event): for i in range(count2): item = self.lin_database_list.item(i) widget = self.lin_database_list.itemWidget(item) - database_files["LIN"].append( - (widget.database.text(), widget.bus.currentIndex()) - ) + database_files["LIN"].append((widget.database.text(), widget.bus.currentIndex())) single_time_base = self.single_time_base_bus.checkState() == QtCore.Qt.Checked time_from_zero = self.time_from_zero_bus.checkState() == QtCore.Qt.Checked @@ -457,9 +423,7 @@ def extract_bus_csv_logging(self, event): delimiter = self.delimiter_bus.text() or "," doublequote = self.doublequote_bus.checkState() == QtCore.Qt.Checked escapechar = self.escapechar_bus.text() or None - lineterminator = ( - self.lineterminator_bus.text().replace("\\r", "\r").replace("\\n", "\n") - ) + lineterminator = self.lineterminator_bus.text().replace("\\r", "\r").replace("\\n", "\n") quotechar = self.quotechar_bus.text() or '"' quoting = self.quoting_bus.currentText() add_units = self.add_units_bus.checkState() == QtCore.Qt.Checked @@ -520,21 +484,15 @@ def extract_bus_csv_logging_thread( icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap(":/csv.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) progress.signals.setWindowIcon.emit(icon) - progress.signals.setWindowTitle.emit( - "Extract Bus logging from measurements to CSV" - ) - progress.signals.setLabelText.emit( - f'Extracting Bus logging from "{count}" files' - ) + progress.signals.setWindowTitle.emit("Extract Bus logging from measurements to CSV") + progress.signals.setLabelText.emit(f'Extracting Bus logging from "{count}" files') files = self._prepare_files(list(source_files), progress) message = [] for i, (file, source_file) in enumerate(zip(files, source_files)): - progress.signals.setLabelText.emit( - f"Extracting Bus logging from file {i+1} of {count}" - ) + progress.signals.setLabelText.emit(f"Extracting Bus logging from file {i+1} of {count}") if not isinstance(file, MDF): mdf = MDF(file) @@ -568,9 +526,7 @@ def extract_bus_csv_logging_thread( f'- {found_id_count} of {len(call_info["total_unique_ids"])} IDs in the MDF4 file were matched in the DBC and converted', ] if call_info["unknown_id_count"]: - message.append( - f'- {call_info["unknown_id_count"]} unknown IDs in the MDF4 file' - ) + message.append(f'- {call_info["unknown_id_count"]} unknown IDs in the MDF4 file') else: message.append("- no unknown IDs inf the MDF4 file") @@ -594,9 +550,7 @@ def extract_bus_csv_logging_thread( file_name = source_file.with_suffix(".bus_logging.csv") # then save it - progress.signals.setLabelText.emit( - f'Saving extracted Bus logging file {i+1} to "{file_name}"' - ) + progress.signals.setLabelText.emit(f'Saving extracted Bus logging file {i+1} to "{file_name}"') mdf_.configure( integer_interpolation=self.integer_interpolation, @@ -638,11 +592,7 @@ def load_can_database(self, event): ) if file_names: - file_names = [ - name - for name in file_names - if Path(name).suffix.lower() in (".arxml", ".dbc") - ] + file_names = [name for name in file_names if Path(name).suffix.lower() in (".arxml", ".dbc")] if file_names: for database in file_names: @@ -663,11 +613,7 @@ def load_lin_database(self, event): ) if file_names: - file_names = [ - name - for name in file_names - if Path(name).suffix.lower() in (".arxml", ".dbc", ".ldf") - ] + file_names = [name for name in file_names if Path(name).suffix.lower() in (".arxml", ".dbc", ".ldf")] if file_names: for database in file_names: @@ -690,9 +636,7 @@ def concatenate(self, event=None): version = self.concatenate_format.currentText() sync = self.concatenate_sync.checkState() == QtCore.Qt.Checked - add_samples_origin = ( - self.concatenate_add_samples_origin.checkState() == QtCore.Qt.Checked - ) + add_samples_origin = self.concatenate_add_samples_origin.checkState() == QtCore.Qt.Checked split = self.concatenate_split.checkState() == QtCore.Qt.Checked if split: @@ -755,9 +699,7 @@ def concatenate_thread( icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap(":/plus.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) progress.signals.setWindowIcon.emit(icon) - progress.signals.setWindowTitle.emit( - f"Concatenating files and saving to {version} format" - ) + progress.signals.setWindowTitle.emit(f"Concatenating files and saving to {version} format") output_file_name = Path(output_file_name) @@ -803,13 +745,9 @@ def stack_thread( progress, ): icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/stack.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/stack.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) progress.signals.setWindowIcon.emit(icon) - progress.signals.setWindowTitle.emit( - f"Stacking files and saving to {version} format" - ) + progress.signals.setWindowTitle.emit(f"Stacking files and saving to {version} format") output_file_name = Path(output_file_name) @@ -855,9 +793,7 @@ def stack(self, event): version = self.stack_format.currentText() sync = self.stack_sync.checkState() == QtCore.Qt.Checked - add_samples_origin = ( - self.stack_add_samples_origin.checkState() == QtCore.Qt.Checked - ) + add_samples_origin = self.stack_add_samples_origin.checkState() == QtCore.Qt.Checked split = self.stack_split.checkState() == QtCore.Qt.Checked if split: @@ -941,9 +877,7 @@ def _prepare_files(self, files=None, progress=None): progress.signals.setWindowTitle.emit("Preparing measurements") for i, file_name in enumerate(files): - progress.signals.setLabelText.emit( - f"Preparing the file {i+1} of {count}\n{file_name}" - ) + progress.signals.setLabelText.emit(f"Preparing the file {i+1} of {count}\n{file_name}") files[i] = self._as_mdf(file_name) progress.signals.setValue.emit(i + 1) @@ -1201,17 +1135,12 @@ def update_channel_tree(self, *args): else: channel_group.setText(0, f"Channel group {i}") channel_group.setFlags( - channel_group.flags() - | QtCore.Qt.ItemIsAutoTristate - | QtCore.Qt.ItemIsUserCheckable + channel_group.flags() | QtCore.Qt.ItemIsAutoTristate | QtCore.Qt.ItemIsUserCheckable ) widget.addTopLevelItem(channel_group) - channels = [ - HelperChannel(name=ch.name, entry=(i, j)) - for j, ch in enumerate(group.channels) - ] + channels = [HelperChannel(name=ch.name, entry=(i, j)) for j, ch in enumerate(group.channels)] add_children( channel_group, @@ -1246,16 +1175,14 @@ def _current_options(self): "needs_cut": self.cut_group.isChecked(), "cut_start": self.cut_start.value(), "cut_stop": self.cut_stop.value(), - "cut_time_from_zero": self.cut_time_from_zero.checkState() - == QtCore.Qt.Checked, + "cut_time_from_zero": self.cut_time_from_zero.checkState() == QtCore.Qt.Checked, "whence": int(self.whence.checkState() == QtCore.Qt.Checked), "needs_resample": self.resample_group.isChecked(), "raster_type_step": self.raster_type_step.isChecked(), "raster_type_channel": self.raster_type_channel.isChecked(), "raster": self.raster.value(), "raster_channel": self.raster_channel.currentText(), - "resample_time_from_zero": self.resample_time_from_zero.checkState() - == QtCore.Qt.Checked, + "resample_time_from_zero": self.resample_time_from_zero.checkState() == QtCore.Qt.Checked, "output_format": self.output_format.currentText(), } @@ -1271,15 +1198,11 @@ def _current_options(self): elif output_format == "MAT": new = { - "single_time_base": self.single_time_base_mat.checkState() - == QtCore.Qt.Checked, - "time_from_zero": self.time_from_zero_mat.checkState() - == QtCore.Qt.Checked, + "single_time_base": self.single_time_base_mat.checkState() == QtCore.Qt.Checked, + "time_from_zero": self.time_from_zero_mat.checkState() == QtCore.Qt.Checked, "time_as_date": self.time_as_date_mat.checkState() == QtCore.Qt.Checked, - "use_display_names": self.use_display_names_mat.checkState() - == QtCore.Qt.Checked, - "reduce_memory_usage": self.reduce_memory_usage_mat.checkState() - == QtCore.Qt.Checked, + "use_display_names": self.use_display_names_mat.checkState() == QtCore.Qt.Checked, + "reduce_memory_usage": self.reduce_memory_usage_mat.checkState() == QtCore.Qt.Checked, "compression": self.export_compression_mat.currentText() == "enabled", "empty_channels": self.empty_channels_mat.currentText(), "mat_format": self.mat_format.currentText(), @@ -1289,13 +1212,10 @@ def _current_options(self): elif output_format == "CSV": new = { - "single_time_base": self.single_time_base_csv.checkState() - == QtCore.Qt.Checked, - "time_from_zero": self.time_from_zero_csv.checkState() - == QtCore.Qt.Checked, + "single_time_base": self.single_time_base_csv.checkState() == QtCore.Qt.Checked, + "time_from_zero": self.time_from_zero_csv.checkState() == QtCore.Qt.Checked, "time_as_date": self.time_as_date_csv.checkState() == QtCore.Qt.Checked, - "use_display_names": self.use_display_names_csv.checkState() - == QtCore.Qt.Checked, + "use_display_names": self.use_display_names_csv.checkState() == QtCore.Qt.Checked, "reduce_memory_usage": False, "compression": False, "empty_channels": self.empty_channels_csv.currentText(), @@ -1303,9 +1223,7 @@ def _current_options(self): "delimiter": self.delimiter.text() or ",", "doublequote": self.doublequote.checkState() == QtCore.Qt.Checked, "escapechar": self.escapechar.text() or None, - "lineterminator": self.lineterminator.text() - .replace("\\r", "\r") - .replace("\\n", "\n"), + "lineterminator": self.lineterminator.text().replace("\\r", "\r").replace("\\n", "\n"), "quotechar": self.quotechar.text() or '"', "quoting": self.quoting.currentText(), "mat_format": None, @@ -1314,14 +1232,11 @@ def _current_options(self): else: new = { - "single_time_base": self.single_time_base.checkState() - == QtCore.Qt.Checked, + "single_time_base": self.single_time_base.checkState() == QtCore.Qt.Checked, "time_from_zero": self.time_from_zero.checkState() == QtCore.Qt.Checked, "time_as_date": self.time_as_date.checkState() == QtCore.Qt.Checked, - "use_display_names": self.use_display_names.checkState() - == QtCore.Qt.Checked, - "reduce_memory_usage": self.reduce_memory_usage.checkState() - == QtCore.Qt.Checked, + "use_display_names": self.use_display_names.checkState() == QtCore.Qt.Checked, + "reduce_memory_usage": self.reduce_memory_usage.checkState() == QtCore.Qt.Checked, "compression": self.export_compression.currentText(), "empty_channels": self.empty_channels.currentText(), "mat_format": None, @@ -1467,16 +1382,10 @@ def apply_processing_thread(self, progress): if needs_filter: icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/filter.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/filter.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) progress.signals.setWindowIcon.emit(icon) - progress.signals.setWindowTitle.emit( - f"Filtering measurement {mdf_index+i} of {count}" - ) - progress.signals.setLabelText.emit( - f'Filtering selected channels from\n"{source_file}"' - ) + progress.signals.setWindowTitle.emit(f"Filtering measurement {mdf_index+i} of {count}") + progress.signals.setLabelText.emit(f'Filtering selected channels from\n"{source_file}"') # filtering self.mdf result = mdf.filter( @@ -1499,13 +1408,9 @@ def apply_processing_thread(self, progress): if opts.needs_cut: icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/cut.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/cut.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) progress.signals.setWindowIcon.emit(icon) - progress.signals.setWindowTitle.emit( - f"Cutting measurement {mdf_index+1} of {count}" - ) + progress.signals.setWindowTitle.emit(f"Cutting measurement {mdf_index+1} of {count}") progress.signals.setLabelText.emit( f"Cutting from {opts.cut_start}s to {opts.cut_stop}s from \n{source_file}" ) @@ -1543,13 +1448,9 @@ def apply_processing_thread(self, progress): message = f"Resampling to {raster}s raster\n{source_file}" icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/resample.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/resample.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) progress.signals.setWindowIcon.emit(icon) - progress.signals.setWindowTitle.emit( - f"Resampling measurement {mdf_index+1} of {count}" - ) + progress.signals.setWindowTitle.emit(f"Resampling measurement {mdf_index+1} of {count}") progress.signals.setLabelText.emit(message) # resample self.mdf @@ -1584,12 +1485,8 @@ def apply_processing_thread(self, progress): QtGui.QIcon.Off, ) progress.signals.setWindowIcon.emit(icon) - progress.signals.setWindowTitle.emit( - f"Converting measurement {mdf_index+1} of {count}" - ) - progress.signals.setLabelText.emit( - f'Converting "{source_file}" from {mdf.version} to {version}' - ) + progress.signals.setWindowTitle.emit(f"Converting measurement {mdf_index+1} of {count}") + progress.signals.setLabelText.emit(f'Converting "{source_file}" from {mdf.version} to {version}') # convert self.mdf result = mdf.convert( @@ -1619,32 +1516,22 @@ def apply_processing_thread(self, progress): if root is None: file_name = output_folder / Path(mdf_file.original_name).name else: - file_name = output_folder / Path(mdf_file.name).relative_to( - root - ) + file_name = output_folder / Path(mdf_file.name).relative_to(root) if not file_name.parent.exists(): os.makedirs(file_name.parent, exist_ok=True) else: file_name = Path(mdf_file.original_name) - file_name = file_name.parent / ( - file_name.stem + ".modified" + suffix - ) + file_name = file_name.parent / (file_name.stem + ".modified" + suffix) file_name = file_name.with_suffix(suffix) # then save it icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/save.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/save.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) progress.signals.setWindowIcon.emit(icon) - progress.signals.setWindowTitle.emit( - f"Saving measurement {mdf_index+1} of {count}" - ) - progress.signals.setLabelText.emit( - f"Saving output file {mdf_index+1} of {count}\n{source_file}" - ) + progress.signals.setWindowTitle.emit(f"Saving measurement {mdf_index+1} of {count}") + progress.signals.setLabelText.emit(f"Saving output file {mdf_index+1} of {count}\n{source_file}") result = mdf.save( dst=file_name, @@ -1658,13 +1545,9 @@ def apply_processing_thread(self, progress): else: icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/export.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/export.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) progress.signals.setWindowIcon.emit(icon) - progress.signals.setWindowTitle.emit( - f"Export measurement {mdf_index+1} of {count}" - ) + progress.signals.setWindowTitle.emit(f"Export measurement {mdf_index+1} of {count}") progress.signals.setLabelText.emit( f"Exporting measurement {mdf_index+1} of {count} to {output_format} (be patient this might take a while)\n{source_file}" ) @@ -1672,9 +1555,7 @@ def apply_processing_thread(self, progress): delimiter = self.delimiter.text() or "," doublequote = self.doublequote.checkState() == QtCore.Qt.Checked escapechar = self.escapechar.text() or None - lineterminator = ( - self.lineterminator.text().replace("\\r", "\r").replace("\\n", "\n") - ) + lineterminator = self.lineterminator.text().replace("\\r", "\r").replace("\\n", "\n") quotechar = self.quotechar.text() or '"' quoting = self.quoting.currentText() add_units = self.add_units.checkState() == QtCore.Qt.Checked @@ -1707,9 +1588,7 @@ def apply_processing_thread(self, progress): target(**kwargs) def change_modify_output_folder(self, event=None): - folder = QtWidgets.QFileDialog.getExistingDirectory( - self, "Select output folder", "" - ) + folder = QtWidgets.QFileDialog.getExistingDirectory(self, "Select output folder", "") if folder: self.modify_output_folder.setText(folder) @@ -1748,9 +1627,7 @@ def sort_alphabetically(self, event=None): if not count: return - source_files = natsorted( - [self.files_list.item(row).text() for row in range(count)] - ) + source_files = natsorted([self.files_list.item(row).text() for row in range(count)]) self.files_list.clear() self.files_list.addItems(source_files) @@ -1789,9 +1666,7 @@ def sort_by_start_time(self, event=None): try: start_times = sorted(start_times) except TypeError: - start_times = [ - (st.replace(tzinfo=timezone.utc), name) for (st, name) in start_times - ] + start_times = [(st.replace(tzinfo=timezone.utc), name) for (st, name) in start_times] start_times = sorted(start_times) self.files_list.clear() @@ -1947,10 +1822,7 @@ def load_filter_list(self, event=None, file_name=None): items = [] self.filter_tree.clear() - source_files = [ - Path(self.files_list.item(row).text()) - for row in range(self.files_list.count()) - ] + source_files = [Path(self.files_list.item(row).text()) for row in range(self.files_list.count())] for file_name in source_files: if file_name.suffix.lower() in (".mdf", ".mf4"): diff --git a/src/asammdf/gui/widgets/bus_database_manager.py b/src/asammdf/gui/widgets/bus_database_manager.py index add23db6b..6cdc5832c 100644 --- a/src/asammdf/gui/widgets/bus_database_manager.py +++ b/src/asammdf/gui/widgets/bus_database_manager.py @@ -67,11 +67,7 @@ def load_can_database(self, event): ) if file_names: - file_names = [ - name - for name in file_names - if Path(name).suffix.lower() in (".arxml", ".dbc") - ] + file_names = [name for name in file_names if Path(name).suffix.lower() in (".arxml", ".dbc")] if file_names: for database in file_names: @@ -92,11 +88,7 @@ def load_lin_database(self, event): ) if file_names: - file_names = [ - name - for name in file_names - if Path(name).suffix.lower() in (".arxml", ".dbc", ".ldf") - ] + file_names = [name for name in file_names if Path(name).suffix.lower() in (".arxml", ".dbc", ".ldf")] if file_names: for database in file_names: diff --git a/src/asammdf/gui/widgets/can_bus_trace.py b/src/asammdf/gui/widgets/can_bus_trace.py index c584c8d90..fbeb030e8 100644 --- a/src/asammdf/gui/widgets/can_bus_trace.py +++ b/src/asammdf/gui/widgets/can_bus_trace.py @@ -15,9 +15,7 @@ class CANBusTrace(TabularBase): add_channels_request = QtCore.Signal(list) - def __init__( - self, signals=None, start=0, format="phys", ranges=None, *args, **kwargs - ): + def __init__(self, signals=None, start=0, format="phys", ranges=None, *args, **kwargs): ranges = ranges or {name: [] for name in signals.columns} if not ranges["Event Type"]: ranges["Event Type"] = [ diff --git a/src/asammdf/gui/widgets/channel_bar_display.py b/src/asammdf/gui/widgets/channel_bar_display.py index 6b862af36..18d99ca7c 100644 --- a/src/asammdf/gui/widgets/channel_bar_display.py +++ b/src/asammdf/gui/widgets/channel_bar_display.py @@ -33,16 +33,9 @@ def resizeEvent(self, event): break if isinstance(self.range[0], int): - self.ticks = [ - int(e) - for e in np.linspace( - self.range[0], self.range[1], parts + 1, True - ).tolist() - ] + self.ticks = [int(e) for e in np.linspace(self.range[0], self.range[1], parts + 1, True).tolist()] else: - self.ticks = np.linspace( - self.range[0], self.range[1], parts + 1, True - ).tolist() + self.ticks = np.linspace(self.range[0], self.range[1], parts + 1, True).tolist() def setValue(self, value): self.value = float(value) @@ -235,15 +228,9 @@ def set_prefix(self, text=""): def update(self): width = self.name.size().width() if self.unit: - self.name.setText( - self.fm.elidedText( - f"{self._name} ({self.unit})", QtCore.Qt.ElideMiddle, width - ) - ) + self.name.setText(self.fm.elidedText(f"{self._name} ({self.unit})", QtCore.Qt.ElideMiddle, width)) else: - self.name.setText( - self.fm.elidedText(self._name, QtCore.Qt.ElideMiddle, width) - ) + self.name.setText(self.fm.elidedText(self._name, QtCore.Qt.ElideMiddle, width)) self.set_value(self._value, update=True) def set_value(self, value, update=False): @@ -265,24 +252,16 @@ def keyPressEvent(self, event): def resizeEvent(self, event): width = self.name.size().width() if self.unit: - self.name.setText( - self.fm.elidedText( - f"{self._name} ({self.unit})", QtCore.Qt.ElideMiddle, width - ) - ) + self.name.setText(self.fm.elidedText(f"{self._name} ({self.unit})", QtCore.Qt.ElideMiddle, width)) else: - self.name.setText( - self.fm.elidedText(self._name, QtCore.Qt.ElideMiddle, width) - ) + self.name.setText(self.fm.elidedText(self._name, QtCore.Qt.ElideMiddle, width)) def text(self): return self._name def does_not_exist(self): icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/error.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/error.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.color_btn.setIcon(icon) self.color_btn.setFlat(True) self.color_btn.clicked.disconnect() diff --git a/src/asammdf/gui/widgets/channel_group_info.py b/src/asammdf/gui/widgets/channel_group_info.py index 805af81f3..d89e3d018 100644 --- a/src/asammdf/gui/widgets/channel_group_info.py +++ b/src/asammdf/gui/widgets/channel_group_info.py @@ -46,9 +46,7 @@ def __init__(self, mdf, group, *args, **kwargs): self.index_size = len(str(channel_group.cycles_nr)) self.cycles = channel_group.cycles_nr if self.mdf.version >= "4.00": - self.record_size = ( - channel_group.samples_byte_nr + channel_group.invalidation_bytes_nr - ) + self.record_size = channel_group.samples_byte_nr + channel_group.invalidation_bytes_nr else: self.record_size = channel_group.samples_byte_nr @@ -84,10 +82,7 @@ def _display(self, position): record_count = record_end - record_offset data = b"".join( - e[0] - for e in self.mdf._load_data( - self.group, record_offset=record_offset, record_count=record_count - ) + e[0] for e in self.mdf._load_data(self.group, record_offset=record_offset, record_count=record_count) ) data = pd.Series(list(np.frombuffer(data, dtype=f"({self.record_size},)u1"))) @@ -111,10 +106,7 @@ def _display(self, position): template.format( index=i, start=l[: self.byte_offset * 3], - middle=l[ - self.byte_offset * 3 : self.byte_offset * 3 - + self.byte_count * 3 - ], + middle=l[self.byte_offset * 3 : self.byte_offset * 3 + self.byte_count * 3], end=l[self.byte_offset * 3 + self.byte_count * 3 :], ) ) @@ -124,6 +116,4 @@ def _display(self, position): if position == 0: self.display.verticalScrollBar().setSliderPosition(0) elif position == self.scroll.maximum(): - self.display.verticalScrollBar().setSliderPosition( - self.display.verticalScrollBar().maximum() - ) + self.display.verticalScrollBar().setSliderPosition(self.display.verticalScrollBar().maximum()) diff --git a/src/asammdf/gui/widgets/channel_stats.py b/src/asammdf/gui/widgets/channel_stats.py index 7cd325441..6561efe78 100644 --- a/src/asammdf/gui/widgets/channel_stats.py +++ b/src/asammdf/gui/widgets/channel_stats.py @@ -52,12 +52,8 @@ def __init__(self, xunit="s", precision=6, *args, **kwargs): label = self.findChild(QtWidgets.QLabel, f"xunit{i}") label.setText(f" {self.xunit}") - self.precision.addItems( - ["Full float precision"] + [f"{i} float decimals" for i in range(16)] - ) - self.precision.setCurrentIndex( - self._settings.value("stats_float_precision", 6, type=int) + 1 - ) + self.precision.addItems(["Full float precision"] + [f"{i} float decimals" for i in range(16)]) + self.precision.setCurrentIndex(self._settings.value("stats_float_precision", 6, type=int) + 1) self.precision.currentIndexChanged.connect(self.set_float_precision) diff --git a/src/asammdf/gui/widgets/collapsiblebox.py b/src/asammdf/gui/widgets/collapsiblebox.py index 96faebe5c..b274e8f2e 100644 --- a/src/asammdf/gui/widgets/collapsiblebox.py +++ b/src/asammdf/gui/widgets/collapsiblebox.py @@ -7,9 +7,7 @@ class CollapsibleBox(QtWidgets.QWidget): def __init__(self, title="", parent=None): super(CollapsibleBox, self).__init__(parent) - self.toggle_button = QtWidgets.QToolButton( - text=title, checkable=True, checked=False - ) + self.toggle_button = QtWidgets.QToolButton(text=title, checkable=True, checked=False) self.toggle_button.setStyleSheet("QToolButton { border: none; }") self.toggle_button.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon) self.toggle_button.setArrowType(QtCore.Qt.RightArrow) @@ -18,9 +16,7 @@ def __init__(self, title="", parent=None): self.toggle_animation = QtCore.QParallelAnimationGroup(self) self.content_area = QtWidgets.QScrollArea(maximumHeight=0, minimumHeight=0) - self.content_area.setSizePolicy( - QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed - ) + self.content_area.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed) self.content_area.setFrameShape(QtWidgets.QFrame.NoFrame) lay = QtWidgets.QVBoxLayout(self) @@ -29,26 +25,16 @@ def __init__(self, title="", parent=None): lay.addWidget(self.toggle_button) lay.addWidget(self.content_area) - self.toggle_animation.addAnimation( - QtCore.QPropertyAnimation(self, b"minimumHeight") - ) - self.toggle_animation.addAnimation( - QtCore.QPropertyAnimation(self, b"maximumHeight") - ) - self.toggle_animation.addAnimation( - QtCore.QPropertyAnimation(self.content_area, b"maximumHeight") - ) + self.toggle_animation.addAnimation(QtCore.QPropertyAnimation(self, b"minimumHeight")) + self.toggle_animation.addAnimation(QtCore.QPropertyAnimation(self, b"maximumHeight")) + self.toggle_animation.addAnimation(QtCore.QPropertyAnimation(self.content_area, b"maximumHeight")) @QtCore.pyqtSlot() def on_pressed(self): checked = self.toggle_button.isChecked() - self.toggle_button.setArrowType( - QtCore.Qt.DownArrow if not checked else QtCore.Qt.RightArrow - ) + self.toggle_button.setArrowType(QtCore.Qt.DownArrow if not checked else QtCore.Qt.RightArrow) self.toggle_animation.setDirection( - QtCore.QAbstractAnimation.Forward - if not checked - else QtCore.QAbstractAnimation.Backward + QtCore.QAbstractAnimation.Forward if not checked else QtCore.QAbstractAnimation.Backward ) self.toggle_animation.start() @@ -64,9 +50,7 @@ def setContentLayout(self, layout): animation.setStartValue(collapsed_height) animation.setEndValue(collapsed_height + content_height) - content_animation = self.toggle_animation.animationAt( - self.toggle_animation.animationCount() - 1 - ) + content_animation = self.toggle_animation.animationAt(self.toggle_animation.animationCount() - 1) content_animation.setDuration(200) content_animation.setStartValue(0) content_animation.setEndValue(content_height) diff --git a/src/asammdf/gui/widgets/cursor.py b/src/asammdf/gui/widgets/cursor.py index 473f583ea..a5b3837b5 100644 --- a/src/asammdf/gui/widgets/cursor.py +++ b/src/asammdf/gui/widgets/cursor.py @@ -72,9 +72,7 @@ def _computeBoundingRect(self): ## add a 6-pixel radius around the line for mouse interaction. - px = self.pixelLength( - direction=pg.Point(1, 0), ortho=True - ) ## get pixel length orthogonal to the line + px = self.pixelLength(direction=pg.Point(1, 0), ortho=True) ## get pixel length orthogonal to the line if px is None: px = 0 pw = max(self.pen.width() / 2, self.hoverPen.width() / 2) @@ -190,14 +188,10 @@ def paint(self, paint, *args, plot=None, uuid=None): paint.drawRect(rect2) pix = QtGui.QPixmap(":/edit.png").scaled(16, 16) - paint.drawPixmap( - QtCore.QPointF(rect.x() + rect.width() - 34, rect.y() + 1), pix - ) + paint.drawPixmap(QtCore.QPointF(rect.x() + rect.width() - 34, rect.y() + 1), pix) pix = QtGui.QPixmap(":/erase.png").scaled(16, 16) - paint.drawPixmap( - QtCore.QPointF(rect.x() + rect.width() - 17, rect.y() + 1), pix - ) + paint.drawPixmap(QtCore.QPointF(rect.x() + rect.width() - 17, rect.y() + 1), pix) def set_value(self, value): self.setPos(value) @@ -329,33 +323,21 @@ def paint(self, paint, *args, plot=None, uuid=None): ) if self.show_circle: - paint.drawLine( - QtCore.QPointF(x, 0), QtCore.QPointF(x, y - 5) - ) - paint.drawLine( - QtCore.QPointF(x, y + 5), QtCore.QPointF(x, height) - ) + paint.drawLine(QtCore.QPointF(x, 0), QtCore.QPointF(x, y - 5)) + paint.drawLine(QtCore.QPointF(x, y + 5), QtCore.QPointF(x, height)) if self.show_horizontal_line: - paint.drawLine( - QtCore.QPointF(delta, y), QtCore.QPointF(x - 5, y) - ) - paint.drawLine( - QtCore.QPointF(x + 5, y), QtCore.QPointF(width, y) - ) + paint.drawLine(QtCore.QPointF(delta, y), QtCore.QPointF(x - 5, y)) + paint.drawLine(QtCore.QPointF(x + 5, y), QtCore.QPointF(width, y)) paint.setRenderHints(paint.RenderHint.Antialiasing, True) paint.drawEllipse(QtCore.QPointF(x, y), 5, 5) paint.setRenderHints(paint.RenderHint.Antialiasing, False) else: - paint.drawLine( - QtCore.QPointF(x, 0), QtCore.QPointF(x, height) - ) + paint.drawLine(QtCore.QPointF(x, 0), QtCore.QPointF(x, height)) if self.show_horizontal_line: - paint.drawLine( - QtCore.QPointF(delta, y), QtCore.QPointF(width, y) - ) + paint.drawLine(QtCore.QPointF(delta, y), QtCore.QPointF(width, y)) else: x, y = plot.scale_curve_to_pixmap( @@ -384,9 +366,7 @@ def _computeBoundingRect(self): ## add a 6-pixel radius around the line for mouse interaction. - px = self.pixelLength( - direction=pg.Point(1, 0), ortho=True - ) ## get pixel length orthogonal to the line + px = self.pixelLength(direction=pg.Point(1, 0), ortho=True) ## get pixel length orthogonal to the line if px is None: px = 0 pw = max(self.pen.width() / 2, self.hoverPen.width() / 2) diff --git a/src/asammdf/gui/widgets/database_item.py b/src/asammdf/gui/widgets/database_item.py index 1cddd4cce..b40d68cd2 100644 --- a/src/asammdf/gui/widgets/database_item.py +++ b/src/asammdf/gui/widgets/database_item.py @@ -10,9 +10,7 @@ def __init__(self, database, bus_type="CAN"): super().__init__() self.setupUi(self) - items = [f"Any {bus_type} bus"] + [ - f"{bus_type} {i:>2} only" for i in range(1, 17) - ] + items = [f"Any {bus_type} bus"] + [f"{bus_type} {i:>2} only" for i in range(1, 17)] self.database.setText(database.strip()) self.bus.addItems(items) diff --git a/src/asammdf/gui/widgets/dict_to_tree.py b/src/asammdf/gui/widgets/dict_to_tree.py index 4ed613d7c..879930c7c 100644 --- a/src/asammdf/gui/widgets/dict_to_tree.py +++ b/src/asammdf/gui/widgets/dict_to_tree.py @@ -23,11 +23,7 @@ def new_item(parent, text, val=None): new_item(item, str(key), val) elif isinstance(value, (list, tuple)): for val in value: - text = ( - str(val) - if not isinstance(val, (dict, list, tuple)) - else "[%s]" % type(val).__name__ - ) + text = str(val) if not isinstance(val, (dict, list, tuple)) else "[%s]" % type(val).__name__ new_item(item, text, val) else: new_item(item, str(value)) diff --git a/src/asammdf/gui/widgets/fft_window.py b/src/asammdf/gui/widgets/fft_window.py index daafe5f7a..39d3fb0e4 100644 --- a/src/asammdf/gui/widgets/fft_window.py +++ b/src/asammdf/gui/widgets/fft_window.py @@ -59,9 +59,7 @@ def update(self, *args, initial=False): if len(self.signal) and steps: f = np.linspace(start_frequency, end_frequency, steps) - pgram = scipy_signal.lombscargle( - signal.timestamps, signal.samples, f * 2 * np.pi, normalize=True - ) + pgram = scipy_signal.lombscargle(signal.timestamps, signal.samples, f * 2 * np.pi, normalize=True) signal = Signal(samples=pgram, timestamps=f, name=f"{self.signal.name}_FFT") signal.color = self.signal.color diff --git a/src/asammdf/gui/widgets/file.py b/src/asammdf/gui/widgets/file.py index 5cba8e8d6..43cbc75c5 100644 --- a/src/asammdf/gui/widgets/file.py +++ b/src/asammdf/gui/widgets/file.py @@ -151,18 +151,14 @@ def __init__( self._show_filter_tree = False self.line_interconnect = line_interconnect if show_progress: - progress = QtWidgets.QProgressDialog( - f'Opening "{self.file_name}"', "", 0, 100, self.parent() - ) + progress = QtWidgets.QProgressDialog(f'Opening "{self.file_name}"', "", 0, 100, self.parent()) progress.setWindowModality(QtCore.Qt.ApplicationModal) progress.setCancelButton(None) progress.setAutoClose(True) progress.setWindowTitle("Opening measurement") icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/open.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/open.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) progress.setWindowIcon(icon) progress.setMinimumWidth(600) progress.show() @@ -280,26 +276,14 @@ def __init__( self.channel_view.setCurrentIndex(-1) self.filter_view.setCurrentIndex(-1) - self.filter_view.setCurrentText( - self._settings.value("filter_view", "Internal file structure") - ) + self.filter_view.setCurrentText(self._settings.value("filter_view", "Internal file structure")) - self.channel_view.currentIndexChanged.connect( - partial(self._update_channel_tree, widget=self.channels_tree) - ) - self.filter_view.currentIndexChanged.connect( - partial(self._update_channel_tree, widget=self.filter_tree) - ) - self.channel_view.currentTextChanged.connect( - partial(self._update_channel_tree, widget=self.channels_tree) - ) - self.filter_view.currentTextChanged.connect( - partial(self._update_channel_tree, widget=self.filter_tree) - ) + self.channel_view.currentIndexChanged.connect(partial(self._update_channel_tree, widget=self.channels_tree)) + self.filter_view.currentIndexChanged.connect(partial(self._update_channel_tree, widget=self.filter_tree)) + self.channel_view.currentTextChanged.connect(partial(self._update_channel_tree, widget=self.channels_tree)) + self.filter_view.currentTextChanged.connect(partial(self._update_channel_tree, widget=self.filter_tree)) - self.channel_view.setCurrentText( - self._settings.value("channels_view", "Internal file structure") - ) + self.channel_view.setCurrentText(self._settings.value("channels_view", "Internal file structure")) if progress: progress.setValue(70) QtWidgets.QApplication.processEvents() @@ -313,9 +297,7 @@ def __init__( self.mdf_version.insertItems(0, SUPPORTED_VERSIONS) self.mdf_version.setCurrentText("4.10") - self.mdf_compression.insertItems( - 0, ("no compression", "deflate", "transposed deflate") - ) + self.mdf_compression.insertItems(0, ("no compression", "deflate", "transposed deflate")) self.mdf_compression.setCurrentText("transposed deflate") self.mdf_split_size.setValue(4) @@ -324,9 +306,7 @@ def __init__( index = self.extract_bus_format.findText(self.mdf.version) if index >= 0: self.extract_bus_format.setCurrentIndex(index) - self.extract_bus_compression.insertItems( - 0, ("no compression", "deflate", "transposed deflate") - ) + self.extract_bus_compression.insertItems(0, ("no compression", "deflate", "transposed deflate")) self.extract_bus_compression.setCurrentText("transposed deflate") self.extract_bus_btn.clicked.connect(self.extract_bus_logging) self.extract_bus_csv_btn.clicked.connect(self.extract_bus_csv_logging) @@ -372,9 +352,7 @@ def __init__( progress.setValue(100) progress.deleteLater() - self.load_channel_list_btn.clicked.connect( - partial(self.load_channel_list, manually=True) - ) + self.load_channel_list_btn.clicked.connect(partial(self.load_channel_list, manually=True)) self.save_channel_list_btn.clicked.connect(self.save_channel_list) self.load_filter_list_btn.clicked.connect(self.load_filter_list) self.save_filter_list_btn.clicked.connect(self.save_filter_list) @@ -397,10 +375,7 @@ def __init__( if self.mdf.version >= "4.00" and self.mdf.attachments: for i, attachment in enumerate(self.mdf.attachments, 1): - if ( - attachment.file_name == "user_embedded_display.dspf" - and attachment.mime == r"application/x-dspf" - ): + if attachment.file_name == "user_embedded_display.dspf" and attachment.mime == r"application/x-dspf": hide_embedded_btn = False att = Attachment(i - 1, self.mdf) @@ -472,9 +447,7 @@ def __init__( if hide_embedded_btn: self.load_embedded_channel_list_btn.setDisabled(True) - self.load_embedded_channel_list_btn.clicked.connect( - self.load_embedded_display_file - ) + self.load_embedded_channel_list_btn.clicked.connect(self.load_embedded_display_file) self.save_embedded_channel_list_btn.clicked.connect(self.embed_display_file) if self.mdf.version >= "4.00": @@ -485,10 +458,7 @@ def __init__( self.save_embedded_channel_list_btn.setEnabled(False) if self.mdf.version >= "4.00": - if not any( - group.channel_group.flags & FLAG_CG_BUS_EVENT - for group in self.mdf.groups - ): + if not any(group.channel_group.flags & FLAG_CG_BUS_EVENT for group in self.mdf.groups): self.aspects.setTabVisible(2, False) else: self.aspects.setTabVisible(2, False) @@ -530,18 +500,14 @@ def __init__( if display_file: self.load_channel_list(file_name=display_file) else: - default_display_file = self.mdf.header._common_properties.get( - "pr_display_file", "" - ) + default_display_file = self.mdf.header._common_properties.get("pr_display_file", "") if default_display_file: default_display_file = Path(default_display_file) if default_display_file.exists(): self.load_channel_list(file_name=default_display_file) else: - default_display_file = ( - Path(self.mdf.original_name).parent / default_display_file.name - ) + default_display_file = Path(self.mdf.original_name).parent / default_display_file.name if default_display_file.exists(): self.load_channel_list(file_name=default_display_file) @@ -645,9 +611,7 @@ def _update_channel_tree(self, index=None, widget=None): if ico is not None: icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(ico), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(ico), QtGui.QIcon.Normal, QtGui.QIcon.Off) channel_group.setIcon(0, icon) @@ -671,19 +635,14 @@ def _update_channel_tree(self, index=None, widget=None): channel_group.setText(0, name) channel_group.setFlags( - channel_group.flags() - | QtCore.Qt.ItemIsAutoTristate - | QtCore.Qt.ItemIsUserCheckable + channel_group.flags() | QtCore.Qt.ItemIsAutoTristate | QtCore.Qt.ItemIsUserCheckable ) if group.channel_group.cycles_nr: channel_group.setForeground(0, QtGui.QBrush(QtGui.QColor(GREEN))) items.append(channel_group) - channels = [ - HelperChannel(name=ch.name, entry=(i, j)) - for j, ch in enumerate(group.channels) - ] + channels = [HelperChannel(name=ch.name, entry=(i, j)) for j, ch in enumerate(group.channels)] add_children( channel_group, @@ -1127,9 +1086,7 @@ def load_channel_list(self, event=None, file_name=None, manually=False): ".mf4", ".mf4z", ) - and not self.mdf.header._common_properties.get( - "pr_display_file", "" - ) + and not self.mdf.header._common_properties.get("pr_display_file", "") and manually ): result = MessageBox.question( @@ -1160,9 +1117,7 @@ def load_channel_list(self, event=None, file_name=None, manually=False): suffix = original_file_name.suffix.lower() if suffix == ".mf4z": - with ZipFile( - original_file_name, allowZip64=True - ) as archive: + with ZipFile(original_file_name, allowZip64=True) as archive: files = archive.namelist() if len(files) != 1: return @@ -1178,9 +1133,7 @@ def load_channel_list(self, event=None, file_name=None, manually=False): with open(mdf_file_name, "r+b") as mdf: try: - header._common_properties[ - "pr_display_file" - ] = display_file_name + header._common_properties["pr_display_file"] = display_file_name comment = TextV4(meta=True, text=header.comment) mdf.seek(0, 2) @@ -1203,9 +1156,7 @@ def load_channel_list(self, event=None, file_name=None, manually=False): return if suffix == ".mf4z": - zipped_mf4 = ZipFile( - original_file_name, "w", compression=ZIP_DEFLATED - ) + zipped_mf4 = ZipFile(original_file_name, "w", compression=ZIP_DEFLATED) zipped_mf4.write( str(mdf_file_name), original_file_name.with_suffix(".mf4").name, @@ -1290,9 +1241,7 @@ def load_channel_list(self, event=None, file_name=None, manually=False): else: for window in info["windows"]: if window["type"] == "Plot": - for name, definition in get_functions( - window["configuration"]["channels"] - ).items(): + for name, definition in get_functions(window["configuration"]["channels"]).items(): if name in self.functions: if self.functions[name] != definition: new_functions[os.urandom(6).hex()] = { @@ -1529,9 +1478,7 @@ def compute_cut_hints(self): if len(master_min): t_min.append(master_min[0]) self.mdf._master_channel_cache.clear() - master_max = self.mdf.get_master( - i, record_offset=cycles_nr - 1, record_count=1 - ) + master_max = self.mdf.get_master(i, record_offset=cycles_nr - 1, record_count=1) if len(master_max): t_max.append(master_max[0]) self.mdf._master_channel_cache.clear() @@ -1542,9 +1489,7 @@ def compute_cut_hints(self): self.cut_start.setRange(*time_range) self.cut_stop.setRange(*time_range) - self.cut_interval.setText( - "Cut interval ({:.6f}s - {:.6f}s)".format(*time_range) - ) + self.cut_interval.setText("Cut interval ({:.6f}s - {:.6f}s)".format(*time_range)) else: self.cut_start.setRange(0, 0) self.cut_stop.setRange(0, 0) @@ -1767,9 +1712,7 @@ def _create_window(self, event=None, window_type=None): def scramble_thread(self, progress): icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/scramble.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/scramble.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) progress.signals.setWindowIcon.emit(icon) progress.signals.setWindowTitle.emit("Scrambling measurement") progress.signals.setLabelText.emit(f'Scrambling "{self.file_name}"') @@ -1816,9 +1759,7 @@ def extract_bus_logging(self, event): for i in range(count1): item = self.can_database_list.item(i) widget = self.can_database_list.itemWidget(item) - database_files["CAN"].append( - (widget.database.text(), widget.bus.currentIndex()) - ) + database_files["CAN"].append((widget.database.text(), widget.bus.currentIndex())) count2 = self.lin_database_list.count() if count2: @@ -1826,9 +1767,7 @@ def extract_bus_logging(self, event): for i in range(count2): item = self.lin_database_list.item(i) widget = self.lin_database_list.itemWidget(item) - database_files["LIN"].append( - (widget.database.text(), widget.bus.currentIndex()) - ) + database_files["LIN"].append((widget.database.text(), widget.bus.currentIndex())) compression = self.extract_bus_compression.currentIndex() @@ -1862,18 +1801,14 @@ def extract_bus_logging(self, event): kwargs={}, ) - def extract_bus_logging_thread( - self, file_name, suffix, database_files, version, compression, progress - ): + def extract_bus_logging_thread(self, file_name, suffix, database_files, version, compression, progress): file_name = Path(file_name).with_suffix(suffix) icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap(":/down.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) progress.signals.setWindowIcon.emit(icon) progress.signals.setWindowTitle.emit("Extract Bus logging") - progress.signals.setLabelText.emit( - f'Extracting Bus signals from "{self.file_name}"' - ) + progress.signals.setLabelText.emit(f'Extracting Bus signals from "{self.file_name}"') # convert self.mdf result = self.mdf.extract_bus_logging( @@ -1913,9 +1848,7 @@ def extract_bus_logging_thread( f'- {found_id_count} of {len(call_info["total_unique_ids"])} IDs in the MDF4 file were matched in the DBC and converted', ] if call_info["unknown_id_count"]: - message.append( - f'- {call_info["unknown_id_count"]} unknown IDs in the MDF4 file' - ) + message.append(f'- {call_info["unknown_id_count"]} unknown IDs in the MDF4 file') else: message.append(f"- no unknown IDs inf the MDF4 file") @@ -1931,21 +1864,15 @@ def extract_bus_logging_thread( message.append(f"- 0x{msg_id:X} --> {msg_name} in <{dbc_name}>") except: pgn, sa = msg_id - message.append( - f"- PGN=0x{pgn:X} SA=0x{sa:X} --> {msg_name} in <{dbc_name}>" - ) + message.append(f"- PGN=0x{pgn:X} SA=0x{sa:X} --> {msg_name} in <{dbc_name}>") message += [ "", f"The following {bus} IDs were in the MDF log file, but not matched in the DBC:", ] - unknown_standard_can = sorted( - [e for e in call_info["unknown_ids"] if isinstance(e, int)] - ) - unknown_j1939 = sorted( - [e for e in call_info["unknown_ids"] if not isinstance(e, int)] - ) + unknown_standard_can = sorted([e for e in call_info["unknown_ids"] if isinstance(e, int)]) + unknown_j1939 = sorted([e for e in call_info["unknown_ids"] if not isinstance(e, int)]) for msg_id in unknown_standard_can: message.append(f"- 0x{msg_id:X}") @@ -1977,9 +1904,7 @@ def extract_bus_csv_logging(self, event): for i in range(count1): item = self.can_database_list.item(i) widget = self.can_database_list.itemWidget(item) - database_files["CAN"].append( - (widget.database.text(), widget.bus.currentIndex()) - ) + database_files["CAN"].append((widget.database.text(), widget.bus.currentIndex())) count2 = self.lin_database_list.count() if count2: @@ -1987,9 +1912,7 @@ def extract_bus_csv_logging(self, event): for i in range(count2): item = self.lin_database_list.item(i) widget = self.lin_database_list.itemWidget(item) - database_files["LIN"].append( - (widget.database.text(), widget.bus.currentIndex()) - ) + database_files["LIN"].append((widget.database.text(), widget.bus.currentIndex())) if not (count1 + count2): return @@ -2002,9 +1925,7 @@ def extract_bus_csv_logging(self, event): delimiter = self.delimiter_bus.text() or "," doublequote = self.doublequote_bus.checkState() == QtCore.Qt.Checked escapechar = self.escapechar_bus.text() or None - lineterminator = ( - self.lineterminator_bus.text().replace("\\r", "\r").replace("\\n", "\n") - ) + lineterminator = self.lineterminator_bus.text().replace("\\r", "\r").replace("\\n", "\n") quotechar = self.quotechar_bus.text() or '"' quoting = self.quoting_bus.currentText() add_units = self.add_units_bus.checkState() == QtCore.Qt.Checked @@ -2068,9 +1989,7 @@ def extract_bus_csv_logging_thread( icon.addPixmap(QtGui.QPixmap(":/csv.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) progress.signals.setWindowIcon.emit(icon) progress.signals.setWindowTitle.emit("Extract Bus logging to CSV") - progress.signals.setLabelText.emit( - f'Extracting Bus signals from "{self.file_name}"' - ) + progress.signals.setLabelText.emit(f'Extracting Bus signals from "{self.file_name}"') # convert self.mdf result = self.mdf.extract_bus_logging( @@ -2129,9 +2048,7 @@ def extract_bus_csv_logging_thread( f'- {found_id_count} of {len(call_info["total_unique_ids"])} IDs in the MDF4 file were matched in the DBC and converted', ] if call_info["unknown_id_count"]: - message.append( - f'- {call_info["unknown_id_count"]} unknown IDs in the MDF4 file' - ) + message.append(f'- {call_info["unknown_id_count"]} unknown IDs in the MDF4 file') else: message.append(f"- no unknown IDs inf the MDF4 file") @@ -2147,9 +2064,7 @@ def extract_bus_csv_logging_thread( message.append(f"- 0x{msg_id:X} --> {msg_name} in <{dbc_name}>") except: pgn, sa = msg_id - message.append( - f"- PGN=0x{pgn:X} SA=0x{sa:X} --> {msg_name} in <{dbc_name}>" - ) + message.append(f"- PGN=0x{pgn:X} SA=0x{sa:X} --> {msg_name} in <{dbc_name}>") message += [ "", @@ -2171,11 +2086,7 @@ def load_can_database(self, event): ) if file_names: - file_names = [ - name - for name in file_names - if Path(name).suffix.lower() in (".arxml", ".dbc") - ] + file_names = [name for name in file_names if Path(name).suffix.lower() in (".arxml", ".dbc")] if file_names: for database in file_names: @@ -2196,11 +2107,7 @@ def load_lin_database(self, event): ) if file_names: - file_names = [ - name - for name in file_names - if Path(name).suffix.lower() in (".arxml", ".dbc", ".ldf") - ] + file_names = [name for name in file_names if Path(name).suffix.lower() in (".arxml", ".dbc", ".ldf")] if file_names: for database in file_names: @@ -2243,9 +2150,7 @@ def keyPressEvent(self, event): elif mode == "tile horizontally": self.mdi_area.tile_horizontally() - elif key == QtCore.Qt.Key_F and modifier == ( - QtCore.Qt.ShiftModifier | QtCore.Qt.AltModifier - ): + elif key == QtCore.Qt.Key_F and modifier == (QtCore.Qt.ShiftModifier | QtCore.Qt.AltModifier): self.toggle_frames() elif key == QtCore.Qt.Key_L and modifier == QtCore.Qt.ShiftModifier: @@ -2297,9 +2202,7 @@ def aspect_changed(self, index): if self.aspects.tabText(current_index) == "Modify && Export": if not self.raster_channel.count(): - self.raster_channel.setSizeAdjustPolicy( - QtWidgets.QComboBox.AdjustToMinimumContentsLengthWithIcon - ) + self.raster_channel.setSizeAdjustPolicy(QtWidgets.QComboBox.AdjustToMinimumContentsLengthWithIcon) self.raster_channel.addItems(self.channels_db_items) self.raster_channel.setMinimumWidth(100) @@ -2347,17 +2250,12 @@ def aspect_changed(self, index): channel_group.setText(0, name) channel_group.setFlags( - channel_group.flags() - | QtCore.Qt.ItemIsAutoTristate - | QtCore.Qt.ItemIsUserCheckable + channel_group.flags() | QtCore.Qt.ItemIsAutoTristate | QtCore.Qt.ItemIsUserCheckable ) widget.addTopLevelItem(channel_group) - channels = [ - HelperChannel(name=ch.name, entry=(i, j)) - for j, ch in enumerate(group.channels) - ] + channels = [HelperChannel(name=ch.name, entry=(i, j)) for j, ch in enumerate(group.channels)] add_children( channel_group, @@ -2444,9 +2342,7 @@ def aspect_changed(self, index): item.setText(0, "Program identification") item.setText( 1, - self.mdf.identification.program_identification.decode("ascii").strip( - " \r\n\t\0" - ), + self.mdf.identification.program_identification.decode("ascii").strip(" \r\n\t\0"), ) children.append(item) @@ -2520,14 +2416,9 @@ def aspect_changed(self, index): size = channel_group.samples_byte_nr * cycles else: if channel_group.flags & 0x1: - size = channel_group.samples_byte_nr + ( - channel_group.invalidation_bytes_nr << 32 - ) + size = channel_group.samples_byte_nr + (channel_group.invalidation_bytes_nr << 32) else: - size = ( - channel_group.samples_byte_nr - + channel_group.invalidation_bytes_nr - ) * cycles + size = (channel_group.samples_byte_nr + channel_group.invalidation_bytes_nr) * cycles if group.channel_group.acq_source: source = group.channel_group.acq_source @@ -2546,9 +2437,7 @@ def aspect_changed(self, index): if ico is not None: icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(ico), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(ico), QtGui.QIcon.Normal, QtGui.QIcon.Off) channel_group_item.setIcon(0, icon) item = QtWidgets.QTreeWidgetItem() @@ -2585,18 +2474,14 @@ def aspect_changed(self, index): channels = QtWidgets.QTreeWidgetItem() channels.setText(0, "Channels") - channels.setText( - 1, str(sum(len(entry) for entry in self.mdf.channels_db.values())) - ) + channels.setText(1, str(sum(len(entry) for entry in self.mdf.channels_db.values()))) children.append(channels) mdf_info.addChildren(children) self.info.expandAll() - self.info.header().setSectionResizeMode( - 0, QtWidgets.QHeaderView.ResizeToContents - ) + self.info.header().setSectionResizeMode(0, QtWidgets.QHeaderView.ResizeToContents) def toggle_frames(self, event=None): self._frameless_windows = not self._frameless_windows @@ -2625,16 +2510,14 @@ def _current_options(self): "needs_cut": self.cut_group.isChecked(), "cut_start": self.cut_start.value(), "cut_stop": self.cut_stop.value(), - "cut_time_from_zero": self.cut_time_from_zero.checkState() - == QtCore.Qt.Checked, + "cut_time_from_zero": self.cut_time_from_zero.checkState() == QtCore.Qt.Checked, "whence": int(self.whence.checkState() == QtCore.Qt.Checked), "needs_resample": self.resample_group.isChecked(), "raster_type_step": self.raster_type_step.isChecked(), "raster_type_channel": self.raster_type_channel.isChecked(), "raster": self.raster.value(), "raster_channel": self.raster_channel.currentText(), - "resample_time_from_zero": self.resample_time_from_zero.checkState() - == QtCore.Qt.Checked, + "resample_time_from_zero": self.resample_time_from_zero.checkState() == QtCore.Qt.Checked, "output_format": self.output_format.currentText(), } @@ -2650,15 +2533,11 @@ def _current_options(self): elif output_format == "MAT": new = { - "single_time_base": self.single_time_base_mat.checkState() - == QtCore.Qt.Checked, - "time_from_zero": self.time_from_zero_mat.checkState() - == QtCore.Qt.Checked, + "single_time_base": self.single_time_base_mat.checkState() == QtCore.Qt.Checked, + "time_from_zero": self.time_from_zero_mat.checkState() == QtCore.Qt.Checked, "time_as_date": self.time_as_date_mat.checkState() == QtCore.Qt.Checked, - "use_display_names": self.use_display_names_mat.checkState() - == QtCore.Qt.Checked, - "reduce_memory_usage": self.reduce_memory_usage_mat.checkState() - == QtCore.Qt.Checked, + "use_display_names": self.use_display_names_mat.checkState() == QtCore.Qt.Checked, + "reduce_memory_usage": self.reduce_memory_usage_mat.checkState() == QtCore.Qt.Checked, "compression": self.export_compression_mat.currentText() == "enabled", "empty_channels": self.empty_channels_mat.currentText(), "mat_format": self.mat_format.currentText(), @@ -2668,13 +2547,10 @@ def _current_options(self): elif output_format == "CSV": new = { - "single_time_base": self.single_time_base_csv.checkState() - == QtCore.Qt.Checked, - "time_from_zero": self.time_from_zero_csv.checkState() - == QtCore.Qt.Checked, + "single_time_base": self.single_time_base_csv.checkState() == QtCore.Qt.Checked, + "time_from_zero": self.time_from_zero_csv.checkState() == QtCore.Qt.Checked, "time_as_date": self.time_as_date_csv.checkState() == QtCore.Qt.Checked, - "use_display_names": self.use_display_names_csv.checkState() - == QtCore.Qt.Checked, + "use_display_names": self.use_display_names_csv.checkState() == QtCore.Qt.Checked, "reduce_memory_usage": False, "compression": False, "empty_channels": self.empty_channels_csv.currentText(), @@ -2682,9 +2558,7 @@ def _current_options(self): "delimiter": self.delimiter.text() or ",", "doublequote": self.doublequote.checkState() == QtCore.Qt.Checked, "escapechar": self.escapechar.text() or None, - "lineterminator": self.lineterminator.text() - .replace("\\r", "\r") - .replace("\\n", "\n"), + "lineterminator": self.lineterminator.text().replace("\\r", "\r").replace("\\n", "\n"), "quotechar": self.quotechar.text() or '"', "quoting": self.quoting.currentText(), "mat_format": None, @@ -2693,14 +2567,11 @@ def _current_options(self): else: new = { - "single_time_base": self.single_time_base.checkState() - == QtCore.Qt.Checked, + "single_time_base": self.single_time_base.checkState() == QtCore.Qt.Checked, "time_from_zero": self.time_from_zero.checkState() == QtCore.Qt.Checked, "time_as_date": self.time_as_date.checkState() == QtCore.Qt.Checked, - "use_display_names": self.use_display_names.checkState() - == QtCore.Qt.Checked, - "reduce_memory_usage": self.reduce_memory_usage.checkState() - == QtCore.Qt.Checked, + "use_display_names": self.use_display_names.checkState() == QtCore.Qt.Checked, + "reduce_memory_usage": self.reduce_memory_usage.checkState() == QtCore.Qt.Checked, "compression": self.export_compression.currentText(), "empty_channels": self.empty_channels.currentText(), "mat_format": None, @@ -2806,9 +2677,7 @@ def apply_processing(self, event): filter = "MDF version 3 files (*.dat *.mdf)" default = filter else: - filter = ( - "MDF version 4 files (*.mf4);;Zipped MDF version 4 files (*.mf4z)" - ) + filter = "MDF version 4 files (*.mf4);;Zipped MDF version 4 files (*.mf4z)" if Path(self.mdf.original_name).suffix.lower() == ".mf4z": default = "Zipped MDF version 4 files (*.mf4z)" else: @@ -2862,9 +2731,7 @@ def apply_processing(self, event): def apply_processing_finished(self): self._progress = None - def apply_processing_thread( - self, file_name, opts, version, needs_filter, channels, progress=None - ): + def apply_processing_thread(self, file_name, opts, version, needs_filter, channels, progress=None): output_format = opts.output_format split_size = opts.mdf_split_size if output_format == "MDF" else 0 @@ -2876,14 +2743,10 @@ def apply_processing_thread( if needs_filter: icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/filter.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/filter.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) progress.signals.setWindowIcon.emit(icon) progress.signals.setWindowTitle.emit("Filtering measurement") - progress.signals.setLabelText.emit( - f'Filtering selected channels from "{self.file_name}"' - ) + progress.signals.setLabelText.emit(f'Filtering selected channels from "{self.file_name}"') # filtering self.mdf result = self.mdf.filter( @@ -2906,14 +2769,10 @@ def apply_processing_thread( if opts.needs_cut: icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/cut.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/cut.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) progress.signals.setWindowIcon.emit(icon) progress.signals.setWindowTitle.emit("Cutting measurement") - progress.signals.setLabelText.emit( - f"Cutting from {opts.cut_start}s to {opts.cut_stop}s" - ) + progress.signals.setLabelText.emit(f"Cutting from {opts.cut_start}s to {opts.cut_stop}s") # cut self.mdf target = self.mdf.cut if mdf is None else mdf.cut @@ -2951,9 +2810,7 @@ def apply_processing_thread( message = f"Resampling to {raster}s raster" icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/resample.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/resample.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) progress.signals.setWindowIcon.emit(icon) progress.signals.setWindowTitle.emit("Resampling measurement") progress.signals.setLabelText.emit(message) @@ -2987,9 +2844,7 @@ def apply_processing_thread( if output_format == "MDF": if mdf is None: icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/convert.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/convert.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) progress.signals.setWindowIcon.emit(icon) progress.signals.setWindowTitle.emit("Converting measurement") progress.signals.setLabelText.emit( @@ -3016,9 +2871,7 @@ def apply_processing_thread( # then save it icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/save.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/save.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) progress.signals.setWindowIcon.emit(icon) progress.signals.setWindowTitle.emit("Saving measurement") progress.signals.setLabelText.emit(f'Saving output file "{file_name}"') @@ -3070,21 +2923,15 @@ def apply_processing_thread( else: icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/export.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/export.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) progress.signals.setWindowIcon.emit(icon) progress.signals.setWindowTitle.emit("Export measurement") - progress.signals.setLabelText.emit( - f"Exporting to {output_format} (be patient this might take a while)" - ) + progress.signals.setLabelText.emit(f"Exporting to {output_format} (be patient this might take a while)") delimiter = self.delimiter.text() or "," doublequote = self.doublequote.checkState() == QtCore.Qt.Checked escapechar = self.escapechar.text() or None - lineterminator = ( - self.lineterminator.text().replace("\\r", "\r").replace("\\n", "\n") - ) + lineterminator = self.lineterminator.text().replace("\\r", "\r").replace("\\n", "\n") quotechar = self.quotechar.text() or '"' quoting = self.quoting.currentText() add_units = self.add_units.checkState() == QtCore.Qt.Checked @@ -3165,10 +3012,7 @@ def update_selected_filter_channels(self): self.selected_filter_channels.addItems(sorted(self._selected_filter)) def embed_display_file(self, event=None): - if ( - not self.save_embedded_channel_list_btn.isVisible() - or not self.save_embedded_channel_list_btn.isEnabled() - ): + if not self.save_embedded_channel_list_btn.isVisible() or not self.save_embedded_channel_list_btn.isEnabled(): return original_file_name = Path(self.mdf.original_name) @@ -3177,8 +3021,7 @@ def embed_display_file(self, event=None): return MessageBox.warning( self, "Wrong file type", - "The display file can only be embedded in .mf4 or .mf4z files" - f"\n{original_file_name}", + "The display file can only be embedded in .mf4 or .mf4z files" f"\n{original_file_name}", ) _password = self.mdf._password @@ -3228,10 +3071,7 @@ def embed_display_file(self, event=None): while at_addr: at_block = AttachmentBlock(stream=mdf, address=at_addr) - if ( - at_block.file_name == embedded_file_name - and at_block.mime == mime - ): + if at_block.file_name == embedded_file_name and at_block.mime == mime: new_at_block = AttachmentBlock( data=data, file_name=embedded_file_name, @@ -3441,23 +3281,14 @@ def embed_display_file(self, event=None): self.aspects.setTabVisible(4, True) def load_embedded_display_file(self, event=None): - if ( - not self.load_embedded_channel_list_btn.isVisible() - or not self.load_embedded_channel_list_btn.isEnabled() - ): + if not self.load_embedded_channel_list_btn.isVisible() or not self.load_embedded_channel_list_btn.isEnabled(): return for index, attachment in enumerate(self.mdf.attachments): - if ( - attachment.file_name == "user_embedded_display.dspf" - and attachment.mime == r"application/x-dspf" - ): + if attachment.file_name == "user_embedded_display.dspf" and attachment.mime == r"application/x-dspf": encryption_info = extract_encryption_information(attachment.comment) password = None - if ( - encryption_info.get("encrypted", False) - and self.mdf._password is None - ): + if encryption_info.get("encrypted", False) and self.mdf._password is None: text, ok = QtWidgets.QInputDialog.getText( self, "Attachment password", @@ -3467,9 +3298,7 @@ def load_embedded_display_file(self, event=None): if ok and text: password = text - data, file_path, md5_sum = self.mdf.extract_attachment( - index, password=password - ) + data, file_path, md5_sum = self.mdf.extract_attachment(index, password=password) dsp = json.loads(data.decode("utf-8", errors="replace")) dsp["display_file_name"] = "user_embedded_display.dspf" diff --git a/src/asammdf/gui/widgets/flexray_bus_trace.py b/src/asammdf/gui/widgets/flexray_bus_trace.py index 19a56aca5..1967dc2ed 100644 --- a/src/asammdf/gui/widgets/flexray_bus_trace.py +++ b/src/asammdf/gui/widgets/flexray_bus_trace.py @@ -15,9 +15,7 @@ class FlexRayBusTrace(TabularBase): add_channels_request = QtCore.Signal(list) - def __init__( - self, signals=None, start=0, format="phys", ranges=None, *args, **kwargs - ): + def __init__(self, signals=None, start=0, format="phys", ranges=None, *args, **kwargs): ranges = ranges or {name: [] for name in signals.columns} if not ranges["Event Type"]: ranges["Event Type"] = [ diff --git a/src/asammdf/gui/widgets/formated_axis.py b/src/asammdf/gui/widgets/formated_axis.py index fe57f7694..1521fa2ec 100644 --- a/src/asammdf/gui/widgets/formated_axis.py +++ b/src/asammdf/gui/widgets/formated_axis.py @@ -198,14 +198,10 @@ def mouseDragEvent(self, event): QtCore.Qt.MouseButton.MiddleButton, ]: if self.orientation in ("left", "right"): - scale = ( - self.range[1] - self.range[0] - ) / self.sceneBoundingRect().height() + scale = (self.range[1] - self.range[0]) / self.sceneBoundingRect().height() delta = scale * dif.y() else: - scale = ( - self.range[1] - self.range[0] - ) / self.sceneBoundingRect().width() + scale = (self.range[1] - self.range[0]) / self.sceneBoundingRect().width() delta = scale * dif.x() self.setRange(self.range[0] - delta, self.range[1] - delta) @@ -428,17 +424,11 @@ def wheelEvent(self, event): pos = event.pos() rect = self.boundingRect() - y_pos_val = ( - (rect.height() + rect.y()) - pos.y() - ) / rect.height() * ( + y_pos_val = ((rect.height() + rect.y()) - pos.y()) / rect.height() * ( self.range[-1] - self.range[0] - ) + self.range[ - 0 - ] + ) + self.range[0] - ratio = abs( - (pos.y() - (rect.height() + rect.y())) / rect.height() - ) + ratio = abs((pos.y() - (rect.height() + rect.y())) / rect.height()) delta = self.range[-1] - self.range[0] @@ -475,9 +465,7 @@ def paint(self, p, opt, widget): painter.begin(picture) if self.isVisible(): - painter.setCompositionMode( - QtGui.QPainter.CompositionMode_SourceOver - ) + painter.setCompositionMode(QtGui.QPainter.CompositionMode_SourceOver) if self.style["tickFont"]: painter.setFont(self.style["tickFont"]) specs = self.generateDrawSpecs(painter) @@ -498,9 +486,7 @@ def paint(self, p, opt, widget): if self.orientation in ("left", "right"): painter.setPen(self._pen) - label_rect = QtCore.QRectF( - 1, 1, rect.height() - (28 + BUTTON_SIZE), rect.width() - ) + label_rect = QtCore.QRectF(1, 1, rect.height() - (28 + BUTTON_SIZE), rect.width()) painter.translate(rect.bottomLeft()) painter.rotate(-90) @@ -552,9 +538,7 @@ def generateDrawSpecs(self, p): tickDir = 1 axis = 1 else: - raise ValueError( - "self.orientation must be in ('left', 'right', 'top', 'bottom')" - ) + raise ValueError("self.orientation must be in ('left', 'right', 'top', 'bottom')") ## determine size of this item in pixels points = list(map(self.mapToDevice, span)) @@ -615,11 +599,7 @@ def generateDrawSpecs(self, p): lineAlpha = 255 / (i + 1) if self.grid is not False: lineAlpha *= ( - self.grid - / 255.0 - * fn.clip_scalar( - (0.05 * lengthInPixels / (len(ticks) + 1)), 0.0, 1.0 - ) + self.grid / 255.0 * fn.clip_scalar((0.05 * lengthInPixels / (len(ticks) + 1)), 0.0, 1.0) ) elif isinstance(lineAlpha, float): lineAlpha *= 255 @@ -634,9 +614,7 @@ def generateDrawSpecs(self, p): for v in ticks: ## determine actual position to draw this tick x = (v * xScale) - offset - if ( - x < xMin or x > xMax - ): ## last check to make sure no out-of-bounds ticks are drawn + if x < xMin or x > xMax: ## last check to make sure no out-of-bounds ticks are drawn tickPositions[i].append(None) continue tickPositions[i].append(x) @@ -670,9 +648,7 @@ def generateDrawSpecs(self, p): span[1].setX(stop) axisSpec = (self.pen(), span[0], span[1]) - textOffset = self.style["tickTextOffset"][ - axis - ] ## spacing between axis and text + textOffset = self.style["tickTextOffset"][axis] ## spacing between axis and text # if self.style['autoExpandTextSpace'] is True: # textWidth = self.textWidth # textHeight = self.textHeight @@ -693,9 +669,7 @@ def generateDrawSpecs(self, p): ## Get the list of strings to display for this level if tickStrings is None: spacing, values = tickLevels[i] - strings = self.tickStrings( - values, self.autoSIPrefixScale * self.scale, spacing - ) + strings = self.tickStrings(values, self.autoSIPrefixScale * self.scale, spacing) else: strings = tickStrings[i] @@ -768,37 +742,17 @@ def generateDrawSpecs(self, p): offset = max(0, self.style["tickLength"]) + textOffset if self.orientation == "left": - alignFlags = ( - QtCore.Qt.AlignmentFlag.AlignRight - | QtCore.Qt.AlignmentFlag.AlignVCenter - ) - rect = QtCore.QRectF( - tickStop - offset - width, x - (height / 2), width, height - ) + alignFlags = QtCore.Qt.AlignmentFlag.AlignRight | QtCore.Qt.AlignmentFlag.AlignVCenter + rect = QtCore.QRectF(tickStop - offset - width, x - (height / 2), width, height) elif self.orientation == "right": - alignFlags = ( - QtCore.Qt.AlignmentFlag.AlignLeft - | QtCore.Qt.AlignmentFlag.AlignVCenter - ) - rect = QtCore.QRectF( - tickStop + offset, x - (height / 2), width, height - ) + alignFlags = QtCore.Qt.AlignmentFlag.AlignLeft | QtCore.Qt.AlignmentFlag.AlignVCenter + rect = QtCore.QRectF(tickStop + offset, x - (height / 2), width, height) elif self.orientation == "top": - alignFlags = ( - QtCore.Qt.AlignmentFlag.AlignHCenter - | QtCore.Qt.AlignmentFlag.AlignBottom - ) - rect = QtCore.QRectF( - x - width / 2.0, tickStop - offset - height, width, height - ) + alignFlags = QtCore.Qt.AlignmentFlag.AlignHCenter | QtCore.Qt.AlignmentFlag.AlignBottom + rect = QtCore.QRectF(x - width / 2.0, tickStop - offset - height, width, height) elif self.orientation == "bottom": - alignFlags = ( - QtCore.Qt.AlignmentFlag.AlignHCenter - | QtCore.Qt.AlignmentFlag.AlignTop - ) - rect = QtCore.QRectF( - x - width / 2.0, tickStop + offset, width, height - ) + alignFlags = QtCore.Qt.AlignmentFlag.AlignHCenter | QtCore.Qt.AlignmentFlag.AlignTop + rect = QtCore.QRectF(x - width / 2.0, tickStop + offset, width, height) textFlags = alignFlags | QtCore.Qt.TextFlag.TextDontClip # p.setPen(self.pen()) diff --git a/src/asammdf/gui/widgets/functions_manager.py b/src/asammdf/gui/widgets/functions_manager.py index bc182bff4..a02b4b6ae 100644 --- a/src/asammdf/gui/widgets/functions_manager.py +++ b/src/asammdf/gui/widgets/functions_manager.py @@ -24,9 +24,7 @@ class FunctionsManager(Ui_FunctionsManager, QtWidgets.QWidget): - def __init__( - self, definitions, channels=None, selected_definition="", *args, **kwargs - ): + def __init__(self, definitions, channels=None, selected_definition="", *args, **kwargs): super().__init__(*args, **kwargs) self.setupUi(self) @@ -54,8 +52,7 @@ def MyAverage(main_clock=0, p_FL=0, p_FR=0, p_RL=0, p_RR=0, vehicle_speed=0, t=0 """ ) self.function_definition.setTabStopDistance( - QtGui.QFontMetricsF(self.function_definition.font()).horizontalAdvance(" ") - * 4 + QtGui.QFontMetricsF(self.function_definition.font()).horizontalAdvance(" ") * 4 ) p = self.function_definition.palette() @@ -69,15 +66,11 @@ def MyAverage(main_clock=0, p_FL=0, p_FR=0, p_RL=0, p_RR=0, vehicle_speed=0, t=0 self.functions_list.minimal_menu = True self.functions_list.all_texts = True - self.functions_list.placeholder_text = ( - "Press the + button to add a new function definition" - ) + self.functions_list.placeholder_text = "Press the + button to add a new function definition" self.functions_list.user_editable = True self.functions_list.setAlternatingRowColors(True) - self.functions_list.currentItemChanged.connect( - self.definition_selection_changed - ) + self.functions_list.currentItemChanged.connect(self.definition_selection_changed) self.functions_list.itemsDeleted.connect(self.definitions_deleted) self.add_btn.clicked.connect(self.add_definition) @@ -142,9 +135,7 @@ def check_syntax(self, silent=False): function_source = self.function_definition.toPlainText().replace("\t", " ") func, trace = generate_python_function(function_source, in_globals=_globals) - return check_generated_function( - func, trace, function_source, silent, parent=self - ) + return check_generated_function(func, trace, function_source, silent, parent=self) def definitions_deleted(self, deleted): count = self.functions_list.count() @@ -181,9 +172,7 @@ def export_definitions(self, *args): ) if file_name and Path(file_name).suffix.lower() == ".def": - definitions = { - name: info["definition"] for name, info in self.definitions.items() - } + definitions = {name: info["definition"] for name, info in self.definitions.items()} Path(file_name).write_text(json.dumps(definitions, indent=2)) def import_definitions(self, *args): @@ -234,9 +223,7 @@ def refresh_definitions(self): if func is not None: name = func.__name__ if name in self.definitions: - self.definitions[name][ - "definition" - ] = self.function_definition.toPlainText() + self.definitions[name]["definition"] = self.function_definition.toPlainText() def store_definition(self, *args): ok, func = self.check_syntax(silent=True) @@ -248,8 +235,7 @@ def store_definition(self, *args): MessageBox.information( self, "Invalid function name", - f'The name "{name}" is already given to another function.\n' - "The function names must be unique", + f'The name "{name}" is already given to another function.\n' "The function names must be unique", ) return diff --git a/src/asammdf/gui/widgets/gps.py b/src/asammdf/gui/widgets/gps.py index 33e22e5cd..7716a69d1 100644 --- a/src/asammdf/gui/widgets/gps.py +++ b/src/asammdf/gui/widgets/gps.py @@ -24,9 +24,7 @@ def __init__(self, latitude_channel, longitude_channel, zoom=15, *args, **kwargs super().__init__(*args, **kwargs) self.setupUi(self) - timebase = np.around( - np.union1d(latitude_channel.timestamps, longitude_channel.timestamps), 9 - ) + timebase = np.around(np.union1d(latitude_channel.timestamps, longitude_channel.timestamps), 9) self.latitude_signal = latitude_channel.interp(timebase) self.longitude_signal = longitude_channel.interp(timebase) if len(timebase): @@ -69,11 +67,7 @@ def __init__(self, latitude_channel, longitude_channel, zoom=15, *args, **kwargs # L.tileLayer("https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png").addTo(self.map) if len(timebase): - line = L.polyline( - np.column_stack( - [self.latitude_signal.samples, self.longitude_signal.samples] - ).tolist() - ) + line = L.polyline(np.column_stack([self.latitude_signal.samples, self.longitude_signal.samples]).tolist()) line.addTo(self.map) self.map.setView([self.latitude, self.longitude], zoom) diff --git a/src/asammdf/gui/widgets/lin_bus_trace.py b/src/asammdf/gui/widgets/lin_bus_trace.py index 2505d89e8..3498248b1 100644 --- a/src/asammdf/gui/widgets/lin_bus_trace.py +++ b/src/asammdf/gui/widgets/lin_bus_trace.py @@ -15,9 +15,7 @@ class LINBusTrace(TabularBase): add_channels_request = QtCore.Signal(list) - def __init__( - self, signals=None, start=0, format="phys", ranges=None, *args, **kwargs - ): + def __init__(self, signals=None, start=0, format="phys", ranges=None, *args, **kwargs): ranges = ranges or {name: [] for name in signals.columns} if not ranges["Event Type"]: ranges["Event Type"] = [ diff --git a/src/asammdf/gui/widgets/list.py b/src/asammdf/gui/widgets/list.py index f252a2d74..e57549646 100644 --- a/src/asammdf/gui/widgets/list.py +++ b/src/asammdf/gui/widgets/list.py @@ -73,9 +73,7 @@ def keyPressEvent(self, event): if not selected_items: return - states = [ - self.itemWidget(item).display.checkState() for item in selected_items - ] + states = [self.itemWidget(item).display.checkState() for item in selected_items] if any(state == QtCore.Qt.Unchecked for state in states): state = QtCore.Qt.Checked @@ -90,10 +88,7 @@ def keyPressEvent(self, event): if not selected_items: return - states = [ - self.itemWidget(item).individual_axis.checkState() - for item in selected_items - ] + states = [self.itemWidget(item).individual_axis.checkState() for item in selected_items] if any(state == QtCore.Qt.Unchecked for state in states): state = QtCore.Qt.Checked @@ -109,9 +104,10 @@ def keyPressEvent(self, event): return self.itemWidget(selected_items[0]).keyPressEvent(event) - elif modifiers == ( - QtCore.Qt.ControlModifier | QtCore.Qt.ShiftModifier - ) and key in (QtCore.Qt.Key_C, QtCore.Qt.Key_P): + elif modifiers == (QtCore.Qt.ControlModifier | QtCore.Qt.ShiftModifier) and key in ( + QtCore.Qt.Key_C, + QtCore.Qt.Key_P, + ): selected_items = self.selectedItems() if not selected_items: return @@ -160,9 +156,7 @@ def startDrag(self, supportedActions): ) ) - mimeData.setData( - "application/octet-stream-asammdf", QtCore.QByteArray(b"".join(data)) - ) + mimeData.setData("application/octet-stream-asammdf", QtCore.QByteArray(b"".join(data))) drag = QtGui.QDrag(self) drag.setMimeData(mimeData) @@ -231,9 +225,7 @@ def open_menu(self, position): return if action.text() == "Copy name (Ctrl+C)": - event = QtGui.QKeyEvent( - QtCore.QEvent.KeyPress, QtCore.Qt.Key_C, QtCore.Qt.ControlModifier - ) + event = QtGui.QKeyEvent(QtCore.QEvent.KeyPress, QtCore.Qt.Key_C, QtCore.Qt.ControlModifier) self.itemWidget(item).keyPressEvent(event) elif action.text() == "Copy display properties (Ctrl+Shift+C)": @@ -321,9 +313,7 @@ def open_menu(self, position): elif action.text() == "Set precision": selected_items = self.selectedItems() - precision, ok = QtWidgets.QInputDialog.getInt( - None, "Set new precision (float decimals)", "Precision:" - ) + precision, ok = QtWidgets.QInputDialog.getInt(None, "Set new precision (float decimals)", "Precision:") if ok and 0 <= precision <= 15: for i in range(self.count()): @@ -363,9 +353,7 @@ def open_menu(self, position): self.set_time_offset.emit([absolute, offset] + uuids) elif action.text() == "Delete (Del)": - event = QtGui.QKeyEvent( - QtCore.QEvent.KeyPress, QtCore.Qt.Key_Delete, QtCore.Qt.NoModifier - ) + event = QtGui.QKeyEvent(QtCore.QEvent.KeyPress, QtCore.Qt.Key_Delete, QtCore.Qt.NoModifier) self.keyPressEvent(event) elif action.text() == "Toggle details": @@ -481,11 +469,7 @@ def keyPressEvent(self, event): text = "" QtWidgets.QApplication.instance().clipboard().setText(text) - elif ( - key == QtCore.Qt.Key_V - and modifiers == QtCore.Qt.ControlModifier - and self.user_editable - ): + elif key == QtCore.Qt.Key_V and modifiers == QtCore.Qt.ControlModifier and self.user_editable: lines = QtWidgets.QApplication.instance().clipboard().text().splitlines() if lines: try: @@ -527,19 +511,13 @@ def open_menu(self, position): return if action.text() == "Delete (Del)": - event = QtGui.QKeyEvent( - QtCore.QEvent.KeyPress, QtCore.Qt.Key_Delete, QtCore.Qt.NoModifier - ) + event = QtGui.QKeyEvent(QtCore.QEvent.KeyPress, QtCore.Qt.Key_Delete, QtCore.Qt.NoModifier) self.keyPressEvent(event) elif action.text() == "Copy names (Ctrl+C)": - event = QtGui.QKeyEvent( - QtCore.QEvent.KeyPress, QtCore.Qt.Key_C, QtCore.Qt.ControlModifier - ) + event = QtGui.QKeyEvent(QtCore.QEvent.KeyPress, QtCore.Qt.Key_C, QtCore.Qt.ControlModifier) self.keyPressEvent(event) elif action.text() == "Paste names (Ctrl+V)": - event = QtGui.QKeyEvent( - QtCore.QEvent.KeyPress, QtCore.Qt.Key_V, QtCore.Qt.ControlModifier - ) + event = QtGui.QKeyEvent(QtCore.QEvent.KeyPress, QtCore.Qt.Key_V, QtCore.Qt.ControlModifier) self.keyPressEvent(event) def paintEvent(self, event): @@ -550,8 +528,6 @@ def paintEvent(self, event): col = self.palette().placeholderText().color() painter.setPen(col) fm = self.fontMetrics() - elided_text = fm.elidedText( - self.placeholder_text, QtCore.Qt.ElideRight, self.viewport().width() - ) + elided_text = fm.elidedText(self.placeholder_text, QtCore.Qt.ElideRight, self.viewport().width()) painter.drawText(self.viewport().rect(), QtCore.Qt.AlignCenter, elided_text) painter.restore() diff --git a/src/asammdf/gui/widgets/main.py b/src/asammdf/gui/widgets/main.py index 6eb9692e9..8ee8007d7 100644 --- a/src/asammdf/gui/widgets/main.py +++ b/src/asammdf/gui/widgets/main.py @@ -35,19 +35,13 @@ def __init__(self, files=None, *args, **kwargs): self._settings.setValue("current_theme", self._settings.value("theme", "Light")) self._light_palette = self.palette() - self.ignore_value2text_conversions = self._settings.value( - "ignore_value2text_conversions", False, type=bool - ) + self.ignore_value2text_conversions = self._settings.value("ignore_value2text_conversions", False, type=bool) self.display_cg_name = self._settings.value("display_cg_name", False, type=bool) - self.integer_interpolation = int( - self._settings.value("integer_interpolation", "2 - hybrid interpolation")[0] - ) + self.integer_interpolation = int(self._settings.value("integer_interpolation", "2 - hybrid interpolation")[0]) - self.float_interpolation = int( - self._settings.value("float_interpolation", "1 - linear interpolation")[0] - ) + self.float_interpolation = int(self._settings.value("float_interpolation", "1 - linear interpolation")[0]) self.batch = BatchWidget( self.ignore_value2text_conversions, @@ -62,9 +56,7 @@ def __init__(self, files=None, *args, **kwargs): multi_search = QtWidgets.QPushButton("Search") icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/search.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/search.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) multi_search.setIcon(icon) multi_search.clicked.connect(self.comparison_search) @@ -143,9 +135,7 @@ def __init__(self, files=None, *args, **kwargs): mode_actions.addAction(action) icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/compare.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/compare.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) action = QtGui.QAction(icon, "{: <20}".format("Comparison"), menu) action.triggered.connect(partial(self.stackedWidget.setCurrentIndex, 2)) mode_actions.addAction(action) @@ -304,9 +294,7 @@ def __init__(self, files=None, *args, **kwargs): theme_option.addAction(action) action.triggered.connect(partial(self.set_integer_interpolation, option)) - if option == self._settings.value( - "integer_interpolation", "2 - hybrid interpolation" - ): + if option == self._settings.value("integer_interpolation", "2 - hybrid interpolation"): action.setChecked(True) action.triggered.emit() @@ -324,9 +312,7 @@ def __init__(self, files=None, *args, **kwargs): theme_option.addAction(action) action.triggered.connect(partial(self.set_float_interpolation, option)) - if option == self._settings.value( - "float_interpolation", "1 - linear interpolation" - ): + if option == self._settings.value("float_interpolation", "1 - linear interpolation"): action.setChecked(True) action.triggered.emit() @@ -348,9 +334,7 @@ def __init__(self, files=None, *args, **kwargs): action.setText("Line width") combo = QtWidgets.QComboBox() combo.addItems([f"{size}pixels width" for size in range(1, 5)]) - combo.currentIndexChanged.connect( - partial(self.edit_cursor_options, action=action) - ) + combo.currentIndexChanged.connect(partial(self.edit_cursor_options, action=action)) action.setDefaultWidget(combo) submenu.addAction(action) @@ -364,9 +348,7 @@ def __init__(self, files=None, *args, **kwargs): action = QtGui.QAction("Show horizontal line") action.setCheckable(True) action.toggled.connect(partial(self.edit_cursor_options, action=action)) - action.setChecked( - self._settings.value("show_cursor_horizontal_line", False, type=bool) - ) + action.setChecked(self._settings.value("show_cursor_horizontal_line", False, type=bool)) submenu.addAction(action) menu.addMenu(submenu) @@ -392,11 +374,7 @@ def __init__(self, files=None, *args, **kwargs): icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap(":/fit.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) action = QtGui.QAction(icon, f"{'Fit selected': <20}\tShift+F", menu) - action.triggered.connect( - partial( - self.plot_action, key=QtCore.Qt.Key_F, modifier=QtCore.Qt.ShiftModifier - ) - ) + action.triggered.connect(partial(self.plot_action, key=QtCore.Qt.Key_F, modifier=QtCore.Qt.ShiftModifier)) action.setShortcut(QtGui.QKeySequence("Shift+F")) plot_actions.addAction(action) @@ -422,40 +400,28 @@ def __init__(self, files=None, *args, **kwargs): plot_actions.addAction(action) icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/list2.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/list2.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) action = QtGui.QAction(icon, "{: <20}\tS".format("Stack all"), menu) action.triggered.connect(partial(self.plot_action, key=QtCore.Qt.Key_S)) action.setShortcut(QtCore.Qt.Key_S) plot_actions.addAction(action) icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/list2.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/list2.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) action = QtGui.QAction(icon, "{: <20}\tShift+S".format("Stack selected"), menu) - action.triggered.connect( - partial( - self.plot_action, key=QtCore.Qt.Key_S, modifier=QtCore.Qt.ShiftModifier - ) - ) + action.triggered.connect(partial(self.plot_action, key=QtCore.Qt.Key_S, modifier=QtCore.Qt.ShiftModifier)) action.setShortcut(QtGui.QKeySequence("Shift+S")) plot_actions.addAction(action) icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/zoom-in.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/zoom-in.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) action = QtGui.QAction(icon, "{: <20}\tI".format("Zoom in"), menu) action.triggered.connect(partial(self.plot_action, key=QtCore.Qt.Key_I)) action.setShortcut(QtCore.Qt.Key_I) plot_actions.addAction(action) icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/zoom-out.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/zoom-out.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) action = QtGui.QAction(icon, "{: <20}\tO".format("Zoom out"), menu) action.triggered.connect(partial(self.plot_action, key=QtCore.Qt.Key_O)) action.setShortcut(QtCore.Qt.Key_O) @@ -472,9 +438,7 @@ def __init__(self, files=None, *args, **kwargs): plot_actions.addAction(action) icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/focus.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/focus.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) action = QtGui.QAction(icon, "{: <20}\t2".format("Focused mode"), menu) action.triggered.connect(partial(self.plot_action, key=QtCore.Qt.Key_2)) action.setShortcut(QtCore.Qt.Key_2) @@ -489,9 +453,7 @@ def __init__(self, files=None, *args, **kwargs): icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap(":/save.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) - action = QtGui.QAction( - icon, "{: <20}\tCtrl+S".format("Save active subplot channels"), menu - ) + action = QtGui.QAction(icon, "{: <20}\tCtrl+S".format("Save active subplot channels"), menu) action.triggered.connect( partial( self.plot_action, @@ -504,18 +466,14 @@ def __init__(self, files=None, *args, **kwargs): icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap(":/save.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) - action = QtGui.QAction( - icon, "{: <20}\tCtrl+Shift+S".format("Save all subplot channels"), menu - ) + action = QtGui.QAction(icon, "{: <20}\tCtrl+Shift+S".format("Save all subplot channels"), menu) action.triggered.connect(self.save_all_subplots) action.setShortcut(QtGui.QKeySequence("Ctrl+Shift+S")) plot_actions.addAction(action) icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap(":/save.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) - action = QtGui.QAction( - icon, "{: <20}\tCtrl+Shift+S".format("Save all subplot channels"), menu - ) + action = QtGui.QAction(icon, "{: <20}\tCtrl+Shift+S".format("Save all subplot channels"), menu) action.triggered.connect(self.save_all_subplots) action.setShortcut(QtGui.QKeySequence("Ctrl+Shift+S")) plot_actions.addAction(action) @@ -525,12 +483,8 @@ def __init__(self, files=None, *args, **kwargs): channel_shift_actions = QtGui.QActionGroup(self) icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/shift_left.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) - action = QtGui.QAction( - icon, "{: <20}\tShift+←".format("Shift channels left"), menu - ) + icon.addPixmap(QtGui.QPixmap(":/shift_left.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) + action = QtGui.QAction(icon, "{: <20}\tShift+←".format("Shift channels left"), menu) action.triggered.connect( partial( self.plot_action, @@ -542,12 +496,8 @@ def __init__(self, files=None, *args, **kwargs): channel_shift_actions.addAction(action) icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/shift_right.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) - action = QtGui.QAction( - icon, "{: <20}\tShift+→".format("Shift channels right"), menu - ) + icon.addPixmap(QtGui.QPixmap(":/shift_right.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) + action = QtGui.QAction(icon, "{: <20}\tShift+→".format("Shift channels right"), menu) action.triggered.connect( partial( self.plot_action, @@ -559,12 +509,8 @@ def __init__(self, files=None, *args, **kwargs): channel_shift_actions.addAction(action) icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/shift_up.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) - action = QtGui.QAction( - icon, "{: <20}\tShift+↑".format("Shift channels up"), menu - ) + icon.addPixmap(QtGui.QPixmap(":/shift_up.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) + action = QtGui.QAction(icon, "{: <20}\tShift+↑".format("Shift channels up"), menu) action.triggered.connect( partial( self.plot_action, @@ -576,12 +522,8 @@ def __init__(self, files=None, *args, **kwargs): channel_shift_actions.addAction(action) icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/shift_down.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) - action = QtGui.QAction( - icon, "{: <20}\tShift+↓".format("Shift channels down"), menu - ) + icon.addPixmap(QtGui.QPixmap(":/shift_down.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) + action = QtGui.QAction(icon, "{: <20}\tShift+↓".format("Shift channels down"), menu) action.triggered.connect( partial( self.plot_action, @@ -634,20 +576,12 @@ def __init__(self, files=None, *args, **kwargs): samples_format_actions = QtGui.QActionGroup(self) action = QtGui.QAction("{: <20}\tAlt+R".format("Raw samples"), menu) - action.triggered.connect( - partial( - self.plot_action, key=QtCore.Qt.Key_R, modifier=QtCore.Qt.AltModifier - ) - ) + action.triggered.connect(partial(self.plot_action, key=QtCore.Qt.Key_R, modifier=QtCore.Qt.AltModifier)) action.setShortcut(QtGui.QKeySequence("Alt+R")) samples_format_actions.addAction(action) action = QtGui.QAction("{: <20}\tAlt+S".format("Scaled samples"), menu) - action.triggered.connect( - partial( - self.plot_action, key=QtCore.Qt.Key_S, modifier=QtCore.Qt.AltModifier - ) - ) + action.triggered.connect(partial(self.plot_action, key=QtCore.Qt.Key_S, modifier=QtCore.Qt.AltModifier)) action.setShortcut(QtGui.QKeySequence("Alt+S")) samples_format_actions.addAction(action) @@ -671,32 +605,22 @@ def __init__(self, files=None, *args, **kwargs): action.setShortcut(QtGui.QKeySequence("Shift+C")) subs.addAction(action) - action = QtGui.QAction( - "{: <20}\tShift+T".format("Tile sub-windows in a grid"), menu - ) + action = QtGui.QAction("{: <20}\tShift+T".format("Tile sub-windows in a grid"), menu) action.triggered.connect(partial(self.show_sub_windows, mode="tile")) action.setShortcut(QtGui.QKeySequence("Shift+T")) subs.addAction(action) - action = QtGui.QAction( - "{: <20}\tShift+V".format("Tile sub-windows vertically"), menu - ) + action = QtGui.QAction("{: <20}\tShift+V".format("Tile sub-windows vertically"), menu) action.triggered.connect(partial(self.show_sub_windows, mode="tile vertically")) action.setShortcut(QtGui.QKeySequence("Shift+V")) subs.addAction(action) - action = QtGui.QAction( - "{: <20}\tShift+H".format("Tile sub-windows horizontally"), menu - ) - action.triggered.connect( - partial(self.show_sub_windows, mode="tile horizontally") - ) + action = QtGui.QAction("{: <20}\tShift+H".format("Tile sub-windows horizontally"), menu) + action.triggered.connect(partial(self.show_sub_windows, mode="tile horizontally")) action.setShortcut(QtGui.QKeySequence("Shift+H")) subs.addAction(action) - action = QtGui.QAction( - "{: <20}\tShift+Alt+F".format("Toggle sub-windows frames"), menu - ) + action = QtGui.QAction("{: <20}\tShift+Alt+F".format("Toggle sub-windows frames"), menu) action.triggered.connect(self.toggle_frames) action.setShortcut(QtGui.QKeySequence("Shift+Alt+F")) subs.addAction(action) @@ -710,18 +634,14 @@ def __init__(self, files=None, *args, **kwargs): cursors_actions = QtGui.QActionGroup(self) icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/cursor.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/cursor.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) action = QtGui.QAction(icon, "{: <20}\tC".format("Cursor"), menu) action.triggered.connect(partial(self.plot_action, key=QtCore.Qt.Key_C)) action.setShortcut(QtCore.Qt.Key_C) cursors_actions.addAction(action) icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/right.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/right.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) action = QtGui.QAction(icon, "{: <20}\t←".format("Move cursor left"), menu) action.triggered.connect(partial(self.plot_action, key=QtCore.Qt.Key_Left)) action.setShortcut(QtCore.Qt.Key_Left) @@ -735,27 +655,21 @@ def __init__(self, files=None, *args, **kwargs): cursors_actions.addAction(action) icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/range.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/range.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) action = QtGui.QAction(icon, "{: <20}\tR".format("Range"), menu) action.triggered.connect(partial(self.plot_action, key=QtCore.Qt.Key_R)) action.setShortcut(QtCore.Qt.Key_R) cursors_actions.addAction(action) icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/lock_range.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/lock_range.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) action = QtGui.QAction(icon, "{: <20}\tY".format("Lock/unlock range"), menu) action.triggered.connect(partial(self.plot_action, key=QtCore.Qt.Key_Y)) action.setShortcut(QtCore.Qt.Key_Y) cursors_actions.addAction(action) icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/bookmark.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/bookmark.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) action = QtGui.QAction(icon, "{: <20}\tCtrl+I".format("Insert bookmark"), menu) action.triggered.connect( partial( @@ -768,15 +682,9 @@ def __init__(self, files=None, *args, **kwargs): cursors_actions.addAction(action) icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/bookmark.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/bookmark.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) action = QtGui.QAction(icon, "{: <20}\tAlt+I".format("Toggle bookmarks"), menu) - action.triggered.connect( - partial( - self.plot_action, key=QtCore.Qt.Key_I, modifier=QtCore.Qt.AltModifier - ) - ) + action.triggered.connect(partial(self.plot_action, key=QtCore.Qt.Key_I, modifier=QtCore.Qt.AltModifier)) action.setShortcut(QtGui.QKeySequence("Alt+I")) cursors_actions.addAction(action) @@ -934,27 +842,19 @@ def edit_cursor_options(self, checked=None, action=None): self._settings.setValue("show_cursor_circle", action.isChecked()) elif action.text() == "Show horizontal line": - self._settings.setValue( - "show_cursor_horizontal_line", action.isChecked() - ) + self._settings.setValue("show_cursor_horizontal_line", action.isChecked()) elif action.text() == "Line width": - self._settings.setValue( - "cursor_line_width", action.defaultWidget().currentIndex() + 1 - ) + self._settings.setValue("cursor_line_width", action.defaultWidget().currentIndex() + 1) cursor_circle = self._settings.value("show_cursor_circle", False, type=bool) - cursor_horizontal_line = self._settings.value( - "show_cursor_horizontal_line", False, type=bool - ) + cursor_horizontal_line = self._settings.value("show_cursor_horizontal_line", False, type=bool) cursor_line_width = self._settings.value("cursor_line_width", 1, type=int) cursor_color = self._settings.value("cursor_color", "#e69138") for i in range(self.files.count()): file = self.files.widget(i) - file.set_cursor_options( - cursor_circle, cursor_horizontal_line, cursor_line_width, cursor_color - ) + file.set_cursor_options(cursor_circle, cursor_horizontal_line, cursor_line_width, cursor_color) def set_subplot_option(self, state): if isinstance(state, str): @@ -1057,9 +957,7 @@ def set_theme(self, option): palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Text, brush) brush = QtGui.QBrush(QtGui.QColor(100, 100, 100)) brush.setStyle(QtCore.Qt.SolidPattern) - palette.setBrush( - QtGui.QPalette.Active, QtGui.QPalette.PlaceholderText, brush - ) + palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.PlaceholderText, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.BrightText, brush) @@ -1122,9 +1020,7 @@ def set_theme(self, option): palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Shadow, brush) brush = QtGui.QBrush(QtGui.QColor(27, 27, 27)) brush.setStyle(QtCore.Qt.SolidPattern) - palette.setBrush( - QtGui.QPalette.Inactive, QtGui.QPalette.AlternateBase, brush - ) + palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.AlternateBase, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 220)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.ToolTipBase, brush) @@ -1169,9 +1065,7 @@ def set_theme(self, option): palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Shadow, brush) brush = QtGui.QBrush(QtGui.QColor(55, 55, 55)) brush.setStyle(QtCore.Qt.SolidPattern) - palette.setBrush( - QtGui.QPalette.Disabled, QtGui.QPalette.AlternateBase, brush - ) + palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.AlternateBase, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 220)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.ToolTipBase, brush) @@ -1245,9 +1139,7 @@ def open_batch_files(self, event): count = self.batch.files_list.count() icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/file.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/file.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) for row in range(count): self.batch.files_list.item(row).setIcon(icon) @@ -1324,8 +1216,7 @@ def open_folder(self, event): self, "Select folder", "", - QtWidgets.QFileDialog.ShowDirsOnly - | QtWidgets.QFileDialog.DontResolveSymlinks, + QtWidgets.QFileDialog.ShowDirsOnly | QtWidgets.QFileDialog.DontResolveSymlinks, ) if not folder: return @@ -1335,23 +1226,17 @@ def open_folder(self, event): if self.stackedWidget.currentIndex() == 0: for root, dirs, files in os.walk(folder): for file in natsorted(files): - if file.lower().endswith( - (".csv", ".erg", ".dl3", ".dat", ".mdf", ".mf4", ".mf4z") - ): + if file.lower().endswith((".csv", ".erg", ".dl3", ".dat", ".mdf", ".mf4", ".mf4z")): self._open_file(os.path.join(root, file)) else: icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/file.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/file.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.batch._ignore = True for root, dirs, files in os.walk(folder): for file in natsorted(files): - if file.lower().endswith( - (".csv", ".erg", ".dl3", ".dat", ".mdf", ".mf4", ".mf4z") - ): + if file.lower().endswith((".csv", ".erg", ".dl3", ".dat", ".mdf", ".mf4", ".mf4z")): item = QtWidgets.QListWidgetItem(icon, os.path.join(root, file)) self.batch.files_list.addItem(item) @@ -1393,9 +1278,7 @@ def dropEvent(self, e): self._open_file(path) else: icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/file.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/file.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) for path in e.mimeData().text().splitlines(): path = Path(path.replace(r"file:///", "")) @@ -1417,19 +1300,13 @@ def dropEvent(self, e): def mode_changed(self, index): if index == 0: self.plot_menu.setEnabled(True) - self.setWindowTitle( - f"asammdf {libversion} [PID={os.getpid()}] - Single files" - ) + self.setWindowTitle(f"asammdf {libversion} [PID={os.getpid()}] - Single files") elif index == 1: self.plot_menu.setEnabled(False) - self.setWindowTitle( - f"asammdf {libversion} [PID={os.getpid()}] - Batch processing" - ) + self.setWindowTitle(f"asammdf {libversion} [PID={os.getpid()}] - Batch processing") elif index == 2: self.plot_menu.setEnabled(True) - self.setWindowTitle( - f"asammdf {libversion} [PID={os.getpid()}] - Comparison" - ) + self.setWindowTitle(f"asammdf {libversion} [PID={os.getpid()}] - Comparison") def keyPressEvent(self, event): key = event.key() @@ -1440,12 +1317,8 @@ def keyPressEvent(self, event): self.files.currentWidget().keyPressEvent(event) elif self.files.count() and self.stackedWidget.currentIndex() == 2: count = self.files.count() - channels_dbs = [ - self.files.widget(i).mdf.channels_db for i in range(count) - ] - measurements = [ - str(self.files.widget(i).mdf.name) for i in range(count) - ] + channels_dbs = [self.files.widget(i).mdf.channels_db for i in range(count)] + measurements = [str(self.files.widget(i).mdf.name) for i in range(count)] dlg = MultiSearch(channels_dbs, measurements, parent=self) dlg.setModal(True) @@ -1502,9 +1375,7 @@ def keyPressEvent(self, event): super().keyPressEvent(event) def comparison_search(self, event): - event = QtGui.QKeyEvent( - QtCore.QEvent.KeyPress, QtCore.Qt.Key_F, QtCore.Qt.ControlModifier - ) + event = QtGui.QKeyEvent(QtCore.QEvent.KeyPress, QtCore.Qt.Key_F, QtCore.Qt.ControlModifier) self.keyPressEvent(event) def comparison_info(self, event): @@ -1515,9 +1386,7 @@ def comparison_info(self, event): for i, name in enumerate(measurements, 1): info.extend(wrap(f"{i:> 2}: {name}", 120)) - MessageBox.information( - self, "Measurement files used for comparison", "\n".join(info) - ) + MessageBox.information(self, "Measurement files used for comparison", "\n".join(info)) def toggle_fullscreen(self): if self.files.count() > 0 or self.fullscreen is not None: @@ -1557,9 +1426,7 @@ def toggle_frames(self, event=None): def toggle_channels_list(self, event=None): if self.stackedWidget.currentIndex() == 0: widget = self.files.currentWidget() - event = QtGui.QKeyEvent( - QtCore.QEvent.KeyPress, QtCore.Qt.Key_L, QtCore.Qt.ShiftModifier - ) + event = QtGui.QKeyEvent(QtCore.QEvent.KeyPress, QtCore.Qt.Key_L, QtCore.Qt.ShiftModifier) if widget: widget.keyPressEvent(event) diff --git a/src/asammdf/gui/widgets/mdi_area.py b/src/asammdf/gui/widgets/mdi_area.py index ebbd9a7d0..9ae9c3325 100644 --- a/src/asammdf/gui/widgets/mdi_area.py +++ b/src/asammdf/gui/widgets/mdi_area.py @@ -164,9 +164,7 @@ def build_mime_from_config( if item_is_computed: group_index, channel_index = -1, -1 computed[uuid] = item - item["computation"] = computation_to_python_function( - item["computation"] - ) + item["computation"] = computation_to_python_function(item["computation"]) item["computation"].pop("definition", None) item["origin_uuid"] = computed_origin_uuid @@ -187,9 +185,7 @@ def build_mime_from_config( return mime, descriptions, found, not_found, computed -def extract_signals_using_pattern( - mdf, pattern_info, ignore_value2text_conversions, uuid -): +def extract_signals_using_pattern(mdf, pattern_info, ignore_value2text_conversions, uuid): pattern = pattern_info["pattern"] match_type = pattern_info["match_type"] case_sensitive = pattern_info.get("case_sensitive", False) @@ -284,11 +280,7 @@ def extract_signals_using_pattern( def generate_window_title(mdi, window_name="", title=""): - used_names = { - window.windowTitle() - for window in mdi.mdiArea().subWindowList() - if window is not mdi - } + used_names = {window.windowTitle() for window in mdi.mdiArea().subWindowList() if window is not mdi} if not title or title in used_names: window_name = title or window_name or "Subwindow" @@ -332,9 +324,7 @@ def get_flatten_entries_from_mime(data, default_index=None): entries.append(new_item) else: - entries.extend( - get_flatten_entries_from_mime(item["channels"], default_index) - ) + entries.extend(get_flatten_entries_from_mime(item["channels"], default_index)) return entries @@ -346,9 +336,7 @@ def get_functions(data): functions.update(get_functions(item["channels"])) else: if item.get("computed", False): - computation = item["computation"] = computation_to_python_function( - item["computation"] - ) + computation = item["computation"] = computation_to_python_function(item["computation"]) functions[computation["function"]] = computation["definition"] @@ -390,12 +378,7 @@ def get_required_from_computed(channel): names.extend(get_required_from_computed(op)) elif computation["type"] == "expression": expression_string = computation["expression"] - names.extend( - [ - match.group("name") - for match in SIG_RE.finditer(expression_string) - ] - ) + names.extend([match.group("name") for match in SIG_RE.finditer(expression_string)]) elif computation["type"] == "python_function": for alternative_names in computation["args"].values(): for name in alternative_names: @@ -423,9 +406,7 @@ def get_required_from_computed(channel): elif channel["type"] == "expression": expression_string = channel["expression"] - names.extend( - [match.group("name") for match in SIG_RE.finditer(expression_string)] - ) + names.extend([match.group("name") for match in SIG_RE.finditer(expression_string)]) elif channel["type"] == "function": op = channel["channel"] @@ -455,9 +436,7 @@ def substitude_mime_uuids(mime, uuid=None, force=False): item["origin_uuid"] = uuid new_mime.append(item) else: - item["channels"] = substitude_mime_uuids( - item["channels"], uuid, force=force - ) + item["channels"] = substitude_mime_uuids(item["channels"], uuid, force=force) if force or item["origin_uuid"] is None: item["origin_uuid"] = uuid new_mime.append(item) @@ -497,9 +476,7 @@ def load_comparison_display_file(file_name, uuids): if window["type"] != "Plot": continue - window["configuration"]["channels"] = get_comparison_mime( - window["configuration"]["channels"], uuids - ) + window["configuration"]["channels"] = get_comparison_mime(window["configuration"]["channels"], uuids) plot_windows.append(window) @@ -545,7 +522,9 @@ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.setAcceptDrops(True) - self.placeholder_text = "Drag and drop channels, or select channels and press the button, to create new windows" + self.placeholder_text = ( + "Drag and drop channels, or select channels and press the button, to create new windows" + ) self.show() def dragEnterEvent(self, e): @@ -565,9 +544,7 @@ def dropEvent(self, e): if dialog.result(): window_type = dialog.selected_type() disable_new_channels = dialog.disable_new_channels() - names = extract_mime_names( - data, disable_new_channels=disable_new_channels - ) + names = extract_mime_names(data, disable_new_channels=disable_new_channels) self.add_window_request.emit([window_type, names]) else: @@ -636,9 +613,7 @@ def paintEvent(self, event): col = self.palette().placeholderText().color() painter.setPen(col) fm = self.fontMetrics() - elided_text = fm.elidedText( - self.placeholder_text, QtCore.Qt.ElideRight, self.viewport().width() - ) + elided_text = fm.elidedText(self.placeholder_text, QtCore.Qt.ElideRight, self.viewport().width()) painter.drawText(self.viewport().rect(), QtCore.Qt.AlignCenter, elided_text) painter.restore() @@ -672,9 +647,7 @@ def add_pattern_group(self, plot, group): signals = { sig_uuid: sig for sig_uuid, sig in signals.items() - if sig.samples.dtype.kind not in "SU" - and not sig.samples.dtype.names - and not len(sig.samples.shape) > 1 + if sig.samples.dtype.kind not in "SU" and not sig.samples.dtype.names and not len(sig.samples.shape) > 1 } group.count = len(signals) @@ -730,22 +703,12 @@ def add_new_channels(self, names, widget, mime_data=None): if self.file_by_uuid(uuid): break else: - mime_data = substitude_mime_uuids( - mime_data, uuid=self.uuid, force=True - ) + mime_data = substitude_mime_uuids(mime_data, uuid=self.uuid, force=True) entries = get_flatten_entries_from_mime(mime_data) - signals_ = [ - entry - for entry in entries - if (entry["group_index"], entry["channel_index"]) != (-1, -1) - ] + signals_ = [entry for entry in entries if (entry["group_index"], entry["channel_index"]) != (-1, -1)] - computed = [ - entry - for entry in entries - if (entry["group_index"], entry["channel_index"]) == (-1, -1) - ] + computed = [entry for entry in entries if (entry["group_index"], entry["channel_index"]) == (-1, -1)] uuids = set(entry["origin_uuid"] for entry in entries) @@ -791,9 +754,7 @@ def add_new_channels(self, names, widget, mime_data=None): if entry["origin_uuid"] == uuid ] - uuids_signals_uuid = [ - entry for entry in signals_ if entry["origin_uuid"] == uuid - ] + uuids_signals_uuid = [entry for entry in signals_ if entry["origin_uuid"] == uuid] file_info = self.file_by_uuid(uuid) if not file_info: @@ -809,9 +770,7 @@ def add_new_channels(self, names, widget, mime_data=None): raw=True, ) - for sig, sig_, sig_uuid in zip( - selected_signals, uuids_signals, uuids_signals_uuid - ): + for sig, sig_, sig_uuid in zip(selected_signals, uuids_signals, uuids_signals_uuid): sig.group_index = sig_[1] sig.channel_index = sig_[2] sig.flags &= ~sig.Flags.computed @@ -831,9 +790,7 @@ def add_new_channels(self, names, widget, mime_data=None): for signal in signals: if len(signal.samples.shape) > 1: - signal.samples = csv_bytearray2hex( - pd.Series(list(signal.samples)) - ) + signal.samples = csv_bytearray2hex(pd.Series(list(signal.samples))) if signal.name.endswith(".ID"): signal.samples = signal.samples.astype(" 1: - signal.samples = csv_bytearray2hex( - pd.Series(list(signal.samples)) - ) + signal.samples = csv_bytearray2hex(pd.Series(list(signal.samples))) if signal.name.endswith(".ID"): signal.samples = signal.samples.astype(" 1) + if sig.samples.dtype.kind not in "SU" and (sig.samples.dtype.names or len(sig.samples.shape) > 1) } signals = { key: sig for key, sig in signals.items() - if sig.samples.dtype.kind not in "SU" - and not sig.samples.dtype.names - and not len(sig.samples.shape) > 1 + if sig.samples.dtype.kind not in "SU" and not sig.samples.dtype.names and not len(sig.samples.shape) > 1 } for sig in nd.values(): @@ -2299,9 +2115,7 @@ def _add_plot_window(self, signals, disable_new_channels=False): matrix_name = sig.name for indexes in itertools.product(*matrix_dims): - indexes_string = "".join( - f"[{_index}]" for _index in indexes - ) + indexes_string = "".join(f"[{_index}]" for _index in indexes) samples = array_samples for idx in indexes: @@ -2336,9 +2150,7 @@ def _add_plot_window(self, signals, disable_new_channels=False): length = None else: length = None - signal.samples = csv_bytearray2hex( - pd.Series(list(signal.samples)), length.astype("u2") - ) + signal.samples = csv_bytearray2hex(pd.Series(list(signal.samples)), length.astype("u2")) if signal.name.endswith(".ID"): signal.samples = signal.samples.astype(" 1 + if sig.samples.dtype.kind not in "SU" and not sig.samples.dtype.names and not len(sig.samples.shape) > 1 } for uuid in descriptions: @@ -3518,9 +3265,7 @@ def _load_plot_window(self, window_info): before = menu.actions()[0] menu.insertAction(before, action) - w.setWindowTitle( - generate_window_title(w, window_info["type"], window_info["title"]) - ) + w.setWindowTitle(generate_window_title(w, window_info["type"], window_info["title"])) if "x_range" in window_info["configuration"] and WithMDIArea.load_plot_x_range: x_range = window_info["configuration"]["x_range"] @@ -3560,9 +3305,7 @@ def _load_plot_window(self, window_info): self.set_subplots_link(self.subplots_link) if "cursor_precision" in window_info["configuration"]: - plot.cursor_info.set_precision( - window_info["configuration"]["cursor_precision"] - ) + plot.cursor_info.set_precision(window_info["configuration"]["cursor_precision"]) iterator = QtWidgets.QTreeWidgetItemIterator(plot.channel_selection) while iterator.value(): @@ -3576,9 +3319,7 @@ def _load_plot_window(self, window_info): item.setCheckState(item.NameColumn, state) if "common_axis_y_range" in window_info["configuration"]: - plot.plot.common_axis_y_range = tuple( - window_info["configuration"]["common_axis_y_range"] - ) + plot.plot.common_axis_y_range = tuple(window_info["configuration"]["common_axis_y_range"]) if "channels_header" in window_info["configuration"]: width, sizes = window_info["configuration"]["channels_header"] @@ -3590,19 +3331,11 @@ def _load_plot_window(self, window_info): plot.set_locked(locked=window_info["configuration"].get("locked", False)) plot.hide_axes(hide=window_info["configuration"].get("hide_axes", False)) plot.hide_selected_channel_value( - hide=window_info["configuration"].get( - "hide_selected_channel_value_panel", True - ) - ) - plot.toggle_bookmarks( - hide=window_info["configuration"].get("hide_bookmarks", False) - ) - plot.toggle_focused_mode( - focused=window_info["configuration"].get("focused_mode", False) - ) - plot.toggle_region_values_display_mode( - mode=window_info["configuration"].get("delta_mode", "value") + hide=window_info["configuration"].get("hide_selected_channel_value_panel", True) ) + plot.toggle_bookmarks(hide=window_info["configuration"].get("hide_bookmarks", False)) + plot.toggle_focused_mode(focused=window_info["configuration"].get("focused_mode", False)) + plot.toggle_region_values_display_mode(mode=window_info["configuration"].get("delta_mode", "value")) plot.plot._can_paint_global = True plot.update() @@ -3644,18 +3377,12 @@ def _load_tabular_window(self, window_info): ranges = pattern_info["ranges"] for range_info in ranges: - range_info["font_color"] = QtGui.QBrush( - QtGui.QColor(range_info["font_color"]) - ) - range_info["background_color"] = QtGui.QBrush( - QtGui.QColor(range_info["background_color"]) - ) + range_info["font_color"] = QtGui.QBrush(QtGui.QColor(range_info["font_color"])) + range_info["background_color"] = QtGui.QBrush(QtGui.QColor(range_info["background_color"])) ranges = {sig.name: copy_ranges(ranges) for sig in signals_} - signals_ = [ - (sig.name, sig.group_index, sig.channel_index) for sig in signals_ - ] + signals_ = [(sig.name, sig.group_index, sig.channel_index) for sig in signals_] pattern_info["ranges"] = ranges @@ -3671,12 +3398,8 @@ def _load_tabular_window(self, window_info): ranges = window_info["configuration"].get("ranges", {}) for channel_ranges in ranges.values(): for range_info in channel_ranges: - range_info["font_color"] = QtGui.QBrush( - QtGui.QColor(range_info["font_color"]) - ) - range_info["background_color"] = QtGui.QBrush( - QtGui.QColor(range_info["background_color"]) - ) + range_info["font_color"] = QtGui.QBrush(QtGui.QColor(range_info["font_color"])) + range_info["background_color"] = QtGui.QBrush(QtGui.QColor(range_info["background_color"])) if not signals_: return None, False @@ -3731,9 +3454,7 @@ def _load_tabular_window(self, window_info): elif window_info.get("minimized", False): w.showMinimized() - w.setWindowTitle( - generate_window_title(w, window_info["type"], window_info["title"]) - ) + w.setWindowTitle(generate_window_title(w, window_info["type"], window_info["title"])) filter_count = 0 available_columns = [signals.index.name] + list(signals.columns) @@ -3741,9 +3462,7 @@ def _load_tabular_window(self, window_info): if filter_info["column"] in available_columns: tabular.add_filter() filter = tabular.filters.itemWidget(tabular.filters.item(filter_count)) - filter.enabled.setCheckState( - QtCore.Qt.Checked if filter_info["enabled"] else QtCore.Qt.Unchecked - ) + filter.enabled.setCheckState(QtCore.Qt.Checked if filter_info["enabled"] else QtCore.Qt.Unchecked) filter.relation.setCurrentText(filter_info["relation"]) filter.column.setCurrentText(filter_info["column"]) filter.op.setCurrentText(filter_info["op"]) @@ -3756,13 +3475,9 @@ def _load_tabular_window(self, window_info): tabular.apply_filters() tabular.time_as_date.setCheckState( - QtCore.Qt.Checked - if window_info["configuration"]["time_as_date"] - else QtCore.Qt.Unchecked - ) - tabular.add_channels_request.connect( - partial(self.add_new_channels, widget=tabular) + QtCore.Qt.Checked if window_info["configuration"]["time_as_date"] else QtCore.Qt.Unchecked ) + tabular.add_channels_request.connect(partial(self.add_new_channels, widget=tabular)) menu = w.systemMenu() @@ -3792,12 +3507,8 @@ def _load_can_bus_trace_window(self, window_info): ranges = window_info["configuration"].get("ranges", {}) for channel_ranges in ranges.values(): for range_info in channel_ranges: - range_info["font_color"] = QtGui.QBrush( - QtGui.QColor(range_info["font_color"]) - ) - range_info["background_color"] = QtGui.QBrush( - QtGui.QColor(range_info["background_color"]) - ) + range_info["font_color"] = QtGui.QBrush(QtGui.QColor(range_info["font_color"])) + range_info["background_color"] = QtGui.QBrush(QtGui.QColor(range_info["background_color"])) widget = self._add_can_bus_trace_window(ranges) @@ -3819,12 +3530,8 @@ def _load_flexray_bus_trace_window(self, window_info): ranges = window_info["configuration"].get("ranges", {}) for channel_ranges in ranges.values(): for range_info in channel_ranges: - range_info["font_color"] = QtGui.QBrush( - QtGui.QColor(range_info["font_color"]) - ) - range_info["background_color"] = QtGui.QBrush( - QtGui.QColor(range_info["background_color"]) - ) + range_info["font_color"] = QtGui.QBrush(QtGui.QColor(range_info["font_color"])) + range_info["background_color"] = QtGui.QBrush(QtGui.QColor(range_info["background_color"])) widget = self._add_flexray_bus_trace_window(ranges) @@ -3846,12 +3553,8 @@ def _load_lin_bus_trace_window(self, window_info): ranges = window_info["configuration"].get("ranges", {}) for channel_ranges in ranges.values(): for range_info in channel_ranges: - range_info["font_color"] = QtGui.QBrush( - QtGui.QColor(range_info["font_color"]) - ) - range_info["background_color"] = QtGui.QBrush( - QtGui.QColor(range_info["background_color"]) - ) + range_info["font_color"] = QtGui.QBrush(QtGui.QColor(range_info["font_color"])) + range_info["background_color"] = QtGui.QBrush(QtGui.QColor(range_info["background_color"])) widget = self._add_lin_bus_trace_window(ranges) @@ -3989,19 +3692,13 @@ def set_splitter(self, widget, selection_width): if selection_width is not None: total_size = sum(wid.splitter.sizes()) if total_size > selection_width: - wid.splitter.setSizes( - [selection_width, total_size - selection_width] - ) + wid.splitter.setSizes([selection_width, total_size - selection_width]) self._splitter_source = None def update_functions(self, original_definitions, modified_definitions): # new definitions - new_functions = [ - info - for uuid, info in modified_definitions.items() - if uuid not in original_definitions - ] + new_functions = [info for uuid, info in modified_definitions.items() if uuid not in original_definitions] for info in new_functions: self.functions[info["name"]] = info["definition"] @@ -4028,11 +3725,7 @@ def update_functions(self, original_definitions, modified_definitions): deleted = set() - deleted_functions = [ - info - for uuid, info in original_definitions.items() - if uuid not in modified_definitions - ] + deleted_functions = [info for uuid, info in original_definitions.items() if uuid not in modified_definitions] for info in deleted_functions: del self.functions[info["name"]] @@ -4065,9 +3758,7 @@ def update_functions(self, original_definitions, modified_definitions): exec(definition.replace("\t", " "), _globals) func = _globals[func_name] - parameters = list( - inspect.signature(func).parameters - )[:-1] + parameters = list(inspect.signature(func).parameters)[:-1] args = {name: [] for name in parameters} for arg_name, alternatives in zip( parameters, @@ -4079,9 +3770,7 @@ def update_functions(self, original_definitions, modified_definitions): except: print(format_exc()) - self.edit_channel( - wid.channel_item_to_config(item), item, wid - ) + self.edit_channel(wid.channel_item_to_config(item), item, wid) iterator += 1 @@ -4183,9 +3872,7 @@ def verify_bookmarks(self, bookmarks, plot): result = MessageBox.question( self, "Save measurement bookmarks?", - "You have modified bookmarks.\n\n" - "Do you want to save the changes in the measurement file?\n" - "", + "You have modified bookmarks.\n\n" "Do you want to save the changes in the measurement file?\n" "", ) if result == MessageBox.No: @@ -4314,9 +4001,7 @@ def verify_bookmarks(self, bookmarks, plot): def window_closed_handler(self, obj=None): self.windows_modified.emit() - def set_cursor_options( - self, cursor_circle, cursor_horizontal_line, cursor_line_width, cursor_color - ): + def set_cursor_options(self, cursor_circle, cursor_horizontal_line, cursor_line_width, cursor_color): cursor_color = QtGui.QColor(cursor_color) self.cursor_circle = cursor_circle self.cursor_horizontal_line = cursor_horizontal_line diff --git a/src/asammdf/gui/widgets/numeric.py b/src/asammdf/gui/widgets/numeric.py index e0ac7d17e..83c81d84c 100644 --- a/src/asammdf/gui/widgets/numeric.py +++ b/src/asammdf/gui/widgets/numeric.py @@ -125,9 +125,7 @@ def __lt__(self, other): return self.name < other.name def set_timestamp(self, timestamp): - if timestamp is not None and ( - self.last_timestamp is None or self.last_timestamp != timestamp - ): + if timestamp is not None and (self.last_timestamp is None or self.last_timestamp != timestamp): self.last_timestamp = timestamp sig = self.signal @@ -173,9 +171,7 @@ def update_signal_origin_uuid(self, signal, origin_uuid): self.map[signal.entry] = signal del self.map[old_entry] - self.numeric_viewer.dataView.ranges[ - signal.entry - ] = self.numeric_viewer.dataView.ranges[old_entry] + self.numeric_viewer.dataView.ranges[signal.entry] = self.numeric_viewer.dataView.ranges[old_entry] del self.numeric_viewer.dataView.ranges[old_entry] def update(self, others=()): @@ -227,9 +223,7 @@ def sort(self): sorted_column_index = self.sorted_column_index if sorted_column_index == 0: - self.signals = natsorted( - self.signals, key=lambda x: x.name, reverse=self.sort_reversed - ) + self.signals = natsorted(self.signals, key=lambda x: x.name, reverse=self.sort_reversed) elif sorted_column_index in (1, 2): numeric = [] @@ -260,9 +254,7 @@ def sort(self): ] elif sorted_column_index == 3: - self.signals = natsorted( - self.signals, key=lambda x: x.unit, reverse=self.sort_reversed - ) + self.signals = natsorted(self.signals, key=lambda x: x.unit, reverse=self.sort_reversed) self.data_changed() @@ -321,10 +313,7 @@ def update(self, others=()): self.signals.append(signal) if self.signals: - timestamps = { - id(signal.signal.timestamps): signal.signal.timestamps - for signal in self.signals - } + timestamps = {id(signal.signal.timestamps): signal.signal.timestamps for signal in self.signals} timestamps = list(timestamps.values()) self.timebase = np.unique(np.concatenate(timestamps)) else: @@ -352,9 +341,7 @@ def sort(self): sorted_column_index = self.sorted_column_index if sorted_column_index == 0: - self.signals = natsorted( - self.signals, key=lambda x: x.name, reverse=self.sort_reversed - ) + self.signals = natsorted(self.signals, key=lambda x: x.name, reverse=self.sort_reversed) elif sorted_column_index in (1, 2): numeric = [] @@ -385,9 +372,7 @@ def sort(self): ] elif sorted_column_index == 3: - self.signals = natsorted( - self.signals, key=lambda x: x.unit, reverse=self.sort_reversed - ) + self.signals = natsorted(self.signals, key=lambda x: x.unit, reverse=self.sort_reversed) self.data_changed() @@ -487,11 +472,7 @@ def data(self, index, role=QtCore.Qt.DisplayRole): default_font_color=self.font_color, ) - return ( - new_background_color - if new_background_color != self.background_color - else None - ) + return new_background_color if new_background_color != self.background_color else None elif role == QtCore.Qt.ForegroundRole: channel_ranges = self.view.ranges[signal.entry] @@ -590,11 +571,7 @@ def data(self, index, role=QtCore.Qt.DisplayRole): return icon def flags(self, index): - return ( - QtCore.Qt.ItemIsEnabled - | QtCore.Qt.ItemIsSelectable - | QtCore.Qt.ItemIsDragEnabled - ) + return QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsDragEnabled def setData(self, index, value, role=None): pass @@ -662,9 +639,7 @@ def keyPressEvent(self, event): modifiers = event.modifiers() if key == QtCore.Qt.Key_Delete and modifiers == QtCore.Qt.NoModifier: - selected_items = set( - index.row() for index in self.selectedIndexes() if index.isValid() - ) + selected_items = set(index.row() for index in self.selectedIndexes() if index.isValid()) for row in reversed(list(selected_items)): signal = self.backend.signals.pop(row) @@ -673,9 +648,7 @@ def keyPressEvent(self, event): self.backend.update() elif key == QtCore.Qt.Key_R and modifiers == QtCore.Qt.ControlModifier: - selected_items = set( - index.row() for index in self.selectedIndexes() if index.isValid() - ) + selected_items = set(index.row() for index in self.selectedIndexes() if index.isValid()) if selected_items: ranges = [] @@ -701,13 +674,8 @@ def keyPressEvent(self, event): self.backend.update() - elif ( - modifiers == (QtCore.Qt.ControlModifier | QtCore.Qt.ShiftModifier) - and key == QtCore.Qt.Key_C - ): - selected_items = set( - index.row() for index in self.selectedIndexes() if index.isValid() - ) + elif modifiers == (QtCore.Qt.ControlModifier | QtCore.Qt.ShiftModifier) and key == QtCore.Qt.Key_C: + selected_items = set(index.row() for index in self.selectedIndexes() if index.isValid()) if not selected_items: return @@ -721,21 +689,14 @@ def keyPressEvent(self, event): } for range_info in info["ranges"]: - range_info["background_color"] = ( - range_info["background_color"].color().name() - ) + range_info["background_color"] = range_info["background_color"].color().name() range_info["font_color"] = range_info["font_color"].color().name() QtWidgets.QApplication.instance().clipboard().setText(json.dumps(info)) - elif ( - modifiers == (QtCore.Qt.ControlModifier | QtCore.Qt.ShiftModifier) - and key == QtCore.Qt.Key_V - ): + elif modifiers == (QtCore.Qt.ControlModifier | QtCore.Qt.ShiftModifier) and key == QtCore.Qt.Key_V: info = QtWidgets.QApplication.instance().clipboard().text() - selected_items = set( - index.row() for index in self.selectedIndexes() if index.isValid() - ) + selected_items = set(index.row() for index in self.selectedIndexes() if index.isValid()) if not selected_items: return @@ -743,12 +704,8 @@ def keyPressEvent(self, event): try: info = json.loads(info) for range_info in info["ranges"]: - range_info["background_color"] = QtGui.QBrush( - QtGui.QColor(range_info["background_color"]) - ) - range_info["font_color"] = QtGui.QBrush( - QtGui.QColor(range_info["font_color"]) - ) + range_info["background_color"] = QtGui.QBrush(QtGui.QColor(range_info["background_color"])) + range_info["font_color"] = QtGui.QBrush(QtGui.QColor(range_info["font_color"])) except: print(format_exc()) else: @@ -764,9 +721,7 @@ def keyPressEvent(self, event): super().keyPressEvent(event) def startDrag(self, supportedActions): - selected_items = [ - index.row() for index in self.selectedIndexes() if index.isValid() - ] + selected_items = [index.row() for index in self.selectedIndexes() if index.isValid()] mimeData = QtCore.QMimeData() @@ -784,9 +739,7 @@ def startDrag(self, supportedActions): for range_info in ranges: range_info["font_color"] = range_info["font_color"].color().name() - range_info["background_color"] = ( - range_info["background_color"].color().name() - ) + range_info["background_color"] = range_info["background_color"].color().name() info = { "name": signal.name, @@ -795,9 +748,7 @@ def startDrag(self, supportedActions): "group_index": group_index, "channel_index": channel_index, "ranges": ranges, - "origin_uuid": str(entry[0]) - if numeric_mode == "online" - else signal.signal.origin_uuid, + "origin_uuid": str(entry[0]) if numeric_mode == "online" else signal.signal.origin_uuid, "type": "channel", "uuid": os.urandom(6).hex(), } @@ -833,9 +784,7 @@ def edit_ranges(self, index): row = index.row() signal = self.backend.signals[row] - dlg = RangeEditor( - signal.name, signal.unit, self.ranges[signal.entry], parent=self, brush=True - ) + dlg = RangeEditor(signal.name, signal.unit, self.ranges[signal.entry], parent=self, brush=True) dlg.exec_() if dlg.pressed_button == "apply": ranges = dlg.result @@ -903,11 +852,7 @@ def __init__(self, parent): self.viewport().installEventFilter(self) self.setIconSize(QtCore.QSize(16, 16)) - self.setSizePolicy( - QtWidgets.QSizePolicy( - QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Maximum - ) - ) + self.setSizePolicy(QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Maximum)) self.setWordWrap(False) self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) @@ -1009,14 +954,10 @@ def over_header_cell_edge(mouse_position, margin=3): if event.type() == QtCore.QEvent.MouseMove: if self.header_cell_being_resized is not None: - size = mouse_position - self.columnViewportPosition( - self.header_cell_being_resized - ) + size = mouse_position - self.columnViewportPosition(self.header_cell_being_resized) if size > 10: self.setColumnWidth(self.header_cell_being_resized, size) - self.numeric_viewer.dataView.setColumnWidth( - self.header_cell_being_resized, size - ) + self.numeric_viewer.dataView.setColumnWidth(self.header_cell_being_resized, size) self.updateGeometry() self.numeric_viewer.dataView.updateGeometry() @@ -1058,13 +999,9 @@ def __init__(self, backend): self.gridLayout.setSpacing(0) self.setLayout(self.gridLayout) - self.dataView.horizontalScrollBar().valueChanged.connect( - self.columnHeader.horizontalScrollBar().setValue - ) + self.dataView.horizontalScrollBar().valueChanged.connect(self.columnHeader.horizontalScrollBar().setValue) - self.columnHeader.horizontalScrollBar().valueChanged.connect( - self.dataView.horizontalScrollBar().setValue - ) + self.columnHeader.horizontalScrollBar().valueChanged.connect(self.dataView.horizontalScrollBar().setValue) # self.dataView.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) # self.dataView.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) @@ -1075,22 +1012,16 @@ def __init__(self, backend): # self.gridLayout.addWidget(self.dataView.verticalScrollBar(), 1, 1, 1, 1) self.dataView.verticalScrollBar().setSizePolicy( - QtWidgets.QSizePolicy( - QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Ignored - ) + QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Ignored) ) self.dataView.horizontalScrollBar().setSizePolicy( - QtWidgets.QSizePolicy( - QtWidgets.QSizePolicy.Ignored, QtWidgets.QSizePolicy.Fixed - ) + QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Ignored, QtWidgets.QSizePolicy.Fixed) ) self.gridLayout.setColumnStretch(0, 1) self.gridLayout.setRowStretch(1, 1) - self.columnHeader.setSizePolicy( - QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Maximum - ) + self.columnHeader.setSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Maximum) self.default_row_height = 24 self.set_styles() @@ -1100,9 +1031,7 @@ def __init__(self, backend): self.columnHeader.horizontalHeader().setStretchLastSection(True) - self.columnHeader.horizontalHeader().sectionResized.connect( - self.update_horizontal_scroll - ) + self.columnHeader.horizontalHeader().sectionResized.connect(self.update_horizontal_scroll) self.columnHeader.horizontalHeader().setMinimumSectionSize(1) self.dataView.horizontalHeader().setMinimumSectionSize(1) @@ -1114,18 +1043,10 @@ def set_styles(self): self.dataView.verticalHeader().setMinimumSectionSize(self.default_row_height) self.dataView.verticalHeader().setMaximumSectionSize(self.default_row_height) self.dataView.verticalHeader().sectionResizeMode(QtWidgets.QHeaderView.Fixed) - self.columnHeader.verticalHeader().setDefaultSectionSize( - self.default_row_height - ) - self.columnHeader.verticalHeader().setMinimumSectionSize( - self.default_row_height - ) - self.columnHeader.verticalHeader().setMaximumSectionSize( - self.default_row_height - ) - self.columnHeader.verticalHeader().sectionResizeMode( - QtWidgets.QHeaderView.Fixed - ) + self.columnHeader.verticalHeader().setDefaultSectionSize(self.default_row_height) + self.columnHeader.verticalHeader().setMinimumSectionSize(self.default_row_height) + self.columnHeader.verticalHeader().setMaximumSectionSize(self.default_row_height) + self.columnHeader.verticalHeader().sectionResizeMode(QtWidgets.QHeaderView.Fixed) def auto_size_header(self): s = 0 @@ -1160,30 +1081,20 @@ def auto_size_column(self, column_index, extra_padding=0): for i in range(self.dataView.model().rowCount())[:N]: mi = self.dataView.model().index(i, column_index) text = self.dataView.model().data(mi) - w = ( - self.dataView.fontMetrics() - .boundingRect(text.replace("\0", " ")) - .width() - ) + w = self.dataView.fontMetrics().boundingRect(text.replace("\0", " ")).width() width = max(width, w) for i in range(self.columnHeader.model().rowCount()): mi = self.columnHeader.model().index(i, column_index) text = self.columnHeader.model().data(mi) - w = ( - self.columnHeader.fontMetrics() - .boundingRect(text.replace("\0", " ")) - .width() - ) + w = self.columnHeader.fontMetrics().boundingRect(text.replace("\0", " ")).width() width = max(width, w) padding = 20 width += padding + extra_padding self.columnHeader.setColumnWidth(column_index, width) - self.dataView.setColumnWidth( - column_index, self.columnHeader.columnWidth(column_index) - ) + self.dataView.setColumnWidth(column_index, self.columnHeader.columnWidth(column_index)) self.dataView.updateGeometry() self.columnHeader.updateGeometry() @@ -1245,9 +1156,7 @@ def __init__( self.main_layout.insertWidget(0, self.channels) self.main_layout.setStretch(0, 1) - self.float_precision.addItems( - ["Full float precision"] + [f"{i} float decimals" for i in range(16)] - ) + self.float_precision.addItems(["Full float precision"] + [f"{i} float decimals" for i in range(16)]) self.float_precision.currentIndexChanged.connect(self.set_float_precision) @@ -1257,9 +1166,7 @@ def __init__( self._settings.setValue("numeric_format", format) if float_precision is None: - float_precision = self._settings.value( - "numeric_float_precision", -1, type=int - ) + float_precision = self._settings.value("numeric_float_precision", -1, type=int) self.float_precision.setCurrentIndex(float_precision + 1) self.timebase = np.array([]) @@ -1269,9 +1176,7 @@ def __init__( self.add_new_channels(channels) self.channels.dataView.add_channels_request.connect(self.add_channels_request) - self.channels.dataView.verticalScrollBar().valueChanged.connect( - self.reset_visible_entries - ) + self.channels.dataView.verticalScrollBar().valueChanged.connect(self.reset_visible_entries) self.channels.columnHeader.sorting_changed.connect(self.reset_visible_entries) self.channels.auto_size_header() @@ -1318,9 +1223,7 @@ def add_new_channels(self, channels, mime_data=None): ranges = copy_ranges(sig.ranges) for range_info in ranges: range_info["font_color"] = fn.mkBrush(range_info["font_color"]) - range_info["background_color"] = fn.mkBrush( - range_info["background_color"] - ) + range_info["background_color"] = fn.mkBrush(range_info["background_color"]) sig.ranges = ranges self.channels.dataView.ranges[entry] = sig.ranges @@ -1335,9 +1238,7 @@ def add_new_channels(self, channels, mime_data=None): exists = getattr(sig, "exists", True) sig = PlotSignal(sig, allow_trim=False) if sig.conversion: - sig.phys_samples = sig.conversion.convert( - sig.raw_samples, as_bytes=True - ) + sig.phys_samples = sig.conversion.convert(sig.raw_samples, as_bytes=True) sig.entry = sig.group_index, sig.channel_index others.append( @@ -1349,9 +1250,7 @@ def add_new_channels(self, channels, mime_data=None): for range_info in ranges: range_info["font_color"] = fn.mkBrush(range_info["font_color"]) - range_info["background_color"] = fn.mkBrush( - range_info["background_color"] - ) + range_info["background_color"] = fn.mkBrush(range_info["background_color"]) sig.ranges = ranges self.channels.dataView.ranges[sig.entry] = ranges @@ -1380,9 +1279,7 @@ def to_config(self): for range_info in ranges: range_info["font_color"] = range_info["font_color"].color().name() - range_info["background_color"] = ( - range_info["background_color"].color().name() - ) + range_info["background_color"] = range_info["background_color"].color().name() channels.append( { @@ -1400,9 +1297,7 @@ def to_config(self): for range_info in ranges: range_info["font_color"] = range_info["font_color"].color().name() - range_info["background_color"] = ( - range_info["background_color"].color().name() - ) + range_info["background_color"] = range_info["background_color"].color().name() pattern["ranges"] = ranges else: @@ -1521,11 +1416,7 @@ def set_timestamp(self, stamp=None, emit=True): self.timestamp_changed_signal.emit(self, stamp) def search_forward(self): - if ( - self.op.currentIndex() < 0 - or not self.target.text().strip() - or not self.pattern_match.text().strip() - ): + if self.op.currentIndex() < 0 or not self.target.text().strip() or not self.pattern_match.text().strip(): self.match.setText("invalid input values") return @@ -1542,9 +1433,7 @@ def search_forward(self): else: pattern = re.compile(f"(?i){pattern}") - matches = [ - sig for sig in self.channels.backend.signals if pattern.fullmatch(sig.name) - ] + matches = [sig for sig in self.channels.backend.signals if pattern.fullmatch(sig.name)] mode = self.match_mode.currentText() @@ -1593,11 +1482,7 @@ def search_forward(self): self.match.setText("condition not found") def search_backward(self): - if ( - self.op.currentIndex() < 0 - or not self.target.text().strip() - or not self.pattern_match.text().strip() - ): + if self.op.currentIndex() < 0 or not self.target.text().strip() or not self.pattern_match.text().strip(): self.match.setText("invalid input values") return @@ -1614,9 +1499,7 @@ def search_backward(self): else: pattern = re.compile(f"(?i){pattern}") - matches = [ - sig for sig in self.channels.backend.signals if pattern.fullmatch(sig.name) - ] + matches = [sig for sig in self.channels.backend.signals if pattern.fullmatch(sig.name)] mode = self.match_mode.currentText() @@ -1681,25 +1564,13 @@ def keyPressEvent(self, event): else: self.set_format("Physical") event.accept() - elif ( - key == QtCore.Qt.Key_Right - and modifiers == QtCore.Qt.NoModifier - and self.mode == "offline" - ): + elif key == QtCore.Qt.Key_Right and modifiers == QtCore.Qt.NoModifier and self.mode == "offline": self.timestamp_slider.setValue(self.timestamp_slider.value() + 1) - elif ( - key == QtCore.Qt.Key_Left - and modifiers == QtCore.Qt.NoModifier - and self.mode == "offline" - ): + elif key == QtCore.Qt.Key_Left and modifiers == QtCore.Qt.NoModifier and self.mode == "offline": self.timestamp_slider.setValue(self.timestamp_slider.value() - 1) - elif ( - key == QtCore.Qt.Key_S - and modifiers == QtCore.Qt.ControlModifier - and self.mode == "offline" - ): + elif key == QtCore.Qt.Key_S and modifiers == QtCore.Qt.ControlModifier and self.mode == "offline": file_name, _ = QtWidgets.QFileDialog.getSaveFileName( self, "Select output measurement file", @@ -1729,21 +1600,13 @@ def keyPressEvent(self, event): mdf.append(sigs, common_timebase=True) mdf.save(file_name, overwrite=True) - elif ( - key == QtCore.Qt.Key_BracketLeft and modifiers == QtCore.Qt.ControlModifier - ): + elif key == QtCore.Qt.Key_BracketLeft and modifiers == QtCore.Qt.ControlModifier: self.decrease_font() - elif ( - key == QtCore.Qt.Key_BracketRight and modifiers == QtCore.Qt.ControlModifier - ): + elif key == QtCore.Qt.Key_BracketRight and modifiers == QtCore.Qt.ControlModifier: self.increase_font() - elif ( - key == QtCore.Qt.Key_G - and modifiers == QtCore.Qt.ShiftModifier - and self.mode == "offline" - ): + elif key == QtCore.Qt.Key_G and modifiers == QtCore.Qt.ShiftModifier and self.mode == "offline": value, ok = QtWidgets.QInputDialog.getDouble( self, "Go to time stamp", @@ -1796,18 +1659,14 @@ def toggle_controls(self, event=None): self.time_group.setHidden(False) self.search_group.setHidden(False) icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/up.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/up.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.toggle_controls_btn.setIcon(icon) else: self.toggle_controls_btn.setText("Show controls") self.time_group.setHidden(True) self.search_group.setHidden(True) icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/down.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/down.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.toggle_controls_btn.setIcon(icon) def update_timebase(self): diff --git a/src/asammdf/gui/widgets/plot.py b/src/asammdf/gui/widgets/plot.py index d97b3c13e..a9fcf1e2a 100644 --- a/src/asammdf/gui/widgets/plot.py +++ b/src/asammdf/gui/widgets/plot.py @@ -44,9 +44,7 @@ def getId(obj): try: return obj._id except AttributeError: - obj._id = next( - pg.graphicsItems.ScatterPlotItem.SymbolAtlas._idGenerator - ) + obj._id = next(pg.graphicsItems.ScatterPlotItem.SymbolAtlas._idGenerator) return obj._id res = [ @@ -542,9 +540,7 @@ def get_stats(self, cursor=None, region=None, view_region=None, precision=6): value, kind, _ = self.value_at_timestamp(position) - stats["cursor_value"] = value_as_str( - value, format, self.plot_samples.dtype, precision - ) + stats["cursor_value"] = value_as_str(value, format, self.plot_samples.dtype, precision) else: stats["cursor_t"] = "" @@ -552,27 +548,17 @@ def get_stats(self, cursor=None, region=None, view_region=None, precision=6): if region: start, stop = region - stats["selected_start"] = value_as_str( - start, format, np.dtype("f8"), precision - ) - stats["selected_stop"] = value_as_str( - stop, format, np.dtype("f8"), precision - ) - stats["selected_delta_t"] = value_as_str( - stop - start, format, np.dtype("f8"), precision - ) + stats["selected_start"] = value_as_str(start, format, np.dtype("f8"), precision) + stats["selected_stop"] = value_as_str(stop, format, np.dtype("f8"), precision) + stats["selected_delta_t"] = value_as_str(stop - start, format, np.dtype("f8"), precision) value, kind, _ = self.value_at_timestamp(start) - stats["selected_left"] = value_as_str( - value, format, self.plot_samples.dtype, precision - ) + stats["selected_left"] = value_as_str(value, format, self.plot_samples.dtype, precision) value, kind, _ = self.value_at_timestamp(stop) - stats["selected_right"] = value_as_str( - value, format, self.plot_samples.dtype, precision - ) + stats["selected_right"] = value_as_str(value, format, self.plot_samples.dtype, precision) else: stats["selected_start"] = "" @@ -603,8 +589,7 @@ def get_stats(self, cursor=None, region=None, view_region=None, precision=6): stats["overall_integral"] = 0 else: stats["overall_gradient"] = value_as_str( - (float(sig.samples[-1]) - float(sig.samples[0])) - / (sig.timestamps[-1] - sig.timestamps[0]), + (float(sig.samples[-1]) - float(sig.samples[0])) / (sig.timestamps[-1] - sig.timestamps[0]), format, None, precision, @@ -613,47 +598,31 @@ def get_stats(self, cursor=None, region=None, view_region=None, precision=6): np.trapz(sig.samples, sig.timestamps), format, None, precision ) - stats["overall_min"] = value_as_str( - self.min, format, self.plot_samples.dtype, precision - ) - stats["overall_max"] = value_as_str( - self.max, format, self.plot_samples.dtype, precision - ) - stats["overall_average"] = value_as_str( - sig.avg, format, None, precision - ) + stats["overall_min"] = value_as_str(self.min, format, self.plot_samples.dtype, precision) + stats["overall_max"] = value_as_str(self.max, format, self.plot_samples.dtype, precision) + stats["overall_average"] = value_as_str(sig.avg, format, None, precision) stats["overall_rms"] = value_as_str(sig.rms, format, None, precision) stats["overall_std"] = value_as_str(sig.std, format, None, precision) - stats["overall_start"] = value_as_str( - sig.timestamps[0], format, np.dtype("f8"), precision - ) - stats["overall_stop"] = value_as_str( - sig.timestamps[-1], format, np.dtype("f8"), precision - ) + stats["overall_start"] = value_as_str(sig.timestamps[0], format, np.dtype("f8"), precision) + stats["overall_stop"] = value_as_str(sig.timestamps[-1], format, np.dtype("f8"), precision) stats["overall_delta"] = value_as_str( sig.samples[-1] - sig.samples[0], format, self.plot_samples.dtype, precision, ) - stats["overall_delta_t"] = value_as_str( - x[-1] - x[0], format, np.dtype("f8"), precision - ) + stats["overall_delta_t"] = value_as_str(x[-1] - x[0], format, np.dtype("f8"), precision) stats["unit"] = sig.unit stats["color"] = sig.color stats["name"] = sig.name if cursor is not None: position = cursor - stats["cursor_t"] = value_as_str( - position, format, np.dtype("f8"), precision - ) + stats["cursor_t"] = value_as_str(position, format, np.dtype("f8"), precision) value, kind, _ = self.value_at_timestamp(position) - stats["cursor_value"] = value_as_str( - value, format, self.plot_samples.dtype, precision - ) + stats["cursor_value"] = value_as_str(value, format, self.plot_samples.dtype, precision) else: stats["cursor_t"] = "" @@ -663,15 +632,9 @@ def get_stats(self, cursor=None, region=None, view_region=None, precision=6): start, stop = region new_stats = {} - new_stats["selected_start"] = value_as_str( - start, format, np.dtype("f8"), precision - ) - new_stats["selected_stop"] = value_as_str( - stop, format, np.dtype("f8"), precision - ) - new_stats["selected_delta_t"] = value_as_str( - stop - start, format, np.dtype("f8"), precision - ) + new_stats["selected_start"] = value_as_str(start, format, np.dtype("f8"), precision) + new_stats["selected_stop"] = value_as_str(stop, format, np.dtype("f8"), precision) + new_stats["selected_delta_t"] = value_as_str(stop - start, format, np.dtype("f8"), precision) cut = sig.cut(start, stop) @@ -695,18 +658,10 @@ def get_stats(self, cursor=None, region=None, view_region=None, precision=6): samples[-1], format, self.plot_samples.dtype, precision ) - new_stats["selected_min"] = value_as_str( - np.nanmin(samples), format, samples.dtype, precision - ) - new_stats["selected_max"] = value_as_str( - np.nanmax(samples), format, samples.dtype, precision - ) - new_stats["selected_average"] = value_as_str( - np.mean(samples), format, None, precision - ) - new_stats["selected_std"] = value_as_str( - np.std(samples), format, None, precision - ) + new_stats["selected_min"] = value_as_str(np.nanmin(samples), format, samples.dtype, precision) + new_stats["selected_max"] = value_as_str(np.nanmax(samples), format, samples.dtype, precision) + new_stats["selected_average"] = value_as_str(np.mean(samples), format, None, precision) + new_stats["selected_std"] = value_as_str(np.std(samples), format, None, precision) new_stats["selected_rms"] = value_as_str( np.sqrt(np.mean(np.square(samples))), format, @@ -733,8 +688,7 @@ def get_stats(self, cursor=None, region=None, view_region=None, precision=6): new_stats["selected_integral"] = 0 else: new_stats["selected_gradient"] = value_as_str( - (float(samples[-1]) - float(samples[0])) - / (timestamps[-1] - timestamps[0]), + (float(samples[-1]) - float(samples[0])) / (timestamps[-1] - timestamps[0]), format, None, precision, @@ -778,15 +732,9 @@ def get_stats(self, cursor=None, region=None, view_region=None, precision=6): start, stop = view_region new_stats = {} - new_stats["visible_start"] = value_as_str( - start, format, np.dtype("f8"), precision - ) - new_stats["visible_stop"] = value_as_str( - stop, format, np.dtype("f8"), precision - ) - new_stats["visible_delta_t"] = value_as_str( - stop - start, format, np.dtype("f8"), precision - ) + new_stats["visible_start"] = value_as_str(start, format, np.dtype("f8"), precision) + new_stats["visible_stop"] = value_as_str(stop, format, np.dtype("f8"), precision) + new_stats["visible_delta_t"] = value_as_str(stop - start, format, np.dtype("f8"), precision) cut = sig.cut(start, stop) @@ -804,18 +752,10 @@ def get_stats(self, cursor=None, region=None, view_region=None, precision=6): if size: kind = samples.dtype.kind - new_stats["visible_min"] = value_as_str( - np.nanmin(samples), format, samples.dtype, precision - ) - new_stats["visible_max"] = value_as_str( - np.nanmax(samples), format, samples.dtype, precision - ) - new_stats["visible_average"] = value_as_str( - np.mean(samples), format, None, precision - ) - new_stats["visible_std"] = value_as_str( - np.std(samples), format, None, precision - ) + new_stats["visible_min"] = value_as_str(np.nanmin(samples), format, samples.dtype, precision) + new_stats["visible_max"] = value_as_str(np.nanmax(samples), format, samples.dtype, precision) + new_stats["visible_average"] = value_as_str(np.mean(samples), format, None, precision) + new_stats["visible_std"] = value_as_str(np.std(samples), format, None, precision) new_stats["visible_rms"] = value_as_str( np.sqrt(np.mean(np.square(samples))), format, None, precision ) @@ -839,8 +779,7 @@ def get_stats(self, cursor=None, region=None, view_region=None, precision=6): new_stats["visible_integral"] = 0 else: new_stats["visible_gradient"] = value_as_str( - (float(samples[-1]) - float(samples[0])) - / (timestamps[-1] - timestamps[0]), + (float(samples[-1]) - float(samples[0])) / (timestamps[-1] - timestamps[0]), format, None, precision, @@ -882,9 +821,7 @@ def get_stats(self, cursor=None, region=None, view_region=None, precision=6): if cursor is not None: position = cursor - stats["cursor_t"] = value_as_str( - position, format, np.dtype("f8"), precision - ) + stats["cursor_t"] = value_as_str(position, format, np.dtype("f8"), precision) stats["cursor_value"] = "n.a." @@ -895,15 +832,9 @@ def get_stats(self, cursor=None, region=None, view_region=None, precision=6): if region is not None: start, stop = region - stats["selected_start"] = value_as_str( - start, format, np.dtype("f8"), precision - ) - stats["selected_stop"] = value_as_str( - stop, format, np.dtype("f8"), precision - ) - stats["selected_delta_t"] = value_as_str( - stop - start, format, np.dtype("f8"), precision - ) + stats["selected_start"] = value_as_str(start, format, np.dtype("f8"), precision) + stats["selected_stop"] = value_as_str(stop, format, np.dtype("f8"), precision) + stats["selected_delta_t"] = value_as_str(stop - start, format, np.dtype("f8"), precision) stats["selected_min"] = "n.a." stats["selected_max"] = "n.a." @@ -933,15 +864,9 @@ def get_stats(self, cursor=None, region=None, view_region=None, precision=6): start, stop = view_region - stats["visible_start"] = value_as_str( - start, format, np.dtype("f8"), precision - ) - stats["visible_stop"] = value_as_str( - stop, format, np.dtype("f8"), precision - ) - stats["visible_delta_t"] = value_as_str( - stop - start, format, np.dtype("f8"), precision - ) + stats["visible_start"] = value_as_str(start, format, np.dtype("f8"), precision) + stats["visible_stop"] = value_as_str(stop, format, np.dtype("f8"), precision) + stats["visible_delta_t"] = value_as_str(stop - start, format, np.dtype("f8"), precision) stats["visible_min"] = "n.a." stats["visible_max"] = "n.a." @@ -1110,9 +1035,7 @@ def trim_c(self, start=None, stop=None, width=1900, force=False): self._dtype = "f8" if samples.dtype != self._plot_samples.dtype: - self._plot_samples = np.empty( - 2 * PLOT_BUFFER_SIZE, dtype=samples.dtype - ) + self._plot_samples = np.empty(2 * PLOT_BUFFER_SIZE, dtype=samples.dtype) self._dtype = samples.dtype @@ -1223,9 +1146,7 @@ def trim_python(self, start=None, stop=None, width=1900, force=False): rows = (stop_ - start_) // visible_duplication stop_2 = start_ + rows * visible_duplication - samples = signal_samples[start_:stop_2].reshape( - rows, visible_duplication - ) + samples = signal_samples[start_:stop_2].reshape(rows, visible_duplication) try: pos_max = samples.argmax(axis=1) @@ -1262,11 +1183,7 @@ def trim_python(self, start=None, stop=None, width=1900, force=False): pos_max = np.nanargmax(samples_) pos_min = np.nanargmin(samples_) - pos2 = ( - [pos_min, pos_max] - if pos_min < pos_max - else [pos_max, pos_min] - ) + pos2 = [pos_min, pos_max] if pos_min < pos_max else [pos_max, pos_min] _size = len(pos) @@ -1376,9 +1293,7 @@ def value_at_timestamp(self, timestamp, numeric=False): try: value = value.decode("utf-8", errors="replace").strip(" \r\n\t\v\0") except: - value = value.decode("latin-1", errors="replace").strip( - " \r\n\t\v\0" - ) + value = value.decode("latin-1", errors="replace").strip(" \r\n\t\v\0") value = value or "" elif kind == "f": @@ -1462,9 +1377,7 @@ def __init__( self._inhibit_timestamp_signals = False self._inhibit_timestamp_signals_timer = QtCore.QTimer() self._inhibit_timestamp_signals_timer.setSingleShot(True) - self._inhibit_timestamp_signals_timer.timeout.connect( - self._inhibit_timestamp_handler - ) + self._inhibit_timestamp_signals_timer.timeout.connect(self._inhibit_timestamp_handler) self.can_edit_ranges = True self.region_values_display_mode = region_values_display_mode @@ -1574,9 +1487,7 @@ def __init__( ) icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/stack.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/stack.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) menu.addAction( icon, "Stack", @@ -1590,15 +1501,11 @@ def __init__( ) icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/increase-font.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/increase-font.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) menu.addAction(icon, "Increase font", self.increase_font) icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/decrease-font.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/decrease-font.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) menu.addAction(icon, "Decrease font", self.decrease_font) btn.setMenu(menu) @@ -1616,9 +1523,7 @@ def __init__( ) ) icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/zoom-in.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/zoom-in.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) btn.setIcon(icon) btn.setToolTip("Zoom in") hbox.addWidget(btn) @@ -1634,9 +1539,7 @@ def __init__( ) ) icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/zoom-out.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/zoom-out.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) btn.setIcon(icon) btn.setToolTip("Zoom out") hbox.addWidget(btn) @@ -1645,9 +1548,7 @@ def __init__( self.undo_btn = btn = QtWidgets.QPushButton("") btn.clicked.connect(self.undo_zoom) icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/undo.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/undo.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) btn.setIcon(icon) btn.setToolTip("Undo zoom") hbox.addWidget(btn) @@ -1656,9 +1557,7 @@ def __init__( self.redo_btn = btn = QtWidgets.QPushButton("") btn.clicked.connect(self.redo_zoom) icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/redo.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/redo.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) btn.setIcon(icon) btn.setToolTip("Redo zoom") hbox.addWidget(btn) @@ -1668,9 +1567,7 @@ def __init__( btn.setObjectName("lock_btn") btn.clicked.connect(self.set_locked) icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/unlocked.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/unlocked.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) btn.setIcon(icon) btn.setToolTip("The Y axis is unlocked. Press to lock") hbox.addWidget(btn) @@ -1681,22 +1578,16 @@ def __init__( btn.setObjectName("hide_axes_btn") self.hide_axes_btn.clicked.connect(self.hide_axes) icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/axis_on.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/axis_on.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) btn.setIcon(icon) btn.setToolTip("Hide axis") hbox.addWidget(self.hide_axes_btn) self.selected_channel_value_btn = btn = QtWidgets.QPushButton("") btn.setObjectName("selected_channel_value_btn") - self.selected_channel_value_btn.clicked.connect( - self.hide_selected_channel_value - ) + self.selected_channel_value_btn.clicked.connect(self.hide_selected_channel_value) icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/number_on.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/number_on.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) btn.setIcon(icon) btn.setToolTip("Hide axis") hbox.addWidget(self.selected_channel_value_btn) @@ -1705,9 +1596,7 @@ def __init__( btn.setObjectName("focused_mode_btn") self.focused_mode_btn.clicked.connect(self.toggle_focused_mode) icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/focus_on.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/focus_on.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) btn.setIcon(icon) btn.setToolTip("Toggle focused mode") hbox.addWidget(self.focused_mode_btn) @@ -1716,9 +1605,7 @@ def __init__( btn.setObjectName("delta_btn") self.delta_btn.clicked.connect(self.toggle_region_values_display_mode) icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/delta_on.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/delta_on.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) btn.setIcon(icon) btn.setToolTip("Toggle region values display mode") hbox.addWidget(self.delta_btn) @@ -1727,9 +1614,7 @@ def __init__( btn.setObjectName("bookmark_btn") btn.clicked.connect(self.toggle_bookmarks) icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/bookmark_on.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/bookmark_on.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) btn.setIcon(icon) btn.setToolTip("Toggle bookmarks") hbox.addWidget(btn) @@ -1737,9 +1622,7 @@ def __init__( hbox.addStretch() self.selected_channel_value = QtWidgets.QLabel("") - self.selected_channel_value.setAlignment( - QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter - ) + self.selected_channel_value.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) self.selected_channel_value.setAutoFillBackground(True) font = self.selected_channel_value.font() font.setBold(True) @@ -1751,24 +1634,18 @@ def __init__( vbox.addWidget(self.channel_selection) vbox.addWidget(self.cursor_info) - self.range_proxy = pg.SignalProxy( - self.plot.range_modified, rateLimit=16, slot=self.range_modified - ) + self.range_proxy = pg.SignalProxy(self.plot.range_modified, rateLimit=16, slot=self.range_modified) # self.plot.range_modified.connect(self.range_modified) self.plot.range_removed.connect(self.range_removed) self.plot.range_modified_finished.connect(self.range_modified_finished) self.plot.cursor_removed.connect(self.cursor_removed) self.plot.current_uuid_changed.connect(self.current_uuid_changed) - self.cursor_proxy = pg.SignalProxy( - self.plot.cursor_moved, rateLimit=16, slot=self.cursor_moved - ) + self.cursor_proxy = pg.SignalProxy(self.plot.cursor_moved, rateLimit=16, slot=self.cursor_moved) # self.plot.cursor_moved.connect(self.cursor_moved) self.plot.cursor_move_finished.connect(self.cursor_move_finished) self.plot.xrange_changed.connect(self.xrange_changed) - self.plot.computation_channel_inserted.connect( - self.computation_channel_inserted - ) + self.plot.computation_channel_inserted.connect(self.computation_channel_inserted) self.plot.curve_clicked.connect(self.curve_clicked) self._visible_entries = set() self.visible_entries_modified = False @@ -1810,19 +1687,11 @@ def __init__( if signals: unitColumnWidth = max([len(signal.unit) + 10 for signal in signals]) - self.channel_selection.setColumnWidth( - self.channel_selection.NameColumn, nameColumnWidth - ) + self.channel_selection.setColumnWidth(self.channel_selection.NameColumn, nameColumnWidth) self.channel_selection.setColumnWidth(self.channel_selection.ValueColumn, 83) - self.channel_selection.setColumnWidth( - self.channel_selection.UnitColumn, unitColumnWidth - ) - self.channel_selection.setColumnWidth( - self.channel_selection.CommonAxisColumn, 35 - ) - self.channel_selection.setColumnWidth( - self.channel_selection.IndividualAxisColumn, 35 - ) + self.channel_selection.setColumnWidth(self.channel_selection.UnitColumn, unitColumnWidth) + self.channel_selection.setColumnWidth(self.channel_selection.CommonAxisColumn, 35) + self.channel_selection.setColumnWidth(self.channel_selection.IndividualAxisColumn, 35) self.hide() if signals: @@ -1835,12 +1704,8 @@ def __init__( self.channel_selection.itemsDeleted.connect(self.channel_selection_reduced) self.channel_selection.group_activation_changed.connect(self.plot.update) - self.channel_selection.currentItemChanged.connect( - self.channel_selection_row_changed - ) - self.channel_selection.itemSelectionChanged.connect( - self.channel_selection_changed - ) + self.channel_selection.currentItemChanged.connect(self.channel_selection_row_changed) + self.channel_selection.itemSelectionChanged.connect(self.channel_selection_changed) self.channel_selection.add_channels_request.connect(self.add_channels_request) self.channel_selection.set_time_offset.connect(self.plot.set_time_offset) self.channel_selection.show_properties.connect(self._show_properties) @@ -1848,24 +1713,16 @@ def __init__( self.channel_selection.edit_computation.connect(self.plot.edit_computation) self.channel_selection.itemClicked.connect(self.flash_curve) - self.channel_selection.model().dataChanged.connect( - self.channel_selection_item_changed - ) + self.channel_selection.model().dataChanged.connect(self.channel_selection_item_changed) - self.channel_selection.visible_items_changed.connect( - self._update_visibile_entries - ) + self.channel_selection.visible_items_changed.connect(self._update_visibile_entries) self.channel_selection.pattern_group_added.connect(self.pattern_group_added_req) - self.channel_selection.double_click.connect( - self.channel_selection_item_double_clicked - ) + self.channel_selection.double_click.connect(self.channel_selection_item_double_clicked) self.channel_selection.compute_fft_request.connect(self.compute_fft) self.channel_selection.itemExpanded.connect(self.update_current_values) - self.channel_selection.verticalScrollBar().valueChanged.connect( - self.update_current_values - ) + self.channel_selection.verticalScrollBar().valueChanged.connect(self.update_current_values) self.keyboard_events = ( set( @@ -1934,20 +1791,12 @@ def __init__( self.splitter.splitterMoved.connect(self.set_splitter) self.hide_selected_channel_value( - hide=self._settings.value( - "plot_hide_selected_channel_value", False, type=bool - ) - ) - self.toggle_focused_mode( - focused=self._settings.value("plot_focused_mode", False, type=bool) - ) - self.toggle_region_values_display_mode( - mode=self._settings.value("plot_region_values_display_mode", "value") + hide=self._settings.value("plot_hide_selected_channel_value", False, type=bool) ) + self.toggle_focused_mode(focused=self._settings.value("plot_focused_mode", False, type=bool)) + self.toggle_region_values_display_mode(mode=self._settings.value("plot_region_values_display_mode", "value")) - self.toggle_bookmarks( - hide=not self._settings.value("plot_bookmarks", False, type=bool) - ) + self.toggle_bookmarks(hide=not self._settings.value("plot_bookmarks", False, type=bool)) self.hide_axes(hide=self._settings.value("plot_hide_axes", False, type=bool)) self.set_locked(locked=self._settings.value("plot_locked", False, type=bool)) @@ -1973,9 +1822,7 @@ def add_new_items(tree, root, items, items_pool): ranges = copy_ranges(info["ranges"]) for range_info in ranges: range_info["font_color"] = fn.mkColor(range_info["font_color"]) - range_info["background_color"] = fn.mkColor( - range_info["background_color"] - ) + range_info["background_color"] = fn.mkColor(range_info["background_color"]) if info.get("type", "channel") == "group": item = ChannelsTreeItem( @@ -1988,9 +1835,7 @@ def add_new_items(tree, root, items, items_pool): children.append(item) item.set_ranges(ranges) - groups.extend( - add_new_items(tree, item, info["channels"], items_pool) - ) + groups.extend(add_new_items(tree, item, info["channels"], items_pool)) groups.append((item, info)) else: @@ -2027,9 +1872,7 @@ def add_new_items(tree, root, items, items_pool): invalid_indexes = invalid_indexes[:10] + 1 idx = invalid_indexes[0] ts = channel.timestamps[idx - 1 : idx + 2] - invalid.append( - f"{channel.name} @ index {invalid_indexes[:10] - 1} with first time stamp error: {ts}" - ) + invalid.append(f"{channel.name} @ index {invalid_indexes[:10] - 1} with first time stamp error: {ts}") if len(np.argwhere(diff < 0).ravel()): can_trim = False @@ -2174,17 +2017,13 @@ def add_new_items(tree, root, items, items_pool): if item.pattern: item.setCheckState( item.NameColumn, - QtCore.Qt.Checked - if info["enabled"] - else QtCore.Qt.Unchecked, + QtCore.Qt.Checked if info["enabled"] else QtCore.Qt.Unchecked, ) else: if not item.childCount(): item.setCheckState( item.NameColumn, - QtCore.Qt.Checked - if info["enabled"] - else QtCore.Qt.Unchecked, + QtCore.Qt.Checked if info["enabled"] else QtCore.Qt.Unchecked, ) if "disabled" in info and info["disabled"]: item.set_disabled(info["disabled"]) @@ -2205,10 +2044,7 @@ def add_new_items(tree, root, items, items_pool): if destination.type() == ChannelsTreeItem.Group: destination.addChildren(children) else: - parent = ( - destination.parent() - or self.channel_selection.invisibleRootItem() - ) + parent = destination.parent() or self.channel_selection.invisibleRootItem() index = parent.indexOfChild(destination) parent.insertChildren(index, children) @@ -2252,17 +2088,10 @@ def adjust_splitter(self, initial=False): size = sum(self.splitter.sizes()) if Plot.dynamic_columns_width or initial: - self.channel_selection.resizeColumnToContents( - self.channel_selection.NameColumn - ) - self.channel_selection.resizeColumnToContents( - self.channel_selection.UnitColumn - ) + self.channel_selection.resizeColumnToContents(self.channel_selection.NameColumn) + self.channel_selection.resizeColumnToContents(self.channel_selection.UnitColumn) - width = sum( - self.channel_selection.columnWidth(col) - for col in range(self.channel_selection.columnCount()) - ) + width = sum(self.channel_selection.columnWidth(col) for col in range(self.channel_selection.columnCount())) if width > self.splitter.sizes()[0]: if size - width >= 300: @@ -2325,9 +2154,7 @@ def channel_item_to_config(self, item): else: channel["individual_axis"] = False - channel["common_axis"] = ( - item.checkState(item.CommonAxisColumn) == QtCore.Qt.Checked - ) + channel["common_axis"] = item.checkState(item.CommonAxisColumn) == QtCore.Qt.Checked channel["color"] = sig.color.name() channel["computed"] = bool(sig.flags & Signal.Flags.computed) channel["ranges"] = copy_ranges(widget.ranges) @@ -2455,10 +2282,7 @@ def channel_selection_item_double_clicked(self, item, button): item.setCheckState(item.NameColumn, QtCore.Qt.Checked) elif item.type() == item.Group: if ( - ( - Plot.item_double_click_handling == "enable/disable" - and button == QtCore.Qt.MouseButton.LeftButton - ) + (Plot.item_double_click_handling == "enable/disable" and button == QtCore.Qt.MouseButton.LeftButton) or Plot.item_double_click_handling == "expand/collapse" and button == QtCore.Qt.MouseButton.RightButton ): @@ -2507,13 +2331,9 @@ def channel_selection_row_changed(self, current, previous): self.flash_curve(current, 0) def clear(self): - event = QtGui.QKeyEvent( - QtCore.QEvent.KeyPress, QtCore.Qt.Key_A, QtCore.Qt.ControlModifier - ) + event = QtGui.QKeyEvent(QtCore.QEvent.KeyPress, QtCore.Qt.Key_A, QtCore.Qt.ControlModifier) self.channel_selection.keyPressEvent(event) - event = QtGui.QKeyEvent( - QtCore.QEvent.KeyPress, QtCore.Qt.Key_Delete, QtCore.Qt.NoModifier - ) + event = QtGui.QKeyEvent(QtCore.QEvent.KeyPress, QtCore.Qt.Key_Delete, QtCore.Qt.NoModifier) self.channel_selection.keyPressEvent(event) def close(self): @@ -2649,9 +2469,7 @@ def cursor_moved(self, cursor=None): self.selected_channel_value.width() - 10, ) - self.selected_channel_value.setText( - elided - ) # (f"{value} {unit}") + self.selected_channel_value.setText(elided) # (f"{value} {unit}") if self.info.isVisible(): stats = self.plot.get_stats(self.info_uuid) @@ -2774,15 +2592,11 @@ def hide_selected_channel_value(self, event=None, hide=None): if hide: self.selected_channel_value.hide() self.selected_channel_value_btn.setFlat(True) - self.selected_channel_value_btn.setToolTip( - "Show selected channel value panel" - ) + self.selected_channel_value_btn.setToolTip("Show selected channel value panel") else: self.selected_channel_value.show() self.selected_channel_value_btn.setFlat(False) - self.selected_channel_value_btn.setToolTip( - "Hide selected channel value panel" - ) + self.selected_channel_value_btn.setToolTip("Hide selected channel value panel") if hide: png = ":/number.png" @@ -2851,8 +2665,7 @@ def keyPressEvent(self, event): and modifiers == QtCore.Qt.ControlModifier ): selected_items = self.channel_selection.selectedItems() or [ - self.channel_selection.topLevelItem(i) - for i in range(self.channel_selection.topLevelItemCount()) + self.channel_selection.topLevelItem(i) for i in range(self.channel_selection.topLevelItemCount()) ] if key == QtCore.Qt.Key_B: @@ -2907,22 +2720,14 @@ def keyPressEvent(self, event): self.current_uuid_changed(self.plot.current_uuid) self.plot.update() - elif ( - key in (QtCore.Qt.Key_R, QtCore.Qt.Key_S) - and modifiers == QtCore.Qt.AltModifier - and self._can_switch_mode - ): + elif key in (QtCore.Qt.Key_R, QtCore.Qt.Key_S) and modifiers == QtCore.Qt.AltModifier and self._can_switch_mode: selected_items = self.channel_selection.selectedItems() if not selected_items: signals = [(sig, i) for i, sig in enumerate(self.plot.signals)] uuids = [sig.uuid for sig in self.plot.signals] else: - uuids = [ - item.uuid - for item in selected_items - if item.type() == ChannelsTreeItem.Channel - ] + uuids = [item.uuid for item in selected_items if item.type() == ChannelsTreeItem.Channel] signals = [self.plot.signal_by_uuid(uuid) for uuid in uuids] @@ -2975,9 +2780,7 @@ def keyPressEvent(self, event): self.plot.y_axis.mode = mode self.plot.y_axis.picture = None self.plot.y_axis.update() - self.plot.viewbox.setYRange( - buttom, top, padding=0, update=True - ) + self.plot.viewbox.setYRange(buttom, top, padding=0, update=True) self.plot.get_axis(idx).mode = mode self.plot.get_axis(idx).picture = None @@ -3038,9 +2841,7 @@ def keyPressEvent(self, event): elif key == QtCore.Qt.Key_G and modifiers == QtCore.Qt.ControlModifier: selected_items = [ - item - for item in self.channel_selection.selectedItems() - if item.type() == ChannelsTreeItem.Channel + item for item in self.channel_selection.selectedItems() if item.type() == ChannelsTreeItem.Channel ] if selected_items: @@ -3097,11 +2898,7 @@ def keyPressEvent(self, event): ): self.channel_selection.keyPressEvent(event) - elif ( - key == QtCore.Qt.Key_R - and modifiers == QtCore.Qt.ControlModifier - and self.can_edit_ranges - ): + elif key == QtCore.Qt.Key_R and modifiers == QtCore.Qt.ControlModifier and self.can_edit_ranges: self.channel_selection.keyPressEvent(event) elif key == QtCore.Qt.Key_V and modifiers in ( @@ -3110,14 +2907,10 @@ def keyPressEvent(self, event): ): self.channel_selection.keyPressEvent(event) - elif ( - key == QtCore.Qt.Key_BracketLeft and modifiers == QtCore.Qt.ControlModifier - ): + elif key == QtCore.Qt.Key_BracketLeft and modifiers == QtCore.Qt.ControlModifier: self.decrease_font() - elif ( - key == QtCore.Qt.Key_BracketRight and modifiers == QtCore.Qt.ControlModifier - ): + elif key == QtCore.Qt.Key_BracketRight and modifiers == QtCore.Qt.ControlModifier: self.increase_font() elif event.keyCombination().toCombined() in self.plot.keyboard_events: @@ -3321,9 +3114,7 @@ def range_removed(self): def redo_zoom(self): if self.enable_zoom_history and self.zoom_history: - self.zoom_history_index = min( - self.zoom_history_index + 1, len(self.zoom_history) - 1 - ) + self.zoom_history_index = min(self.zoom_history_index + 1, len(self.zoom_history) - 1) snapshot = self.zoom_history[self.zoom_history_index] @@ -3381,9 +3172,7 @@ def set_locked(self, event=None, locked=None): self.lock_btn.setToolTip(tooltip) self.lock_btn.setIcon(icon) - self.channel_selection.setColumnHidden( - self.channel_selection.CommonAxisColumn, locked - ) + self.channel_selection.setColumnHidden(self.channel_selection.CommonAxisColumn, locked) self.locked = locked self.plot.set_locked(locked) @@ -3436,9 +3225,7 @@ def item_to_config(tree, root): for range_info in ranges: range_info["font_color"] = range_info["font_color"].name() - range_info["background_color"] = range_info[ - "background_color" - ].name() + range_info["background_color"] = range_info["background_color"].name() pattern["ranges"] = ranges @@ -3446,14 +3233,10 @@ def item_to_config(tree, root): for range_info in ranges: range_info["font_color"] = range_info["font_color"].name() - range_info["background_color"] = range_info[ - "background_color" - ].name() + range_info["background_color"] = range_info["background_color"].name() channel = self.channel_group_item_to_config(item) - channel["channels"] = ( - item_to_config(tree, item) if item.pattern is None else [] - ) + channel["channels"] = item_to_config(tree, item) if item.pattern is None else [] channels.append(channel) @@ -3470,9 +3253,7 @@ def item_to_config(tree, root): pattern["ranges"] = ranges config = { - "channels": item_to_config( - self.channel_selection, self.channel_selection.invisibleRootItem() - ) + "channels": item_to_config(self.channel_selection, self.channel_selection.invisibleRootItem()) if not self.pattern else [], "pattern": pattern, @@ -3530,9 +3311,7 @@ def toggle_focused_mode(self, event=None, focused=None): # invert so that the key press event will set the desider focused mode self.focused_mode = not focused - key_event = QtGui.QKeyEvent( - QtCore.QEvent.KeyPress, QtCore.Qt.Key_2, QtCore.Qt.NoModifier - ) + key_event = QtGui.QKeyEvent(QtCore.QEvent.KeyPress, QtCore.Qt.Key_2, QtCore.Qt.NoModifier) self.keyPressEvent(key_event) if focused is None: @@ -3555,9 +3334,7 @@ def toggle_focused_mode(self, event=None, focused=None): def toggle_region_values_display_mode(self, event=None, mode=None): if mode is None: - self.region_values_display_mode = ( - "delta" if self.region_values_display_mode == "value" else "value" - ) + self.region_values_display_mode = "delta" if self.region_values_display_mode == "value" else "value" else: self.region_values_display_mode = mode @@ -3566,9 +3343,7 @@ def toggle_region_values_display_mode(self, event=None, mode=None): self.delta_btn.setToolTip("Switch to region cursors delta display mode") else: self.delta_btn.setFlat(False) - self.delta_btn.setToolTip( - "Switch to active region cursor value display mode" - ) + self.delta_btn.setToolTip("Switch to active region cursor value display mode") if self.delta_btn.isFlat(): png = ":/delta.png" @@ -3579,9 +3354,7 @@ def toggle_region_values_display_mode(self, event=None, mode=None): self.delta_btn.setIcon(icon) if mode is None: - self._settings.setValue( - "plot_region_values_display_mode", self.region_values_display_mode - ) + self._settings.setValue("plot_region_values_display_mode", self.region_values_display_mode) self.range_modified() @@ -3644,10 +3417,7 @@ def _update_visibile_entries(self): if ( item.uuid == self.info_uuid or item.exists - and ( - item.checkState(item.NameColumn) == QtCore.Qt.Checked - or item._is_visible - ) + and (item.checkState(item.NameColumn) == QtCore.Qt.Checked or item._is_visible) ): entry = (item.origin_uuid, item.signal.name, item.uuid) _visible_entries.add(entry) @@ -3670,11 +3440,7 @@ def xrange_changed(self, *args): self.info.set_stats(stats) def zoom_changed(self, inplace=False): - if ( - self.enable_zoom_history - and self.plot.signals - and not self.plot.block_zoom_signal - ): + if self.enable_zoom_history and self.plot.signals and not self.plot.block_zoom_signal: snapshot = { "x": self.plot.viewbox.viewRange()[0], "y": {sig.uuid: sig.y_range for sig in self.plot.signals}, @@ -3687,10 +3453,7 @@ def zoom_changed(self, inplace=False): else: self.zoom_history[self.zoom_history_index] = snapshot else: - if ( - not self.zoom_history - or self.zoom_history[self.zoom_history_index] != snapshot - ): + if not self.zoom_history or self.zoom_history[self.zoom_history_index] != snapshot: self.zoom_history = self.zoom_history[: self.zoom_history_index + 1] self.zoom_history.append(snapshot) @@ -3762,9 +3525,7 @@ def __init__( self.cursor_unit = "s" if x_axis == "time" else "Hz" - self.line_interconnect = ( - line_interconnect if line_interconnect != "line" else "" - ) + self.line_interconnect = line_interconnect if line_interconnect != "line" else "" self._can_trim = True self._can_paint = True @@ -3849,17 +3610,13 @@ def __init__( else: color = "black" - self.cursor1 = Cursor( - pos=pos, angle=90, movable=True, pen=color, hoverPen=color - ) + self.cursor1 = Cursor(pos=pos, angle=90, movable=True, pen=color, hoverPen=color) self.viewbox.cursor = self.cursor1 self.viewbox.addItem(self.cursor1, ignoreBounds=True) self.cursor1.sigPositionChanged.connect(self.cursor_moved.emit) - self.cursor1.sigPositionChangeFinished.connect( - self.cursor_move_finished.emit - ) + self.cursor1.sigPositionChangeFinished.connect(self.cursor_move_finished.emit) self.cursor_move_finished.emit(self.cursor1) self.cursor1.show() else: @@ -3868,9 +3625,7 @@ def __init__( self.viewbox.sigYRangeChanged.connect(self.y_changed) self.viewbox.sigRangeChangedManually.connect(self.y_changed) - self.x_axis = FormatedAxis( - "bottom", maxTickLength=5, background=self.backgroundBrush().color() - ) + self.x_axis = FormatedAxis("bottom", maxTickLength=5, background=self.backgroundBrush().color()) if x_axis == "time": fmt = self._settings.value("plot_xaxis") @@ -3881,9 +3636,7 @@ def __init__( self.x_axis.format = fmt self.x_axis.origin = origin - self.y_axis = FormatedAxis( - "left", maxTickLength=-5, background=self.backgroundBrush().color() - ) + self.y_axis = FormatedAxis("left", maxTickLength=-5, background=self.backgroundBrush().color()) self.y_axis.setWidth(48) self.y_axis.scale_editor_requested.connect(self.open_scale_editor) @@ -4157,9 +3910,7 @@ def add_new_channels(self, channels, descriptions=None): if self.initial_x_range == "adjust": self.viewbox.setXRange(start_t, stop_t, update=False) else: - delta = ( - self.viewbox.viewRange()[0][1] - self.viewbox.viewRange()[0][0] - ) + delta = self.viewbox.viewRange()[0][1] - self.viewbox.viewRange()[0][0] stop_t = start_t + delta self.viewbox.setXRange(start_t, stop_t, padding=0, update=False) @@ -4169,8 +3920,7 @@ def add_new_channels(self, channels, descriptions=None): trim_info = start, stop, width channels = [ - PlotSignal(sig, i, trim_info=trim_info) - for i, sig in enumerate(channels.values(), len(self.signals)) + PlotSignal(sig, i, trim_info=trim_info) for i, sig in enumerate(channels.values(), len(self.signals)) ] self.signals.extend(channels) @@ -4276,9 +4026,7 @@ def _clicked(self, event): break else: if ( - QtCore.QKeyCombination( - QtCore.Qt.Key_C, QtCore.Qt.ControlModifier - ).toCombined() + QtCore.QKeyCombination(QtCore.Qt.Key_C, QtCore.Qt.ControlModifier).toCombined() not in self.disabled_keys ): if self.region is not None: @@ -4313,11 +4061,7 @@ def _compute_all_timebase(self): if self._timebase_db: stamps = {id(sig.timestamps): sig.timestamps for sig in self.signals} - timebases = [ - timestamps - for id_, timestamps in stamps.items() - if id_ in self._timebase_db - ] + timebases = [timestamps for id_, timestamps in stamps.items() if id_ in self._timebase_db] count = len(timebases) @@ -4360,10 +4104,7 @@ def _cursor_zoom_finished(self, zoom=None): self.block_zoom_signal = True - if ( - zoom_mode in (self.viewbox.Y_zoom, *self.viewbox.XY_zoom) - and not self.locked - ): + if zoom_mode in (self.viewbox.Y_zoom, *self.viewbox.XY_zoom) and not self.locked: y1, y2 = sorted([p1.y(), p2.y()]) y_bottom, y_top = self.viewbox.viewRange()[1] r_top = (y2 - y_bottom) / (y_top - y_bottom) @@ -4568,9 +4309,7 @@ def get_stats(self, uuid): cursor=self.cursor1.value() if self.cursor1 else None, region=self.region.getRegion() if self.region else None, view_region=self.viewbox.viewRange()[0], - precision=self._settings.value( - "stats_float_precision", sig.precision, type=int - ), + precision=self._settings.value("stats_float_precision", sig.precision, type=int), ) def get_timestamp_index(self, timestamp, timestamps): @@ -4630,9 +4369,7 @@ def keyPressEvent(self, event): handled = True if key == QtCore.Qt.Key_Y and modifier == QtCore.Qt.NoModifier: if self.region is None: - event_ = QtGui.QKeyEvent( - QtCore.QEvent.KeyPress, QtCore.Qt.Key_R, QtCore.Qt.NoModifier - ) + event_ = QtGui.QKeyEvent(QtCore.QEvent.KeyPress, QtCore.Qt.Key_R, QtCore.Qt.NoModifier) self.keyPressEvent(event_) if self.region_lock is not None: @@ -4651,16 +4388,10 @@ def keyPressEvent(self, event): elif key == QtCore.Qt.Key_X and modifier == QtCore.Qt.NoModifier: if self.region is not None: self.viewbox.setXRange(*self.region.getRegion(), padding=0) - event_ = QtGui.QKeyEvent( - QtCore.QEvent.KeyPress, QtCore.Qt.Key_R, QtCore.Qt.NoModifier - ) + event_ = QtGui.QKeyEvent(QtCore.QEvent.KeyPress, QtCore.Qt.Key_R, QtCore.Qt.NoModifier) self.keyPressEvent(event_) - elif ( - key == QtCore.Qt.Key_F - and modifier == QtCore.Qt.NoModifier - and not self.locked - ): + elif key == QtCore.Qt.Key_F and modifier == QtCore.Qt.NoModifier and not self.locked: self.block_zoom_signal = True if self.common_axis_items: if any( @@ -4691,9 +4422,7 @@ def keyPressEvent(self, event): min_ = common_min max_ = common_max else: - samples = signal.plot_samples[ - np.isfinite(signal.plot_samples) - ] + samples = signal.plot_samples[np.isfinite(signal.plot_samples)] if len(samples): min_, max_ = ( np.nanmin(samples), @@ -4716,11 +4445,7 @@ def keyPressEvent(self, event): self.zoom_changed.emit(False) self.update() - elif ( - key == QtCore.Qt.Key_F - and modifier == QtCore.Qt.ShiftModifier - and not self.locked - ): + elif key == QtCore.Qt.Key_F and modifier == QtCore.Qt.ShiftModifier and not self.locked: self.block_zoom_signal = True parent = self.parent().parent() uuids = [ @@ -4787,10 +4512,7 @@ def keyPressEvent(self, event): self.cursor1.setPos(value) self.cursor_move_finished.emit(self.cursor1) - elif ( - key in (QtCore.Qt.Key_I, QtCore.Qt.Key_O) - and modifier == QtCore.Qt.NoModifier - ): + elif key in (QtCore.Qt.Key_I, QtCore.Qt.Key_O) and modifier == QtCore.Qt.NoModifier: x_range, _ = self.viewbox.viewRange() delta = x_range[1] - x_range[0] if key == QtCore.Qt.Key_I: @@ -4803,11 +4525,7 @@ def keyPressEvent(self, event): self.viewbox.setXRange(x_range[0] - step, x_range[1] + step, padding=0) - elif ( - key in (QtCore.Qt.Key_I, QtCore.Qt.Key_O) - and modifier == QtCore.Qt.ShiftModifier - and not self.locked - ): + elif key in (QtCore.Qt.Key_I, QtCore.Qt.Key_O) and modifier == QtCore.Qt.ShiftModifier and not self.locked: if key == QtCore.Qt.Key_I: factor = 0.25 else: @@ -4848,9 +4566,7 @@ def keyPressEvent(self, event): self.viewbox.addItem(self.region) self.region.sigRegionChanged.connect(self.range_modified.emit) self.region.sigRegionChanged.connect(self.range_modified_handler) - self.region.sigRegionChangeFinished.connect( - self.range_modified_finished_handler - ) + self.region.sigRegionChangeFinished.connect(self.range_modified_finished_handler) start, stop = self.viewbox.viewRange()[0] start, stop = ( start + 0.1 * (stop - start), @@ -4860,9 +4576,7 @@ def keyPressEvent(self, event): if self.cursor1 is not None: self.cursor1.hide() - self.region.setRegion( - tuple(sorted((self.cursor1.value(), stop))) - ) + self.region.setRegion(tuple(sorted((self.cursor1.value(), stop)))) else: self.region_lock = None @@ -4911,9 +4625,7 @@ def keyPressEvent(self, event): tmpf = Path(gettempdir()) / f"{perf_counter()}.mf4" mdf.save(tmpf, overwrite=True, compression=2) - zipped_mf4 = ZipFile( - file_name, "w", compression=ZIP_DEFLATED - ) + zipped_mf4 = ZipFile(file_name, "w", compression=ZIP_DEFLATED) zipped_mf4.write( str(tmpf), file_name.with_suffix(".mf4").name, @@ -4925,11 +4637,7 @@ def keyPressEvent(self, event): else: mdf.save(file_name, overwrite=True, compression=2) - elif ( - key == QtCore.Qt.Key_S - and modifier == QtCore.Qt.NoModifier - and not self.locked - ): + elif key == QtCore.Qt.Key_S and modifier == QtCore.Qt.NoModifier and not self.locked: self.block_zoom_signal = True parent = self.parent().parent() uuids = [] @@ -4950,33 +4658,24 @@ def keyPressEvent(self, event): count = sum( 1 for sig in self.signals - if sig.min != "n.a." - and sig.enable - and sig.uuid not in self.common_axis_items + if sig.min != "n.a." and sig.enable and sig.uuid not in self.common_axis_items ) - if any( - sig.min != "n.a." - and sig.enable - and sig.uuid in self.common_axis_items - for sig in self.signals - ): + if any(sig.min != "n.a." and sig.enable and sig.uuid in self.common_axis_items for sig in self.signals): count += 1 common_min_ = np.nanmin( [ np.nanmin(self.signal_by_uuid(uuid)[0].plot_samples) for uuid in self.common_axis_items - if len(self.signal_by_uuid(uuid)[0].plot_samples) - and self.signal_by_uuid(uuid)[0].enable + if len(self.signal_by_uuid(uuid)[0].plot_samples) and self.signal_by_uuid(uuid)[0].enable ] ) common_max_ = np.nanmax( [ np.nanmax(self.signal_by_uuid(uuid)[0].plot_samples) for uuid in self.common_axis_items - if len(self.signal_by_uuid(uuid)[0].plot_samples) - and self.signal_by_uuid(uuid)[0].enable + if len(self.signal_by_uuid(uuid)[0].plot_samples) and self.signal_by_uuid(uuid)[0].enable ] ) @@ -5047,11 +4746,7 @@ def keyPressEvent(self, event): self.update() - elif ( - key == QtCore.Qt.Key_S - and modifier == QtCore.Qt.ShiftModifier - and not self.locked - ): + elif key == QtCore.Qt.Key_S and modifier == QtCore.Qt.ShiftModifier and not self.locked: self.block_zoom_signal = True parent = self.parent().parent() uuids = [ @@ -5084,27 +4779,19 @@ def keyPressEvent(self, event): min_ = np.nanmin( [ - np.nanmin( - self.signal_by_uuid(uuid)[0].plot_samples - ) + np.nanmin(self.signal_by_uuid(uuid)[0].plot_samples) for uuid in self.common_axis_items if uuid in uuids_set - and len( - self.signal_by_uuid(uuid)[0].plot_samples - ) + and len(self.signal_by_uuid(uuid)[0].plot_samples) and self.signal_by_uuid(uuid)[0].enable ] ) max_ = np.nanmax( [ - np.nanmax( - self.signal_by_uuid(uuid)[0].plot_samples - ) + np.nanmax(self.signal_by_uuid(uuid)[0].plot_samples) for uuid in self.common_axis_items if uuid in uuids_set - and len( - self.signal_by_uuid(uuid)[0].plot_samples - ) + and len(self.signal_by_uuid(uuid)[0].plot_samples) and self.signal_by_uuid(uuid)[0].enable ] ) @@ -5193,14 +4880,10 @@ def keyPressEvent(self, event): if pos >= right_side: delta = abs(pos - prev_pos) - self.viewbox.setXRange( - left_side + delta, right_side + delta, padding=0 - ) + self.viewbox.setXRange(left_side + delta, right_side + delta, padding=0) elif pos <= left_side: delta = abs(pos - prev_pos) - self.viewbox.setXRange( - left_side - delta, right_side - delta, padding=0 - ) + self.viewbox.setXRange(left_side - delta, right_side - delta, padding=0) self.cursor1.set_value(pos) @@ -5249,10 +4932,7 @@ def keyPressEvent(self, event): else: self.region.setRegion(tuple(sorted((second_pos, pos)))) - elif ( - key in (QtCore.Qt.Key_Left, QtCore.Qt.Key_Right) - and modifier == QtCore.Qt.ShiftModifier - ): + elif key in (QtCore.Qt.Key_Left, QtCore.Qt.Key_Right) and modifier == QtCore.Qt.ShiftModifier: parent = self.parent().parent() uuids = list( set( @@ -5296,9 +4976,7 @@ def keyPressEvent(self, event): if not uuids: return - factor = ( - 10 if key in (QtCore.Qt.Key_PageUp, QtCore.Qt.Key_PageDown) else 100 - ) + factor = 10 if key in (QtCore.Qt.Key_PageUp, QtCore.Qt.Key_PageDown) else 100 for uuid in uuids: signal, index = self.signal_by_uuid(uuid) @@ -5457,9 +5135,7 @@ def paintEvent(self, ev): x = sig.plot_timestamps if len(x): - x, y = self.scale_curve_to_pixmap( - x, y, y_range=sig.y_range, x_start=x_start, delta=delta - ) + x, y = self.scale_curve_to_pixmap(x, y, y_range=sig.y_range, x_start=x_start, delta=delta) sig.pen.setWidth(pen_width) @@ -5545,9 +5221,7 @@ def paintEvent(self, ev): y[~idx] = np.inf x = sig.plot_timestamps - x, y = self.scale_curve_to_pixmap( - x, y, y_range=sig.y_range, x_start=x_start, delta=delta - ) + x, y = self.scale_curve_to_pixmap(x, y, y_range=sig.y_range, x_start=x_start, delta=delta) color = range_info["font_color"] pen = fn.mkPen(color.name()) @@ -5557,9 +5231,7 @@ def paintEvent(self, ev): paint.drawPath(self.generatePath(x, y)) if with_dots: - paint.setRenderHints( - paint.RenderHint.Antialiasing, True - ) + paint.setRenderHints(paint.RenderHint.Antialiasing, True) pen.setWidth(dots_with) pen.setCapStyle(cap_style) paint.setPen(pen) @@ -5573,9 +5245,7 @@ def paintEvent(self, ev): arr[:, 0] = x arr[:, 1] = y paint.drawPoints(poly) - paint.setRenderHints( - paint.RenderHint.Antialiasing, False - ) + paint.setRenderHints(paint.RenderHint.Antialiasing, False) paint.end() paint = QtGui.QPainter() @@ -5652,11 +5322,7 @@ def paintEvent(self, ev): rect = None - if ( - zoom_mode == self.viewbox.X_zoom - or zoom_mode in self.viewbox.XY_zoom - and self.locked - ): + if zoom_mode == self.viewbox.X_zoom or zoom_mode in self.viewbox.XY_zoom and self.locked: x1, x2 = sorted([x1, x2]) rect = QtCore.QRectF( x1, @@ -5763,9 +5429,7 @@ def select_curve(self, x, y): if val == "n.a.": continue - x_val, y_val = self.scale_curve_to_pixmap( - x, val, y_range=sig.y_range, x_start=x_start, delta=delta - ) + x_val, y_val = self.scale_curve_to_pixmap(x, val, y_range=sig.y_range, x_start=x_start, delta=delta) candidates.append((abs(y_val - y), sig.uuid)) @@ -5805,9 +5469,7 @@ def set_common_axis(self, uuid, state): else: self.common_axis_items.remove(uuid) - self.common_axis_label = ", ".join( - self.signal_by_uuid(uuid)[0].name for uuid in self.common_axis_items - ) + self.common_axis_label = ", ".join(self.signal_by_uuid(uuid)[0].name for uuid in self.common_axis_items) self.set_current_uuid(self.current_uuid, True) self.update() @@ -6077,9 +5739,7 @@ def signal_by_name(self, name): if sig.name == name: return sig, i - raise Exception( - f"Signal not found: {name} {[sig.name for sig in self.signals]}" - ) + raise Exception(f"Signal not found: {name} {[sig.name for sig in self.signals]}") def signal_by_uuid(self, uuid): return self._uuid_map[uuid] @@ -6171,9 +5831,7 @@ def __init__(self, precision, name="t", unit="s", plot=None, *args, **kwargs): self.plot = plot self.setTextFormat(QtCore.Qt.RichText) - self.setAlignment( - QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter - ) + self.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter) self.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) self.customContextMenuRequested.connect(self.open_menu) @@ -6181,9 +5839,7 @@ def __init__(self, precision, name="t", unit="s", plot=None, *args, **kwargs): if precision == -1: self.setToolTip(f"Cursor information uses maximum precision") else: - self.setToolTip( - f"Cursor information precision is set to {self.precision} decimals" - ) + self.setToolTip(f"Cursor information precision is set to {self.precision} decimals") def open_menu(self, point): menu = QtWidgets.QMenu(self) @@ -6218,9 +5874,7 @@ def update_value(self): elif fmt == "time": cursor_info_text = f"{self.name} = {timedelta(seconds=position)}" elif fmt == "date": - position_date = self.plot.x_axis.origin + timedelta( - seconds=position - ) + position_date = self.plot.x_axis.origin + timedelta(seconds=position) cursor_info_text = f"{self.name} = {position_date}" if cursor_info_text: @@ -6265,9 +5919,7 @@ def set_precision(self, precision): if precision == -1: self.setToolTip(f"Cursor information uses maximum precision") else: - self.setToolTip( - f"Cursor information precision is set to {precision} decimals" - ) + self.setToolTip(f"Cursor information precision is set to {precision} decimals") self.update_value() diff --git a/src/asammdf/gui/widgets/plot_standalone.py b/src/asammdf/gui/widgets/plot_standalone.py index 91bcde3ff..e17134202 100644 --- a/src/asammdf/gui/widgets/plot_standalone.py +++ b/src/asammdf/gui/widgets/plot_standalone.py @@ -120,27 +120,21 @@ def __init__(self, signals, *args, **kwargs): plot_actions.addAction(action) icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/list2.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/list2.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) action = QtGui.QAction(icon, "{: <20}\tS".format("Stack"), menu) action.triggered.connect(partial(self.plot_action, key=QtCore.Qt.Key_S)) action.setShortcut(QtCore.Qt.Key_S) plot_actions.addAction(action) icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/zoom-in.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/zoom-in.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) action = QtGui.QAction(icon, "{: <20}\tI".format("Zoom in"), menu) action.triggered.connect(partial(self.plot_action, key=QtCore.Qt.Key_I)) action.setShortcut(QtCore.Qt.Key_I) plot_actions.addAction(action) icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/zoom-out.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/zoom-out.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) action = QtGui.QAction(icon, "{: <20}\tO".format("Zoom out"), menu) action.triggered.connect(partial(self.plot_action, key=QtCore.Qt.Key_O)) action.setShortcut(QtCore.Qt.Key_O) @@ -160,9 +154,7 @@ def __init__(self, signals, *args, **kwargs): icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap(":/save.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) - action = QtGui.QAction( - icon, "{: <20}\tCtrl+S".format("Save active subplot channels"), menu - ) + action = QtGui.QAction(icon, "{: <20}\tCtrl+S".format("Save active subplot channels"), menu) action.triggered.connect( partial( self.plot_action, @@ -215,20 +207,12 @@ def __init__(self, signals, *args, **kwargs): samples_format_actions = QtGui.QActionGroup(self) action = QtGui.QAction("{: <20}\tAlt+R".format("Raw samples"), menu) - action.triggered.connect( - partial( - self.plot_action, key=QtCore.Qt.Key_R, modifier=QtCore.Qt.AltModifier - ) - ) + action.triggered.connect(partial(self.plot_action, key=QtCore.Qt.Key_R, modifier=QtCore.Qt.AltModifier)) action.setShortcut(QtGui.QKeySequence("Alt+R")) samples_format_actions.addAction(action) action = QtGui.QAction("{: <20}\tAlt+S".format("Scaled samples"), menu) - action.triggered.connect( - partial( - self.plot_action, key=QtCore.Qt.Key_S, modifier=QtCore.Qt.AltModifier - ) - ) + action.triggered.connect(partial(self.plot_action, key=QtCore.Qt.Key_S, modifier=QtCore.Qt.AltModifier)) action.setShortcut(QtGui.QKeySequence("Alt+S")) samples_format_actions.addAction(action) @@ -247,18 +231,14 @@ def __init__(self, signals, *args, **kwargs): cursors_actions = QtGui.QActionGroup(self) icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/cursor.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/cursor.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) action = QtGui.QAction(icon, "{: <20}\tC".format("Cursor"), menu) action.triggered.connect(partial(self.plot_action, key=QtCore.Qt.Key_C)) action.setShortcut(QtCore.Qt.Key_C) cursors_actions.addAction(action) icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/right.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/right.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) action = QtGui.QAction(icon, "{: <20}\t←".format("Move cursor left"), menu) action.triggered.connect(partial(self.plot_action, key=QtCore.Qt.Key_Left)) action.setShortcut(QtCore.Qt.Key_Left) @@ -272,30 +252,22 @@ def __init__(self, signals, *args, **kwargs): cursors_actions.addAction(action) icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/range.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/range.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) action = QtGui.QAction(icon, "{: <20}\tR".format("Range"), menu) action.triggered.connect(partial(self.plot_action, key=QtCore.Qt.Key_R)) action.setShortcut(QtCore.Qt.Key_R) cursors_actions.addAction(action) icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/lock_range.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/lock_range.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) action = QtGui.QAction(icon, "{: <20}\tY".format("Lock/unlock range"), menu) action.triggered.connect(partial(self.plot_action, key=QtCore.Qt.Key_Y)) action.setShortcut(QtCore.Qt.Key_Y) cursors_actions.addAction(action) icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/comments.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) - action = QtGui.QAction( - icon, "{: <20}\tCtrl+I".format("Insert cursor comment"), menu - ) + icon.addPixmap(QtGui.QPixmap(":/comments.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) + action = QtGui.QAction(icon, "{: <20}\tCtrl+I".format("Insert cursor comment"), menu) action.triggered.connect( partial( self.plot_action, @@ -308,11 +280,7 @@ def __init__(self, signals, *args, **kwargs): icon = QtGui.QIcon() action = QtGui.QAction("{: <20}\tAlt+I".format("Toggle trigger texts"), menu) - action.triggered.connect( - partial( - self.plot_action, key=QtCore.Qt.Key_I, modifier=QtCore.Qt.AltModifier - ) - ) + action.triggered.connect(partial(self.plot_action, key=QtCore.Qt.Key_I, modifier=QtCore.Qt.AltModifier)) action.setShortcut(QtGui.QKeySequence("Alt+I")) cursors_actions.addAction(action) @@ -475,9 +443,7 @@ def set_theme(self, option): palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Shadow, brush) brush = QtGui.QBrush(QtGui.QColor(27, 27, 27)) brush.setStyle(QtCore.Qt.SolidPattern) - palette.setBrush( - QtGui.QPalette.Inactive, QtGui.QPalette.AlternateBase, brush - ) + palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.AlternateBase, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 220)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.ToolTipBase, brush) @@ -523,9 +489,7 @@ def set_theme(self, option): palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Shadow, brush) brush = QtGui.QBrush(QtGui.QColor(55, 55, 55)) brush.setStyle(QtCore.Qt.SolidPattern) - palette.setBrush( - QtGui.QPalette.Disabled, QtGui.QPalette.AlternateBase, brush - ) + palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.AlternateBase, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 220)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.ToolTipBase, brush) diff --git a/src/asammdf/gui/widgets/python_highlighter.py b/src/asammdf/gui/widgets/python_highlighter.py index 00a5fb231..89f63c115 100644 --- a/src/asammdf/gui/widgets/python_highlighter.py +++ b/src/asammdf/gui/widgets/python_highlighter.py @@ -104,14 +104,10 @@ def __init__(self, parent: QtGui.QTextDocument) -> None: rules = [] # Keyword, operator, and brace rules - rules += [ - (rf"\b{w}\b", 0, STYLES["keyword"]) for w in PythonHighlighter.keywords - ] + rules += [(rf"\b{w}\b", 0, STYLES["keyword"]) for w in PythonHighlighter.keywords] rules += [(o, 0, STYLES["operator"]) for o in PythonHighlighter.operators] rules += [(b, 0, STYLES["brace"]) for b in PythonHighlighter.braces] - rules += [ - (rf"\b{b}\b", 0, STYLES["builtins"]) for b in PythonHighlighter.builtins - ] + rules += [(rf"\b{b}\b", 0, STYLES["builtins"]) for b in PythonHighlighter.builtins] # All other rules rules += [ @@ -138,9 +134,7 @@ def __init__(self, parent: QtGui.QTextDocument) -> None: ] # Build a QRegularExpression for each pattern - self.rules = [ - (QtCore.QRegularExpression(pat), index, fmt) for (pat, index, fmt) in rules - ] + self.rules = [(QtCore.QRegularExpression(pat), index, fmt) for (pat, index, fmt) in rules] def highlightBlock(self, text): """Apply syntax highlighting to the given block of text.""" diff --git a/src/asammdf/gui/widgets/range_widget.py b/src/asammdf/gui/widgets/range_widget.py index 83b0b8b81..fb4029880 100644 --- a/src/asammdf/gui/widgets/range_widget.py +++ b/src/asammdf/gui/widgets/range_widget.py @@ -69,12 +69,8 @@ def __init__( self.font_color = font_color self.background_color = background_color - self.name.setStyleSheet( - f"background-color: {background_color}; color: {font_color};" - ) - self.background_color_btn.setStyleSheet( - f"background-color: {background_color};" - ) + self.name.setStyleSheet(f"background-color: {background_color}; color: {font_color};") + self.background_color_btn.setStyleSheet(f"background-color: {background_color};") self.font_color_btn.setStyleSheet(f"background-color: {font_color};") def value1_changed(self, text): @@ -96,9 +92,7 @@ def select_background_color(self, event=None): color = color.name() self.background_color = color self.background_color_btn.setStyleSheet(f"background-color: {color};") - self.name.setStyleSheet( - f"background-color: {self.background_color}; color: {self.font_color};" - ) + self.name.setStyleSheet(f"background-color: {self.background_color}; color: {self.font_color};") def select_font_color(self, event=None): color = self.font_color_btn.palette().button().color() @@ -107,9 +101,7 @@ def select_font_color(self, event=None): color = color.name() self.font_color = color self.font_color_btn.setStyleSheet(f"background-color: {color};") - self.name.setStyleSheet( - f"background-color: {self.background_color}; color: {self.font_color};" - ) + self.name.setStyleSheet(f"background-color: {self.background_color}; color: {self.font_color};") def to_dict(self, brush=False): value1 = self.value1.text().strip() diff --git a/src/asammdf/gui/widgets/tabular.py b/src/asammdf/gui/widgets/tabular.py index 39ce9bcb2..48f1a903f 100644 --- a/src/asammdf/gui/widgets/tabular.py +++ b/src/asammdf/gui/widgets/tabular.py @@ -25,9 +25,7 @@ class Tabular(TabularBase): add_channels_request = QtCore.Signal(list) - def __init__( - self, signals=None, start=None, format="phys", ranges=None, *args, **kwargs - ): + def __init__(self, signals=None, start=None, format="phys", ranges=None, *args, **kwargs): # super().__init__(*args, **kwargs) self.signals_descr = {} @@ -53,9 +51,7 @@ def __init__( if col.dtype.kind == "O": if name_.endswith("DataBytes"): try: - sizes = signals[ - name_.replace("DataBytes", "DataLength") - ].astype("u2") + sizes = signals[name_.replace("DataBytes", "DataLength")].astype("u2") except: sizes = None dropped[name_] = pd.Series( @@ -68,9 +64,7 @@ def __init__( elif name_.endswith("Data Bytes"): try: - sizes = signals[ - name_.replace("Data Bytes", "Data Length") - ].astype("u2") + sizes = signals[name_.replace("Data Bytes", "Data Length")].astype("u2") except: sizes = None dropped[name_] = pd.Series( @@ -83,9 +77,7 @@ def __init__( elif col.dtype.name != "category": try: - dropped[name_] = pd.Series( - csv_bytearray2hex(col), index=signals.index - ) + dropped[name_] = pd.Series(csv_bytearray2hex(col), index=signals.index) except: pass @@ -93,13 +85,9 @@ def __init__( elif col.dtype.kind == "S": try: - dropped[name_] = pd.Series( - npchar.decode(col, "utf-8"), index=signals.index - ) + dropped[name_] = pd.Series(npchar.decode(col, "utf-8"), index=signals.index) except: - dropped[name_] = pd.Series( - npchar.decode(col, "latin-1"), index=signals.index - ) + dropped[name_] = pd.Series(npchar.decode(col, "latin-1"), index=signals.index) self.signals_descr[name_] = 0 else: self.signals_descr[name_] = 0 @@ -112,11 +100,7 @@ def __init__( names = [ "timestamps", *[name for name in names if name.endswith((".ID", ".DataBytes"))], - *[ - name - for name in names - if name != "timestamps" and not name.endswith((".ID", ".DataBytes")) - ], + *[name for name in names if name != "timestamps" and not name.endswith((".ID", ".DataBytes"))], ] signals = signals[names] diff --git a/src/asammdf/gui/widgets/tabular_base.py b/src/asammdf/gui/widgets/tabular_base.py index b4c71569b..3b4f339df 100644 --- a/src/asammdf/gui/widgets/tabular_base.py +++ b/src/asammdf/gui/widgets/tabular_base.py @@ -202,23 +202,17 @@ def sort_column(self, ix, next_sort_state=None): next_sort_state = "None" if next_sort_state == "Asc": - self.df_unfiltered = self.df_unfiltered.sort_values( - col_name, ascending=True, kind="mergesort" - ) + self.df_unfiltered = self.df_unfiltered.sort_values(col_name, ascending=True, kind="mergesort") self.sorted_column_name = self.df_unfiltered.columns[ix] self.sort_state = "Asc" elif next_sort_state == "Desc": - self.df_unfiltered = self.df_unfiltered.sort_values( - col_name, ascending=False, kind="mergesort" - ) + self.df_unfiltered = self.df_unfiltered.sort_values(col_name, ascending=False, kind="mergesort") self.sorted_column_name = self.df_unfiltered.columns[ix] self.sort_state = "Desc" elif next_sort_state == "None": - self.df_unfiltered = self.df_unfiltered.sort_index( - ascending=True, kind="mergesort" - ) + self.df_unfiltered = self.df_unfiltered.sort_index(ascending=True, kind="mergesort") self.sorted_column_name = None self.sort_state = "None" @@ -228,25 +222,19 @@ def sort_column(self, ix, next_sort_state=None): def sort_index(self, ix: int): # Clicked an unsorted index level if ix != self.sorted_index_level: - self.df_unfiltered = self.df_unfiltered.sort_index( - level=ix, ascending=True, kind="mergesort" - ) + self.df_unfiltered = self.df_unfiltered.sort_index(level=ix, ascending=True, kind="mergesort") self.sorted_index_level = ix self.sort_state = "Asc" # Clicked a sorted index level elif ix == self.sorted_index_level and self.sort_state == "Asc": - self.df_unfiltered = self.df_unfiltered.sort_index( - level=ix, ascending=False, kind="mergesort" - ) + self.df_unfiltered = self.df_unfiltered.sort_index(level=ix, ascending=False, kind="mergesort") self.sorted_index_level = ix self.sort_state = "Desc" # Clicked a reverse sorted index level - reset to sorted by full index elif ix == self.sorted_index_level: - self.df_unfiltered = self.df_unfiltered.sort_index( - ascending=True, kind="mergesort" - ) + self.df_unfiltered = self.df_unfiltered.sort_index(ascending=True, kind="mergesort") self.sorted_index_level = None self.sort_state = "None" @@ -339,11 +327,7 @@ def data(self, index, role=QtCore.Qt.DisplayRole): default_font_color=self.font_color, ) - return ( - new_background_color - if new_background_color != self.background_color - else None - ) + return new_background_color if new_background_color != self.background_color else None elif role == QtCore.Qt.ForegroundRole: channel_ranges = self.pgdf.tabular.ranges[name] @@ -368,9 +352,7 @@ def data(self, index, role=QtCore.Qt.DisplayRole): elif isinstance(cell, pd.Timestamp): return int(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter) else: - if self.float_precision == -1 and isinstance( - cell, (float, np.floating) - ): + if self.float_precision == -1 and isinstance(cell, (float, np.floating)): return int(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter) else: return int(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) @@ -435,16 +417,14 @@ def on_selectionChanged(self): selection = self.selectionModel().selection() columnHeader.selectionModel().select( selection, - QtCore.QItemSelectionModel.Columns - | QtCore.QItemSelectionModel.ClearAndSelect, + QtCore.QItemSelectionModel.Columns | QtCore.QItemSelectionModel.ClearAndSelect, ) if not indexHeader.hasFocus(): selection = self.selectionModel().selection() indexHeader.selectionModel().select( selection, - QtCore.QItemSelectionModel.Rows - | QtCore.QItemSelectionModel.ClearAndSelect, + QtCore.QItemSelectionModel.Rows | QtCore.QItemSelectionModel.ClearAndSelect, ) def sizeHint(self): @@ -483,9 +463,7 @@ def keyPressEvent(self, event): modifiers = event.modifiers() if key == QtCore.Qt.Key_R and modifiers == QtCore.Qt.ControlModifier: - selected_items = set( - index.column() for index in self.selectedIndexes() if index.isValid() - ) + selected_items = set(index.column() for index in self.selectedIndexes() if index.isValid()) if selected_items: ranges = [] @@ -493,9 +471,7 @@ def keyPressEvent(self, event): original_name = self.pgdf.df_unfiltered.columns[index] ranges.update(self.pgdf.tabular.ranges[original_name]) - dlg = RangeEditor( - "", "", ranges=ranges, parent=self, brush=True - ) + dlg = RangeEditor("", "", ranges=ranges, parent=self, brush=True) dlg.exec_() if dlg.pressed_button == "apply": ranges = dlg.result @@ -555,11 +531,7 @@ def data(self, index, role=QtCore.Qt.DisplayRole): else: return - if ( - col == self.pgdf.sorted_column_ix - and row == self.rowCount() - 1 - and self.orientation == Qt.Horizontal - ): + if col == self.pgdf.sorted_column_ix and row == self.rowCount() - 1 and self.orientation == Qt.Horizontal: return icon elif role == QtCore.Qt.TextAlignmentRole: @@ -567,9 +539,7 @@ def data(self, index, role=QtCore.Qt.DisplayRole): name = self.pgdf.df_unfiltered.columns[col] dtype = self.pgdf.df_unfiltered[name].values.dtype - float_precision = ( - self.pgdf.dataframe_viewer.dataView.model().float_precision - ) + float_precision = self.pgdf.dataframe_viewer.dataView.model().float_precision if np.issubdtype(dtype, np.integer): return int(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) @@ -595,9 +565,7 @@ def __init__(self, parent, orientation): super().__init__(parent) self.dataframe_viewer = parent self.pgdf = parent.pgdf - self.setProperty( - "orientation", "horizontal" if orientation == 1 else "vertical" - ) # Used in stylesheet + self.setProperty("orientation", "horizontal" if orientation == 1 else "vertical") # Used in stylesheet # Setup self.orientation = orientation @@ -621,11 +589,7 @@ def __init__(self, parent, orientation): # Settings self.setIconSize(QtCore.QSize(16, 16)) - self.setSizePolicy( - QtWidgets.QSizePolicy( - QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Maximum - ) - ) + self.setSizePolicy(QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Maximum)) self.setWordWrap(False) self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.setHorizontalScrollMode(QtWidgets.QAbstractItemView.ScrollPerPixel) @@ -636,9 +600,7 @@ def __init__(self, parent, orientation): self.setFont(font) # Link selection to DataTable - self.selectionModel().selectionChanged.connect( - lambda x: self.on_selectionChanged() - ) + self.selectionModel().selectionChanged.connect(lambda x: self.on_selectionChanged()) # self.set_spans() self.horizontalHeader().hide() @@ -648,9 +610,7 @@ def __init__(self, parent, orientation): # Automatically stretch rows/columns as widget is resized if self.orientation == Qt.Vertical: - self.horizontalHeader().setSectionResizeMode( - QtWidgets.QHeaderView.ResizeMode.Stretch - ) + self.horizontalHeader().setSectionResizeMode(QtWidgets.QHeaderView.ResizeMode.Stretch) # Set initial size self.resize(self.sizeHint()) @@ -676,10 +636,7 @@ def mousePressEvent(self, event): point = event.pos() ix = self.indexAt(point) col = ix.column() - if ( - event.button() == QtCore.Qt.RightButton - and self.orientation == Qt.Horizontal - ): + if event.button() == QtCore.Qt.RightButton and self.orientation == Qt.Horizontal: self.dataframe_viewer.show_column_menu(col) else: super().mousePressEvent(event) @@ -695,9 +652,7 @@ def on_selectionChanged(self, force=False): dataView = self.dataframe_viewer.dataView # Set selection mode so selecting one row or column at a time adds to selection each time - if ( - self.orientation == Qt.Horizontal - ): # This case is for the horizontal header + if self.orientation == Qt.Horizontal: # This case is for the horizontal header # Get the header's selected columns selection = self.selectionModel().selection() @@ -713,8 +668,7 @@ def on_selectionChanged(self, force=False): # Select the cells in the data view dataView.selectionModel().select( selection, - QtCore.QItemSelectionModel.Columns - | QtCore.QItemSelectionModel.ClearAndSelect, + QtCore.QItemSelectionModel.Columns | QtCore.QItemSelectionModel.ClearAndSelect, ) if self.orientation == Qt.Vertical: selection = self.selectionModel().selection() @@ -729,8 +683,7 @@ def on_selectionChanged(self, force=False): dataView.selectionModel().select( selection, - QtCore.QItemSelectionModel.Rows - | QtCore.QItemSelectionModel.ClearAndSelect, + QtCore.QItemSelectionModel.Rows | QtCore.QItemSelectionModel.ClearAndSelect, ) self.selectAbove() @@ -753,16 +706,12 @@ def selectAbove(self): # Loop over the rows above this one for row in range(ix.row()): ix2 = self.model().index(row, ix.column()) - self.setSelection( - self.visualRect(ix2), QtCore.QItemSelectionModel.Select - ) + self.setSelection(self.visualRect(ix2), QtCore.QItemSelectionModel.Select) else: # Loop over the columns left of this one for col in range(ix.column()): ix2 = self.model().index(ix.row(), col) - self.setSelection( - self.visualRect(ix2), QtCore.QItemSelectionModel.Select - ) + self.setSelection(self.visualRect(ix2), QtCore.QItemSelectionModel.Select) # This sets spans to group together adjacent cells with the same values def set_spans(self): @@ -922,10 +871,7 @@ def over_header_edge(mouse_position: QtCore.QPoint(), margin=7) -> bool: self.header_cell_being_resized = over_header_cell_edge(mouse_position) return True # Disabling vertical resizing of top header for now - elif ( - over_header_edge(orthogonal_mouse_position) - and self.orientation == Qt.Vertical - ): + elif over_header_edge(orthogonal_mouse_position) and self.orientation == Qt.Vertical: self.header_being_resized = True return True else: @@ -951,20 +897,14 @@ def over_header_edge(mouse_position: QtCore.QPoint(), margin=7) -> bool: if event.type() == QtCore.QEvent.MouseMove: # If this is None, there is no drag resize happening if self.header_cell_being_resized is not None: - size = mouse_position - self.columnViewportPosition( - self.header_cell_being_resized - ) + size = mouse_position - self.columnViewportPosition(self.header_cell_being_resized) if size > 10: if self.orientation == Qt.Horizontal: self.setColumnWidth(self.header_cell_being_resized, size) - self.dataframe_viewer.dataView.setColumnWidth( - self.header_cell_being_resized, size - ) + self.dataframe_viewer.dataView.setColumnWidth(self.header_cell_being_resized, size) if self.orientation == Qt.Vertical: self.setRowHeight(self.header_cell_being_resized, size) - self.dataframe_viewer.dataView.setRowHeight( - self.header_cell_being_resized, size - ) + self.dataframe_viewer.dataView.setRowHeight(self.header_cell_being_resized, size) self.updateGeometry() self.dataframe_viewer.dataView.updateGeometry() @@ -1071,9 +1011,7 @@ def __init__(self, parent, orientation): self.dataframe_viewer = parent self.pgdf = parent.pgdf - self.setProperty( - "orientation", "horizontal" if orientation == 1 else "vertical" - ) # Used in stylesheet + self.setProperty("orientation", "horizontal" if orientation == 1 else "vertical") # Used in stylesheet # Setup self.orientation = orientation @@ -1092,13 +1030,9 @@ def __init__(self, parent, orientation): # Automatically stretch rows/columns as widget is resized if self.orientation == Qt.Horizontal: - self.verticalHeader().setSectionResizeMode( - QtWidgets.QHeaderView.ResizeMode.Stretch - ) + self.verticalHeader().setSectionResizeMode(QtWidgets.QHeaderView.ResizeMode.Stretch) else: - self.horizontalHeader().setSectionResizeMode( - QtWidgets.QHeaderView.ResizeMode.Stretch - ) + self.horizontalHeader().setSectionResizeMode(QtWidgets.QHeaderView.ResizeMode.Stretch) font = QtGui.QFont() font.fromString(MONOSPACE_FONT) @@ -1157,9 +1091,7 @@ def __init__(self, pgdf, column_ix, parent=None): ######################## # Info idx = self.pgdf.dataframe_viewer.columnHeader.model().index(0, column_ix) - self.name = self.pgdf.dataframe_viewer.columnHeader.model().data( - idx, role=QtCore.Qt.DisplayRole - ) + self.name = self.pgdf.dataframe_viewer.columnHeader.model().data(idx, role=QtCore.Qt.DisplayRole) label = QtWidgets.QLabel(self.name) font = QtGui.QFont() font.setBold(True) @@ -1174,33 +1106,18 @@ def __init__(self, pgdf, column_ix, parent=None): self.add_widget(QtWidgets.QLabel("Set sorting")) def select_button(): - self.sort_b1.setDown( - self.pgdf.sort_state == "Asc" - and self.pgdf.sorted_column_ix == column_ix - ) - self.sort_b2.setDown( - self.pgdf.sort_state == "Desc" - and self.pgdf.sorted_column_ix == column_ix - ) - self.sort_b3.setDown( - self.pgdf.sort_state == "None" - or self.pgdf.sorted_column_ix != column_ix - ) + self.sort_b1.setDown(self.pgdf.sort_state == "Asc" and self.pgdf.sorted_column_ix == column_ix) + self.sort_b2.setDown(self.pgdf.sort_state == "Desc" and self.pgdf.sorted_column_ix == column_ix) + self.sort_b3.setDown(self.pgdf.sort_state == "None" or self.pgdf.sorted_column_ix != column_ix) self.sort_b1 = QtWidgets.QPushButton("Asc") - self.sort_b1.clicked.connect( - lambda: [self.pgdf.sort_column(self.column_ix, "Asc"), select_button()] - ) + self.sort_b1.clicked.connect(lambda: [self.pgdf.sort_column(self.column_ix, "Asc"), select_button()]) self.sort_b2 = QtWidgets.QPushButton("Desc") - self.sort_b2.clicked.connect( - lambda: [self.pgdf.sort_column(self.column_ix, "Desc"), select_button()] - ) + self.sort_b2.clicked.connect(lambda: [self.pgdf.sort_column(self.column_ix, "Desc"), select_button()]) self.sort_b3 = QtWidgets.QPushButton("None") - self.sort_b3.clicked.connect( - lambda: [self.pgdf.sort_column(self.column_ix, "None"), select_button()] - ) + self.sort_b3.clicked.connect(lambda: [self.pgdf.sort_column(self.column_ix, "None"), select_button()]) select_button() @@ -1209,10 +1126,7 @@ def select_button(): sort_control_layout.setSpacing(0) sort_control_layout.setContentsMargins(0, 0, 0, 0) sort_control.setLayout(sort_control_layout) - [ - sort_control_layout.addWidget(w) - for w in [self.sort_b1, self.sort_b2, self.sort_b3] - ] + [sort_control_layout.addWidget(w) for w in [self.sort_b1, self.sort_b2, self.sort_b3]] self.add_widget(sort_control) @@ -1343,9 +1257,7 @@ def __init__(self, df, ranges=None, *args, **kwargs): for name, ranges_ in ranges.items(): for range_info in ranges_: range_info["font_color"] = fn.mkBrush(range_info["font_color"]) - range_info["background_color"] = fn.mkBrush( - range_info["background_color"] - ) + range_info["background_color"] = fn.mkBrush(range_info["background_color"]) self.ranges[name] = ranges_ df = DataFrameStorage(df, self) @@ -1366,9 +1278,7 @@ def __init__(self, df, ranges=None, *args, **kwargs): self.toggle_filters_btn.clicked.connect(self.toggle_filters) self.filters_group.setHidden(True) - self.float_precision.addItems( - ["Full float precision"] + [f"{i} float decimals" for i in range(16)] - ) + self.float_precision.addItems(["Full float precision"] + [f"{i} float decimals" for i in range(16)]) self.float_precision.setCurrentIndex(0) self.float_precision.currentIndexChanged.connect(self.float_precision_changed) @@ -1385,9 +1295,7 @@ def float_precision_changed(self, index): def current_changed(self, current, previous): if current.isValid(): row = current.row() - self._filtered_ts_series = self._original_ts_series.reindex( - self.tree.pgdf.df.index - ) + self._filtered_ts_series = self._original_ts_series.reindex(self.tree.pgdf.df.index) ts = float(self._filtered_ts_series.iloc[row]) self.timestamp_changed_signal.emit(self, ts) @@ -1396,17 +1304,13 @@ def toggle_filters(self, event=None): self.toggle_filters_btn.setText("Hide filters") self.filters_group.setHidden(False) icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/up.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/up.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.toggle_filters_btn.setIcon(icon) else: self.toggle_filters_btn.setText("Show filters") self.filters_group.setHidden(True) icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/down.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/down.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.toggle_filters_btn.setIcon(icon) def add_filter(self, event=None): @@ -1496,9 +1400,7 @@ def apply_filters(self, event=None): target = str(target).replace(" ", "").strip('"') if f"{column_name}__as__bytes" not in df.columns: - df[f"{column_name}__as__bytes"] = pd.Series( - [bytes(s) for s in df[column_name]], index=df.index - ) + df[f"{column_name}__as__bytes"] = pd.Series([bytes(s) for s in df[column_name]], index=df.index) val = bytes.fromhex(target) filters.append(f"{column_name}__as__bytes") @@ -1514,9 +1416,7 @@ def apply_filters(self, event=None): try: new_df = df.query(" ".join(filters)) except: - logger.exception( - f'Failed to apply filter for tabular window: {" ".join(filters)}' - ) + logger.exception(f'Failed to apply filter for tabular window: {" ".join(filters)}') self.query.setText(format_exc()) else: to_drop = [name for name in df.columns if name.endswith("__as__bytes")] @@ -1549,9 +1449,7 @@ def add_new_channels(self, signals, mime_data=None): ranges = { name: channel_ranges - for name, channel_ranges in zip( - self.tree.pgdf.df_unfiltered.columns, self.ranges.values() - ) + for name, channel_ranges in zip(self.tree.pgdf.df_unfiltered.columns, self.ranges.values()) } for name_ in signals.columns: @@ -1585,9 +1483,7 @@ def add_new_channels(self, signals, mime_data=None): elif col.dtype.name != "category": try: - dropped[name_] = pd.Series( - csv_bytearray2hex(col), index=signals.index - ) + dropped[name_] = pd.Series(csv_bytearray2hex(col), index=signals.index) except: pass @@ -1595,13 +1491,9 @@ def add_new_channels(self, signals, mime_data=None): elif col.dtype.kind == "S": try: - dropped[name_] = pd.Series( - npchar.decode(col, "utf-8"), index=signals.index - ) + dropped[name_] = pd.Series(npchar.decode(col, "utf-8"), index=signals.index) except: - dropped[name_] = pd.Series( - npchar.decode(col, "latin-1"), index=signals.index - ) + dropped[name_] = pd.Series(npchar.decode(col, "latin-1"), index=signals.index) self.signals_descr[name_] = 0 else: self.signals_descr[name_] = 0 @@ -1615,17 +1507,11 @@ def add_new_channels(self, signals, mime_data=None): names = list(signals.columns) names = [ *[name for name in names if name.endswith((".ID", ".DataBytes"))], - *[ - name - for name in names - if name != "timestamps" and not name.endswith((".ID", ".DataBytes")) - ], + *[name for name in names if name != "timestamps" and not name.endswith((".ID", ".DataBytes"))], ] signals = signals[names] - self.tree.pgdf.df_unfiltered = self.tree.pgdf.df = pd.concat( - [self.tree.pgdf.df_unfiltered, signals], axis=1 - ) + self.tree.pgdf.df_unfiltered = self.tree.pgdf.df = pd.concat([self.tree.pgdf.df_unfiltered, signals], axis=1) self.ranges = ranges if filtered: @@ -1645,9 +1531,7 @@ def to_config(self): for range_info in ranges: range_info["font_color"] = range_info["font_color"].color().name() - range_info["background_color"] = ( - range_info["background_color"].color().name() - ) + range_info["background_color"] = range_info["background_color"].color().name() pattern["ranges"] = ranges @@ -1657,22 +1541,15 @@ def to_config(self): for range_info in channel_ranges: range_info["font_color"] = range_info["font_color"].color().name() - range_info["background_color"] = ( - range_info["background_color"].color().name() - ) + range_info["background_color"] = range_info["background_color"].color().name() ranges[name] = channel_ranges config = { "sorted": True, - "channels": list(self.tree.pgdf.df_unfiltered.columns) - if not self.pattern - else [], + "channels": list(self.tree.pgdf.df_unfiltered.columns) if not self.pattern else [], "filtered": bool(self.query.toPlainText()), - "filters": [ - self.filters.itemWidget(self.filters.item(i)).to_config() - for i in range(count) - ] + "filters": [self.filters.itemWidget(self.filters.item(i)).to_config() for i in range(count)] if not self.pattern else [], "time_as_date": self.time_as_date.checkState() == QtCore.Qt.Checked, @@ -1702,9 +1579,7 @@ def time_as_date_changed(self, state): else: filter.validate_target() - delta = pd.to_timedelta( - self.tree.pgdf.df_unfiltered["timestamps"], unit="s" - ) + delta = pd.to_timedelta(self.tree.pgdf.df_unfiltered["timestamps"], unit="s") timestamps = self.start + delta self.tree.pgdf.df_unfiltered["timestamps"] = timestamps @@ -1765,18 +1640,14 @@ def open_menu(self, position): if file_name: self.progress = 0, 0 - progress = QtWidgets.QProgressDialog( - f'Data export to CSV file "{file_name}"', "", 0, 0, self.parent() - ) + progress = QtWidgets.QProgressDialog(f'Data export to CSV file "{file_name}"', "", 0, 0, self.parent()) progress.setWindowModality(QtCore.Qt.ApplicationModal) progress.setCancelButton(None) progress.setAutoClose(True) progress.setWindowTitle("Export tabular window to CSV") icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap(":/csv.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + icon.addPixmap(QtGui.QPixmap(":/csv.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) progress.setWindowIcon(icon) progress.show() @@ -1802,10 +1673,7 @@ def keyPressEvent(self, event): key = event.key() modifiers = event.modifiers() - if ( - key in (QtCore.Qt.Key_H, QtCore.Qt.Key_B, QtCore.Qt.Key_P) - and modifiers == QtCore.Qt.ControlModifier - ): + if key in (QtCore.Qt.Key_H, QtCore.Qt.Key_B, QtCore.Qt.Key_P) and modifiers == QtCore.Qt.ControlModifier: if key == QtCore.Qt.Key_H: self.format_selection.setCurrentText("hex") elif key == QtCore.Qt.Key_B: @@ -1828,14 +1696,10 @@ def keyPressEvent(self, event): mdf.append(self.tree.pgdf.df_unfiltered) mdf.save(file_name, overwrite=True) - elif ( - key == QtCore.Qt.Key_BracketLeft and modifiers == QtCore.Qt.ControlModifier - ): + elif key == QtCore.Qt.Key_BracketLeft and modifiers == QtCore.Qt.ControlModifier: self.decrease_font() - elif ( - key == QtCore.Qt.Key_BracketRight and modifiers == QtCore.Qt.ControlModifier - ): + elif key == QtCore.Qt.Key_BracketRight and modifiers == QtCore.Qt.ControlModifier: self.increase_font() elif key == QtCore.Qt.Key_G and modifiers == QtCore.Qt.ShiftModifier: @@ -1868,18 +1732,12 @@ def set_format(self, fmt): self.apply_filters() def set_timestamp(self, stamp): - self._filtered_ts_series = self._original_ts_series.reindex( - self.tree.pgdf.df.index - ) + self._filtered_ts_series = self._original_ts_series.reindex(self.tree.pgdf.df.index) if not len(self._filtered_ts_series): return - if not ( - self._filtered_ts_series.iloc[0] - <= stamp - <= self._filtered_ts_series.iloc[-1] - ): + if not (self._filtered_ts_series.iloc[0] <= stamp <= self._filtered_ts_series.iloc[-1]): return idx = self._filtered_ts_series.searchsorted(stamp, side="right") - 1 @@ -1892,9 +1750,7 @@ def edit_ranges(self, index, name): if index >= 0: original_name = self.tree.pgdf.df_unfiltered.columns[index] - dlg = RangeEditor( - name, "", self.ranges[original_name], parent=self, brush=True - ) + dlg = RangeEditor(name, "", self.ranges[original_name], parent=self, brush=True) dlg.exec_() if dlg.pressed_button == "apply": ranges = dlg.result @@ -1955,9 +1811,7 @@ def __init__(self, pgdf): "Courier", ): if family in families: - MONOSPACE_FONT = ( - f"{family},9,-1,5,400,0,0,0,0,0,0,0,0,0,0,1,Regular" - ) + MONOSPACE_FONT = f"{family},9,-1,5,400,0,0,0,0,0,0,0,0,0,0,1,Regular" break pgdf.dataframe_viewer = self @@ -1986,22 +1840,12 @@ def __init__(self, pgdf): # Linking scrollbars # Scrolling in data table also scrolls the headers - self.dataView.horizontalScrollBar().valueChanged.connect( - self.columnHeader.horizontalScrollBar().setValue - ) - self.dataView.horizontalScrollBar().valueChanged.connect( - self.columnHeaderNames.horizontalScrollBar().setValue - ) - self.dataView.verticalScrollBar().valueChanged.connect( - self.indexHeader.verticalScrollBar().setValue - ) + self.dataView.horizontalScrollBar().valueChanged.connect(self.columnHeader.horizontalScrollBar().setValue) + self.dataView.horizontalScrollBar().valueChanged.connect(self.columnHeaderNames.horizontalScrollBar().setValue) + self.dataView.verticalScrollBar().valueChanged.connect(self.indexHeader.verticalScrollBar().setValue) # Scrolling in headers also scrolls the data table - self.columnHeader.horizontalScrollBar().valueChanged.connect( - self.dataView.horizontalScrollBar().setValue - ) - self.indexHeader.verticalScrollBar().valueChanged.connect( - self.dataView.verticalScrollBar().setValue - ) + self.columnHeader.horizontalScrollBar().valueChanged.connect(self.dataView.horizontalScrollBar().setValue) + self.indexHeader.verticalScrollBar().valueChanged.connect(self.dataView.verticalScrollBar().setValue) # Turn off default scrollbars self.dataView.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.dataView.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) @@ -2016,9 +1860,7 @@ def __init__(self): self.corner_widget = CornerWidget() self.corner_widget.setSizePolicy( - QtWidgets.QSizePolicy( - QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding - ) + QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding) ) # Add items to grid layout # self.gridLayout.addWidget(self.corner_widget, 0, 0) @@ -2032,14 +1874,10 @@ def __init__(self): # Fix scrollbars forcing a minimum height of the dataView which breaks layout for small number of rows self.dataView.verticalScrollBar().setSizePolicy( - QtWidgets.QSizePolicy( - QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Ignored - ) + QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Ignored) ) self.dataView.horizontalScrollBar().setSizePolicy( - QtWidgets.QSizePolicy( - QtWidgets.QSizePolicy.Ignored, QtWidgets.QSizePolicy.Fixed - ) + QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Ignored, QtWidgets.QSizePolicy.Fixed) ) # These expand when the window is enlarged instead of having the grid squares spread out @@ -2056,12 +1894,8 @@ def __init__(self): self.default_row_height = 24 self.set_styles() - self.indexHeader.setSizePolicy( - QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.Maximum - ) - self.columnHeader.setSizePolicy( - QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.MinimumExpanding - ) + self.indexHeader.setSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.Maximum) + self.columnHeader.setSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.MinimumExpanding) # Set column widths for column_index in range(self.columnHeader.model().columnCount()): @@ -2070,9 +1904,7 @@ def __init__(self): self.columnHeader.horizontalHeader().setStretchLastSection(True) self.columnHeaderNames.horizontalHeader().setStretchLastSection(True) - self.columnHeader.horizontalHeader().sectionResized.connect( - self.update_horizontal_scroll - ) + self.columnHeader.horizontalHeader().sectionResized.connect(self.update_horizontal_scroll) self.columnHeader.horizontalHeader().setMinimumSectionSize(1) self.dataView.horizontalHeader().setMinimumSectionSize(1) @@ -2092,18 +1924,10 @@ def set_styles(self): item.setContentsMargins(0, 0, 0, 0) # item.setItemDelegate(NoFocusDelegate()) - self.indexHeaderNames.verticalHeader().setDefaultSectionSize( - self.default_row_height - ) - self.indexHeaderNames.verticalHeader().setMinimumSectionSize( - self.default_row_height - ) - self.indexHeaderNames.verticalHeader().setMaximumSectionSize( - self.default_row_height - ) - self.indexHeaderNames.verticalHeader().sectionResizeMode( - QtWidgets.QHeaderView.Fixed - ) + self.indexHeaderNames.verticalHeader().setDefaultSectionSize(self.default_row_height) + self.indexHeaderNames.verticalHeader().setMinimumSectionSize(self.default_row_height) + self.indexHeaderNames.verticalHeader().setMaximumSectionSize(self.default_row_height) + self.indexHeaderNames.verticalHeader().sectionResizeMode(QtWidgets.QHeaderView.Fixed) self.indexHeader.verticalHeader().setDefaultSectionSize(self.default_row_height) self.indexHeader.verticalHeader().setMinimumSectionSize(self.default_row_height) self.indexHeader.verticalHeader().setMaximumSectionSize(self.default_row_height) @@ -2112,18 +1936,10 @@ def set_styles(self): self.dataView.verticalHeader().setMinimumSectionSize(self.default_row_height) self.dataView.verticalHeader().setMaximumSectionSize(self.default_row_height) self.dataView.verticalHeader().sectionResizeMode(QtWidgets.QHeaderView.Fixed) - self.columnHeader.verticalHeader().setDefaultSectionSize( - self.default_row_height - ) - self.columnHeader.verticalHeader().setMinimumSectionSize( - self.default_row_height - ) - self.columnHeader.verticalHeader().setMaximumSectionSize( - self.default_row_height - ) - self.columnHeader.verticalHeader().sectionResizeMode( - QtWidgets.QHeaderView.Fixed - ) + self.columnHeader.verticalHeader().setDefaultSectionSize(self.default_row_height) + self.columnHeader.verticalHeader().setMinimumSectionSize(self.default_row_height) + self.columnHeader.verticalHeader().setMaximumSectionSize(self.default_row_height) + self.columnHeader.verticalHeader().sectionResizeMode(QtWidgets.QHeaderView.Fixed) def __reduce__(self): # This is so dataclasses.asdict doesn't complain about this being unpicklable @@ -2214,11 +2030,7 @@ def keyPressEvent(self, event): if event.key() == Qt.Key_C and (mods & Qt.ControlModifier): self.copy(header=True) # Ctrl+Shift+C - elif ( - event.key() == Qt.Key_C - and (mods & Qt.ShiftModifier) - and (mods & Qt.ControlModifier) - ): + elif event.key() == Qt.Key_C and (mods & Qt.ShiftModifier) and (mods & Qt.ControlModifier): self.copy(header=True) else: self.dataView.keyPressEvent(event) @@ -2312,9 +2124,7 @@ def show_column_menu(self, column_ix_or_name): column_ix = column_ix_or_name point = QtCore.QPoint( - self.columnHeader.columnViewportPosition(column_ix) - + self.columnHeader.columnWidth(column_ix) - - 15, + self.columnHeader.columnViewportPosition(column_ix) + self.columnHeader.columnWidth(column_ix) - 15, self.columnHeader.geometry().bottom() - 6, ) diff --git a/src/asammdf/gui/widgets/tree.py b/src/asammdf/gui/widgets/tree.py index 39d8711fd..2d409f805 100644 --- a/src/asammdf/gui/widgets/tree.py +++ b/src/asammdf/gui/widgets/tree.py @@ -44,9 +44,7 @@ def substitude_mime_uuids(mime, uuid=None, force=False): item["origin_uuid"] = uuid new_mime.append(item) else: - item["channels"] = substitude_mime_uuids( - item["channels"], uuid, force=force - ) + item["channels"] = substitude_mime_uuids(item["channels"], uuid, force=force) if force or item["origin_uuid"] is None: item["origin_uuid"] = uuid new_mime.append(item) @@ -80,11 +78,7 @@ def add_children( dep = channel_dependencies[entry[1]] if version >= "4.00": if dep and isinstance(dep[0], tuple): - child.setFlags( - child.flags() - | QtCore.Qt.ItemIsAutoTristate - | QtCore.Qt.ItemIsUserCheckable - ) + child.setFlags(child.flags() | QtCore.Qt.ItemIsAutoTristate | QtCore.Qt.ItemIsUserCheckable) add_children( child, @@ -231,9 +225,7 @@ def keyPressEvent(self, event): else: item.setCheckState(0, QtCore.Qt.Checked) else: - if any( - item.checkState(0) == QtCore.Qt.Unchecked for item in selected_items - ): + if any(item.checkState(0) == QtCore.Qt.Unchecked for item in selected_items): checked = QtCore.Qt.Checked else: checked = QtCore.Qt.Unchecked @@ -295,11 +287,7 @@ def get_data(item): for item in selected_items: data.extend(get_data(item)) - data = json.dumps( - sorted( - data, key=lambda x: (x["name"], x["group_index"], x["channel_index"]) - ) - ).encode("utf-8") + data = json.dumps(sorted(data, key=lambda x: (x["name"], x["group_index"], x["channel_index"]))).encode("utf-8") mimeData.setData("application/octet-stream-asammdf", QtCore.QByteArray(data)) @@ -453,12 +441,8 @@ def __init__( self.header().setMinimumSectionSize(10) self.header().resizeSection(self.CommonAxisColumn, 10) self.header().resizeSection(self.IndividualAxisColumn, 10) - self.header().setSectionResizeMode( - self.CommonAxisColumn, QtWidgets.QHeaderView.Fixed - ) - self.header().setSectionResizeMode( - self.IndividualAxisColumn, QtWidgets.QHeaderView.Fixed - ) + self.header().setSectionResizeMode(self.CommonAxisColumn, QtWidgets.QHeaderView.Fixed) + self.header().setSectionResizeMode(self.IndividualAxisColumn, QtWidgets.QHeaderView.Fixed) self.header().setStretchLastSection(False) @@ -489,18 +473,13 @@ def __init__( self._font_size = self.font().pointSize() self._background = background self._style = SCROLLBAR_STYLE - self.setStyleSheet( - self._style.format( - font_size=self._font_size, background=self._background - ) - ) + self.setStyleSheet(self._style.format(font_size=self._font_size, background=self._background)) else: self._dark = False def autoscroll(self): step = max( - (self.verticalScrollBar().maximum() - self.verticalScrollBar().minimum()) - // 90, + (self.verticalScrollBar().maximum() - self.verticalScrollBar().minimum()) // 90, 1, ) @@ -519,9 +498,7 @@ def autoscroll(self): self.verticalScrollBar().setValue(pos) def startDrag(self, supportedActions): - selected_items = validate_drag_items( - self.invisibleRootItem(), self.selectedItems(), [] - ) + selected_items = validate_drag_items(self.invisibleRootItem(), self.selectedItems(), []) mimeData = QtCore.QMimeData() @@ -637,9 +614,7 @@ def keyPressEvent(self, event): pattern = dlg.result if pattern: - group = ChannelsTreeItem( - ChannelsTreeItem.Group, name=pattern["name"], pattern=pattern - ) + group = ChannelsTreeItem(ChannelsTreeItem.Group, name=pattern["name"], pattern=pattern) item = self.currentItem() @@ -672,9 +647,7 @@ def keyPressEvent(self, event): self.update_channel_groups_count() elif key == QtCore.Qt.Key_Insert and modifiers == QtCore.Qt.ShiftModifier: - text, ok = QtWidgets.QInputDialog.getText( - self, "Channel group name", "New channel group name:" - ) + text, ok = QtWidgets.QInputDialog.getText(self, "Channel group name", "New channel group name:") if ok: group = ChannelsTreeItem(ChannelsTreeItem.Group, name=text) @@ -708,10 +681,7 @@ def keyPressEvent(self, event): else: item.setCheckState(self.NameColumn, QtCore.Qt.Checked) else: - if any( - item.checkState(self.NameColumn) == QtCore.Qt.Unchecked - for item in selected_items - ): + if any(item.checkState(self.NameColumn) == QtCore.Qt.Unchecked for item in selected_items): checked = QtCore.Qt.Checked else: checked = QtCore.Qt.Unchecked @@ -739,9 +709,7 @@ def keyPressEvent(self, event): item.color = color elif modifiers == QtCore.Qt.ControlModifier and key == QtCore.Qt.Key_C: - selected_items = validate_drag_items( - self.invisibleRootItem(), self.selectedItems(), [] - ) + selected_items = validate_drag_items(self.invisibleRootItem(), self.selectedItems(), []) data = get_data(self.plot, selected_items, uuids_only=False) data = substitude_mime_uuids(data, None, force=True) QtWidgets.QApplication.instance().clipboard().setText(json.dumps(data)) @@ -773,18 +741,14 @@ def keyPressEvent(self, event): type = item.type() if type == ChannelsTreeItem.Group: - dlg = RangeEditor( - f"channels from <{item._name}>", ranges=item.ranges, parent=self - ) + dlg = RangeEditor(f"channels from <{item._name}>", ranges=item.ranges, parent=self) dlg.exec_() if dlg.pressed_button == "apply": item.set_ranges(dlg.result) item.update_child_values() elif type == ChannelsTreeItem.Channel: - dlg = RangeEditor( - item.signal.name, item.unit, item.ranges, parent=self - ) + dlg = RangeEditor(item.signal.name, item.unit, item.ranges, parent=self) dlg.exec_() if dlg.pressed_button == "apply": item.set_ranges(dlg.result) @@ -794,9 +758,7 @@ def keyPressEvent(self, event): ranges = [] for item in selected_items: ranges.extend(item.ranges) - dlg = RangeEditor( - f"", ranges=unique_ranges(ranges), parent=self - ) + dlg = RangeEditor(f"", ranges=unique_ranges(ranges), parent=self) dlg.exec_() if dlg.pressed_button == "apply": for item in selected_items: @@ -811,23 +773,15 @@ def keyPressEvent(self, event): self.refresh() self.plot.plot.update() - elif ( - modifiers == (QtCore.Qt.ControlModifier | QtCore.Qt.ShiftModifier) - and key == QtCore.Qt.Key_C - ): + elif modifiers == (QtCore.Qt.ControlModifier | QtCore.Qt.ShiftModifier) and key == QtCore.Qt.Key_C: selected_items = self.selectedItems() if not selected_items: return else: item = selected_items[0] - QtWidgets.QApplication.instance().clipboard().setText( - item.get_display_properties() - ) + QtWidgets.QApplication.instance().clipboard().setText(item.get_display_properties()) - elif ( - modifiers == (QtCore.Qt.ControlModifier | QtCore.Qt.ShiftModifier) - and key == QtCore.Qt.Key_V - ): + elif modifiers == (QtCore.Qt.ControlModifier | QtCore.Qt.ShiftModifier) and key == QtCore.Qt.Key_V: info = QtWidgets.QApplication.instance().clipboard().text() selected_items = self.selectedItems() if not selected_items: @@ -847,9 +801,7 @@ def keyPressEvent(self, event): item.setCheckState( self.IndividualAxisColumn, - QtCore.Qt.Checked - if info["individual_axis"] - else QtCore.Qt.Unchecked, + QtCore.Qt.Checked if info["individual_axis"] else QtCore.Qt.Unchecked, ) item.setCheckState( self.CommonAxisColumn, @@ -888,7 +840,8 @@ def mousePressEvent(self, event) -> None: self.context_menu = None # If there was a click performed on disabled item, then clear selection - item = self.itemAt(event.pos()) + position = event.position() + item = self.itemAt(position.x(), position.y()) if item and item.isDisabled(): self.clearSelection() super().mousePressEvent(event) @@ -980,11 +933,7 @@ def open_menu(self): menu.addAction(self.tr("Set channel conversion")) menu.addAction(self.tr("Set channel comment")) menu.addAction(self.tr("Set unit")) - if ( - item - and item.type() == ChannelsTreeItem.Channel - and item.signal.flags & Signal.Flags.computed - ): + if item and item.type() == ChannelsTreeItem.Channel and item.signal.flags & Signal.Flags.computed: menu.addSeparator() menu.addAction(self.tr("Edit this computed channel")) menu.addSeparator() @@ -1022,9 +971,7 @@ def open_menu(self): action_text = action.text() if action_text == "Copy names [Ctrl+N]": - event = QtGui.QKeyEvent( - QtCore.QEvent.KeyPress, QtCore.Qt.Key_N, QtCore.Qt.ControlModifier - ) + event = QtGui.QKeyEvent(QtCore.QEvent.KeyPress, QtCore.Qt.Key_N, QtCore.Qt.ControlModifier) self.keyPressEvent(event) elif action_text == "Copy names and values": @@ -1329,9 +1276,7 @@ def open_menu(self): self.set_time_offset.emit([absolute, offset] + uuids) elif action_text == "Delete [Del]": - event = QtGui.QKeyEvent( - QtCore.QEvent.KeyPress, QtCore.Qt.Key_Delete, QtCore.Qt.NoModifier - ) + event = QtGui.QKeyEvent(QtCore.QEvent.KeyPress, QtCore.Qt.Key_Delete, QtCore.Qt.NoModifier) self.keyPressEvent(event) elif action_text == "Toggle details": @@ -1392,15 +1337,11 @@ def open_menu(self): self.compute_fft_request.emit(item.uuid) elif action_text == "Add channel group [Shift+Insert]": - event = QtGui.QKeyEvent( - QtCore.QEvent.KeyPress, QtCore.Qt.Key_Insert, QtCore.Qt.ShiftModifier - ) + event = QtGui.QKeyEvent(QtCore.QEvent.KeyPress, QtCore.Qt.Key_Insert, QtCore.Qt.ShiftModifier) self.keyPressEvent(event) elif action_text == "Add pattern based channel group [Ctrl+Insert]": - event = QtGui.QKeyEvent( - QtCore.QEvent.KeyPress, QtCore.Qt.Key_Insert, QtCore.Qt.ControlModifier - ) + event = QtGui.QKeyEvent(QtCore.QEvent.KeyPress, QtCore.Qt.Key_Insert, QtCore.Qt.ControlModifier) self.keyPressEvent(event) elif action_text == "Rename channel": @@ -1464,9 +1405,7 @@ def open_menu(self): item.name = text.strip() elif action_text == "Search item": - pattern, ok = QtWidgets.QInputDialog.getText( - self, "Search item", "Item name:" - ) + pattern, ok = QtWidgets.QInputDialog.getText(self, "Search item", "Item name:") if ok and pattern: original_pattern = pattern wildcard = f"{os.urandom(6).hex()}_WILDCARD_{os.urandom(6).hex()}" @@ -1486,8 +1425,7 @@ def open_menu(self): if ( item is not start_item - and item.type() - in (ChannelsTreeItem.Channel, ChannelsTreeItem.Group) + and item.type() in (ChannelsTreeItem.Channel, ChannelsTreeItem.Group) and compiled_pattern.search(item.name) ): self.scrollToItem(item) @@ -1586,11 +1524,7 @@ def resizeEvent(self, e: QtGui.QResizeEvent) -> None: def set_font_size(self, size): if self._dark: self._font_size = size - self.setStyleSheet( - self._style.format( - font_size=self._font_size, background=self._background - ) - ) + self.setStyleSheet(self._style.format(font_size=self._font_size, background=self._background)) def update_channel_groups_count(self): iterator = QtWidgets.QTreeWidgetItemIterator(self) @@ -1617,16 +1551,10 @@ def update_hidden_states(self): if item.type() == ChannelsTreeItem.Channel: if hide_missing_channels and not item.exists: hidden = True - if ( - hide_disabled_channels - and item.checkState(self.NameColumn) == QtCore.Qt.Unchecked - ): + if hide_disabled_channels and item.checkState(self.NameColumn) == QtCore.Qt.Unchecked: hidden = True else: - if ( - hide_disabled_channels - and item.checkState(self.NameColumn) == QtCore.Qt.Unchecked - ): + if hide_disabled_channels and item.checkState(self.NameColumn) == QtCore.Qt.Unchecked: hidden = True item.setHidden(hidden) @@ -1735,9 +1663,7 @@ def __init__( self.kind = kind - tooltip = ( - getattr(signal, "tooltip", "") or f"{signal.name}\n{signal.comment}" - ) + tooltip = getattr(signal, "tooltip", "") or f"{signal.name}\n{signal.comment}" if signal.source: details = signal.source.get_details() else: @@ -1871,9 +1797,7 @@ def comment(self, value): self.signal.comment = value self.signal.flags |= Signal.Flags.user_defined_comment - tooltip = ( - getattr(self.signal, "tooltip", "") or f"{self.signal.name}\n{value}" - ) + tooltip = getattr(self.signal, "tooltip", "") or f"{self.signal.name}\n{value}" self.setToolTip(self.NameColumn, tooltip) def copy(self): @@ -1922,9 +1846,7 @@ def does_not_exist(self, exists=False): if self.type() == self.Channel: if utils.ERROR_ICON is None: utils.ERROR_ICON = QtGui.QIcon() - utils.ERROR_ICON.addPixmap( - QtGui.QPixmap(":/error.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + utils.ERROR_ICON.addPixmap(QtGui.QPixmap(":/error.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) utils.NO_ICON = QtGui.QIcon() @@ -1967,17 +1889,14 @@ def format(self, format): @lru_cache(maxsize=1024) def get_color_using_ranges(self, value, pen=False): - return get_color_using_ranges( - value, self.get_ranges(), self.signal.color, pen=pen - ) + return get_color_using_ranges(value, self.get_ranges(), self.signal.color, pen=pen) def get_display_properties(self): info = { "color": self.color.name(), "precision": self.precision, "ylink": self.checkState(self.CommonAxisColumn) == QtCore.Qt.Checked, - "individual_axis": self.checkState(self.IndividualAxisColumn) - == QtCore.Qt.Checked, + "individual_axis": self.checkState(self.IndividualAxisColumn) == QtCore.Qt.Checked, "format": self.format, "ranges": copy_ranges(self.ranges), } @@ -2087,9 +2006,7 @@ def set_conversion(self, conversion): self.signal.text_conversion = None if self.signal.conversion: - samples = self.signal.conversion.convert( - self.signal.samples, as_bytes=True - ) + samples = self.signal.conversion.convert(self.signal.samples, as_bytes=True) if samples.dtype.kind not in "SUV": nans = np.isnan(samples) if np.any(nans): @@ -2102,9 +2019,7 @@ def set_conversion(self, conversion): self.signal.phys_samples = samples else: self.signal.text_conversion = self.signal.conversion - self.signal.phys_samples = ( - self.signal.raw_samples - ) = self.signal.samples + self.signal.phys_samples = self.signal.raw_samples = self.signal.samples self.unit = conversion.unit else: @@ -2147,9 +2062,7 @@ def set_disabled(self, disabled, preserve_subgroup_state=True): if disabled: self.setIcon(self.NameColumn, QtGui.QIcon(":/erase.png")) - elif not self.parent() or ( - self.parent() and not self.parent().isDisabled() - ): + elif not self.parent() or (self.parent() and not self.parent().isDisabled()): self.setIcon(self.NameColumn, QtGui.QIcon(":/open.png")) self.setDisabled(disabled) @@ -2181,9 +2094,7 @@ def set_pattern(self, pattern): if isinstance(range_info["font_color"], str): range_info["font_color"] = fn.mkColor(range_info["font_color"]) if isinstance(range_info["background_color"], str): - range_info["background_color"] = fn.mkColor( - range_info["background_color"] - ) + range_info["background_color"] = fn.mkColor(range_info["background_color"]) else: self.setIcon(self.NameColumn, QtGui.QIcon(":/open.png")) self.pattern = None @@ -2196,9 +2107,7 @@ def set_ranges(self, ranges): if utils.RANGE_INDICATOR_ICON is None: utils.RANGE_INDICATOR_ICON = QtGui.QIcon() - utils.RANGE_INDICATOR_ICON.addPixmap( - QtGui.QPixmap(":/paint.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off - ) + utils.RANGE_INDICATOR_ICON.addPixmap(QtGui.QPixmap(":/paint.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) utils.NO_ICON = QtGui.QIcon() utils.NO_ERROR_ICON = QtGui.QIcon() @@ -2232,9 +2141,7 @@ def set_ranges(self, ranges): if isinstance(range_info["font_color"], str): range_info["font_color"] = fn.mkColor(range_info["font_color"]) if isinstance(range_info["background_color"], str): - range_info["background_color"] = fn.mkColor( - range_info["background_color"] - ) + range_info["background_color"] = fn.mkColor(range_info["background_color"]) self.ranges.append(range_info) self.reset_resolved_ranges() @@ -2306,9 +2213,7 @@ def set_value(self, value=None, update=False, force=False): self.setText(self.ValueColumn, text) else: if self.signal.text_conversion and self.mode == "phys": - value = self.signal.text_conversion.convert([value], as_bytes=True)[ - 0 - ] + value = self.signal.text_conversion.convert([value], as_bytes=True)[0] if isinstance(value, bytes): try: text = value.decode("utf-8", errors="replace") @@ -2335,9 +2240,7 @@ def set_value(self, value=None, update=False, force=False): def show_info(self): if self.type() == self.Group: - ChannnelGroupDialog( - self.name, self.pattern, self.get_ranges(), self.treeWidget() - ).show() + ChannnelGroupDialog(self.name, self.pattern, self.get_ranges(), self.treeWidget()).show() @property def unit(self): diff --git a/src/asammdf/gui/widgets/tree_numeric.py b/src/asammdf/gui/widgets/tree_numeric.py index 629191e25..b33ac2c11 100644 --- a/src/asammdf/gui/widgets/tree_numeric.py +++ b/src/asammdf/gui/widgets/tree_numeric.py @@ -32,10 +32,7 @@ def set_double_clicked_enabled(self, state): def keyPressEvent(self, event): key = event.key() - if ( - event.key() == QtCore.Qt.Key_Delete - and event.modifiers() == QtCore.Qt.NoModifier - ): + if event.key() == QtCore.Qt.Key_Delete and event.modifiers() == QtCore.Qt.NoModifier: selected = reversed(self.selectedItems()) names = [(item.origin_uuid, item.text(0)) for item in selected] for item in selected: diff --git a/src/asammdf/gui/widgets/viewbox.py b/src/asammdf/gui/widgets/viewbox.py index 738e8ff77..8a427f388 100644 --- a/src/asammdf/gui/widgets/viewbox.py +++ b/src/asammdf/gui/widgets/viewbox.py @@ -18,9 +18,7 @@ def __init__(self, view): view ) ## keep weakref to view to avoid circular reference (don't know why, but this prevents the ViewBox from being collected) self.valid = False ## tells us whether the ui needs to be updated - self.viewMap = ( - weakref.WeakValueDictionary() - ) ## weakrefs to all views listed in the link combos + self.viewMap = weakref.WeakValueDictionary() ## weakrefs to all views listed in the link combos self.leftMenu = QtWidgets.QMenu("Mouse Mode") group = QtGui.QActionGroup(self) @@ -169,10 +167,7 @@ def mouseDragEvent(self, ev, axis=None, ignore_cursor=False): if axis is not None: mask[1 - axis] = 0.0 - if ( - self.state["mouseMode"] == ViewBoxWithCursor.CursorMode - and not ignore_cursor - ): + if self.state["mouseMode"] == ViewBoxWithCursor.CursorMode and not ignore_cursor: if ev.button() == QtCore.Qt.MouseButton.LeftButton: self.sigCursorMoved.emit(ev) if self.zoom_start is not None: @@ -228,9 +223,7 @@ def mouseDragEvent(self, ev, axis=None, ignore_cursor=False): x = s[0] if mouseEnabled[0] == 1 else None y = s[1] if mouseEnabled[1] == 1 else None - center = pg.Point( - tr.map(ev.buttonDownPos(QtCore.Qt.MouseButton.RightButton)) - ) + center = pg.Point(tr.map(ev.buttonDownPos(QtCore.Qt.MouseButton.RightButton))) self._resetTarget() self.scaleBy(x=x, y=y, center=center) self.sigRangeChangedManually.emit(self.state["mouseEnabled"]) @@ -294,9 +287,7 @@ def wheelEvent(self, ev, axis=None): else: pos = ev.pos() - s = 1.02 ** ( - ev.delta() * self.state["wheelScaleFactor"] - ) # actual scaling factor + s = 1.02 ** (ev.delta() * self.state["wheelScaleFactor"]) # actual scaling factor s = [(None if m is False else s) for m in mask] center = pg.Point(fn.invertQTransform(self.childGroup.transform()).map(pos)) diff --git a/src/asammdf/gui/widgets/vtt_widget.py b/src/asammdf/gui/widgets/vtt_widget.py index 421a43889..1c9cdee81 100644 --- a/src/asammdf/gui/widgets/vtt_widget.py +++ b/src/asammdf/gui/widgets/vtt_widget.py @@ -37,9 +37,7 @@ def __init__( self.conversion_btn.clicked.connect(self.edit_conversion) def edit_conversion(self): - dlg = ConversionEditor( - f"Raw={self.value.value()} referenced", self.conversion, parent=self - ) + dlg = ConversionEditor(f"Raw={self.value.value()} referenced", self.conversion, parent=self) dlg.exec_() if dlg.pressed_button == "apply": self.conversion = dlg.conversion() diff --git a/src/asammdf/mdf.py b/src/asammdf/mdf.py index d59f39df8..7f76c375c 100644 --- a/src/asammdf/mdf.py +++ b/src/asammdf/mdf.py @@ -132,9 +132,7 @@ def get_measurement_timestamp_and_version( return header.start_time, version -def get_temporary_filename( - path: Path = Path("temporary.mf4"), dir: str | Path | None = None -) -> Path: +def get_temporary_filename(path: Path = Path("temporary.mf4"), dir: str | Path | None = None) -> Path: if not dir: folder = gettempdir() else: @@ -244,9 +242,7 @@ def __init__( elif isinstance(name, bz2.BZ2File): original_name = Path(name._fp.name) - tmp_name = get_temporary_filename( - original_name, dir=temporary_folder - ) + tmp_name = get_temporary_filename(original_name, dir=temporary_folder) tmp_name.write_bytes(name.read()) file_stream = open(tmp_name, "rb") name = tmp_name @@ -255,26 +251,20 @@ def __init__( elif isinstance(name, gzip.GzipFile): original_name = Path(name.name) - tmp_name = get_temporary_filename( - original_name, dir=temporary_folder - ) + tmp_name = get_temporary_filename(original_name, dir=temporary_folder) tmp_name.write_bytes(name.read()) file_stream = open(tmp_name, "rb") name = tmp_name do_close = True - elif FSSPEF_AVAILABLE and isinstance( - name, fsspec.spec.AbstractBufferedFile - ): + elif FSSPEF_AVAILABLE and isinstance(name, fsspec.spec.AbstractBufferedFile): original_name = "AzureFile" file_stream = name do_close = False else: - raise MdfException( - f"{type(name)} is not supported as input for the MDF class" - ) + raise MdfException(f"{type(name)} is not supported as input for the MDF class") elif isinstance(name, zipfile.ZipFile): archive = name @@ -285,9 +275,7 @@ def __init__( original_name = fname break else: - raise Exception( - "invalid zipped MF4: no supported file found in the archive" - ) + raise Exception("invalid zipped MF4: no supported file found in the archive") name = get_temporary_filename(Path(original_name), dir=temporary_folder) @@ -311,9 +299,7 @@ def __init__( if Path(fname).suffix.lower() in (".mdf", ".dat", ".mf4"): break else: - raise Exception( - "invalid zipped MF4: no supported file found in the archive" - ) + raise Exception("invalid zipped MF4: no supported file found in the archive") tmpdir = mkdtemp() output = archive.extract(fname, tmpdir) @@ -329,9 +315,7 @@ def __init__( if magic_header.strip() not in (b"MDF", b"UnFinMF"): if do_close: file_stream.close() - raise MdfException( - f'"{name}" is not a valid ASAM MDF file: magic header is {magic_header}' - ) + raise MdfException(f'"{name}" is not a valid ASAM MDF file: magic header is {magic_header}') file_stream.seek(8) version = file_stream.read(4).decode("ascii").strip(" \0") @@ -366,8 +350,7 @@ def __init__( self._mdf = MDF4(version=version, **kwargs) else: message = ( - f'"{version}" is not a supported MDF file version; ' - f"Supported versions are {SUPPORTED_VERSIONS}" + f'"{version}" is not a supported MDF file version; ' f"Supported versions are {SUPPORTED_VERSIONS}" ) raise MdfException(message) @@ -485,11 +468,7 @@ def get_scopes(event, events): timestamp = ev_base * ev_factor try: - comment = ET.fromstring( - event.comment.replace( - ' xmlns="http://www.asam.net/mdf/v4"', "" - ) - ) + comment = ET.fromstring(event.comment.replace(' xmlns="http://www.asam.net/mdf/v4"', "")) pre = comment.find(".//pre_trigger_interval") if pre is not None: pre = float(pre.text) @@ -617,9 +596,7 @@ def _transfer_header_data(self, other: MDF, message: str = "") -> None: self.file_history = [fh] @staticmethod - def _transfer_channel_group_data( - sgroup: ChannelGroupType, ogroup: ChannelGroupType - ) -> None: + def _transfer_channel_group_data(sgroup: ChannelGroupType, ogroup: ChannelGroupType) -> None: if not hasattr(sgroup, "acq_name") or not hasattr(ogroup, "acq_name"): sgroup.comment = ogroup.comment else: @@ -654,13 +631,9 @@ def configure( write_fragment_size: int | None = None, use_display_names: bool | None = None, single_bit_uint_as_bool: bool | None = None, - integer_interpolation: IntInterpolationModeType - | IntegerInterpolation - | None = None, + integer_interpolation: IntInterpolationModeType | IntegerInterpolation | None = None, copy_on_get: bool | None = None, - float_interpolation: FloatInterpolationModeType - | FloatInterpolation - | None = None, + float_interpolation: FloatInterpolationModeType | FloatInterpolation | None = None, raise_on_multiple_occurrences: bool | None = None, temporary_folder: str | None = None, fill_0_for_missing_computation_channels: bool | None = None, @@ -748,9 +721,7 @@ def configure( self._integer_interpolation = from_other._integer_interpolation self.copy_on_get = from_other.copy_on_get self._float_interpolation = from_other._float_interpolation - self._raise_on_multiple_occurrences = ( - from_other._raise_on_multiple_occurrences - ) + self._raise_on_multiple_occurrences = from_other._raise_on_multiple_occurrences if read_fragment_size is not None: self._read_fragment_size = int(read_fragment_size) @@ -824,9 +795,7 @@ def convert(self, version: str, progress=None) -> MDF: # walk through all groups and get all channels for i, virtual_group in enumerate(self.virtual_groups): - for idx, sigs in enumerate( - self._yield_selected_signals(virtual_group, version=version) - ): + for idx, sigs in enumerate(self._yield_selected_signals(virtual_group, version=version)): if idx == 0: if sigs: cg = self.groups[virtual_group].channel_group @@ -835,9 +804,7 @@ def convert(self, version: str, progress=None) -> MDF: common_timebase=True, comment=cg.comment, ) - MDF._transfer_channel_group_data( - out.groups[cg_nr].channel_group, cg - ) + MDF._transfer_channel_group_data(out.groups[cg_nr].channel_group, cg) else: break else: @@ -962,9 +929,7 @@ def cut( idx = 0 signals = [] - for j, sigs in enumerate( - self._yield_selected_signals(group_index, groups=included_channels) - ): + for j, sigs in enumerate(self._yield_selected_signals(group_index, groups=included_channels)): if not sigs: break if j == 0: @@ -993,9 +958,7 @@ def cut( break else: fragment_stop = min(stop, master[-1]) - stop_index = np.searchsorted( - master, fragment_stop, side="right" - ) + stop_index = np.searchsorted(master, fragment_stop, side="right") if stop_index == len(master): needs_cutting = False @@ -1005,9 +968,7 @@ def cut( continue else: fragment_start = max(start, master[0]) - start_index = np.searchsorted( - master, fragment_start, side="left" - ) + start_index = np.searchsorted(master, fragment_start, side="left") stop_index = len(master) if start_index == 0: needs_cutting = False @@ -1018,13 +979,9 @@ def cut( continue else: fragment_start = max(start, master[0]) - start_index = np.searchsorted( - master, fragment_start, side="left" - ) + start_index = np.searchsorted(master, fragment_start, side="left") fragment_stop = min(stop, master[-1]) - stop_index = np.searchsorted( - master, fragment_stop, side="right" - ) + stop_index = np.searchsorted(master, fragment_stop, side="right") if start_index == 0 and stop_index == len(master): needs_cutting = False @@ -1082,9 +1039,7 @@ def cut( common_timebase=True, comment=cg.comment, ) - MDF._transfer_channel_group_data( - out.groups[cg_nr].channel_group, cg - ) + MDF._transfer_channel_group_data(out.groups[cg_nr].channel_group, cg) else: sigs = [(sig.samples, sig.invalidation_bits) for sig in signals] @@ -1270,10 +1225,7 @@ def export( fmt = fmt.lower() if fmt != "pandas" and filename is None and self.name is None: - message = ( - "Must specify filename for export" - "if MDF was created without a file name" - ) + message = "Must specify filename for export" "if MDF was created without a file name" logger.warning(message) return @@ -1287,18 +1239,14 @@ def export( reduce_memory_usage = kwargs.get("reduce_memory_usage", False) compression = kwargs.get("compression", "") time_as_date = kwargs.get("time_as_date", False) - ignore_value2text_conversions = kwargs.get( - "ignore_value2text_conversions", False - ) + ignore_value2text_conversions = kwargs.get("ignore_value2text_conversions", False) raw = bool(kwargs.get("raw", False)) if compression == "SNAPPY": try: import snappy except ImportError: - logger.warning( - "snappy compressor is not installed; compression will be set to GZIP" - ) + logger.warning("snappy compressor is not installed; compression will be set to GZIP") compression = "GZIP" filename = Path(filename) if filename else self.name @@ -1307,9 +1255,7 @@ def export( try: from fastparquet import write as write_parquet except ImportError: - logger.warning( - "fastparquet not found; export to parquet is unavailable" - ) + logger.warning("fastparquet not found; export to parquet is unavailable") return elif fmt == "hdf5": @@ -1324,17 +1270,13 @@ def export( try: from hdf5storage import savemat except ImportError: - logger.warning( - "hdf5storage not found; export to mat v7.3 is unavailable" - ) + logger.warning("hdf5storage not found; export to mat v7.3 is unavailable") return else: try: from scipy.io import savemat except ImportError: - logger.warning( - "scipy not found; export to mat v4 and v5 is unavailable" - ) + logger.warning("scipy not found; export to mat v4 and v5 is unavailable") return elif fmt not in ("csv", "asc"): @@ -1384,9 +1326,7 @@ def export( for ch in grp.channels: if use_display_names: - channel_name = ( - list(ch.display_names)[0] if ch.display_names else ch.name - ) + channel_name = list(ch.display_names)[0] if ch.display_names else ch.name else: channel_name = ch.name @@ -1453,9 +1393,7 @@ def export( continue if compression: - dataset = group.create_dataset( - channel, data=samples, compression=compression - ) + dataset = group.create_dataset(channel, data=samples, compression=compression) else: dataset = group.create_dataset(channel, data=samples) unit = unit.replace("\0", "") @@ -1500,9 +1438,7 @@ def export( if progress.stop: return TERMINATED - for i, (group_index, virtual_group) in enumerate( - self.virtual_groups.items() - ): + for i, (group_index, virtual_group) in enumerate(self.virtual_groups.items()): channels = self.included_channels(group_index)[group_index] if not channels: @@ -1513,9 +1449,7 @@ def export( return TERMINATED if len(virtual_group.groups) == 1: - comment = self.groups[ - virtual_group.groups[0] - ].channel_group.comment + comment = self.groups[virtual_group.groups[0]].channel_group.comment else: comment = "Virtual group i" @@ -1527,9 +1461,7 @@ def export( master_index = self.masters_db.get(group_index, -1) if master_index >= 0: - group.attrs["master"] = ( - self.groups[group_index].channels[master_index].name - ) + group.attrs["master"] = self.groups[group_index].channels[master_index].name master = self.get(group.attrs["master"], group_index) if reduce_memory_usage: master.timestamps = downcast(master.timestamps) @@ -1565,11 +1497,7 @@ def export( for j, sig in enumerate(channels): if use_display_names: - name = ( - list(sig.display_names)[0] - if sig.display_names - else sig.name - ) + name = list(sig.display_names)[0] if sig.display_names else sig.name else: name = sig.name name = name.replace("\\", "_").replace("/", "_") @@ -1577,13 +1505,9 @@ def export( if reduce_memory_usage: sig.samples = downcast(sig.samples) if compression: - dataset = group.create_dataset( - name, data=sig.samples, compression=compression - ) + dataset = group.create_dataset(name, data=sig.samples, compression=compression) else: - dataset = group.create_dataset( - name, data=sig.samples, dtype=sig.samples.dtype - ) + dataset = group.create_dataset(name, data=sig.samples, dtype=sig.samples.dtype) unit = sig.unit.replace("\0", "") if unit: dataset.attrs["unit"] = unit @@ -1626,9 +1550,7 @@ def export( if time_as_date: index = ( - pd.to_datetime( - df.index + self.header.start_time.timestamp(), unit="s" - ) + pd.to_datetime(df.index + self.header.start_time.timestamp(), unit="s") .tz_localize("UTC") .tz_convert(LOCAL_TIMEZONE) .astype(str) @@ -1651,9 +1573,7 @@ def export( ) elif name_.endswith("CAN_DataFrame.DataBytes"): - dropped[name_] = pd.Series( - csv_bytearray2hex(df[name_]), index=df.index - ) + dropped[name_] = pd.Series(csv_bytearray2hex(df[name_]), index=df.index) df = df.drop(columns=list(dropped)) for name, s in dropped.items(): @@ -1678,9 +1598,7 @@ def export( ("latin-1", "replace"), ): try: - df[col] = df[col] = df[col].str.decode( - encoding, errors - ) + df[col] = df[col] = df[col].str.decode(encoding, errors) break except: continue @@ -1732,9 +1650,7 @@ def export( if progress.stop: return TERMINATED - for i, (group_index, virtual_group) in enumerate( - self.virtual_groups.items() - ): + for i, (group_index, virtual_group) in enumerate(self.virtual_groups.items()): if progress is not None and progress.stop: return TERMINATED @@ -1742,23 +1658,16 @@ def export( logger.info(message) if len(virtual_group.groups) == 1: - comment = self.groups[ - virtual_group.groups[0] - ].channel_group.comment + comment = self.groups[virtual_group.groups[0]].channel_group.comment else: comment = "" if comment: for char in f'\n\t\r\b <>\/:"?*|': comment = comment.replace(char, "_") - group_csv_name = ( - filename.parent - / f"{filename.stem}.ChannelGroup_{i}_{comment}.csv" - ) + group_csv_name = filename.parent / f"{filename.stem}.ChannelGroup_{i}_{comment}.csv" else: - group_csv_name = ( - filename.parent / f"{filename.stem}.ChannelGroup_{i}.csv" - ) + group_csv_name = filename.parent / f"{filename.stem}.ChannelGroup_{i}.csv" df = self.get_group( group_index, @@ -1774,18 +1683,12 @@ def export( units = {} used_names = UniqueDB() - for gp_index, channel_indexes in self.included_channels( - group_index - )[group_index].items(): + for gp_index, channel_indexes in self.included_channels(group_index)[group_index].items(): for ch_index in channel_indexes: ch = self.groups[gp_index].channels[ch_index] if use_display_names: - channel_name = ( - list(ch.display_names)[0] - if ch.display_names - else ch.name - ) + channel_name = list(ch.display_names)[0] if ch.display_names else ch.name else: channel_name = ch.name @@ -1804,9 +1707,7 @@ def export( if time_as_date: index = ( - pd.to_datetime( - df.index + self.header.start_time.timestamp(), unit="s" - ) + pd.to_datetime(df.index + self.header.start_time.timestamp(), unit="s") .tz_localize("UTC") .tz_convert(LOCAL_TIMEZONE) .astype(str) @@ -1832,9 +1733,7 @@ def export( ) elif name_.endswith("CAN_DataFrame.DataBytes"): - dropped[name_] = pd.Series( - csv_bytearray2hex(df[name_]), index=df.index - ) + dropped[name_] = pd.Series(csv_bytearray2hex(df[name_]), index=df.index) df = df.drop(columns=list(dropped)) for name_, s in dropped.items(): @@ -1903,9 +1802,7 @@ def decompose(samples): if progress.stop: return TERMINATED - for i, (group_index, virtual_group) in enumerate( - self.virtual_groups.items() - ): + for i, (group_index, virtual_group) in enumerate(self.virtual_groups.items()): if progress is not None and progress.stop: return TERMINATED @@ -1939,11 +1836,7 @@ def decompose(samples): channel_name = master_name_template.format(i, "timestamps") else: if use_display_names: - channel_name = ( - list(sig.display_names)[0] - if sig.display_names - else sig.name - ) + channel_name = list(sig.display_names)[0] if sig.display_names else sig.name else: channel_name = sig.name channel_name = channel_name_template.format(i, channel_name) @@ -1952,16 +1845,12 @@ def decompose(samples): channel_name = used_names.get_unique_name(channel_name) if sig.samples.dtype.names: - sig.samples.dtype.names = [ - matlab_compatible(name) - for name in sig.samples.dtype.names - ] + sig.samples.dtype.names = [matlab_compatible(name) for name in sig.samples.dtype.names] sigs = decompose(sig.samples) sigs = { - channel_name_template.format(i, channel_name): _v - for channel_name, _v in sigs.items() + channel_name_template.format(i, channel_name): _v for channel_name, _v in sigs.items() } mdict.update(sigs) @@ -2063,16 +1952,11 @@ def decompose(samples): write_parquet(filename, df) else: - message = ( - 'Unsopported export type "{}". ' - 'Please select "csv", "excel", "hdf5", "mat" or "pandas"' - ) + message = 'Unsopported export type "{}". ' 'Please select "csv", "excel", "hdf5", "mat" or "pandas"' message.format(fmt) logger.warning(message) - def filter( - self, channels: ChannelsType, version: str | None = None, progress=None - ) -> MDF: + def filter(self, channels: ChannelsType, version: str | None = None, progress=None) -> MDF: """return new *MDF* object that contains only the channels listed in *channels* argument @@ -2175,11 +2059,7 @@ def filter( return TERMINATED for i, (group_index, groups) in enumerate(gps.items()): - for idx, sigs in enumerate( - self._yield_selected_signals( - group_index, groups=groups, version=version - ) - ): + for idx, sigs in enumerate(self._yield_selected_signals(group_index, groups=groups, version=version)): if not sigs: break @@ -2191,9 +2071,7 @@ def filter( common_timebase=True, comment=cg.comment, ) - MDF._transfer_channel_group_data( - mdf.groups[cg_nr].channel_group, cg - ) + MDF._transfer_channel_group_data(mdf.groups[cg_nr].channel_group, cg) else: break @@ -2402,9 +2280,7 @@ def concatenate( try: oldest = min(timestamps) except TypeError: - timestamps = [ - timestamp.astimezone(timezone.utc) for timestamp in timestamps - ] + timestamps = [timestamp.astimezone(timezone.utc) for timestamp in timestamps] oldest = min(timestamps) offsets = [(timestamp - oldest).total_seconds() for timestamp in timestamps] @@ -2434,9 +2310,7 @@ def concatenate( origin_conversion = {} for i, mdf in enumerate(files): origin_conversion[f"val_{i}"] = i - origin_conversion[f"text_{i}"] = str( - mdf.original_name if isinstance(mdf, MDF) else str(mdf) - ) + origin_conversion[f"text_{i}"] = str(mdf.original_name if isinstance(mdf, MDF) else str(mdf)) origin_conversion = from_dict(origin_conversion) for mdf_index, (offset, mdf) in enumerate(zip(offsets, files)): @@ -2512,15 +2386,11 @@ def concatenate( for _ch_name, _gp_idx, _ch_idx in vlds_channels: key = (_ch_name, _gp_idx) - for _second_gp_idx, _second_ch_idx in w_mdf.whereis( - _ch_name - ): + for _second_gp_idx, _second_ch_idx in w_mdf.whereis(_ch_name): if _second_gp_idx == _gp_idx: vlsd_max_length[key] = max( vlsd_max_length[key], - _file.determine_max_vlsd_sample_size( - _second_gp_idx, _second_ch_idx - ), + _file.determine_max_vlsd_sample_size(_second_gp_idx, _second_ch_idx), ) break else: @@ -2543,9 +2413,7 @@ def concatenate( # check if the order of the channel groups is the same for i, group_index in enumerate(mdf.virtual_groups): - included_channels = mdf.included_channels(group_index)[ - group_index - ] + included_channels = mdf.included_channels(group_index)[group_index] names = [ mdf.groups[gp_index].channels[ch_index].name for gp_index, channels in included_channels.items() @@ -2564,8 +2432,7 @@ def concatenate( for j, new_group in enumerate(mdf.groups): new_group_source = new_group.channel_group.acq_source if ( - new_group.channel_group.acq_name - == org_group.channel_group.acq_name + new_group.channel_group.acq_name == org_group.channel_group.acq_name and (new_group_source and org_group_source) and new_group_source.name == org_group_source.name and new_group_source.path == org_group_source.path @@ -2580,9 +2447,7 @@ def concatenate( for ch_index in channels ] - if sorted(new_names) == sorted( - included_channel_names[i] - ): + if sorted(new_names) == sorted(included_channel_names[i]): cg_translations[i] = j break @@ -2631,9 +2496,7 @@ def concatenate( mdf.vlsd_max_length.clear() mdf.vlsd_max_length.update(vlsd_max_length) - for idx, signals in enumerate( - mdf._yield_selected_signals(group_index, groups=included_channels) - ): + for idx, signals in enumerate(mdf._yield_selected_signals(group_index, groups=included_channels)): if not signals: break if mdf_index == 0 and idx == 0: @@ -2650,8 +2513,7 @@ def concatenate( if add_samples_origin: signals.append( Signal( - samples=np.ones(len(first_signal), dtype="= master[0] - or direct_timestamp_continuation - ): + if last_timestamp >= master[0] or direct_timestamp_continuation: if len(master) >= 2: delta = master[1] - master[0] else: @@ -2847,9 +2704,7 @@ def stack( try: oldest = min(timestamps) except TypeError: - timestamps = [ - timestamp.astimezone(timezone.utc) for timestamp in timestamps - ] + timestamps = [timestamp.astimezone(timezone.utc) for timestamp in timestamps] oldest = min(timestamps) offsets = [(timestamp - oldest).total_seconds() for timestamp in timestamps] @@ -2887,9 +2742,7 @@ def stack( continue for idx, signals in enumerate( - mdf._yield_selected_signals( - group, groups=included_channels, version=version - ) + mdf._yield_selected_signals(group, groups=included_channels, version=version) ): if not signals: break @@ -2903,9 +2756,7 @@ def stack( signals, common_timebase=True, ) - MDF._transfer_channel_group_data( - stacked.groups[dg_cntr].channel_group, cg - ) + MDF._transfer_channel_group_data(stacked.groups[dg_cntr].channel_group, cg) else: master = signals[0][0] if sync: @@ -2918,9 +2769,7 @@ def stack( for index in range(dg_cntr, len(stacked.groups)): stacked.groups[ index - ].channel_group.comment = ( - f'stacked from channel group {i} of "{mdf.name.parent}"' - ) + ].channel_group.comment = f'stacked from channel group {i} of "{mdf.name.parent}"' if progress is not None: if callable(progress): @@ -2949,9 +2798,7 @@ def stack( return stacked - def iter_channels( - self, skip_master: bool = True, copy_master: bool = True, raw: bool = False - ) -> Iterator[Signal]: + def iter_channels(self, skip_master: bool = True, copy_master: bool = True, raw: bool = False) -> Iterator[Signal]: """generator that yields a *Signal* for each non-master channel Parameters @@ -2968,9 +2815,7 @@ def iter_channels( for index in self.virtual_groups: channels = [ (None, gp_index, ch_index) - for gp_index, channel_indexes in self.included_channels(index)[ - index - ].items() + for gp_index, channel_indexes in self.included_channels(index)[index].items() for ch_index in channel_indexes ] @@ -3276,9 +3121,7 @@ def resample( for i, (group_index, virtual_group) in enumerate(self.virtual_groups.items()): channels = [ (None, gp_index, ch_index) - for gp_index, channel_indexes in self.included_channels(group_index)[ - group_index - ].items() + for gp_index, channel_indexes in self.included_channels(group_index)[group_index].items() for ch_index in channel_indexes ] @@ -3414,18 +3257,14 @@ def select( """ - virtual_groups = self.included_channels( - channels=channels, minimal=False, skip_master=False - ) + virtual_groups = self.included_channels(channels=channels, minimal=False, skip_master=False) output_signals = {} for virtual_group, groups in virtual_groups.items(): cycles_nr = self._mdf.virtual_groups[virtual_group].cycles_nr pairs = [ - (gp_index, ch_index) - for gp_index, channel_indexes in groups.items() - for ch_index in channel_indexes + (gp_index, ch_index) for gp_index, channel_indexes in groups.items() for ch_index in channel_indexes ] if record_count is None: @@ -3515,9 +3354,7 @@ def select( signal.raw = False signal.conversion = None if signal.samples.dtype.kind == "S": - signal.encoding = ( - "utf-8" if self.version >= "4.00" else "latin-1" - ) + signal.encoding = "utf-8" if self.version >= "4.00" else "latin-1" if validate: signals = [sig.validate(copy=False) for sig in signals] @@ -3540,9 +3377,7 @@ def select( return signals @staticmethod - def scramble( - name: StrPathType, skip_attachments: bool = False, progress=None, **kwargs - ) -> Path: + def scramble(name: StrPathType, skip_attachments: bool = False, progress=None, **kwargs) -> Path: """scramble text blocks and keep original file structure Parameters @@ -3610,9 +3445,7 @@ def scramble( size = UINT64_u(stream.read(8))[0] - 24 texts[addr] = randomized_string(size) if not skip_attachments and at.embedded_data: - texts[at.address + v4c.AT_COMMON_SIZE] = randomized_string( - at.embedded_size - ) + texts[at.address + v4c.AT_COMMON_SIZE] = randomized_string(at.embedded_size) for idx, gp in enumerate(mdf.groups, 1): addr = gp.data_group.comment_addr @@ -3633,9 +3466,7 @@ def scramble( source = cg.acq_source_addr if source: - source = SourceInformation( - address=source, stream=stream, mapped=False, tx_map={} - ) + source = SourceInformation(address=source, stream=stream, mapped=False, tx_map={}) for addr in ( source.name_addr, source.path_addr, @@ -3655,9 +3486,7 @@ def scramble( source = ch.source_addr if source: - source = SourceInformation( - address=source, stream=stream, mapped=False, tx_map={} - ) + source = SourceInformation(address=source, stream=stream, mapped=False, tx_map={}) for addr in ( source.name_addr, source.path_addr, @@ -3713,9 +3542,7 @@ def scramble( return TERMINATED except: - print( - f"Error while scrambling the file: {format_exc()}.\nWill now use fallback method" - ) + print(f"Error while scrambling the file: {format_exc()}.\nWill now use fallback method") texts = MDF._fallback_scramble_mf4(name) mdf.close() @@ -3970,9 +3797,7 @@ def get_group( channels = [ (None, gp_index, ch_index) - for gp_index, channel_indexes in self.included_channels(index)[ - index - ].items() + for gp_index, channel_indexes in self.included_channels(index)[index].items() for ch_index in channel_indexes ] @@ -4121,9 +3946,7 @@ def iter_to_dataframe( assert raster > 0 except (TypeError, ValueError): if isinstance(raster, str): - raster = self.get( - raster, raw=True, ignore_invalidation_bits=True - ).timestamps + raster = self.get(raster, raw=True, ignore_invalidation_bits=True).timestamps else: raster = np.array(raster) else: @@ -4174,17 +3997,13 @@ def iter_to_dataframe( if group_cycles == 0 and empty_channels == "skip": continue - record_offset = max( - np.searchsorted(masters[group_index], start).flatten()[0] - 1, 0 - ) + record_offset = max(np.searchsorted(masters[group_index], start).flatten()[0] - 1, 0) stop = np.searchsorted(masters[group_index], end).flatten()[0] record_count = min(stop - record_offset + 1, group_cycles) channels = [ (None, gp_index, ch_index) - for gp_index, channel_indexes in self.included_channels( - group_index - )[group_index].items() + for gp_index, channel_indexes in self.included_channels(group_index)[group_index].items() for ch_index in channel_indexes ] signals = [ @@ -4208,14 +4027,10 @@ def iter_to_dataframe( if len(sig) == 0: if empty_channels == "zeros": sig.samples = np.zeros( - len(master) - if virtual_group.cycles_nr == 0 - else virtual_group.cycles_nr, + len(master) if virtual_group.cycles_nr == 0 else virtual_group.cycles_nr, dtype=sig.samples.dtype, ) - sig.timestamps = ( - master if virtual_group.cycles_nr == 0 else group_master - ) + sig.timestamps = master if virtual_group.cycles_nr == 0 else group_master if not raw: if ignore_value2text_conversions: @@ -4226,18 +4041,13 @@ def iter_to_dataframe( for signal in signals: conversion = signal.conversion - if ( - conversion - and conversion.conversion_type < text_conversion - ): + if conversion and conversion.conversion_type < text_conversion: signal.samples = conversion.convert(signal.samples) else: for signal in signals: if signal.conversion: - signal.samples = signal.conversion.convert( - signal.samples - ) + signal.samples = signal.conversion.convert(signal.samples) for s_index, sig in enumerate(signals): sig = sig.validate(copy=False) @@ -4245,14 +4055,10 @@ def iter_to_dataframe( if len(sig) == 0: if empty_channels == "zeros": sig.samples = np.zeros( - len(master) - if virtual_group.cycles_nr == 0 - else virtual_group.cycles_nr, + len(master) if virtual_group.cycles_nr == 0 else virtual_group.cycles_nr, dtype=sig.samples.dtype, ) - sig.timestamps = ( - master if virtual_group.cycles_nr == 0 else group_master - ) + sig.timestamps = master if virtual_group.cycles_nr == 0 else group_master signals[s_index] = sig @@ -4260,9 +4066,7 @@ def iter_to_dataframe( same_master = np.array_equal(master, group_master) if not same_master and interpolate_outwards_with_nan: - idx = np.argwhere( - (master >= group_master[0]) & (master <= group_master[-1]) - ).flatten() + idx = np.argwhere((master >= group_master[0]) & (master <= group_master[-1])).flatten() cycles = len(group_master) @@ -4310,20 +4114,12 @@ def iter_to_dataframe( if sig.timestamps.dtype.byteorder not in target_byte_order: sig.timestamps = sig.timestamps.byteswap().newbyteorder() - sig_index = ( - index - if len(sig) == size - else pd.Index(sig.timestamps, tupleize_cols=False) - ) + sig_index = index if len(sig) == size else pd.Index(sig.timestamps, tupleize_cols=False) # byte arrays if len(sig.samples.shape) > 1: if use_display_names: - channel_name = ( - list(sig.display_names)[0] - if sig.display_names - else sig.name - ) + channel_name = list(sig.display_names)[0] if sig.display_names else sig.name else: channel_name = sig.name @@ -4351,11 +4147,7 @@ def iter_to_dataframe( # scalars else: if use_display_names: - channel_name = ( - list(sig.display_names)[0] - if sig.display_names - else sig.name - ) + channel_name = list(sig.display_names)[0] if sig.display_names else sig.name else: channel_name = sig.name @@ -4410,11 +4202,7 @@ def iter_to_dataframe( nonstrings[col] = series if numeric_1D_only: - nonstrings = { - col: series - for col, series in nonstrings.items() - if series.dtype.kind in "uif" - } + nonstrings = {col: series for col, series in nonstrings.items() if series.dtype.kind in "uif"} strings = {} df = pd.DataFrame(nonstrings, index=master) @@ -4599,27 +4387,20 @@ def to_dataframe( if progress.stop: return TERMINATED - for group_index, (virtual_group_index, virtual_group) in enumerate( - self.virtual_groups.items() - ): + for group_index, (virtual_group_index, virtual_group) in enumerate(self.virtual_groups.items()): if virtual_group.cycles_nr == 0 and empty_channels == "skip": continue channels = [ (None, gp_index, ch_index) - for gp_index, channel_indexes in self.included_channels( + for gp_index, channel_indexes in self.included_channels(virtual_group_index)[ virtual_group_index - )[virtual_group_index].items() + ].items() for ch_index in channel_indexes if ch_index != self.masters_db.get(gp_index, None) ] - signals = [ - signal - for signal in self.select( - channels, raw=True, copy_master=False, validate=False - ) - ] + signals = [signal for signal in self.select(channels, raw=True, copy_master=False, validate=False)] if not signals: continue @@ -4630,14 +4411,10 @@ def to_dataframe( if len(sig) == 0: if empty_channels == "zeros": sig.samples = np.zeros( - len(master) - if virtual_group.cycles_nr == 0 - else virtual_group.cycles_nr, + len(master) if virtual_group.cycles_nr == 0 else virtual_group.cycles_nr, dtype=sig.samples.dtype, ) - sig.timestamps = ( - master if virtual_group.cycles_nr == 0 else group_master - ) + sig.timestamps = master if virtual_group.cycles_nr == 0 else group_master if not raw: if ignore_value2text_conversions: @@ -4658,14 +4435,10 @@ def to_dataframe( if len(sig) == 0: if empty_channels == "zeros": sig.samples = np.zeros( - len(master) - if virtual_group.cycles_nr == 0 - else virtual_group.cycles_nr, + len(master) if virtual_group.cycles_nr == 0 else virtual_group.cycles_nr, dtype=sig.samples.dtype, ) - sig.timestamps = ( - master if virtual_group.cycles_nr == 0 else group_master - ) + sig.timestamps = master if virtual_group.cycles_nr == 0 else group_master signals[s_index] = sig @@ -4673,9 +4446,7 @@ def to_dataframe( same_master = np.array_equal(master, group_master) if not same_master and interpolate_outwards_with_nan: - idx = np.argwhere( - (master >= group_master[0]) & (master <= group_master[-1]) - ).flatten() + idx = np.argwhere((master >= group_master[0]) & (master <= group_master[-1])).flatten() cycles = len(group_master) @@ -4725,20 +4496,12 @@ def to_dataframe( if sig.timestamps.dtype.byteorder not in target_byte_order: sig.timestamps = sig.timestamps.byteswap().newbyteorder() - sig_index = ( - index - if len(sig) == size - else pd.Index(sig.timestamps, tupleize_cols=False) - ) + sig_index = index if len(sig) == size else pd.Index(sig.timestamps, tupleize_cols=False) # byte arrays if len(sig.samples.shape) > 1: if use_display_names: - channel_name = ( - list(sig.display_names)[0] - if sig.display_names - else sig.name - ) + channel_name = list(sig.display_names)[0] if sig.display_names else sig.name else: channel_name = sig.name @@ -4766,11 +4529,7 @@ def to_dataframe( # scalars else: if use_display_names: - channel_name = ( - list(sig.display_names)[0] - if sig.display_names - else sig.name - ) + channel_name = list(sig.display_names)[0] if sig.display_names else sig.name else: channel_name = sig.name @@ -4783,9 +4542,7 @@ def to_dataframe( if sig.samples.dtype.byteorder not in target_byte_order: sig.samples = sig.samples.byteswap().newbyteorder() - df[channel_name] = pd.Series( - sig.samples, index=sig_index, fastpath=True - ) + df[channel_name] = pd.Series(sig.samples, index=sig_index, fastpath=True) if progress is not None: if callable(progress): @@ -4805,11 +4562,7 @@ def to_dataframe( nonstrings[col] = series if numeric_1D_only: - nonstrings = { - col: series - for col, series in nonstrings.items() - if series.dtype.kind in "uif" - } + nonstrings = {col: series for col, series in nonstrings.items() if series.dtype.kind in "uif"} strings = {} df = pd.DataFrame(nonstrings, index=master) @@ -5023,9 +4776,7 @@ def _extract_can_logging( else: messages = {message.arbitration_id.id: message for message in dbc} - current_not_found_ids = { - (msg_id, message.name) for msg_id, message in messages.items() - } + current_not_found_ids = {(msg_id, message.name) for msg_id, message in messages.items()} msg_map = {} @@ -5049,14 +4800,11 @@ def _extract_can_logging( group=i, data=fragment, samples_only=True, - )[0].astype(" self.timestamps[0] - ): + if include_ends and original_start not in self.timestamps and original_start > self.timestamps[0]: interpolated = self.interp( [original_start], integer_interpolation_mode=integer_interpolation_mode, float_interpolation_mode=float_interpolation_mode, ) if len(interpolated): - samples = np.append( - interpolated.samples, self.samples[start:], axis=0 - ) - timestamps = np.append( - interpolated.timestamps, self.timestamps[start:] - ) + samples = np.append(interpolated.samples, self.samples[start:], axis=0) + timestamps = np.append(interpolated.timestamps, self.timestamps[start:]) if self.invalidation_bits is not None: invalidation_bits = np.append( interpolated.invalidation_bits, @@ -697,9 +669,7 @@ def cut( if start == stop: if include_ends: if original_start == original_stop: - ends = np.array( - [original_start], dtype=self.timestamps.dtype - ) + ends = np.array([original_start], dtype=self.timestamps.dtype) else: ends = np.array( [original_start, original_stop], @@ -725,9 +695,7 @@ def cut( samples = self.samples[start:stop].copy() timestamps = self.timestamps[start:stop].copy() if self.invalidation_bits is not None: - invalidation_bits = self.invalidation_bits[ - start:stop - ].copy() + invalidation_bits = self.invalidation_bits[start:stop].copy() else: invalidation_bits = None @@ -743,12 +711,8 @@ def cut( ) if len(interpolated): - samples = np.append( - samples, interpolated.samples, axis=0 - ) - timestamps = np.append( - timestamps, interpolated.timestamps - ) + samples = np.append(samples, interpolated.samples, axis=0) + timestamps = np.append(timestamps, interpolated.timestamps) if invalidation_bits is not None: invalidation_bits = np.append( invalidation_bits, @@ -767,12 +731,8 @@ def cut( ) if len(interpolated): - samples = np.append( - interpolated.samples, samples, axis=0 - ) - timestamps = np.append( - interpolated.timestamps, timestamps - ) + samples = np.append(interpolated.samples, samples, axis=0) + timestamps = np.append(interpolated.timestamps, timestamps) if invalidation_bits is not None: invalidation_bits = np.append( @@ -832,17 +792,11 @@ def extend(self, other: Signal) -> Signal: if self.invalidation_bits is None and other.invalidation_bits is None: invalidation_bits = None elif self.invalidation_bits is None and other.invalidation_bits is not None: - invalidation_bits = np.concatenate( - (np.zeros(len(self), dtype=bool), other.invalidation_bits) - ) + invalidation_bits = np.concatenate((np.zeros(len(self), dtype=bool), other.invalidation_bits)) elif self.invalidation_bits is not None and other.invalidation_bits is None: - invalidation_bits = np.concatenate( - (self.invalidation_bits, np.zeros(len(other), dtype=bool)) - ) + invalidation_bits = np.concatenate((self.invalidation_bits, np.zeros(len(other), dtype=bool))) else: - invalidation_bits = np.append( - self.invalidation_bits, other.invalidation_bits - ) + invalidation_bits = np.append(self.invalidation_bits, other.invalidation_bits) result = Signal( np.append(self.samples, other.samples, axis=0), @@ -957,9 +911,7 @@ def interp( master_metadata=self.master_metadata, display_names=self.display_names, attachment=self.attachment, - invalidation_bits=None - if invalidation_bits is None - else np.array([], dtype=bool), + invalidation_bits=None if invalidation_bits is None else np.array([], dtype=bool), encoding=self.encoding, group_index=self.group_index, channel_index=self.channel_index, @@ -977,13 +929,8 @@ def interp( kind = signal.samples.dtype.kind if kind == "f": - if ( - float_interpolation_mode - == FloatInterpolation.REPEAT_PREVIOUS_SAMPLE - ): - idx = np.searchsorted( - signal.timestamps, new_timestamps, side="right" - ) + if float_interpolation_mode == FloatInterpolation.REPEAT_PREVIOUS_SAMPLE: + idx = np.searchsorted(signal.timestamps, new_timestamps, side="right") idx -= 1 idx[idx < 0] = 0 s = signal.samples[idx] @@ -995,58 +942,32 @@ def interp( s = np.interp(new_timestamps, signal.timestamps, signal.samples) if invalidation_bits is not None: - idx = np.searchsorted( - signal.timestamps, new_timestamps, side="right" - ) + idx = np.searchsorted(signal.timestamps, new_timestamps, side="right") idx -= 1 idx[idx < 0] = 0 invalidation_bits = invalidation_bits[idx] elif kind in "ui": - if ( - integer_interpolation_mode - == IntegerInterpolation.HYBRID_INTERPOLATION - ): + if integer_interpolation_mode == IntegerInterpolation.HYBRID_INTERPOLATION: if signal.raw and signal.conversion: - kind = signal.conversion.convert( - signal.samples[:1] - ).dtype.kind + kind = signal.conversion.convert(signal.samples[:1]).dtype.kind if kind == "f": - integer_interpolation_mode = ( - IntegerInterpolation.LINEAR_INTERPOLATION - ) + integer_interpolation_mode = IntegerInterpolation.LINEAR_INTERPOLATION - if ( - integer_interpolation_mode - == IntegerInterpolation.HYBRID_INTERPOLATION - ): - integer_interpolation_mode = ( - IntegerInterpolation.REPEAT_PREVIOUS_SAMPLE - ) + if integer_interpolation_mode == IntegerInterpolation.HYBRID_INTERPOLATION: + integer_interpolation_mode = IntegerInterpolation.REPEAT_PREVIOUS_SAMPLE - if ( - integer_interpolation_mode - == IntegerInterpolation.LINEAR_INTERPOLATION - ): - s = np.interp( - new_timestamps, signal.timestamps, signal.samples - ).astype(signal.samples.dtype) + if integer_interpolation_mode == IntegerInterpolation.LINEAR_INTERPOLATION: + s = np.interp(new_timestamps, signal.timestamps, signal.samples).astype(signal.samples.dtype) if invalidation_bits is not None: - idx = np.searchsorted( - signal.timestamps, new_timestamps, side="right" - ) + idx = np.searchsorted(signal.timestamps, new_timestamps, side="right") idx -= 1 idx[idx < 0] = 0 invalidation_bits = invalidation_bits[idx] - elif ( - integer_interpolation_mode - == IntegerInterpolation.REPEAT_PREVIOUS_SAMPLE - ): - idx = np.searchsorted( - signal.timestamps, new_timestamps, side="right" - ) + elif integer_interpolation_mode == IntegerInterpolation.REPEAT_PREVIOUS_SAMPLE: + idx = np.searchsorted(signal.timestamps, new_timestamps, side="right") idx -= 1 idx[idx < 0] = 0 @@ -1056,9 +977,7 @@ def interp( invalidation_bits = invalidation_bits[idx] else: - idx = np.searchsorted( - signal.timestamps, new_timestamps, side="right" - ) + idx = np.searchsorted(signal.timestamps, new_timestamps, side="right") idx -= 1 idx[idx < 0] = 0 s = signal.samples[idx] @@ -1088,9 +1007,7 @@ def interp( flags=self.flags, ) - def __apply_func( - self, other: Signal | NDArray[Any] | None, func_name: str - ) -> Signal: + def __apply_func(self, other: Signal | NDArray[Any] | None, func_name: str) -> Signal: """delegate operations to the *samples* attribute, but in a time correct manner by considering the *timestamps* @@ -1435,9 +1352,7 @@ def copy(self) -> Signal: self.attachment, self.source, self.bit_count, - invalidation_bits=self.invalidation_bits.copy() - if self.invalidation_bits is not None - else None, + invalidation_bits=self.invalidation_bits.copy() if self.invalidation_bits is not None else None, encoding=self.encoding, group_index=self.group_index, channel_index=self.channel_index, diff --git a/src/asammdf/types.py b/src/asammdf/types.py index ce97c34a9..a943d070a 100644 --- a/src/asammdf/types.py +++ b/src/asammdf/types.py @@ -26,13 +26,9 @@ # asammdf specific types BusType = Literal["CAN", "LIN"] -ChannelConversionType = Union[ - "v2_v3_blocks.ChannelConversion", "v4_blocks.ChannelConversion" -] +ChannelConversionType = Union["v2_v3_blocks.ChannelConversion", "v4_blocks.ChannelConversion"] ChannelGroupType = Union["v2_v3_blocks.ChannelGroup", "v4_blocks.ChannelGroup"] -ChannelsType = Union[ - Sequence[str], Sequence[Tuple[Optional[str], int, int]], Sequence[Tuple[str, int]] -] +ChannelsType = Union[Sequence[str], Sequence[Tuple[Optional[str], int, int]], Sequence[Tuple[str, int]]] ChannelType = Union["v2_v3_blocks.Channel", "v4_blocks.Channel"] CompressionType = Literal[0, 1, 2] DataGroupType = Union["v2_v3_blocks.DataGroup", "v4_blocks.DataGroup"] @@ -43,7 +39,5 @@ IntInterpolationModeType = Literal[0, 1, 2] MDF_v2_v3_v4 = Union["MDF2", "MDF3", "MDF4"] RasterType = Union[float, str, NDArray[Any]] -SourceType = Union[ - "v2_v3_blocks.ChannelExtension", "v4_blocks.SourceInformation", "Source" -] +SourceType = Union["v2_v3_blocks.ChannelExtension", "v4_blocks.SourceInformation", "Source"] SyncType = Literal[0, 1, 2, 3, 4] diff --git a/test/asammdf/gui/dialogs/test_FunctionsManagerDialog.py b/test/asammdf/gui/dialogs/test_FunctionsManagerDialog.py index 8fda061de..e7b80f9ae 100644 --- a/test/asammdf/gui/dialogs/test_FunctionsManagerDialog.py +++ b/test/asammdf/gui/dialogs/test_FunctionsManagerDialog.py @@ -37,19 +37,13 @@ def test_PushButton_Add(self): - Ensure that two items will be added in functions list """ # Events: - QtTest.QTest.mouseClick( - self.fm.widget.add_btn, QtCore.Qt.MouseButton.LeftButton - ) - QtTest.QTest.mouseClick( - self.fm.widget.add_btn, QtCore.Qt.MouseButton.LeftButton - ) + QtTest.QTest.mouseClick(self.fm.widget.add_btn, QtCore.Qt.MouseButton.LeftButton) + QtTest.QTest.mouseClick(self.fm.widget.add_btn, QtCore.Qt.MouseButton.LeftButton) # Evaluate self.assertEqual(2, self.fm.widget.functions_list.count()) for index in range(3, 1): - self.assertEqual( - f"Function{index}", self.fm.widget.functions_list.item(index - 1) - ) + self.assertEqual(f"Function{index}", self.fm.widget.functions_list.item(index - 1)) def test_PushButton_DeleteAll(self): """ @@ -65,22 +59,14 @@ def test_PushButton_DeleteAll(self): - Evaluate that items are deleted from functions list. """ # Events: - QtTest.QTest.mouseClick( - self.fm.widget.add_btn, QtCore.Qt.MouseButton.LeftButton - ) - QtTest.QTest.mouseClick( - self.fm.widget.add_btn, QtCore.Qt.MouseButton.LeftButton - ) + QtTest.QTest.mouseClick(self.fm.widget.add_btn, QtCore.Qt.MouseButton.LeftButton) + QtTest.QTest.mouseClick(self.fm.widget.add_btn, QtCore.Qt.MouseButton.LeftButton) self.assertEqual(2, self.fm.widget.functions_list.count()) for index in range(3, 1): - self.assertEqual( - f"Function{index}", self.fm.widget.functions_list.item(index - 1) - ) + self.assertEqual(f"Function{index}", self.fm.widget.functions_list.item(index - 1)) - QtTest.QTest.mouseClick( - self.fm.widget.erase_btn, QtCore.Qt.MouseButton.LeftButton - ) + QtTest.QTest.mouseClick(self.fm.widget.erase_btn, QtCore.Qt.MouseButton.LeftButton) # Evaluate self.assertEqual(0, self.fm.widget.functions_list.count()) @@ -102,18 +88,14 @@ def test_PushButton_LoadDefinitions_0(self): "asammdf.gui.widgets.functions_manager.QtWidgets.QFileDialog.getOpenFileName" ) as mc_getOpenFileName: mc_getOpenFileName.return_value = definition_file, None - QtTest.QTest.mouseClick( - self.fm.widget.import_btn, QtCore.Qt.MouseButton.LeftButton - ) + QtTest.QTest.mouseClick(self.fm.widget.import_btn, QtCore.Qt.MouseButton.LeftButton) # Evaluate self.assertEqual(4, self.fm.widget.functions_list.count()) self.assertEqual("Function1", self.fm.widget.functions_list.item(0).text()) self.assertEqual("gray2dec", self.fm.widget.functions_list.item(1).text()) self.assertEqual("maximum", self.fm.widget.functions_list.item(2).text()) - self.assertEqual( - "rpm_to_rad_per_second", self.fm.widget.functions_list.item(3).text() - ) + self.assertEqual("rpm_to_rad_per_second", self.fm.widget.functions_list.item(3).text()) def test_PushButton_LoadDefinitions_1(self): """ @@ -132,9 +114,7 @@ def test_PushButton_LoadDefinitions_1(self): "asammdf.gui.widgets.functions_manager.QtWidgets.QFileDialog.getOpenFileName" ) as mc_getOpenFileName: mc_getOpenFileName.return_value = definition_file, None - QtTest.QTest.mouseClick( - self.fm.widget.import_btn, QtCore.Qt.MouseButton.LeftButton - ) + QtTest.QTest.mouseClick(self.fm.widget.import_btn, QtCore.Qt.MouseButton.LeftButton) # Evaluate self.assertEqual(0, self.fm.widget.functions_list.count()) @@ -155,9 +135,7 @@ def test_PushButton_LoadDefinitions_2(self): "asammdf.gui.widgets.functions_manager.QtWidgets.QFileDialog.getOpenFileName" ) as mc_getOpenFileName: mc_getOpenFileName.return_value = None, None - QtTest.QTest.mouseClick( - self.fm.widget.import_btn, QtCore.Qt.MouseButton.LeftButton - ) + QtTest.QTest.mouseClick(self.fm.widget.import_btn, QtCore.Qt.MouseButton.LeftButton) # Evaluate self.assertEqual(0, self.fm.widget.functions_list.count()) @@ -182,9 +160,7 @@ def test_PushButton_LoadDefinitions_3(self): "asammdf.gui.widgets.functions_manager.QtWidgets.QFileDialog.getOpenFileName" ) as mc_getOpenFileName: mc_getOpenFileName.return_value = definition_file, None - QtTest.QTest.mouseClick( - self.fm.widget.import_btn, QtCore.Qt.MouseButton.LeftButton - ) + QtTest.QTest.mouseClick(self.fm.widget.import_btn, QtCore.Qt.MouseButton.LeftButton) # Evaluate self.assertEqual(0, self.fm.widget.functions_list.count()) @@ -215,9 +191,7 @@ def test_PushButton_LoadDefinitions_4(self): "asammdf.gui.widgets.functions_manager.QtWidgets.QFileDialog.getOpenFileName" ) as mc_getOpenFileName: mc_getOpenFileName.return_value = definition_file, None - QtTest.QTest.mouseClick( - self.fm.widget.import_btn, QtCore.Qt.MouseButton.LeftButton - ) + QtTest.QTest.mouseClick(self.fm.widget.import_btn, QtCore.Qt.MouseButton.LeftButton) # Evaluate self.assertEqual(0, self.fm.widget.functions_list.count()) @@ -236,25 +210,19 @@ def test_PushButton_SaveDefinitions(self): - Evaluate that new function is present in saved file. """ # Event - QtTest.QTest.mouseClick( - self.fm.widget.add_btn, QtCore.Qt.MouseButton.LeftButton - ) + QtTest.QTest.mouseClick(self.fm.widget.add_btn, QtCore.Qt.MouseButton.LeftButton) saved_file = pathlib.Path(self.test_workspace, f"{self.id()}.def") with mock.patch( "asammdf.gui.widgets.functions_manager.QtWidgets.QFileDialog.getSaveFileName" ) as mc_getSaveFileName: mc_getSaveFileName.return_value = str(saved_file), None - QtTest.QTest.mouseClick( - self.fm.widget.export_btn, QtCore.Qt.MouseButton.LeftButton - ) + QtTest.QTest.mouseClick(self.fm.widget.export_btn, QtCore.Qt.MouseButton.LeftButton) # Evaluate self.assertTrue(saved_file.exists()) with open(saved_file, "r") as fpr: content = json.load(fpr) - self.assertDictEqual( - content, {"Function1": "def Function1(t=0):\n return 0"} - ) + self.assertDictEqual(content, {"Function1": "def Function1(t=0):\n return 0"}) def test_PushButton_CheckSyntax_0(self): """ @@ -268,9 +236,7 @@ def test_PushButton_CheckSyntax_0(self): - Evaluate that python function is evaluated as valid. """ # Event - QtTest.QTest.mouseClick( - self.fm.widget.add_btn, QtCore.Qt.MouseButton.LeftButton - ) + QtTest.QTest.mouseClick(self.fm.widget.add_btn, QtCore.Qt.MouseButton.LeftButton) for f in ( Function1, @@ -285,9 +251,7 @@ def test_PushButton_CheckSyntax_0(self): self.fm.widget.function_definition.clear() self.fm.widget.function_definition.setPlainText(source) - with mock.patch( - "asammdf.gui.utils.MessageBox.information" - ) as mc_information: + with mock.patch("asammdf.gui.utils.MessageBox.information") as mc_information: QtTest.QTest.mouseClick( self.fm.widget.check_syntax_btn, QtCore.Qt.MouseButton.LeftButton, @@ -309,9 +273,7 @@ def test_PushButton_CheckSyntax_1(self): - Evaluate that python function is evaluated as valid. """ # Event - QtTest.QTest.mouseClick( - self.fm.widget.add_btn, QtCore.Qt.MouseButton.LeftButton - ) + QtTest.QTest.mouseClick(self.fm.widget.add_btn, QtCore.Qt.MouseButton.LeftButton) for f in ( Function2, @@ -325,9 +287,7 @@ def test_PushButton_CheckSyntax_1(self): self.fm.widget.function_definition.clear() self.fm.widget.function_definition.setPlainText(source) - with mock.patch( - "asammdf.gui.utils.MessageBox.information" - ) as mc_information: + with mock.patch("asammdf.gui.utils.MessageBox.information") as mc_information: QtTest.QTest.mouseClick( self.fm.widget.check_syntax_btn, QtCore.Qt.MouseButton.LeftButton, @@ -351,26 +311,20 @@ def test_PushButton_StoreFunctionChanges_0(self): - Evaluate that content of the function was changed. """ # Events: - QtTest.QTest.mouseClick( - self.fm.widget.add_btn, QtCore.Qt.MouseButton.LeftButton - ) + QtTest.QTest.mouseClick(self.fm.widget.add_btn, QtCore.Qt.MouseButton.LeftButton) source = inspect.getsource(maximum) self.fm.widget.function_definition.clear() self.fm.widget.function_definition.setPlainText(source) - QtTest.QTest.mouseClick( - self.fm.widget.store_btn, QtCore.Qt.MouseButton.LeftButton - ) + QtTest.QTest.mouseClick(self.fm.widget.store_btn, QtCore.Qt.MouseButton.LeftButton) saved_file = pathlib.Path(self.test_workspace, f"{self.id()}.def") with mock.patch( "asammdf.gui.widgets.functions_manager.QtWidgets.QFileDialog.getSaveFileName" ) as mc_getSaveFileName: mc_getSaveFileName.return_value = str(saved_file), None - QtTest.QTest.mouseClick( - self.fm.widget.export_btn, QtCore.Qt.MouseButton.LeftButton - ) + QtTest.QTest.mouseClick(self.fm.widget.export_btn, QtCore.Qt.MouseButton.LeftButton) # Evaluate self.assertTrue(saved_file.exists()) @@ -392,12 +346,8 @@ def test_PushButton_StoreFunctionChanges_1(self): - Evaluate that overwriting is not possible """ # Events: - QtTest.QTest.mouseClick( - self.fm.widget.add_btn, QtCore.Qt.MouseButton.LeftButton - ) - QtTest.QTest.mouseClick( - self.fm.widget.add_btn, QtCore.Qt.MouseButton.LeftButton - ) + QtTest.QTest.mouseClick(self.fm.widget.add_btn, QtCore.Qt.MouseButton.LeftButton) + QtTest.QTest.mouseClick(self.fm.widget.add_btn, QtCore.Qt.MouseButton.LeftButton) self.mouseClick_WidgetItem(self.fm.widget.functions_list.item(0)) function1 = self.fm.widget.function_definition.toPlainText() @@ -406,12 +356,8 @@ def test_PushButton_StoreFunctionChanges_1(self): self.fm.widget.function_definition.clear() self.fm.widget.function_definition.setPlainText(function1) - with mock.patch( - "asammdf.gui.widgets.functions_manager.MessageBox.information" - ) as mc_information: - QtTest.QTest.mouseClick( - self.fm.widget.store_btn, QtCore.Qt.MouseButton.LeftButton - ) + with mock.patch("asammdf.gui.widgets.functions_manager.MessageBox.information") as mc_information: + QtTest.QTest.mouseClick(self.fm.widget.store_btn, QtCore.Qt.MouseButton.LeftButton) mc_information.assert_called() @@ -429,20 +375,14 @@ def test_PushButton_Apply(self): - Evaluate that definitions attribute is the same. """ # Events - QtTest.QTest.mouseClick( - self.fm.widget.add_btn, QtCore.Qt.MouseButton.LeftButton - ) - QtTest.QTest.mouseClick( - self.fm.widget.add_btn, QtCore.Qt.MouseButton.LeftButton - ) + QtTest.QTest.mouseClick(self.fm.widget.add_btn, QtCore.Qt.MouseButton.LeftButton) + QtTest.QTest.mouseClick(self.fm.widget.add_btn, QtCore.Qt.MouseButton.LeftButton) definitions = copy.deepcopy(self.fm.widget.definitions) self.fm.widget.function_definition.clear() source = inspect.getsource(maximum) self.fm.widget.function_definition.setPlainText(source) - QtTest.QTest.mouseClick( - self.fm.widget.store_btn, QtCore.Qt.MouseButton.LeftButton - ) + QtTest.QTest.mouseClick(self.fm.widget.store_btn, QtCore.Qt.MouseButton.LeftButton) QtTest.QTest.mouseClick(self.fm.apply_btn, QtCore.Qt.MouseButton.LeftButton) self.assertEqual("apply", self.fm.pressed_button) @@ -462,19 +402,13 @@ def test_PushButton_Cancel(self): - Evaluate that definitions attribute is the same. """ # Events - QtTest.QTest.mouseClick( - self.fm.widget.add_btn, QtCore.Qt.MouseButton.LeftButton - ) - QtTest.QTest.mouseClick( - self.fm.widget.add_btn, QtCore.Qt.MouseButton.LeftButton - ) + QtTest.QTest.mouseClick(self.fm.widget.add_btn, QtCore.Qt.MouseButton.LeftButton) + QtTest.QTest.mouseClick(self.fm.widget.add_btn, QtCore.Qt.MouseButton.LeftButton) self.fm.widget.function_definition.clear() source = inspect.getsource(maximum) self.fm.widget.function_definition.setPlainText(source) - QtTest.QTest.mouseClick( - self.fm.widget.store_btn, QtCore.Qt.MouseButton.LeftButton - ) + QtTest.QTest.mouseClick(self.fm.widget.store_btn, QtCore.Qt.MouseButton.LeftButton) QtTest.QTest.mouseClick(self.fm.cancel_btn, QtCore.Qt.MouseButton.LeftButton) self.assertEqual("cancel", self.fm.pressed_button) @@ -484,9 +418,7 @@ def test_PushButton_Cancel(self): class TestTreeWidget(TestBase): def setUp(self) -> None: super().setUp() - self.fm = FunctionsManagerDialog( - {"Function10": "def Function10(t=0):\n return 0"} - ) + self.fm = FunctionsManagerDialog({"Function10": "def Function10(t=0):\n return 0"}) def test_KeyPress_Delete(self): """ @@ -503,9 +435,7 @@ def test_KeyPress_Delete(self): """ # Events: for _ in range(3): - QtTest.QTest.mouseClick( - self.fm.widget.add_btn, QtCore.Qt.MouseButton.LeftButton - ) + QtTest.QTest.mouseClick(self.fm.widget.add_btn, QtCore.Qt.MouseButton.LeftButton) self.assertEqual(4, self.fm.widget.functions_list.count()) self.mouseClick_WidgetItem(self.fm.widget.functions_list.item(2)) @@ -528,9 +458,7 @@ def test_FunctionDefinition_ContentUpdate(self): - Evaluate that content of function definition is changed. """ # Event - QtTest.QTest.mouseClick( - self.fm.widget.add_btn, QtCore.Qt.MouseButton.LeftButton - ) + QtTest.QTest.mouseClick(self.fm.widget.add_btn, QtCore.Qt.MouseButton.LeftButton) self.assertEqual(2, self.fm.widget.functions_list.count()) self.mouseClick_WidgetItem(self.fm.widget.functions_list.item(0)) diff --git a/test/asammdf/gui/test_base.py b/test/asammdf/gui/test_base.py index acd0341c2..92e94eadb 100644 --- a/test/asammdf/gui/test_base.py +++ b/test/asammdf/gui/test_base.py @@ -40,9 +40,7 @@ class DragAndDrop app.setApplicationName("py-asammdf") -@unittest.skipIf( - sys.platform == "darwin", "Test Development on MacOS was not done yet." -) +@unittest.skipIf(sys.platform == "darwin", "Test Development on MacOS was not done yet.") class TestBase(unittest.TestCase): """ - setUp and tearDown test workspace @@ -53,9 +51,7 @@ class TestBase(unittest.TestCase): longMessage = False resource = os.path.normpath(os.path.join(os.path.dirname(__file__), "resources")) - test_workspace = os.path.join( - os.path.join(os.path.dirname(__file__), "test_workspace") - ) + test_workspace = os.path.join(os.path.join(os.path.dirname(__file__), "test_workspace")) patchers = [] # MockClass ErrorDialog mc_ErrorDialog = None @@ -163,9 +159,7 @@ def run(self): QtTest.QTest.mouseMove(self.widget, self.position) else: for step in range(self.step): - QtTest.QTest.mouseMove( - self.widget, self.position + QtCore.QPoint(step, step) - ) + QtTest.QTest.mouseMove(self.widget, self.position + QtCore.QPoint(step, step)) QtTest.QTest.qWait(2) QtTest.QTest.qWait(10) # Release @@ -180,9 +174,7 @@ def run(self): def __init__(self, source_widget, destination_widget, source_pos, destination_pos): # Ensure that previous drop was not in the same place because mouse needs to be moved. if self._previous_position and self._previous_position == destination_pos: - move_thread = DragAndDrop.MoveThread( - widget=source_widget, position=QtCore.QPoint(101, 101) - ) + move_thread = DragAndDrop.MoveThread(widget=source_widget, position=QtCore.QPoint(101, 101)) move_thread.start() move_thread.wait() move_thread.quit() @@ -208,9 +200,7 @@ def __init__(self, source_widget, destination_widget, source_pos, destination_po destination_viewport = destination_widget.viewport() else: destination_viewport = destination_widget - move_thread = DragAndDrop.MoveThread( - widget=destination_viewport, position=destination_pos - ) + move_thread = DragAndDrop.MoveThread(widget=destination_viewport, position=destination_pos) move_thread.start() source_widget.startDrag(QtCore.Qt.MoveAction) diff --git a/test/asammdf/gui/test_util.py b/test/asammdf/gui/test_util.py index e4ea542fc..e35fb5ba4 100644 --- a/test/asammdf/gui/test_util.py +++ b/test/asammdf/gui/test_util.py @@ -90,9 +90,7 @@ def test_GeneratePythonFunction_Exception(self): - Evaluate trace. (position 1) """ # Event - result = generate_python_function( - rf"def Function1(t=0):\n return true", None - ) + result = generate_python_function(rf"def Function1(t=0):\n return true", None) # Evaluate self.assertIsInstance(result, tuple) @@ -126,9 +124,7 @@ def test_GeneratePythonFunction_Args(self): trace = 'The last function argument must be "t=0"' # Event - result = generate_python_function( - f"def Function1(t=0, x=0):\n\treturn 0", None - ) + result = generate_python_function(f"def Function1(t=0, x=0):\n\treturn 0", None) # Evaluate self.assertIsInstance(result, tuple) @@ -150,9 +146,7 @@ def test_GeneratePythonFunction_Args(self): trace = 'All the arguments must have default values. The argument "channel" has no default value.' # Event - result = generate_python_function( - f"def Function1(channel, t=0):\n\treturn 0", None - ) + result = generate_python_function(f"def Function1(channel, t=0):\n\treturn 0", None) # Evaluate self.assertIsInstance(result, tuple) diff --git a/test/asammdf/gui/widgets/test_BaseFileWidget.py b/test/asammdf/gui/widgets/test_BaseFileWidget.py index a59a453aa..868eb32db 100644 --- a/test/asammdf/gui/widgets/test_BaseFileWidget.py +++ b/test/asammdf/gui/widgets/test_BaseFileWidget.py @@ -8,6 +8,7 @@ class TestFileWidget(TestBase): def setUp(self): super().setUp() self.widget = None + self.plot = None patcher = mock.patch("asammdf.gui.widgets.file.ErrorDialog") self.mc_widget_ed = patcher.start() @@ -42,6 +43,7 @@ def setUpFileWidget(self, *args, measurement_file, default): else: self.widget = FileWidget(measurement_file, *args) self.widget.showNormal() + self.processEvents() def get_subwindows(self): widget_types = sorted( diff --git a/test/asammdf/gui/widgets/test_BasePlotWidget.py b/test/asammdf/gui/widgets/test_BasePlotWidget.py index d6fc6a6be..56b86d94d 100644 --- a/test/asammdf/gui/widgets/test_BasePlotWidget.py +++ b/test/asammdf/gui/widgets/test_BasePlotWidget.py @@ -16,7 +16,10 @@ class Column: measurement_file = str(pathlib.Path(TestFileWidget.resource, "ASAP2_Demo_V171.mf4")) - def add_channel_to_plot(self, plot, channel_name=None, channel_index=None): + def add_channel_to_plot(self, plot=None, channel_name=None, channel_index=None): + if not plot and self.plot: + plot = self.plot + # Select channel selected_channel = None channel_tree = self.widget.channels_tree @@ -59,13 +62,9 @@ def add_channel_to_plot(self, plot, channel_name=None, channel_index=None): return plot_channel def create_window(self, window_type): - with mock.patch( - "asammdf.gui.widgets.file.WindowSelectionDialog" - ) as mc_WindowSelectionDialog: + with mock.patch("asammdf.gui.widgets.file.WindowSelectionDialog") as mc_WindowSelectionDialog: mc_WindowSelectionDialog.return_value.result.return_value = True - mc_WindowSelectionDialog.return_value.selected_type.return_value = ( - window_type - ) + mc_WindowSelectionDialog.return_value.selected_type.return_value = window_type # - Press PushButton "Create Window" QtTest.QTest.mouseClick(self.widget.create_window_btn, QtCore.Qt.LeftButton) widget_types = self.get_subwindows() diff --git a/test/asammdf/gui/widgets/test_FileWidget_TabChannels.py b/test/asammdf/gui/widgets/test_FileWidget_TabChannels.py index bba7f83c8..56bc28014 100644 --- a/test/asammdf/gui/widgets/test_FileWidget_TabChannels.py +++ b/test/asammdf/gui/widgets/test_FileWidget_TabChannels.py @@ -34,9 +34,7 @@ def test_PushButton_LoadOfflineWindows_DSP(self): # Event self.setUpFileWidget(measurement_file=measurement_file, default=True) - with mock.patch( - "asammdf.gui.widgets.file.QtWidgets.QFileDialog.getOpenFileName" - ) as mo_getOpenFileName: + with mock.patch("asammdf.gui.widgets.file.QtWidgets.QFileDialog.getOpenFileName") as mo_getOpenFileName: mo_getOpenFileName.return_value = valid_dsp, None QtTest.QTest.mouseClick( self.widget.load_channel_list_btn, @@ -97,18 +95,10 @@ def test_PushButton_LoadOfflineWindows_DSPF(self, mc_file_ErrorDialog): # Setup measurement_file = str(pathlib.Path(self.resource, "ASAP2_Demo_V171.mf4")) valid_dspf = str(pathlib.Path(self.resource, "valid.dspf")) - invalid_json_decode_error_dspf = str( - pathlib.Path(self.resource, "invalid_JsonDecodeError.dspf") - ) - invalid_numeric_section_key_error_dspf = str( - pathlib.Path(self.resource, "invalid_NumericSectionKeyError.dspf") - ) - invalid_plot_section_key_error_dspf = str( - pathlib.Path(self.resource, "invalid_PlotSectionKeyError.dspf") - ) - invalid_tabular_section_key_error_dspf = str( - pathlib.Path(self.resource, "invalid_TabularSectionKeyError.dspf") - ) + invalid_json_decode_error_dspf = str(pathlib.Path(self.resource, "invalid_JsonDecodeError.dspf")) + invalid_numeric_section_key_error_dspf = str(pathlib.Path(self.resource, "invalid_NumericSectionKeyError.dspf")) + invalid_plot_section_key_error_dspf = str(pathlib.Path(self.resource, "invalid_PlotSectionKeyError.dspf")) + invalid_tabular_section_key_error_dspf = str(pathlib.Path(self.resource, "invalid_TabularSectionKeyError.dspf")) # Event self.setUpFileWidget(measurement_file=measurement_file, default=True) @@ -168,9 +158,7 @@ def test_PushButton_LoadOfflineWindows_DSPF(self, mc_file_ErrorDialog): # Case 3 with self.subTest("test_PushButton_LoadOfflineWindows_DSPF_3"): - with mock.patch( - "asammdf.gui.widgets.file.ErrorDialog" - ) as mc_ErrorDialog, mock.patch( + with mock.patch("asammdf.gui.widgets.file.ErrorDialog") as mc_ErrorDialog, mock.patch( "asammdf.gui.widgets.file.QtWidgets.QFileDialog.getOpenFileName" ) as mo_getOpenFileName: mo_getOpenFileName.return_value = ( @@ -190,9 +178,7 @@ def test_PushButton_LoadOfflineWindows_DSPF(self, mc_file_ErrorDialog): # Case 4 with self.subTest("test_PushButton_LoadOfflineWindows_DSPF_4"): - with mock.patch( - "asammdf.gui.widgets.file.ErrorDialog" - ) as mc_ErrorDialog, mock.patch( + with mock.patch("asammdf.gui.widgets.file.ErrorDialog") as mc_ErrorDialog, mock.patch( "asammdf.gui.widgets.file.QtWidgets.QFileDialog.getOpenFileName" ) as mo_getOpenFileName: mo_getOpenFileName.return_value = ( @@ -212,9 +198,7 @@ def test_PushButton_LoadOfflineWindows_DSPF(self, mc_file_ErrorDialog): # Case 5 with self.subTest("test_PushButton_LoadOfflineWindows_DSPF_5"): - with mock.patch( - "asammdf.gui.widgets.file.ErrorDialog" - ) as mc_ErrorDialog, mock.patch( + with mock.patch("asammdf.gui.widgets.file.ErrorDialog") as mc_ErrorDialog, mock.patch( "asammdf.gui.widgets.file.QtWidgets.QFileDialog.getOpenFileName" ) as mo_getOpenFileName: mo_getOpenFileName.return_value = ( @@ -274,12 +258,8 @@ def test_PushButton_LoadOfflineWindows_LAB(self): """ # Setup valid_lab = str(pathlib.Path(self.resource, "valid.lab")) - invalid_missing_section_lab = str( - pathlib.Path(self.resource, "invalid_MissingSection.lab") - ) - invalid_empty_section_lab = str( - pathlib.Path(self.resource, "invalid_EmptySection.lab") - ) + invalid_missing_section_lab = str(pathlib.Path(self.resource, "invalid_MissingSection.lab")) + invalid_empty_section_lab = str(pathlib.Path(self.resource, "invalid_EmptySection.lab")) measurement_file = str(pathlib.Path(self.resource, "ASAP2_Demo_V171.mf4")) # Event @@ -288,9 +268,7 @@ def test_PushButton_LoadOfflineWindows_LAB(self): self.widget.channel_view.setCurrentText("Internal file structure") # Case 0: with self.subTest("test_PushButton_LoadOfflineWindows_LAB_0"): - with mock.patch( - "asammdf.gui.widgets.file.QtWidgets.QFileDialog.getOpenFileName" - ) as mo_getOpenFileName: + with mock.patch("asammdf.gui.widgets.file.QtWidgets.QFileDialog.getOpenFileName") as mo_getOpenFileName: mo_getOpenFileName.return_value = ( invalid_empty_section_lab, None, @@ -320,9 +298,7 @@ def test_PushButton_LoadOfflineWindows_LAB(self): # Case 1: with self.subTest("test_PushButton_LoadOfflineWindows_LAB_1"): - with mock.patch( - "asammdf.gui.widgets.file.QtWidgets.QFileDialog.getOpenFileName" - ) as mo_getOpenFileName: + with mock.patch("asammdf.gui.widgets.file.QtWidgets.QFileDialog.getOpenFileName") as mo_getOpenFileName: mo_getOpenFileName.return_value = ( invalid_missing_section_lab, None, @@ -417,9 +393,7 @@ def test_PushButton_SaveOfflineWindows(self): # Switch ComboBox to "Internal file structure" self.widget.channel_view.setCurrentText("Internal file structure") - with mock.patch.object( - self.widget, "load_window", wraps=self.widget.load_window - ) as mo_load_window, mock.patch( + with mock.patch.object(self.widget, "load_window", wraps=self.widget.load_window) as mo_load_window, mock.patch( "asammdf.gui.widgets.file.QtWidgets.QFileDialog.getOpenFileName" ) as mo_getOpenFileName: mo_getOpenFileName.return_value = valid_dspf, None @@ -452,21 +426,13 @@ def test_PushButton_SaveOfflineWindows(self): item_rect = channels_tree.visualItemRect(item) drag_position = item_rect.center() - drop_position = mdi_area.viewport().rect().center() - QtCore.QPoint( - 200, 200 - ) + drop_position = mdi_area.viewport().rect().center() - QtCore.QPoint(200, 200) - with mock.patch( - "asammdf.gui.widgets.mdi_area.WindowSelectionDialog" - ) as mc_WindowSelectionDialog: + with mock.patch("asammdf.gui.widgets.mdi_area.WindowSelectionDialog") as mc_WindowSelectionDialog: # Setup mc_WindowSelectionDialog.return_value.result.return_value = True - mc_WindowSelectionDialog.return_value.disable_new_channels.return_value = ( - False - ) - mc_WindowSelectionDialog.return_value.selected_type.return_value = ( - "Plot" - ) + mc_WindowSelectionDialog.return_value.disable_new_channels.return_value = False + mc_WindowSelectionDialog.return_value.selected_type.return_value = "Plot" DragAndDrop( source_widget=channels_tree, @@ -478,9 +444,7 @@ def test_PushButton_SaveOfflineWindows(self): iterator += 1 # Press PushButton: "Save offline windows" - with mock.patch( - "asammdf.gui.widgets.file.QtWidgets.QFileDialog.getSaveFileName" - ) as mo_getSaveFileName: + with mock.patch("asammdf.gui.widgets.file.QtWidgets.QFileDialog.getSaveFileName") as mo_getSaveFileName: mo_getSaveFileName.return_value = str(saved_dspf), None QtTest.QTest.mouseClick( self.widget.save_channel_list_btn, @@ -490,9 +454,7 @@ def test_PushButton_SaveOfflineWindows(self): self.assertTrue(saved_dspf.exists()) # Event - with mock.patch.object( - self.widget, "load_window", wraps=self.widget.load_window - ) as mo_load_window, mock.patch( + with mock.patch.object(self.widget, "load_window", wraps=self.widget.load_window) as mo_load_window, mock.patch( "asammdf.gui.widgets.file.QtWidgets.QFileDialog.getOpenFileName" ) as mo_getOpenFileName: mo_getOpenFileName.return_value = saved_dspf, None @@ -532,9 +494,7 @@ def test_PushButton_SelectAll(self): # Switch ComboBox to "Natural sort" self.widget.channel_view.setCurrentText("Natural Sort") # Press PushButton: "Select all the channels" - QtTest.QTest.mouseClick( - self.widget.select_all_btn, QtCore.Qt.MouseButton.LeftButton - ) + QtTest.QTest.mouseClick(self.widget.select_all_btn, QtCore.Qt.MouseButton.LeftButton) # Evaluate iterator = QtWidgets.QTreeWidgetItemIterator(self.widget.channels_tree) @@ -554,9 +514,7 @@ def test_PushButton_SelectAll(self): # Switch ComboBox to "Internal file structure" self.widget.channel_view.setCurrentText("Internal file structure") # Press PushButton: "Select all the channels" - QtTest.QTest.mouseClick( - self.widget.select_all_btn, QtCore.Qt.MouseButton.LeftButton - ) + QtTest.QTest.mouseClick(self.widget.select_all_btn, QtCore.Qt.MouseButton.LeftButton) # Evaluate iterator = QtWidgets.QTreeWidgetItemIterator(self.widget.channels_tree) @@ -604,9 +562,7 @@ def test_PushButton_ClearAll(self): self.assertTrue(item.checkState(0)) iterator += 1 # Press PushButton: "Clear all selected channels" - QtTest.QTest.mouseClick( - self.widget.clear_channels_btn, QtCore.Qt.MouseButton.LeftButton - ) + QtTest.QTest.mouseClick(self.widget.clear_channels_btn, QtCore.Qt.MouseButton.LeftButton) # Evaluate iterator = QtWidgets.QTreeWidgetItemIterator(self.widget.channels_tree) @@ -623,9 +579,7 @@ def test_PushButton_ClearAll(self): self.assertTrue(item.checkState(0)) iterator += 1 # Press PushButton: "Clear all selected channels" - QtTest.QTest.mouseClick( - self.widget.clear_channels_btn, QtCore.Qt.MouseButton.LeftButton - ) + QtTest.QTest.mouseClick(self.widget.clear_channels_btn, QtCore.Qt.MouseButton.LeftButton) # Evaluate iterator = QtWidgets.QTreeWidgetItemIterator(self.widget.channels_tree) @@ -673,17 +627,13 @@ def test_PushButton_Search(self): self.setUpFileWidget(measurement_file=measurement_file, default=True) # Case 0: with self.subTest("test_PushButton_Search_0"): - with mock.patch( - "asammdf.gui.widgets.file.AdvancedSearch" - ) as mc_AdvancedSearch: + with mock.patch("asammdf.gui.widgets.file.AdvancedSearch") as mc_AdvancedSearch: mc_AdvancedSearch.return_value.result = {} mc_AdvancedSearch.return_value.pattern_window = False mc_AdvancedSearch.return_value.add_window_request = False # - Press PushButton: "Search and select channels" - QtTest.QTest.mouseClick( - self.widget.advanced_search_btn, QtCore.Qt.LeftButton - ) + QtTest.QTest.mouseClick(self.widget.advanced_search_btn, QtCore.Qt.LeftButton) # Evaluate iterator = QtWidgets.QTreeWidgetItemIterator(self.widget.channels_tree) while iterator.value(): @@ -693,9 +643,7 @@ def test_PushButton_Search(self): # Case 1: with self.subTest("test_PushButton_Search_1"): - with mock.patch( - "asammdf.gui.widgets.file.AdvancedSearch" - ) as mc_AdvancedSearch: + with mock.patch("asammdf.gui.widgets.file.AdvancedSearch") as mc_AdvancedSearch: mc_AdvancedSearch.return_value.result = { (4, 3): "ASAM.M.SCALAR.FLOAT64.IDENTICAL", (2, 10): "ASAM.M.SCALAR.FLOAT32.IDENTICAL", @@ -704,9 +652,7 @@ def test_PushButton_Search(self): mc_AdvancedSearch.return_value.add_window_request = False # - Press PushButton: "Search and select channels" - QtTest.QTest.mouseClick( - self.widget.advanced_search_btn, QtCore.Qt.LeftButton - ) + QtTest.QTest.mouseClick(self.widget.advanced_search_btn, QtCore.Qt.LeftButton) # Evaluate checked_channels = 0 iterator = QtWidgets.QTreeWidgetItemIterator(self.widget.channels_tree) @@ -726,9 +672,7 @@ def test_PushButton_Search(self): item = iterator.value() item.setCheckState(0, QtCore.Qt.Unchecked) iterator += 1 - with mock.patch( - "asammdf.gui.widgets.file.AdvancedSearch" - ) as mc_AdvancedSearch, mock.patch( + with mock.patch("asammdf.gui.widgets.file.AdvancedSearch") as mc_AdvancedSearch, mock.patch( "asammdf.gui.widgets.file.WindowSelectionDialog" ) as mc_WindowSelectionDialog: mc_AdvancedSearch.return_value.result = { @@ -738,17 +682,11 @@ def test_PushButton_Search(self): mc_AdvancedSearch.return_value.pattern_window = False mc_AdvancedSearch.return_value.add_window_request = True mc_WindowSelectionDialog.return_value.result.return_value = True - mc_WindowSelectionDialog.return_value.selected_type.return_value = ( - "New plot window" - ) - mc_WindowSelectionDialog.return_value.disable_new_channels.return_value = ( - False - ) + mc_WindowSelectionDialog.return_value.selected_type.return_value = "New plot window" + mc_WindowSelectionDialog.return_value.disable_new_channels.return_value = False # - Press PushButton: "Search and select channels" - QtTest.QTest.mouseClick( - self.widget.advanced_search_btn, QtCore.Qt.LeftButton - ) + QtTest.QTest.mouseClick(self.widget.advanced_search_btn, QtCore.Qt.LeftButton) # Evaluate checked_channels = 0 iterator = QtWidgets.QTreeWidgetItemIterator(self.widget.channels_tree) @@ -795,30 +733,20 @@ def test_PushButton_CreateWindow(self): # Case 0: with self.subTest("test_PushButton_CreateWindow_0"): - with mock.patch( - "asammdf.gui.widgets.file.WindowSelectionDialog" - ) as mc_WindowSelectionDialog: + with mock.patch("asammdf.gui.widgets.file.WindowSelectionDialog") as mc_WindowSelectionDialog: mc_WindowSelectionDialog.return_value.result.return_value = False # - Press PushButton "Create Window" - QtTest.QTest.mouseClick( - self.widget.create_window_btn, QtCore.Qt.LeftButton - ) + QtTest.QTest.mouseClick(self.widget.create_window_btn, QtCore.Qt.LeftButton) # Evaluate self.assertEqual(len(self.widget.mdi_area.subWindowList()), 0) # Case 1: with self.subTest("test_PushButton_CreateWindow_1"): - with mock.patch( - "asammdf.gui.widgets.file.WindowSelectionDialog" - ) as mc_WindowSelectionDialog: + with mock.patch("asammdf.gui.widgets.file.WindowSelectionDialog") as mc_WindowSelectionDialog: mc_WindowSelectionDialog.return_value.result.return_value = True - mc_WindowSelectionDialog.return_value.selected_type.return_value = ( - "Plot" - ) + mc_WindowSelectionDialog.return_value.selected_type.return_value = "Plot" # - Press PushButton "Create Window" - QtTest.QTest.mouseClick( - self.widget.create_window_btn, QtCore.Qt.LeftButton - ) + QtTest.QTest.mouseClick(self.widget.create_window_btn, QtCore.Qt.LeftButton) # Evaluate self.assertEqual(len(self.widget.mdi_area.subWindowList()), 1) widget_types = self.get_subwindows() @@ -826,47 +754,29 @@ def test_PushButton_CreateWindow(self): # Case 2: with self.subTest("test_PushButton_CreateWindow_2"): - with mock.patch( - "asammdf.gui.widgets.file.WindowSelectionDialog" - ) as mc_WindowSelectionDialog: + with mock.patch("asammdf.gui.widgets.file.WindowSelectionDialog") as mc_WindowSelectionDialog: mc_WindowSelectionDialog.return_value.result.return_value = True - mc_WindowSelectionDialog.return_value.selected_type.return_value = ( - "Numeric" - ) + mc_WindowSelectionDialog.return_value.selected_type.return_value = "Numeric" # - Select one channel channel = self.widget.channels_tree.topLevelItem(0).text(0) - self.widget.channels_tree.topLevelItem(0).setCheckState( - 0, QtCore.Qt.Checked - ) + self.widget.channels_tree.topLevelItem(0).setCheckState(0, QtCore.Qt.Checked) # - Press PushButton "Create Window" - QtTest.QTest.mouseClick( - self.widget.create_window_btn, QtCore.Qt.LeftButton - ) + QtTest.QTest.mouseClick(self.widget.create_window_btn, QtCore.Qt.LeftButton) # Evaluate self.assertEqual(len(self.widget.mdi_area.subWindowList()), 2) widget_types = self.get_subwindows() self.assertIn("Numeric", widget_types) - numeric_data = ( - self.widget.mdi_area.subWindowList()[1].widget().channels.dataView - ) - numeric_channel = numeric_data.model().data( - numeric_data.model().index(0, 0) - ) + numeric_data = self.widget.mdi_area.subWindowList()[1].widget().channels.dataView + numeric_channel = numeric_data.model().data(numeric_data.model().index(0, 0)) self.assertEqual(channel, numeric_channel) # Case 3: with self.subTest("test_PushButton_CreateWindow_3"): - with mock.patch( - "asammdf.gui.widgets.file.WindowSelectionDialog" - ) as mc_WindowSelectionDialog: + with mock.patch("asammdf.gui.widgets.file.WindowSelectionDialog") as mc_WindowSelectionDialog: mc_WindowSelectionDialog.return_value.result.return_value = True - mc_WindowSelectionDialog.return_value.selected_type.return_value = ( - "Tabular" - ) + mc_WindowSelectionDialog.return_value.selected_type.return_value = "Tabular" # - Press PushButton "Create Window" - QtTest.QTest.mouseClick( - self.widget.create_window_btn, QtCore.Qt.LeftButton - ) + QtTest.QTest.mouseClick(self.widget.create_window_btn, QtCore.Qt.LeftButton) # Evaluate self.assertEqual(len(self.widget.mdi_area.subWindowList()), 3) widget_types = self.get_subwindows() @@ -874,17 +784,11 @@ def test_PushButton_CreateWindow(self): # Case 4: with self.subTest("test_PushButton_CreateWindow_4"): - with mock.patch( - "asammdf.gui.widgets.file.WindowSelectionDialog" - ) as mc_WindowSelectionDialog: + with mock.patch("asammdf.gui.widgets.file.WindowSelectionDialog") as mc_WindowSelectionDialog: mc_WindowSelectionDialog.return_value.result.return_value = True - mc_WindowSelectionDialog.return_value.selected_type.return_value = ( - "Plot" - ) + mc_WindowSelectionDialog.return_value.selected_type.return_value = "Plot" # - Press PushButton "Create Window" - QtTest.QTest.mouseClick( - self.widget.create_window_btn, QtCore.Qt.LeftButton - ) + QtTest.QTest.mouseClick(self.widget.create_window_btn, QtCore.Qt.LeftButton) # Evaluate self.assertEqual(len(self.widget.mdi_area.subWindowList()), 4) widget_types = self.get_subwindows() @@ -912,9 +816,7 @@ def test_DoubleClick_Channel(self): self.widget.channel_view.setCurrentText("Internal file structure") first_item = self.widget.channels_tree.topLevelItem(0) - first_item_center = self.widget.channels_tree.visualItemRect( - first_item - ).center() + first_item_center = self.widget.channels_tree.visualItemRect(first_item).center() QtTest.QTest.mouseClick( self.widget.channels_tree.viewport(), QtCore.Qt.MouseButton.LeftButton, @@ -945,9 +847,7 @@ def test_DoubleClick_Channel(self): # Case 1: child_item = first_item.child(0) - child_item_center = self.widget.channels_tree.visualItemRect( - child_item - ).center() + child_item_center = self.widget.channels_tree.visualItemRect(child_item).center() QtTest.QTest.mouseClick( self.widget.channels_tree.viewport(), QtCore.Qt.MouseButton.LeftButton, diff --git a/test/asammdf/gui/widgets/test_FileWidget_TabModifyAndExport.py b/test/asammdf/gui/widgets/test_FileWidget_TabModifyAndExport.py index 7ce00d4f4..9d7e3973b 100644 --- a/test/asammdf/gui/widgets/test_FileWidget_TabModifyAndExport.py +++ b/test/asammdf/gui/widgets/test_FileWidget_TabModifyAndExport.py @@ -24,9 +24,7 @@ def test_PushButton_ScrambleTexts(self): """ # Setup measurement_file = str(pathlib.Path(self.test_workspace, "ASAP2_Demo_V171.mf4")) - shutil.copy( - pathlib.Path(self.resource, "ASAP2_Demo_V171.mf4"), measurement_file - ) + shutil.copy(pathlib.Path(self.resource, "ASAP2_Demo_V171.mf4"), measurement_file) # Event self.setUpFileWidget(measurement_file=measurement_file, default=True) # Go to Tab: "Modify & Export": Index 1 @@ -37,9 +35,7 @@ def test_PushButton_ScrambleTexts(self): channels = self.widget.channels_db_items # Evaluate - scrambled_filepath = pathlib.Path( - self.test_workspace, "ASAP2_Demo_V171.scrambled.mf4" - ) + scrambled_filepath = pathlib.Path(self.test_workspace, "ASAP2_Demo_V171.scrambled.mf4") # Wait for Thread to finish time.sleep(0.1) # TearDown Current Widget. @@ -101,9 +97,7 @@ def test_ExportMDF(self): with self.subTest("test_ExportMDF_0"): with mock.patch( "asammdf.gui.widgets.file.QtWidgets.QFileDialog.getSaveFileName" - ) as mc_getSaveFileName, mock.patch( - "asammdf.gui.widgets.file.setup_progress" - ) as mo_setup_progress: + ) as mc_getSaveFileName, mock.patch("asammdf.gui.widgets.file.setup_progress") as mo_setup_progress: mc_getSaveFileName.return_value = None, None QtTest.QTest.mouseClick(self.widget.apply_btn, QtCore.Qt.LeftButton) self.processEvents() @@ -115,9 +109,7 @@ def test_ExportMDF(self): self.processEvents() with self.subTest("test_ExportMDF_1"): saved_file = pathlib.Path(self.test_workspace, f"{self.id()}.mf4") - with mock.patch( - "asammdf.gui.widgets.file.QtWidgets.QFileDialog.getSaveFileName" - ) as mc_getSaveFileName: + with mock.patch("asammdf.gui.widgets.file.QtWidgets.QFileDialog.getSaveFileName") as mc_getSaveFileName: mc_getSaveFileName.return_value = str(saved_file), None QtTest.QTest.mouseClick(self.widget.apply_btn, QtCore.Qt.LeftButton) self.processEvents() diff --git a/test/asammdf/gui/widgets/test_PlotWidget_DoubleClick.py b/test/asammdf/gui/widgets/test_PlotWidget_DoubleClick.py index 38a51eb1c..82731e162 100644 --- a/test/asammdf/gui/widgets/test_PlotWidget_DoubleClick.py +++ b/test/asammdf/gui/widgets/test_PlotWidget_DoubleClick.py @@ -8,6 +8,22 @@ class TestDoubleClick(TestPlotWidget): # Note: Test Plot Widget through FileWidget. + def setUp(self): + super().setUp() + + # Open File Widget + self.setUpFileWidget(measurement_file=self.measurement_file, default=True) + # Switch ComboBox to "Natural sort" + self.widget.channel_view.setCurrentText("Natural sort") + # Create a plot window + self.create_window(window_type="Plot") + self.assertEqual(len(self.widget.mdi_area.subWindowList()), 1) + # Drag and Drop channel from FileWidget.channel_tree to Plot + self.plot = self.widget.mdi_area.subWindowList()[0].widget() + + # Press PushButton 'FocusMode' - disabled (easy for evaluation) + if not self.plot.focused_mode_btn.isFlat(): + QtTest.QTest.mouseClick(self.plot.focused_mode_btn, QtCore.Qt.LeftButton) def test_ChannelSelection(self): """ @@ -25,16 +41,7 @@ def test_ChannelSelection(self): - Evaluate that channel checkbox is checked. """ # Event - # Open File Widget - self.setUpFileWidget(measurement_file=self.measurement_file, default=True) - # Switch ComboBox to "Natural sort" - self.widget.channel_view.setCurrentText("Natural sort") - # Create a plot window - self.create_window(window_type="Plot") - self.assertEqual(len(self.widget.mdi_area.subWindowList()), 1) - # Drag and Drop channel from FileWidget.channel_tree to Plot - plot = self.widget.mdi_area.subWindowList()[0].widget() - plot_channel = self.add_channel_to_plot(plot=plot) + plot_channel = self.add_channel_to_plot() # Pre-evaluation self.assertEqual(QtCore.Qt.Checked, plot_channel.checkState(0)) @@ -70,37 +77,22 @@ def test_EnableDisable_Group(self): - Evaluate that channel is not present on plot when is disabled. """ # Event - # Open File Widget - self.setUpFileWidget(measurement_file=self.measurement_file, default=True) - # Switch ComboBox to "Natural sort" - self.widget.channel_view.setCurrentText("Natural sort") - # Create a plot window - self.create_window(window_type="Plot") - self.assertEqual(len(self.widget.mdi_area.subWindowList()), 1) - plot = self.widget.mdi_area.subWindowList()[0].widget() - # Press PushButton 'FocusMode' - disabled (easy for evaluation) - if not plot.focused_mode_btn.isFlat(): - QtTest.QTest.mouseClick(plot.focused_mode_btn, QtCore.Qt.LeftButton) # Drag and Drop channel from FileWidget.channel_tree to Plot - plot_channel_0 = self.add_channel_to_plot(plot=plot, channel_index=10) - _ = self.add_channel_to_plot(plot=plot, channel_index=11) - plot_channel_2 = self.add_channel_to_plot(plot=plot, channel_index=12) + plot_channel_0 = self.add_channel_to_plot(channel_index=10) + _ = self.add_channel_to_plot(channel_index=11) + plot_channel_2 = self.add_channel_to_plot(channel_index=12) # Press 'Shift-Insert' in order to Insert Group # Create Channel Group. Drag channels inside the group one by one - with mock.patch( - "asammdf.gui.widgets.tree.QtWidgets.QInputDialog.getText" - ) as mc_getText: + with mock.patch("asammdf.gui.widgets.tree.QtWidgets.QInputDialog.getText") as mc_getText: # Create Channel Group mc_getText.return_value = "FirstGroup", True - QtTest.QTest.keySequence( - plot.channel_selection, QtGui.QKeySequence("Shift+Insert") - ) + QtTest.QTest.keySequence(self.plot.channel_selection, QtGui.QKeySequence("Shift+Insert")) self.processEvents() # PreEvaluation: Check if there is one extra-item - self.assertEqual(4, plot.channel_selection.topLevelItemCount()) + self.assertEqual(4, self.plot.channel_selection.topLevelItemCount()) # Get Group Position - for index in range(plot.channel_selection.topLevelItemCount()): - item = plot.channel_selection.topLevelItem(index) + for index in range(self.plot.channel_selection.topLevelItemCount()): + item = self.plot.channel_selection.topLevelItem(index) if item.text(self.Column.NAME) == "FirstGroup": first_group = item break @@ -108,26 +100,24 @@ def test_EnableDisable_Group(self): self.fail("FirstGroup is not present on Plot Channel Selection.") first_group.setExpanded(True) # Get the First Item that will be moved - drag_position = plot.channel_selection.visualItemRect( - plot_channel_0 - ).center() - drop_position = plot.channel_selection.visualItemRect(first_group).center() + drag_position = self.plot.channel_selection.visualItemRect(plot_channel_0).center() + drop_position = self.plot.channel_selection.visualItemRect(first_group).center() # Get the Name of the first channel first_channel = plot_channel_0.text(self.Column.NAME) # PreEvaluation: Ensure that group has no child self.assertEqual(0, first_group.childCount()) DragAndDrop( - source_widget=plot.channel_selection, - destination_widget=plot.channel_selection.viewport(), + source_widget=self.plot.channel_selection, + destination_widget=self.plot.channel_selection.viewport(), source_pos=drag_position, destination_pos=drop_position, ) # PreEvaluate: Ensure that channel was added to group self.assertEqual(1, first_group.childCount()) self.assertEqual(first_channel, first_group.child(0).text(self.Column.NAME)) - self.assertEqual(3, plot.channel_selection.topLevelItemCount()) + self.assertEqual(3, self.plot.channel_selection.topLevelItemCount()) - enabled_groups_pixmap = plot.plot.viewport().grab() + enabled_groups_pixmap = self.plot.plot.viewport().grab() # Evaluate self.assertTrue( Pixmap.has_color( @@ -137,7 +127,7 @@ def test_EnableDisable_Group(self): ) # Press mouse double click on channel self.mouseDClick_WidgetItem(first_group) - disabled_groups_pixmap = plot.plot.viewport().grab() + disabled_groups_pixmap = self.plot.plot.viewport().grab() # Evaluate self.assertFalse( @@ -148,11 +138,11 @@ def test_EnableDisable_Group(self): ) for _ in range(4): - QtTest.QTest.keyClick(plot.channel_selection, QtCore.Qt.Key_Down) + QtTest.QTest.keyClick(self.plot.channel_selection, QtCore.Qt.Key_Down) self.processEvents() # Evaluate that item is still 2nd one because - selectedItems = plot.channel_selection.selectedItems() + selectedItems = self.plot.channel_selection.selectedItems() self.assertEqual(1, len(selectedItems)) selectedItem = selectedItems[0].text(self.Column.NAME) self.assertEqual(plot_channel_2.text(self.Column.NAME), selectedItem) @@ -162,11 +152,11 @@ def test_EnableDisable_Group(self): self.processEvents() for _ in range(4): - QtTest.QTest.keyClick(plot.channel_selection, QtCore.Qt.Key_Down) + QtTest.QTest.keyClick(self.plot.channel_selection, QtCore.Qt.Key_Down) self.processEvents() # Evaluate that item is the one from the group - selectedItems = plot.channel_selection.selectedItems() + selectedItems = self.plot.channel_selection.selectedItems() self.assertEqual(1, len(selectedItems)) selectedItem = selectedItems[0].text(self.Column.NAME) self.assertEqual(plot_channel_0.text(self.Column.NAME), selectedItem) @@ -175,15 +165,15 @@ def test_EnableDisable_Group(self): # After channels are enabled, they first flash a few times on plot. # ProcessEvents few times for channels to be present for _ in range(20): - self.processEvents() + self.processEvents(0.05) - self.processEvents(0.1) - enabled_groups_pixmap = plot.plot.viewport().grab() + enabled_groups_pixmap = self.plot.plot.viewport().grab() self.assertTrue( Pixmap.has_color( pixmap=enabled_groups_pixmap, color_name=plot_channel_0.color, - ) + ), + msg=f"Color of channel {plot_channel_0.text(self.Column.NAME)} is not present on plot.", ) def test_EnableDisable_ParentGroup(self): @@ -215,61 +205,40 @@ def test_EnableDisable_ParentGroup(self): - Evaluate channel color is darkGray when it's disabled. """ # Event - # Open File Widget - self.setUpFileWidget(measurement_file=self.measurement_file, default=True) - # Switch ComboBox to "Natural sort" - self.widget.channel_view.setCurrentText("Natural sort") - # Create a plot window - self.create_window(window_type="Plot") - self.assertEqual(len(self.widget.mdi_area.subWindowList()), 1) - plot = self.widget.mdi_area.subWindowList()[0].widget() - # Press PushButton 'FocusMode' - disabled (easy for evaluation) - if not plot.focused_mode_btn.isFlat(): - QtTest.QTest.mouseClick(plot.focused_mode_btn, QtCore.Qt.LeftButton) # Drag and Drop channel from FileWidget.channel_tree to Plot - plot_channel_a = self.add_channel_to_plot(plot=plot, channel_index=10) - plot_channel_b = self.add_channel_to_plot(plot=plot, channel_index=11) - plot_channel_c = self.add_channel_to_plot(plot=plot, channel_index=12) - plot_channel_d = self.add_channel_to_plot(plot=plot, channel_index=13) + plot_channel_a = self.add_channel_to_plot(channel_index=10) + plot_channel_b = self.add_channel_to_plot(channel_index=11) + plot_channel_c = self.add_channel_to_plot(channel_index=12) + plot_channel_d = self.add_channel_to_plot(channel_index=13) + self.processEvents() # Press 'Shift-Insert' in order to Insert Group # Create Channel Group. Drag channels inside the group one by one groups = {} - with mock.patch( - "asammdf.gui.widgets.tree.QtWidgets.QInputDialog.getText" - ) as mc_getText: + with mock.patch("asammdf.gui.widgets.tree.QtWidgets.QInputDialog.getText") as mc_getText: for group_name in ("A", "B", "C"): # Create Channel Group mc_getText.return_value = group_name, True - QtTest.QTest.keySequence( - plot.channel_selection, QtGui.QKeySequence("Shift+Insert") - ) + QtTest.QTest.keySequence(self.plot.channel_selection, QtGui.QKeySequence("Shift+Insert")) self.processEvents() # Get Groups Position - for index in range(plot.channel_selection.topLevelItemCount()): - item = plot.channel_selection.topLevelItem(index) + for index in range(self.plot.channel_selection.topLevelItemCount()): + item = self.plot.channel_selection.topLevelItem(index) group_name = item.text(self.Column.NAME) if group_name in ("A", "B", "C"): groups[group_name] = item item.setExpanded(True) # Get the First Item that will be moved - for group_name in ("A", "B", "C"): - plot_channel = locals()[f"plot_channel_{group_name.lower()}"] - drag_position = plot.channel_selection.visualItemRect( - plot_channel - ).center() - drop_position = plot.channel_selection.visualItemRect( - groups[group_name] - ).center() - - # Get the Name of the first channel - first_channel = plot_channel.text(self.Column.NAME) + for group_name, plot_channel in zip(("A", "B", "C"), (plot_channel_a, plot_channel_b, plot_channel_c)): + drag_position = self.plot.channel_selection.visualItemRect(plot_channel).center() + drop_position = self.plot.channel_selection.visualItemRect(groups[group_name]).center() + # PreEvaluation: Ensure that group has no child self.assertEqual(0, groups[group_name].childCount()) DragAndDrop( - source_widget=plot.channel_selection, - destination_widget=plot.channel_selection.viewport(), + source_widget=self.plot.channel_selection, + destination_widget=self.plot.channel_selection.viewport(), source_pos=drag_position, destination_pos=drop_position, ) @@ -277,20 +246,20 @@ def test_EnableDisable_ParentGroup(self): self.processEvents() # Move Group C inside Group B - drag_position = plot.channel_selection.visualItemRect(groups["C"]).center() - drop_position = plot.channel_selection.visualItemRect(groups["B"]).center() + drag_position = self.plot.channel_selection.visualItemRect(groups["C"]).center() + drop_position = self.plot.channel_selection.visualItemRect(groups["B"]).center() DragAndDrop( - source_widget=plot.channel_selection, - destination_widget=plot.channel_selection.viewport(), + source_widget=self.plot.channel_selection, + destination_widget=self.plot.channel_selection.viewport(), source_pos=drag_position, destination_pos=drop_position, ) # Move Group B inside Group A - drag_position = plot.channel_selection.visualItemRect(groups["B"]).center() - drop_position = plot.channel_selection.visualItemRect(groups["A"]).center() + drag_position = self.plot.channel_selection.visualItemRect(groups["B"]).center() + drop_position = self.plot.channel_selection.visualItemRect(groups["A"]).center() DragAndDrop( - source_widget=plot.channel_selection, - destination_widget=plot.channel_selection.viewport(), + source_widget=self.plot.channel_selection, + destination_widget=self.plot.channel_selection.viewport(), source_pos=drag_position, destination_pos=drop_position, ) @@ -300,13 +269,11 @@ def test_EnableDisable_ParentGroup(self): groups["C"].setExpanded(True) self.processEvents() - enabled_groups_pixmap = plot.plot.viewport().grab() + enabled_groups_pixmap = self.plot.plot.viewport().grab() # Evaluate for channel in (plot_channel_a, plot_channel_b, plot_channel_c): self.assertTrue( - Pixmap.has_color( - pixmap=enabled_groups_pixmap, color_name=channel.color - ), + Pixmap.has_color(pixmap=enabled_groups_pixmap, color_name=channel.color), msg=f"Color of Channel: {channel.text(self.Column.NAME)} not present on 'plot'.", ) color_name = channel.foreground(self.Column.NAME).color().name() @@ -314,7 +281,7 @@ def test_EnableDisable_ParentGroup(self): # Press mouse double click on Group A self.mouseDClick_WidgetItem(groups["A"]) self.processEvents() - disabled_groups_pixmap = plot.plot.viewport().grab() + disabled_groups_pixmap = self.plot.plot.viewport().grab() # Evaluate for channel in (plot_channel_a, plot_channel_b, plot_channel_c): @@ -328,13 +295,13 @@ def test_EnableDisable_ParentGroup(self): color_name = channel.foreground(self.Column.NAME).color().name() self.assertEqual(color_name, "#808080") - QtTest.QTest.keyClick(plot.channel_selection, QtCore.Qt.Key_Up) + QtTest.QTest.keyClick(self.plot.channel_selection, QtCore.Qt.Key_Up) for _ in range(4): - QtTest.QTest.keyClick(plot.channel_selection, QtCore.Qt.Key_Down) + QtTest.QTest.keyClick(self.plot.channel_selection, QtCore.Qt.Key_Down) self.processEvents() # Evaluate that item is still plot_channel_d - selectedItems = plot.channel_selection.selectedItems() + selectedItems = self.plot.channel_selection.selectedItems() self.assertEqual(1, len(selectedItems)) selectedItem = selectedItems[0].text(self.Column.NAME) self.assertEqual(plot_channel_d.text(self.Column.NAME), selectedItem) @@ -344,22 +311,22 @@ def test_EnableDisable_ParentGroup(self): self.processEvents() for _ in range(8): - QtTest.QTest.keyClick(plot.channel_selection, QtCore.Qt.Key_Down) + QtTest.QTest.keyClick(self.plot.channel_selection, QtCore.Qt.Key_Down) self.processEvents() # Evaluate that item is the one from the group C - selectedItems = plot.channel_selection.selectedItems() + selectedItems = self.plot.channel_selection.selectedItems() self.assertEqual(1, len(selectedItems)) selectedItem = selectedItems[0].text(self.Column.NAME) self.assertEqual(plot_channel_c.text(self.Column.NAME), selectedItem) # Evaluate - # After channels are enabled, they first flash a few times on plot. + # After channels are enabled, they first flash a few times on self.plot. # ProcessEvents few times for channels to be present for _ in range(20): - self.processEvents() + self.processEvents(0.05) - enabled_groups_pixmap = plot.plot.viewport().grab() + enabled_groups_pixmap = self.plot.plot.viewport().grab() for channel in ( plot_channel_a, plot_channel_b, @@ -367,9 +334,7 @@ def test_EnableDisable_ParentGroup(self): plot_channel_d, ): self.assertTrue( - Pixmap.has_color( - pixmap=enabled_groups_pixmap, color_name=channel.color - ), + Pixmap.has_color(pixmap=enabled_groups_pixmap, color_name=channel.color), msg=f"Color for Channel: {channel.text(self.Column.NAME)} not present on 'plot'", ) color_name = channel.foreground(self.Column.NAME).color().name() @@ -403,61 +368,40 @@ def test_EnableDisable_Subgroup(self): - Evaluate that channel is not present on plot when is disabled. """ # Event - # Open File Widget - self.setUpFileWidget(measurement_file=self.measurement_file, default=True) - # Switch ComboBox to "Natural sort" - self.widget.channel_view.setCurrentText("Natural sort") - # Create a plot window - self.create_window(window_type="Plot") - self.assertEqual(len(self.widget.mdi_area.subWindowList()), 1) - plot = self.widget.mdi_area.subWindowList()[0].widget() - # Press PushButton 'FocusMode' - disabled (easy for evaluation) - if not plot.focused_mode_btn.isFlat(): - QtTest.QTest.mouseClick(plot.focused_mode_btn, QtCore.Qt.LeftButton) # Drag and Drop channel from FileWidget.channel_tree to Plot - plot_channel_a = self.add_channel_to_plot(plot=plot, channel_index=10) - plot_channel_b = self.add_channel_to_plot(plot=plot, channel_index=11) - plot_channel_c = self.add_channel_to_plot(plot=plot, channel_index=12) - plot_channel_d = self.add_channel_to_plot(plot=plot, channel_index=13) + plot_channel_a = self.add_channel_to_plot(channel_index=10) + plot_channel_b = self.add_channel_to_plot(channel_index=11) + plot_channel_c = self.add_channel_to_plot(channel_index=12) + plot_channel_d = self.add_channel_to_plot(channel_index=13) + # Press 'Shift-Insert' in order to Insert Group # Create Channel Group. Drag channels inside the group one by one groups = {} - with mock.patch( - "asammdf.gui.widgets.tree.QtWidgets.QInputDialog.getText" - ) as mc_getText: + with mock.patch("asammdf.gui.widgets.tree.QtWidgets.QInputDialog.getText") as mc_getText: for group_name in ("A", "B", "C"): # Create Channel Group mc_getText.return_value = group_name, True - QtTest.QTest.keySequence( - plot.channel_selection, QtGui.QKeySequence("Shift+Insert") - ) + QtTest.QTest.keySequence(self.plot.channel_selection, QtGui.QKeySequence("Shift+Insert")) self.processEvents() # Get Groups Position - for index in range(plot.channel_selection.topLevelItemCount()): - item = plot.channel_selection.topLevelItem(index) + for index in range(self.plot.channel_selection.topLevelItemCount()): + item = self.plot.channel_selection.topLevelItem(index) group_name = item.text(self.Column.NAME) if group_name in ("A", "B", "C"): groups[group_name] = item item.setExpanded(True) # Get the First Item that will be moved - for group_name in ("A", "B", "C"): - plot_channel = locals()[f"plot_channel_{group_name.lower()}"] - drag_position = plot.channel_selection.visualItemRect( - plot_channel - ).center() - drop_position = plot.channel_selection.visualItemRect( - groups[group_name] - ).center() - - # Get the Name of the first channel - first_channel = plot_channel.text(self.Column.NAME) + for group_name, plot_channel in zip(("A", "B", "C"), (plot_channel_a, plot_channel_b, plot_channel_c)): + drag_position = self.plot.channel_selection.visualItemRect(plot_channel).center() + drop_position = self.plot.channel_selection.visualItemRect(groups[group_name]).center() + # PreEvaluation: Ensure that group has no child self.assertEqual(0, groups[group_name].childCount()) DragAndDrop( - source_widget=plot.channel_selection, - destination_widget=plot.channel_selection.viewport(), + source_widget=self.plot.channel_selection, + destination_widget=self.plot.channel_selection.viewport(), source_pos=drag_position, destination_pos=drop_position, ) @@ -465,20 +409,20 @@ def test_EnableDisable_Subgroup(self): self.processEvents() # Move Group C inside Group B - drag_position = plot.channel_selection.visualItemRect(groups["C"]).center() - drop_position = plot.channel_selection.visualItemRect(groups["B"]).center() + drag_position = self.plot.channel_selection.visualItemRect(groups["C"]).center() + drop_position = self.plot.channel_selection.visualItemRect(groups["B"]).center() DragAndDrop( - source_widget=plot.channel_selection, - destination_widget=plot.channel_selection.viewport(), + source_widget=self.plot.channel_selection, + destination_widget=self.plot.channel_selection.viewport(), source_pos=drag_position, destination_pos=drop_position, ) # Move Group B inside Group A - drag_position = plot.channel_selection.visualItemRect(groups["B"]).center() - drop_position = plot.channel_selection.visualItemRect(groups["A"]).center() + drag_position = self.plot.channel_selection.visualItemRect(groups["B"]).center() + drop_position = self.plot.channel_selection.visualItemRect(groups["A"]).center() DragAndDrop( - source_widget=plot.channel_selection, - destination_widget=plot.channel_selection.viewport(), + source_widget=self.plot.channel_selection, + destination_widget=self.plot.channel_selection.viewport(), source_pos=drag_position, destination_pos=drop_position, ) @@ -487,25 +431,21 @@ def test_EnableDisable_Subgroup(self): groups["B"].setExpanded(True) groups["C"].setExpanded(True) - enabled_groups_pixmap = plot.plot.viewport().grab() + enabled_groups_pixmap = self.plot.plot.viewport().grab() self.processEvents() # Evaluate for channel in (plot_channel_a, plot_channel_b, plot_channel_c): self.assertTrue( - Pixmap.has_color( - pixmap=enabled_groups_pixmap, color_name=channel.color - ), + Pixmap.has_color(pixmap=enabled_groups_pixmap, color_name=channel.color), msg=f"Color of Channel: {channel.text(self.Column.NAME)} not present on 'plot'.", ) # Press mouse double click on Group B self.mouseDClick_WidgetItem(groups["B"]) - disabled_groups_pixmap = plot.plot.viewport().grab() + disabled_groups_pixmap = self.plot.plot.viewport().grab() # Evaluate self.assertTrue( - Pixmap.has_color( - pixmap=enabled_groups_pixmap, color_name=plot_channel_a.color - ), + Pixmap.has_color(pixmap=enabled_groups_pixmap, color_name=plot_channel_a.color), msg=f"Color of Channel: {plot_channel_a.text(self.Column.NAME)} not present on 'plot'.", ) for channel in (plot_channel_b, plot_channel_c): @@ -517,9 +457,9 @@ def test_EnableDisable_Subgroup(self): msg=f"Color of Channel: {channel.text(self.Column.NAME)} present on 'plot'.", ) - QtTest.QTest.keyClick(plot.channel_selection, QtCore.Qt.Key_Up) + QtTest.QTest.keyClick(self.plot.channel_selection, QtCore.Qt.Key_Up) for _ in range(4): - QtTest.QTest.keyClick(plot.channel_selection, QtCore.Qt.Key_Down) + QtTest.QTest.keyClick(self.plot.channel_selection, QtCore.Qt.Key_Down) self.processEvents() # Press mouse double click on group B @@ -527,16 +467,16 @@ def test_EnableDisable_Subgroup(self): self.processEvents() for _ in range(8): - QtTest.QTest.keyClick(plot.channel_selection, QtCore.Qt.Key_Down) + QtTest.QTest.keyClick(self.plot.channel_selection, QtCore.Qt.Key_Down) self.processEvents() # Evaluate - # After channels are enabled, they first flash a few times on plot. + # After channels are enabled, they first flash a few times on self.plot. # ProcessEvents few times for channels to be present for _ in range(20): - self.processEvents() + self.processEvents(0.05) - enabled_groups_pixmap = plot.plot.viewport().grab() + enabled_groups_pixmap = self.plot.plot.viewport().grab() for channel in ( plot_channel_a, plot_channel_b, @@ -544,9 +484,7 @@ def test_EnableDisable_Subgroup(self): plot_channel_d, ): self.assertTrue( - Pixmap.has_color( - pixmap=enabled_groups_pixmap, color_name=channel.color - ), + Pixmap.has_color(pixmap=enabled_groups_pixmap, color_name=channel.color), msg=f"Color for Channel: {channel.text(self.Column.NAME)} not present on 'plot'", ) @@ -580,82 +518,60 @@ def test_EnableDisable_Preserve_Subgroup_State_0(self): - Evaluate that subgroup C state is maintained after subgroup B is enabled. """ # Event - # Open File Widget - self.setUpFileWidget(measurement_file=self.measurement_file, default=True) - # Switch ComboBox to "Natural sort" - self.widget.channel_view.setCurrentText("Natural sort") - # Create a plot window - self.create_window(window_type="Plot") - self.assertEqual(len(self.widget.mdi_area.subWindowList()), 1) - plot = self.widget.mdi_area.subWindowList()[0].widget() - # Press PushButton 'FocusMode' - disabled (easy for evaluation) - if not plot.focused_mode_btn.isFlat(): - QtTest.QTest.mouseClick(plot.focused_mode_btn, QtCore.Qt.LeftButton) # Drag and Drop channel from FileWidget.channel_tree to Plot - plot_channel_a = self.add_channel_to_plot(plot=plot, channel_index=10) - plot_channel_b = self.add_channel_to_plot(plot=plot, channel_index=11) - plot_channel_c = self.add_channel_to_plot(plot=plot, channel_index=12) - plot_channel_d = self.add_channel_to_plot(plot=plot, channel_index=13) + plot_channel_a = self.add_channel_to_plot(channel_index=10) + plot_channel_b = self.add_channel_to_plot(channel_index=11) + plot_channel_c = self.add_channel_to_plot(channel_index=12) + plot_channel_d = self.add_channel_to_plot(channel_index=13) # Press 'Shift-Insert' in order to Insert Group # Create Channel Group. Drag channels inside the group one by one groups = {} - with mock.patch( - "asammdf.gui.widgets.tree.QtWidgets.QInputDialog.getText" - ) as mc_getText: + with mock.patch("asammdf.gui.widgets.tree.QtWidgets.QInputDialog.getText") as mc_getText: for group_name in ("A", "B", "C"): # Create Channel Group mc_getText.return_value = group_name, True - QtTest.QTest.keySequence( - plot.channel_selection, QtGui.QKeySequence("Shift+Insert") - ) + QtTest.QTest.keySequence(self.plot.channel_selection, QtGui.QKeySequence("Shift+Insert")) self.processEvents() # Get Groups Position - for index in range(plot.channel_selection.topLevelItemCount()): - item = plot.channel_selection.topLevelItem(index) + for index in range(self.plot.channel_selection.topLevelItemCount()): + item = self.plot.channel_selection.topLevelItem(index) group_name = item.text(self.Column.NAME) if group_name in ("A", "B", "C"): groups[group_name] = item item.setExpanded(True) # Get the First Item that will be moved - for group_name in ("A", "B", "C"): - plot_channel = locals()[f"plot_channel_{group_name.lower()}"] - drag_position = plot.channel_selection.visualItemRect( - plot_channel - ).center() - drop_position = plot.channel_selection.visualItemRect( - groups[group_name] - ).center() - - # Get the Name of the first channel - first_channel = plot_channel.text(self.Column.NAME) + for group_name, plot_channel in zip(("A", "B", "C"), (plot_channel_a, plot_channel_b, plot_channel_c)): + drag_position = self.plot.channel_selection.visualItemRect(plot_channel).center() + drop_position = self.plot.channel_selection.visualItemRect(groups[group_name]).center() + # PreEvaluation: Ensure that group has no child self.assertEqual(0, groups[group_name].childCount()) DragAndDrop( - source_widget=plot.channel_selection, - destination_widget=plot.channel_selection.viewport(), + source_widget=self.plot.channel_selection, + destination_widget=self.plot.channel_selection.viewport(), source_pos=drag_position, destination_pos=drop_position, ) + self.processEvents(0.05) self.assertEqual(1, groups[group_name].childCount()) - self.processEvents() # Move Group C inside Group B - drag_position = plot.channel_selection.visualItemRect(groups["C"]).center() - drop_position = plot.channel_selection.visualItemRect(groups["B"]).center() + drag_position = self.plot.channel_selection.visualItemRect(groups["C"]).center() + drop_position = self.plot.channel_selection.visualItemRect(groups["B"]).center() DragAndDrop( - source_widget=plot.channel_selection, - destination_widget=plot.channel_selection.viewport(), + source_widget=self.plot.channel_selection, + destination_widget=self.plot.channel_selection.viewport(), source_pos=drag_position, destination_pos=drop_position, ) # Move Group B inside Group A - drag_position = plot.channel_selection.visualItemRect(groups["B"]).center() - drop_position = plot.channel_selection.visualItemRect(groups["A"]).center() + drag_position = self.plot.channel_selection.visualItemRect(groups["B"]).center() + drop_position = self.plot.channel_selection.visualItemRect(groups["A"]).center() DragAndDrop( - source_widget=plot.channel_selection, - destination_widget=plot.channel_selection.viewport(), + source_widget=self.plot.channel_selection, + destination_widget=self.plot.channel_selection.viewport(), source_pos=drag_position, destination_pos=drop_position, ) @@ -664,27 +580,23 @@ def test_EnableDisable_Preserve_Subgroup_State_0(self): groups["B"].setExpanded(True) groups["C"].setExpanded(True) - enabled_groups_pixmap = plot.plot.viewport().grab() + enabled_groups_pixmap = self.plot.plot.viewport().grab() self.processEvents() # Evaluate for channel in (plot_channel_a, plot_channel_b, plot_channel_c): self.assertTrue( - Pixmap.has_color( - pixmap=enabled_groups_pixmap, color_name=channel.color - ), + Pixmap.has_color(pixmap=enabled_groups_pixmap, color_name=channel.color), msg=f"Color of Channel: {channel.text(self.Column.NAME)} not present on 'plot'.", ) # Press mouse double click on Group C self.mouseDClick_WidgetItem(groups["C"]) # Press mouse double click on Group B self.mouseDClick_WidgetItem(groups["B"]) - disabled_groups_pixmap = plot.plot.viewport().grab() + disabled_groups_pixmap = self.plot.plot.viewport().grab() # Evaluate self.assertTrue( - Pixmap.has_color( - pixmap=enabled_groups_pixmap, color_name=plot_channel_a.color - ), + Pixmap.has_color(pixmap=enabled_groups_pixmap, color_name=plot_channel_a.color), msg=f"Color of Channel: {plot_channel_a.text(self.Column.NAME)} not present on 'plot'.", ) for channel in (plot_channel_b, plot_channel_c): @@ -696,9 +608,9 @@ def test_EnableDisable_Preserve_Subgroup_State_0(self): msg=f"Color of Channel: {channel.text(self.Column.NAME)} present on 'plot'.", ) - QtTest.QTest.keyClick(plot.channel_selection, QtCore.Qt.Key_Up) + QtTest.QTest.keyClick(self.plot.channel_selection, QtCore.Qt.Key_Up) for _ in range(4): - QtTest.QTest.keyClick(plot.channel_selection, QtCore.Qt.Key_Down) + QtTest.QTest.keyClick(self.plot.channel_selection, QtCore.Qt.Key_Down) self.processEvents() # Press mouse double click on group B @@ -706,27 +618,23 @@ def test_EnableDisable_Preserve_Subgroup_State_0(self): self.processEvents() for _ in range(8): - QtTest.QTest.keyClick(plot.channel_selection, QtCore.Qt.Key_Down) + QtTest.QTest.keyClick(self.plot.channel_selection, QtCore.Qt.Key_Down) self.processEvents() # Evaluate - # After channels are enabled, they first flash a few times on plot. + # After channels are enabled, they first flash a few times on self.plot. # ProcessEvents few times for channels to be present for _ in range(20): - self.processEvents() + self.processEvents(0.05) - enabled_groups_pixmap = plot.plot.viewport().grab() + enabled_groups_pixmap = self.plot.plot.viewport().grab() self.assertFalse( - Pixmap.has_color( - pixmap=enabled_groups_pixmap, color_name=plot_channel_c.color - ), + Pixmap.has_color(pixmap=enabled_groups_pixmap, color_name=plot_channel_c.color), msg=f"Color for Channel: {plot_channel_c.text(self.Column.NAME)} present on 'plot'", ) for channel in (plot_channel_a, plot_channel_b, plot_channel_d): self.assertTrue( - Pixmap.has_color( - pixmap=enabled_groups_pixmap, color_name=channel.color - ), + Pixmap.has_color(pixmap=enabled_groups_pixmap, color_name=channel.color), msg=f"Color for Channel: {channel.text(self.Column.NAME)} not present on 'plot'", ) @@ -763,82 +671,60 @@ def test_EnableDisable_Preserve_Subgroup_State_1(self): - Evaluate that channel is not present on plot when is disabled. """ # Event - # Open File Widget - self.setUpFileWidget(measurement_file=self.measurement_file, default=True) - # Switch ComboBox to "Natural sort" - self.widget.channel_view.setCurrentText("Natural sort") - # Create a plot window - self.create_window(window_type="Plot") - self.assertEqual(len(self.widget.mdi_area.subWindowList()), 1) - plot = self.widget.mdi_area.subWindowList()[0].widget() - # Press PushButton 'FocusMode' - disabled (easy for evaluation) - if not plot.focused_mode_btn.isFlat(): - QtTest.QTest.mouseClick(plot.focused_mode_btn, QtCore.Qt.LeftButton) # Drag and Drop channel from FileWidget.channel_tree to Plot - plot_channel_a = self.add_channel_to_plot(plot=plot, channel_index=10) - plot_channel_b = self.add_channel_to_plot(plot=plot, channel_index=11) - plot_channel_c = self.add_channel_to_plot(plot=plot, channel_index=12) - plot_channel_d = self.add_channel_to_plot(plot=plot, channel_index=13) + plot_channel_a = self.add_channel_to_plot(channel_index=10) + plot_channel_b = self.add_channel_to_plot(channel_index=11) + plot_channel_c = self.add_channel_to_plot(channel_index=12) + plot_channel_d = self.add_channel_to_plot(channel_index=13) # Press 'Shift-Insert' in order to Insert Group # Create Channel Group. Drag channels inside the group one by one groups = {} - with mock.patch( - "asammdf.gui.widgets.tree.QtWidgets.QInputDialog.getText" - ) as mc_getText: + with mock.patch("asammdf.gui.widgets.tree.QtWidgets.QInputDialog.getText") as mc_getText: for group_name in ("A", "B", "C"): # Create Channel Group mc_getText.return_value = group_name, True - QtTest.QTest.keySequence( - plot.channel_selection, QtGui.QKeySequence("Shift+Insert") - ) + QtTest.QTest.keySequence(self.plot.channel_selection, QtGui.QKeySequence("Shift+Insert")) self.processEvents() # Get Groups Position - for index in range(plot.channel_selection.topLevelItemCount()): - item = plot.channel_selection.topLevelItem(index) + for index in range(self.plot.channel_selection.topLevelItemCount()): + item = self.plot.channel_selection.topLevelItem(index) group_name = item.text(self.Column.NAME) if group_name in ("A", "B", "C"): groups[group_name] = item item.setExpanded(True) # Get the First Item that will be moved - for group_name in ("A", "B", "C"): - plot_channel = locals()[f"plot_channel_{group_name.lower()}"] - drag_position = plot.channel_selection.visualItemRect( - plot_channel - ).center() - drop_position = plot.channel_selection.visualItemRect( - groups[group_name] - ).center() - - # Get the Name of the first channel - first_channel = plot_channel.text(self.Column.NAME) + for group_name, plot_channel in zip(("A", "B", "C"), (plot_channel_a, plot_channel_b, plot_channel_c)): + drag_position = self.plot.channel_selection.visualItemRect(plot_channel).center() + drop_position = self.plot.channel_selection.visualItemRect(groups[group_name]).center() + # PreEvaluation: Ensure that group has no child self.assertEqual(0, groups[group_name].childCount()) DragAndDrop( - source_widget=plot.channel_selection, - destination_widget=plot.channel_selection.viewport(), + source_widget=self.plot.channel_selection, + destination_widget=self.plot.channel_selection.viewport(), source_pos=drag_position, destination_pos=drop_position, ) + self.processEvents(0.05) self.assertEqual(1, groups[group_name].childCount()) - self.processEvents() # Move Group C inside Group B - drag_position = plot.channel_selection.visualItemRect(groups["C"]).center() - drop_position = plot.channel_selection.visualItemRect(groups["B"]).center() + drag_position = self.plot.channel_selection.visualItemRect(groups["C"]).center() + drop_position = self.plot.channel_selection.visualItemRect(groups["B"]).center() DragAndDrop( - source_widget=plot.channel_selection, - destination_widget=plot.channel_selection.viewport(), + source_widget=self.plot.channel_selection, + destination_widget=self.plot.channel_selection.viewport(), source_pos=drag_position, destination_pos=drop_position, ) # Move Group B inside Group A - drag_position = plot.channel_selection.visualItemRect(groups["B"]).center() - drop_position = plot.channel_selection.visualItemRect(groups["A"]).center() + drag_position = self.plot.channel_selection.visualItemRect(groups["B"]).center() + drop_position = self.plot.channel_selection.visualItemRect(groups["A"]).center() DragAndDrop( - source_widget=plot.channel_selection, - destination_widget=plot.channel_selection.viewport(), + source_widget=self.plot.channel_selection, + destination_widget=self.plot.channel_selection.viewport(), source_pos=drag_position, destination_pos=drop_position, ) @@ -847,27 +733,23 @@ def test_EnableDisable_Preserve_Subgroup_State_1(self): groups["B"].setExpanded(True) groups["C"].setExpanded(True) - enabled_groups_pixmap = plot.plot.viewport().grab() + enabled_groups_pixmap = self.plot.plot.viewport().grab() self.processEvents() # Evaluate for channel in (plot_channel_a, plot_channel_b, plot_channel_c): self.assertTrue( - Pixmap.has_color( - pixmap=enabled_groups_pixmap, color_name=channel.color - ), + Pixmap.has_color(pixmap=enabled_groups_pixmap, color_name=channel.color), msg=f"Color of Channel: {channel.text(self.Column.NAME)} not present on 'plot'.", ) # Press mouse double click on Group C self.mouseDClick_WidgetItem(groups["C"]) # Press mouse double click on Group B self.mouseDClick_WidgetItem(groups["B"]) - disabled_groups_pixmap = plot.plot.viewport().grab() + disabled_groups_pixmap = self.plot.plot.viewport().grab() # Evaluate self.assertTrue( - Pixmap.has_color( - pixmap=enabled_groups_pixmap, color_name=plot_channel_a.color - ), + Pixmap.has_color(pixmap=enabled_groups_pixmap, color_name=plot_channel_a.color), msg=f"Color of Channel: {plot_channel_a.text(self.Column.NAME)} not present on 'plot'.", ) for channel in (plot_channel_b, plot_channel_c): @@ -879,9 +761,9 @@ def test_EnableDisable_Preserve_Subgroup_State_1(self): msg=f"Color of Channel: {channel.text(self.Column.NAME)} present on 'plot'.", ) - QtTest.QTest.keyClick(plot.channel_selection, QtCore.Qt.Key_Up) + QtTest.QTest.keyClick(self.plot.channel_selection, QtCore.Qt.Key_Up) for _ in range(4): - QtTest.QTest.keyClick(plot.channel_selection, QtCore.Qt.Key_Down) + QtTest.QTest.keyClick(self.plot.channel_selection, QtCore.Qt.Key_Down) self.processEvents() # Press mouse double click on group B @@ -890,7 +772,7 @@ def test_EnableDisable_Preserve_Subgroup_State_1(self): self.processEvents() # Evaluate selected items - selectedItems = plot.channel_selection.selectedItems() + selectedItems = self.plot.channel_selection.selectedItems() self.assertEqual(1, len(selectedItems)) self.assertEqual("B", selectedItems[0].text(self.Column.NAME)) @@ -904,30 +786,26 @@ def test_EnableDisable_Preserve_Subgroup_State_1(self): self.mouseClick_WidgetItem(groups["C"]) # Evaluate that selection was changed. - selectedItems = plot.channel_selection.selectedItems() + selectedItems = self.plot.channel_selection.selectedItems() self.assertEqual(0, len(selectedItems)) for _ in range(8): - QtTest.QTest.keyClick(plot.channel_selection, QtCore.Qt.Key_Down) + QtTest.QTest.keyClick(self.plot.channel_selection, QtCore.Qt.Key_Down) self.processEvents() # Evaluate - # After channels are enabled, they first flash a few times on plot. + # After channels are enabled, they first flash a few times on self.plot. # ProcessEvents few times for channels to be present for _ in range(20): - self.processEvents() + self.processEvents(0.05) - enabled_groups_pixmap = plot.plot.viewport().grab() + enabled_groups_pixmap = self.plot.plot.viewport().grab() self.assertFalse( - Pixmap.has_color( - pixmap=enabled_groups_pixmap, color_name=plot_channel_c.color - ), + Pixmap.has_color(pixmap=enabled_groups_pixmap, color_name=plot_channel_c.color), msg=f"Color for Channel: {plot_channel_c.text(self.Column.NAME)} present on 'plot'", ) for channel in (plot_channel_a, plot_channel_b, plot_channel_d): self.assertTrue( - Pixmap.has_color( - pixmap=enabled_groups_pixmap, color_name=channel.color - ), + Pixmap.has_color(pixmap=enabled_groups_pixmap, color_name=channel.color), msg=f"Color for Channel: {channel.text(self.Column.NAME)} not present on 'plot'", ) diff --git a/test/asammdf/gui/widgets/test_PlotWidget_DragAndDrop.py b/test/asammdf/gui/widgets/test_PlotWidget_DragAndDrop.py index 32cbc95e5..0b68fb0da 100644 --- a/test/asammdf/gui/widgets/test_PlotWidget_DragAndDrop.py +++ b/test/asammdf/gui/widgets/test_PlotWidget_DragAndDrop.py @@ -239,19 +239,13 @@ def test_Plot_ChannelSelection_DragAndDrop_fromPlotCS_toPlot(self): self.assertEqual(6, plot.channel_selection.topLevelItemCount()) # Case 0: - with self.subTest( - "test_test_Plot_ChannelSelection_DragAndDrop_fromPlotCS_toPlot_0" - ): + with self.subTest("test_test_Plot_ChannelSelection_DragAndDrop_fromPlotCS_toPlot_0"): # DragAndDrop first channel to 3rd position. first_channel = plot.channel_selection.topLevelItem(0) third_channel = plot.channel_selection.topLevelItem(2) # Get Positions - drag_position = plot.channel_selection.visualItemRect( - first_channel - ).center() - drop_position = plot.channel_selection.visualItemRect( - third_channel - ).center() + drag_position = plot.channel_selection.visualItemRect(first_channel).center() + drop_position = plot.channel_selection.visualItemRect(third_channel).center() # Get Names first_channel = first_channel.text(self.Column.NAME) third_channel = third_channel.text(self.Column.NAME) @@ -263,32 +257,22 @@ def test_Plot_ChannelSelection_DragAndDrop_fromPlotCS_toPlot(self): ) # Evaluate # First channel position was changed. - new_first_channel = plot.channel_selection.topLevelItem(0).text( - self.Column.NAME - ) + new_first_channel = plot.channel_selection.topLevelItem(0).text(self.Column.NAME) self.assertNotEqual(first_channel, new_first_channel) # Evaluate that first channel was moved to third channel position. - new_third_channel = plot.channel_selection.topLevelItem(2).text( - self.Column.NAME - ) - new_fourth_channel = plot.channel_selection.topLevelItem(1).text( - self.Column.NAME - ) + new_third_channel = plot.channel_selection.topLevelItem(2).text(self.Column.NAME) + new_fourth_channel = plot.channel_selection.topLevelItem(1).text(self.Column.NAME) self.assertEqual(first_channel, new_third_channel) self.assertEqual(third_channel, new_fourth_channel) # Case 1: - with self.subTest( - "test_test_Plot_ChannelSelection_DragAndDrop_fromPlotCS_toPlot_1" - ): + with self.subTest("test_test_Plot_ChannelSelection_DragAndDrop_fromPlotCS_toPlot_1"): # DragAndDrop 2nd and 3rd channels on last position. second_channel = plot.channel_selection.topLevelItem(1) third_channel = plot.channel_selection.topLevelItem(2) last_channel = plot.channel_selection.topLevelItem(5) # Get Positions - drag_position = plot.channel_selection.visualItemRect( - third_channel - ).center() + drag_position = plot.channel_selection.visualItemRect(third_channel).center() drop_position = plot.channel_selection.visualItemRect(last_channel).center() # Select second_channel.setSelected(True) @@ -303,36 +287,22 @@ def test_Plot_ChannelSelection_DragAndDrop_fromPlotCS_toPlot(self): destination_pos=drop_position, ) # Evaluate - new_second_channel = plot.channel_selection.topLevelItem(1).text( - self.Column.NAME - ) - new_third_channel = plot.channel_selection.topLevelItem(2).text( - self.Column.NAME - ) + new_second_channel = plot.channel_selection.topLevelItem(1).text(self.Column.NAME) + new_third_channel = plot.channel_selection.topLevelItem(2).text(self.Column.NAME) self.assertNotEqual(second_channel, new_second_channel) self.assertNotEqual(third_channel, new_third_channel) - new_fifth_channel = plot.channel_selection.topLevelItem(4).text( - self.Column.NAME - ) - new_sixth_channel = plot.channel_selection.topLevelItem(5).text( - self.Column.NAME - ) + new_fifth_channel = plot.channel_selection.topLevelItem(4).text(self.Column.NAME) + new_sixth_channel = plot.channel_selection.topLevelItem(5).text(self.Column.NAME) self.assertEqual(second_channel, new_fifth_channel) self.assertEqual(third_channel, new_sixth_channel) # Case 2: - with self.subTest( - "test_test_Plot_ChannelSelection_DragAndDrop_fromPlotCS_toPlot_2" - ): + with self.subTest("test_test_Plot_ChannelSelection_DragAndDrop_fromPlotCS_toPlot_2"): # Create Channel Group. Drag channels inside the group one by one - with mock.patch( - "asammdf.gui.widgets.tree.QtWidgets.QInputDialog.getText" - ) as mc_getText: + with mock.patch("asammdf.gui.widgets.tree.QtWidgets.QInputDialog.getText") as mc_getText: # Create Channel Group mc_getText.return_value = "FirstGroup", True - QtTest.QTest.keySequence( - plot.channel_selection, QtGui.QKeySequence("Shift+Insert") - ) + QtTest.QTest.keySequence(plot.channel_selection, QtGui.QKeySequence("Shift+Insert")) # PreEvaluation: Check if there is one extra-item self.assertEqual(7, plot.channel_selection.topLevelItemCount()) # Get Group Position @@ -350,12 +320,8 @@ def test_Plot_ChannelSelection_DragAndDrop_fromPlotCS_toPlot(self): if first_channel.text(self.Column.NAME) == duplicated_channel: first_channel = plot.channel_selection.topLevelItem(2) - drag_position = plot.channel_selection.visualItemRect( - first_channel - ).center() - drop_position = plot.channel_selection.visualItemRect( - first_group - ).center() + drag_position = plot.channel_selection.visualItemRect(first_channel).center() + drop_position = plot.channel_selection.visualItemRect(first_group).center() # Get Name of first channel first_channel = first_channel.text(self.Column.NAME) # PreEvaluation: Ensure that group has no child @@ -368,9 +334,7 @@ def test_Plot_ChannelSelection_DragAndDrop_fromPlotCS_toPlot(self): ) # Evaluate self.assertEqual(1, first_group.childCount()) - self.assertEqual( - first_channel, first_group.child(0).text(self.Column.NAME) - ) + self.assertEqual(first_channel, first_group.child(0).text(self.Column.NAME)) self.assertEqual(6, plot.channel_selection.topLevelItemCount()) second_channel = None @@ -381,13 +345,9 @@ def test_Plot_ChannelSelection_DragAndDrop_fromPlotCS_toPlot(self): break else: self.fail("Duplicate Channel is not found anymore.") - drag_position = plot.channel_selection.visualItemRect( - second_channel - ).center() + drag_position = plot.channel_selection.visualItemRect(second_channel).center() # Now drop over the first item from group. - drop_position = plot.channel_selection.visualItemRect( - first_group.child(0) - ).center() + drop_position = plot.channel_selection.visualItemRect(first_group.child(0)).center() DragAndDrop( source_widget=plot.channel_selection, destination_widget=plot.channel_selection.viewport(), @@ -396,24 +356,16 @@ def test_Plot_ChannelSelection_DragAndDrop_fromPlotCS_toPlot(self): ) # Evaluate self.assertEqual(2, first_group.childCount()) - self.assertEqual( - duplicated_channel, first_group.child(1).text(self.Column.NAME) - ) + self.assertEqual(duplicated_channel, first_group.child(1).text(self.Column.NAME)) self.assertEqual(5, plot.channel_selection.topLevelItemCount()) # Case 3: - with self.subTest( - "test_test_Plot_ChannelSelection_DragAndDrop_fromPlotCS_toPlot_3" - ): + with self.subTest("test_test_Plot_ChannelSelection_DragAndDrop_fromPlotCS_toPlot_3"): # Create Channel Group. Drag multiple channels inside the group - with mock.patch( - "asammdf.gui.widgets.tree.QtWidgets.QInputDialog.getText" - ) as mc_getText: + with mock.patch("asammdf.gui.widgets.tree.QtWidgets.QInputDialog.getText") as mc_getText: # Create Channel Group mc_getText.return_value = "SecondGroup", True - QtTest.QTest.keySequence( - plot.channel_selection, QtGui.QKeySequence("Shift+Insert") - ) + QtTest.QTest.keySequence(plot.channel_selection, QtGui.QKeySequence("Shift+Insert")) # PreEvaluation: Check if there is one extra-item self.assertEqual(6, plot.channel_selection.topLevelItemCount()) # Get Group Position @@ -427,20 +379,12 @@ def test_Plot_ChannelSelection_DragAndDrop_fromPlotCS_toPlot(self): self.fail("SecondGroup is not present on Plot Channel Selection.") second_group.setExpanded(True) # Get Channels - last_channel_0 = plot.channel_selection.topLevelItem( - plot.channel_selection.topLevelItemCount() - 1 - ) - last_channel_1 = plot.channel_selection.topLevelItem( - plot.channel_selection.topLevelItemCount() - 2 - ) + last_channel_0 = plot.channel_selection.topLevelItem(plot.channel_selection.topLevelItemCount() - 1) + last_channel_1 = plot.channel_selection.topLevelItem(plot.channel_selection.topLevelItemCount() - 2) last_channel_0.setSelected(True) last_channel_1.setSelected(True) - drag_position = plot.channel_selection.visualItemRect( - last_channel_1 - ).center() - drop_position = plot.channel_selection.visualItemRect( - second_group - ).center() + drag_position = plot.channel_selection.visualItemRect(last_channel_1).center() + drop_position = plot.channel_selection.visualItemRect(second_group).center() DragAndDrop( source_widget=plot.channel_selection, destination_widget=plot.channel_selection.viewport(), @@ -452,9 +396,7 @@ def test_Plot_ChannelSelection_DragAndDrop_fromPlotCS_toPlot(self): self.assertEqual(4, plot.channel_selection.topLevelItemCount()) # Case 4: - with self.subTest( - "test_test_Plot_ChannelSelection_DragAndDrop_fromPlotCS_toPlot_4" - ): + with self.subTest("test_test_Plot_ChannelSelection_DragAndDrop_fromPlotCS_toPlot_4"): # Drag Group inside the Group # Get Group Positions first_group, second_group = None, None @@ -481,9 +423,7 @@ def test_Plot_ChannelSelection_DragAndDrop_fromPlotCS_toPlot(self): self.assertEqual(3, plot.channel_selection.topLevelItemCount()) # Case 5: - with self.subTest( - "test_test_Plot_ChannelSelection_DragAndDrop_fromPlotCS_toPlot_5" - ): + with self.subTest("test_test_Plot_ChannelSelection_DragAndDrop_fromPlotCS_toPlot_5"): # Drag Group outside the Group # Get Group Positions first_group, second_group = None, None diff --git a/test/asammdf/gui/widgets/test_PlotWidget_PushButtons.py b/test/asammdf/gui/widgets/test_PlotWidget_PushButtons.py index 994a22af1..b6b4a64a1 100644 --- a/test/asammdf/gui/widgets/test_PlotWidget_PushButtons.py +++ b/test/asammdf/gui/widgets/test_PlotWidget_PushButtons.py @@ -30,13 +30,9 @@ def setUp(self): self.assertTrue(Pixmap.is_black(clear_pixmap)) # Add Channels to Plot - self.plot_tree_channel_0 = self.add_channel_to_plot( - plot=self.plot, channel_name=self.channel_0_name - ) + self.plot_tree_channel_0 = self.add_channel_to_plot(plot=self.plot, channel_name=self.channel_0_name) self.assertEqual(1, self.plot.channel_selection.topLevelItemCount()) - self.plot_tree_channel_1 = self.add_channel_to_plot( - plot=self.plot, channel_name=self.channel_1_name - ) + self.plot_tree_channel_1 = self.add_channel_to_plot(plot=self.plot, channel_name=self.channel_1_name) self.assertEqual(2, self.plot.channel_selection.topLevelItemCount()) # Identify PlotSignal @@ -74,24 +70,16 @@ def test_Plot_ChannelSelection_PushButton_ValuePanel(self): # Event if self.plot.selected_channel_value.isVisible(): # Press PushButton "Hide selected channel value panel" - QtTest.QTest.mouseClick( - self.plot.selected_channel_value_btn, QtCore.Qt.LeftButton - ) + QtTest.QTest.mouseClick(self.plot.selected_channel_value_btn, QtCore.Qt.LeftButton) # Press PushButton "Show selected channel value panel" - QtTest.QTest.mouseClick( - self.plot.selected_channel_value_btn, QtCore.Qt.LeftButton - ) + QtTest.QTest.mouseClick(self.plot.selected_channel_value_btn, QtCore.Qt.LeftButton) self.assertTrue(self.plot.selected_channel_value.isVisible()) # Press PushButton "Hide selected channel value panel" - QtTest.QTest.mouseClick( - self.plot.selected_channel_value_btn, QtCore.Qt.LeftButton - ) + QtTest.QTest.mouseClick(self.plot.selected_channel_value_btn, QtCore.Qt.LeftButton) self.assertFalse(self.plot.selected_channel_value.isVisible()) # Press PushButton "Show selected channel value panel" - QtTest.QTest.mouseClick( - self.plot.selected_channel_value_btn, QtCore.Qt.LeftButton - ) + QtTest.QTest.mouseClick(self.plot.selected_channel_value_btn, QtCore.Qt.LeftButton) self.assertTrue(self.plot.selected_channel_value.isVisible()) # Select Channel @@ -205,9 +193,7 @@ def test_Plot_ChannelSelection_PushButton_FocusedMode(self): self.plot.channel_selection.viewport(), QtCore.Qt.LeftButton, QtCore.Qt.KeyboardModifiers(), - self.plot.channel_selection.visualItemRect( - self.plot_tree_channel_1 - ).center(), + self.plot.channel_selection.visualItemRect(self.plot_tree_channel_1).center(), ) # Process flash until signal is present on plot. for _ in range(10): @@ -293,9 +279,7 @@ def test_Plot_ChannelSelection_PushButton_RegionDelta(self): self.plot.channel_selection.viewport(), QtCore.Qt.LeftButton, QtCore.Qt.KeyboardModifiers(), - self.plot.channel_selection.visualItemRect( - self.plot_tree_channel_1 - ).center(), + self.plot.channel_selection.visualItemRect(self.plot_tree_channel_1).center(), ) self.plot.plot.setFocus() self.processEvents(0.1) @@ -305,22 +289,14 @@ def test_Plot_ChannelSelection_PushButton_RegionDelta(self): self.processEvents(timeout=0.1) # Get current value: Ex: 'Δ = 8'. Get last number - old_channel_0_value = int( - self.plot_tree_channel_0.text(self.Column.VALUE).split(" ")[-1] - ) - old_channel_1_value = int( - self.plot_tree_channel_1.text(self.Column.VALUE).split(" ")[-1] - ) + old_channel_0_value = int(self.plot_tree_channel_0.text(self.Column.VALUE).split(" ")[-1]) + old_channel_1_value = int(self.plot_tree_channel_1.text(self.Column.VALUE).split(" ")[-1]) for count in range(5): QtTest.QTest.keyClick(self.plot.plot, QtCore.Qt.Key_Right) self.processEvents(timeout=0.1) # Evaluate - channel_0_value = int( - self.plot_tree_channel_0.text(self.Column.VALUE).split(" ")[-1] - ) - channel_1_value = int( - self.plot_tree_channel_1.text(self.Column.VALUE).split(" ")[-1] - ) + channel_0_value = int(self.plot_tree_channel_0.text(self.Column.VALUE).split(" ")[-1]) + channel_1_value = int(self.plot_tree_channel_1.text(self.Column.VALUE).split(" ")[-1]) self.assertLess(old_channel_0_value, channel_0_value) self.assertGreater(old_channel_1_value, channel_1_value) old_channel_0_value = channel_0_value diff --git a/test/asammdf/gui/widgets/test_PlotWidget_Shortcuts.py b/test/asammdf/gui/widgets/test_PlotWidget_Shortcuts.py index 4fa4e3d5c..636a80cd0 100644 --- a/test/asammdf/gui/widgets/test_PlotWidget_Shortcuts.py +++ b/test/asammdf/gui/widgets/test_PlotWidget_Shortcuts.py @@ -36,12 +36,8 @@ def test_Plot_Plot_Shortcut_Key_LeftRight(self): plot = self.widget.mdi_area.subWindowList()[0].widget() channel_selection = plot.channel_selection - channel_14 = self.add_channel_to_plot( - plot=plot, channel_name="ASAM_[14].M.MATRIX_DIM_16.UBYTE.IDENTICAL" - ) - channel_15 = self.add_channel_to_plot( - plot=plot, channel_name="ASAM_[15].M.MATRIX_DIM_16.UBYTE.IDENTICAL" - ) + channel_14 = self.add_channel_to_plot(plot=plot, channel_name="ASAM_[14].M.MATRIX_DIM_16.UBYTE.IDENTICAL") + channel_15 = self.add_channel_to_plot(plot=plot, channel_name="ASAM_[15].M.MATRIX_DIM_16.UBYTE.IDENTICAL") self.assertEqual(2, plot.channel_selection.topLevelItemCount()) # Case 0: diff --git a/test/run_all.py b/test/run_all.py index 47ab214e8..31a95e119 100644 --- a/test/run_all.py +++ b/test/run_all.py @@ -12,9 +12,7 @@ def main(): tests = unittest.TestLoader().discover(".", "test_*.py") - testResult = xmlrunner.XMLTestRunner( - output=str(Path(".").resolve() / "test-reports") - ).run(tests) + testResult = xmlrunner.XMLTestRunner(output=str(Path(".").resolve() / "test-reports")).run(tests) return not testResult.wasSuccessful() diff --git a/test/test_CAN_bus_loogging.py b/test/test_CAN_bus_loogging.py index 461924c0c..45b714377 100644 --- a/test/test_CAN_bus_loogging.py +++ b/test/test_CAN_bus_loogging.py @@ -37,25 +37,13 @@ def test_obd_extract(self): for file in temp_dir.iterdir(): print(file) - mdf = [ - input_file - for input_file in temp_dir.iterdir() - if input_file.suffix == ".mf4" - ][0] + mdf = [input_file for input_file in temp_dir.iterdir() if input_file.suffix == ".mf4"][0] mdf = MDF(mdf) - dbc = [ - input_file - for input_file in temp_dir.iterdir() - if input_file.suffix == ".dbc" - ][0] + dbc = [input_file for input_file in temp_dir.iterdir() if input_file.suffix == ".dbc"][0] - signals = [ - input_file - for input_file in temp_dir.iterdir() - if input_file.suffix == ".npy" - ] + signals = [input_file for input_file in temp_dir.iterdir() if input_file.suffix == ".npy"] out = mdf.extract_bus_logging({"CAN": [(dbc, 0)]}) @@ -65,34 +53,20 @@ def test_obd_extract(self): target = np.load(signal) sig = out.get(name) - self.assertTrue( - np.array_equal(sig.samples, target), f"{name} {sig} {target}" - ) + self.assertTrue(np.array_equal(sig.samples, target), f"{name} {sig} {target}") def test_j1939_extract(self): print("J1939 extract") temp_dir = Path(TestCANBusLogging.tempdir_j1939.name) - mdf = [ - input_file - for input_file in temp_dir.iterdir() - if input_file.suffix == ".mf4" - ][0] + mdf = [input_file for input_file in temp_dir.iterdir() if input_file.suffix == ".mf4"][0] mdf = MDF(mdf) - dbc = [ - input_file - for input_file in temp_dir.iterdir() - if input_file.suffix == ".dbc" - ][0] + dbc = [input_file for input_file in temp_dir.iterdir() if input_file.suffix == ".dbc"][0] - signals = [ - input_file - for input_file in temp_dir.iterdir() - if input_file.suffix == ".npy" - ] + signals = [input_file for input_file in temp_dir.iterdir() if input_file.suffix == ".npy"] out = mdf.extract_bus_logging({"CAN": [(dbc, 0)]}) @@ -109,25 +83,13 @@ def test_j1939_get_can_signal(self): temp_dir = Path(TestCANBusLogging.tempdir_j1939.name) - mdf = [ - input_file - for input_file in temp_dir.iterdir() - if input_file.suffix == ".mf4" - ][0] + mdf = [input_file for input_file in temp_dir.iterdir() if input_file.suffix == ".mf4"][0] mdf = MDF(mdf) - dbc = [ - input_file - for input_file in temp_dir.iterdir() - if input_file.suffix == ".dbc" - ][0] - - signals = [ - input_file - for input_file in temp_dir.iterdir() - if input_file.suffix == ".npy" - ] + dbc = [input_file for input_file in temp_dir.iterdir() if input_file.suffix == ".dbc"][0] + + signals = [input_file for input_file in temp_dir.iterdir() if input_file.suffix == ".npy"] for signal in signals: name = signal.stem diff --git a/test/test_endianess.py b/test/test_endianess.py index 7d709f512..41e590fef 100644 --- a/test/test_endianess.py +++ b/test/test_endianess.py @@ -21,20 +21,14 @@ def setUpClass(cls): def test_mixed(self): t = np.arange(15, dtype=" version >= "3.20" -] +SUPPORTED_VERSIONS = [version for version in SUPPORTED_VERSIONS if "4.20" > version >= "3.20"] CHANNEL_LEN = 100000 @@ -108,16 +106,9 @@ def test_read(self): elif i == 4: for j in range(1, 20): target = np.array( - [ - "Channel {} sample {}".format(j, k).encode( - "ascii" - ) - for k in range(cycles) - ] + ["Channel {} sample {}".format(j, k).encode("ascii") for k in range(cycles)] ) - vals = mdf.get(group=i, index=j + 1, samples_only=True)[ - 0 - ] + vals = mdf.get(group=i, index=j + 1, samples_only=True)[0] cond = np.array_equal(vals, target) if not cond: print(i, j, vals, target, len(vals), len(target)) @@ -127,9 +118,7 @@ def test_read(self): v = np.ones(cycles, dtype=np.dtype("(8,)u1")) for j in range(1, 20): target = v * j - vals = mdf.get(group=i, index=j + 1, samples_only=True)[ - 0 - ] + vals = mdf.get(group=i, index=j + 1, samples_only=True)[0] cond = np.array_equal(vals, target) if not cond: print(i, j, vals, target, len(vals), len(target)) @@ -137,12 +126,8 @@ def test_read(self): elif i == 6: for j in range(1, 20): - target = np.array( - [b"Value %d" % j for _ in range(cycles)] - ) - vals = mdf.get(group=i, index=j + 1, samples_only=True)[ - 0 - ] + target = np.array([b"Value %d" % j for _ in range(cycles)]) + vals = mdf.get(group=i, index=j + 1, samples_only=True)[0] cond = np.array_equal(vals, target) if not cond: print(i, j, vals, target, len(vals), len(target)) @@ -179,9 +164,7 @@ def test_read_arrays(self): ] types = np.dtype(types) - vals = mdf.get( - "Channel_{}".format(j), group=i, samples_only=True - )[0] + vals = mdf.get("Channel_{}".format(j), group=i, samples_only=True)[0] target = [arr * j for arr in samples] target = np.core.records.fromarrays(target, dtype=types) if not np.array_equal(vals, target): @@ -197,9 +180,7 @@ def test_read_arrays(self): types = [("Channel_{}".format(j), "(2, 3)= "4.00" - else v3c.CONVERSION_TYPE_LINEAR, + "conversion_type": v4c.CONVERSION_TYPE_LIN if version >= "4.00" else v3c.CONVERSION_TYPE_LINEAR, "a": float(i), "b": -0.5, } @@ -79,9 +77,7 @@ def generate_test_file(tmpdir, version="4.10"): sigs = [] for i in range(channels_count): conversion = { - "conversion_type": v4c.CONVERSION_TYPE_ALG - if version >= "4.00" - else v3c.CONVERSION_TYPE_FORMULA, + "conversion_type": v4c.CONVERSION_TYPE_ALG if version >= "4.00" else v3c.CONVERSION_TYPE_FORMULA, "formula": "{} * sin(X)".format(i), } sig = Signal( @@ -100,9 +96,7 @@ def generate_test_file(tmpdir, version="4.10"): sigs = [] for i in range(channels_count): conversion = { - "conversion_type": v4c.CONVERSION_TYPE_RAT - if version >= "4.00" - else v3c.CONVERSION_TYPE_RAT, + "conversion_type": v4c.CONVERSION_TYPE_RAT if version >= "4.00" else v3c.CONVERSION_TYPE_RAT, "P1": 0, "P2": i, "P3": -0.5, @@ -126,9 +120,7 @@ def generate_test_file(tmpdir, version="4.10"): sigs = [] encoding = "latin-1" if version < "4.00" else "utf-8" for i in range(channels_count): - sig = [ - "Channel {} sample {}".format(i, j).encode(encoding) for j in range(cycles) - ] + sig = ["Channel {} sample {}".format(i, j).encode(encoding) for j in range(cycles)] sig = Signal( np.array(sig), t, @@ -162,17 +154,13 @@ def generate_test_file(tmpdir, version="4.10"): conversion = { "raw": np.arange(255, dtype=np.float64), "phys": np.array(["Value {}".format(i).encode("ascii") for i in range(255)]), - "conversion_type": v4c.CONVERSION_TYPE_TABX - if version >= "4.00" - else v3c.CONVERSION_TYPE_TABX, + "conversion_type": v4c.CONVERSION_TYPE_TABX if version >= "4.00" else v3c.CONVERSION_TYPE_TABX, "links_nr": 260, "ref_param_nr": 255, } for i in range(255): - conversion["val_{}".format(i)] = conversion[ - "param_val_{}".format(i) - ] = conversion["raw"][i] + conversion["val_{}".format(i)] = conversion["param_val_{}".format(i)] = conversion["raw"][i] conversion["text_{}".format(i)] = conversion["phys"][i] conversion["text_{}".format(255)] = "Default" From 899b4050a657ec58394b354bb68abc6bac804b02 Mon Sep 17 00:00:00 2001 From: tov101 Date: Mon, 11 Sep 2023 09:57:13 +0300 Subject: [PATCH 08/11] .. --- .../gui/widgets/test_BasePlotWidget.py | 2 +- .../widgets/test_PlotWidget_DoubleClick.py | 30 +++++++++++-------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/test/asammdf/gui/widgets/test_BasePlotWidget.py b/test/asammdf/gui/widgets/test_BasePlotWidget.py index 56b86d94d..dc2928e5f 100644 --- a/test/asammdf/gui/widgets/test_BasePlotWidget.py +++ b/test/asammdf/gui/widgets/test_BasePlotWidget.py @@ -58,7 +58,7 @@ def add_channel_to_plot(self, plot=None, channel_name=None, channel_index=None): plot_channel = item iterator += 1 - self.processEvents() + self.processEvents(0.05) return plot_channel def create_window(self, window_type): diff --git a/test/asammdf/gui/widgets/test_PlotWidget_DoubleClick.py b/test/asammdf/gui/widgets/test_PlotWidget_DoubleClick.py index 82731e162..f83d41a6c 100644 --- a/test/asammdf/gui/widgets/test_PlotWidget_DoubleClick.py +++ b/test/asammdf/gui/widgets/test_PlotWidget_DoubleClick.py @@ -1,11 +1,15 @@ #!/usr/bin/env python -from test.asammdf.gui.test_base import DragAndDrop, Pixmap -from test.asammdf.gui.widgets.test_BasePlotWidget import TestPlotWidget +import sys +import unittest from unittest import mock from PySide6 import QtCore, QtGui, QtTest +from test.asammdf.gui.test_base import DragAndDrop, Pixmap +from test.asammdf.gui.widgets.test_BasePlotWidget import TestPlotWidget + +@unittest.skipIf(sys.platform != "win32", "Timers cannot be started/stopped from another thread.") class TestDoubleClick(TestPlotWidget): # Note: Test Plot Widget through FileWidget. def setUp(self): @@ -88,8 +92,7 @@ def test_EnableDisable_Group(self): mc_getText.return_value = "FirstGroup", True QtTest.QTest.keySequence(self.plot.channel_selection, QtGui.QKeySequence("Shift+Insert")) self.processEvents() - # PreEvaluation: Check if there is one extra-item - self.assertEqual(4, self.plot.channel_selection.topLevelItemCount()) + # Get Group Position for index in range(self.plot.channel_selection.topLevelItemCount()): item = self.plot.channel_selection.topLevelItem(index) @@ -127,9 +130,10 @@ def test_EnableDisable_Group(self): ) # Press mouse double click on channel self.mouseDClick_WidgetItem(first_group) - disabled_groups_pixmap = self.plot.plot.viewport().grab() # Evaluate + self.processEvents(0.05) + disabled_groups_pixmap = self.plot.plot.viewport().grab() self.assertFalse( Pixmap.has_color( pixmap=disabled_groups_pixmap, @@ -328,10 +332,10 @@ def test_EnableDisable_ParentGroup(self): enabled_groups_pixmap = self.plot.plot.viewport().grab() for channel in ( - plot_channel_a, - plot_channel_b, - plot_channel_c, - plot_channel_d, + plot_channel_a, + plot_channel_b, + plot_channel_c, + plot_channel_d, ): self.assertTrue( Pixmap.has_color(pixmap=enabled_groups_pixmap, color_name=channel.color), @@ -478,10 +482,10 @@ def test_EnableDisable_Subgroup(self): enabled_groups_pixmap = self.plot.plot.viewport().grab() for channel in ( - plot_channel_a, - plot_channel_b, - plot_channel_c, - plot_channel_d, + plot_channel_a, + plot_channel_b, + plot_channel_c, + plot_channel_d, ): self.assertTrue( Pixmap.has_color(pixmap=enabled_groups_pixmap, color_name=channel.color), From e3fd6b0b411669a880050275dbec5c1f93738341 Mon Sep 17 00:00:00 2001 From: tov101 Date: Mon, 11 Sep 2023 10:07:38 +0300 Subject: [PATCH 09/11] .. --- src/asammdf/gui/widgets/tree.py | 3 ++- test/asammdf/gui/test_base.py | 1 + .../gui/widgets/test_BasePlotWidget.py | 2 +- .../widgets/test_PlotWidget_DoubleClick.py | 21 +++++++++---------- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/asammdf/gui/widgets/tree.py b/src/asammdf/gui/widgets/tree.py index 2d409f805..8ac7bb53e 100644 --- a/src/asammdf/gui/widgets/tree.py +++ b/src/asammdf/gui/widgets/tree.py @@ -851,7 +851,8 @@ def mouseDoubleClickEvent(self, event): self.context_menu_timer.stop() self.context_menu_pos = None - self.double_click.emit(self.itemAt(event.pos()), event.button()) + position = event.position() + self.double_click.emit(self.itemAt(position.x(), position.y()), event.button()) def open_menu(self): position = self.context_menu_pos diff --git a/test/asammdf/gui/test_base.py b/test/asammdf/gui/test_base.py index 92e94eadb..84a580a57 100644 --- a/test/asammdf/gui/test_base.py +++ b/test/asammdf/gui/test_base.py @@ -209,6 +209,7 @@ def __init__(self, source_widget, destination_widget, source_pos, destination_po # drag_thread.wait() move_thread.wait() move_thread.quit() + QtCore.QCoreApplication.processEvents() class Pixmap: diff --git a/test/asammdf/gui/widgets/test_BasePlotWidget.py b/test/asammdf/gui/widgets/test_BasePlotWidget.py index dc2928e5f..ce322cc38 100644 --- a/test/asammdf/gui/widgets/test_BasePlotWidget.py +++ b/test/asammdf/gui/widgets/test_BasePlotWidget.py @@ -50,6 +50,7 @@ def add_channel_to_plot(self, plot=None, channel_name=None, channel_index=None): source_pos=drag_position, destination_pos=drop_position, ) + self.processEvents(0.05) plot_channel = None iterator = QtWidgets.QTreeWidgetItemIterator(plot.channel_selection) while iterator.value(): @@ -58,7 +59,6 @@ def add_channel_to_plot(self, plot=None, channel_name=None, channel_index=None): plot_channel = item iterator += 1 - self.processEvents(0.05) return plot_channel def create_window(self, window_type): diff --git a/test/asammdf/gui/widgets/test_PlotWidget_DoubleClick.py b/test/asammdf/gui/widgets/test_PlotWidget_DoubleClick.py index f83d41a6c..410e04518 100644 --- a/test/asammdf/gui/widgets/test_PlotWidget_DoubleClick.py +++ b/test/asammdf/gui/widgets/test_PlotWidget_DoubleClick.py @@ -1,13 +1,12 @@ #!/usr/bin/env python import sys +from test.asammdf.gui.test_base import DragAndDrop, Pixmap +from test.asammdf.gui.widgets.test_BasePlotWidget import TestPlotWidget import unittest from unittest import mock from PySide6 import QtCore, QtGui, QtTest -from test.asammdf.gui.test_base import DragAndDrop, Pixmap -from test.asammdf.gui.widgets.test_BasePlotWidget import TestPlotWidget - @unittest.skipIf(sys.platform != "win32", "Timers cannot be started/stopped from another thread.") class TestDoubleClick(TestPlotWidget): @@ -332,10 +331,10 @@ def test_EnableDisable_ParentGroup(self): enabled_groups_pixmap = self.plot.plot.viewport().grab() for channel in ( - plot_channel_a, - plot_channel_b, - plot_channel_c, - plot_channel_d, + plot_channel_a, + plot_channel_b, + plot_channel_c, + plot_channel_d, ): self.assertTrue( Pixmap.has_color(pixmap=enabled_groups_pixmap, color_name=channel.color), @@ -482,10 +481,10 @@ def test_EnableDisable_Subgroup(self): enabled_groups_pixmap = self.plot.plot.viewport().grab() for channel in ( - plot_channel_a, - plot_channel_b, - plot_channel_c, - plot_channel_d, + plot_channel_a, + plot_channel_b, + plot_channel_c, + plot_channel_d, ): self.assertTrue( Pixmap.has_color(pixmap=enabled_groups_pixmap, color_name=channel.color), From a010137c6c6dc45e37481c62ee2fdd365cc14145 Mon Sep 17 00:00:00 2001 From: tov101 Date: Mon, 11 Sep 2023 10:17:05 +0300 Subject: [PATCH 10/11] Give some time for plot to be updated. --- test/asammdf/gui/widgets/test_PlotWidget_DoubleClick.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/asammdf/gui/widgets/test_PlotWidget_DoubleClick.py b/test/asammdf/gui/widgets/test_PlotWidget_DoubleClick.py index 410e04518..1c7f7c6d9 100644 --- a/test/asammdf/gui/widgets/test_PlotWidget_DoubleClick.py +++ b/test/asammdf/gui/widgets/test_PlotWidget_DoubleClick.py @@ -131,7 +131,8 @@ def test_EnableDisable_Group(self): self.mouseDClick_WidgetItem(first_group) # Evaluate - self.processEvents(0.05) + for _ in range(10): + self.processEvents(0.05) disabled_groups_pixmap = self.plot.plot.viewport().grab() self.assertFalse( Pixmap.has_color( @@ -283,10 +284,11 @@ def test_EnableDisable_ParentGroup(self): self.assertNotEqual(color_name, "#808080") # Press mouse double click on Group A self.mouseDClick_WidgetItem(groups["A"]) - self.processEvents() - disabled_groups_pixmap = self.plot.plot.viewport().grab() # Evaluate + for _ in range(10): + self.processEvents(0.05) + disabled_groups_pixmap = self.plot.plot.viewport().grab() for channel in (plot_channel_a, plot_channel_b, plot_channel_c): self.assertFalse( Pixmap.has_color( From 9f30d473f656aaf6d455bd0b7525d1ab64b2648a Mon Sep 17 00:00:00 2001 From: tov101 Date: Mon, 11 Sep 2023 10:27:41 +0300 Subject: [PATCH 11/11] Maybe Axis colors remains on plot. --- test/asammdf/gui/widgets/test_PlotWidget_DoubleClick.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/asammdf/gui/widgets/test_PlotWidget_DoubleClick.py b/test/asammdf/gui/widgets/test_PlotWidget_DoubleClick.py index 1c7f7c6d9..d37ea917d 100644 --- a/test/asammdf/gui/widgets/test_PlotWidget_DoubleClick.py +++ b/test/asammdf/gui/widgets/test_PlotWidget_DoubleClick.py @@ -27,6 +27,10 @@ def setUp(self): # Press PushButton 'FocusMode' - disabled (easy for evaluation) if not self.plot.focused_mode_btn.isFlat(): QtTest.QTest.mouseClick(self.plot.focused_mode_btn, QtCore.Qt.LeftButton) + # Press PushButton "Hide axis" + if not self.plot.hide_axes_btn.isFlat(): + QtTest.QTest.mouseClick(self.plot.hide_axes_btn, QtCore.Qt.LeftButton) + self.processEvents() def test_ChannelSelection(self): """ @@ -127,7 +131,7 @@ def test_EnableDisable_Group(self): color_name=plot_channel_0.color, ) ) - # Press mouse double click on channel + # Press mouse double click on Group self.mouseDClick_WidgetItem(first_group) # Evaluate