diff options
author | Adrian Herrmann <[email protected]> | 2023-12-05 13:00:27 +0100 |
---|---|---|
committer | Adrian Herrmann <[email protected]> | 2023-12-06 11:52:07 +0100 |
commit | 592c734e57b00040329b49dfbe11869980dff88a (patch) | |
tree | 79fa3498cb974e5026415971ec83107b92b65919 | |
parent | c0329cff9d7378b8bf6a17baeb97bf5a240977fc (diff) |
Examples: Fix a number of flake8 errors (part 1)
First batch, including low-hanging fruit like Alignments, whitespaces,
line length, indents, etc.
Pick-to: 6.6
Change-Id: I55966876077f7fddfdc82cbe376677af9995f329
Reviewed-by: Friedemann Kleint <[email protected]>
104 files changed, 673 insertions, 698 deletions
diff --git a/examples/bluetooth/btscanner/device.py b/examples/bluetooth/btscanner/device.py index e51160b84..c75f5b8a1 100644 --- a/examples/bluetooth/btscanner/device.py +++ b/examples/bluetooth/btscanner/device.py @@ -46,7 +46,7 @@ class DeviceDiscoveryDialog(QDialog): item = QListWidgetItem(label) pairing_status = self._local_device.pairingStatus(info.address()) if (pairing_status == QBluetoothLocalDevice.Paired - or pairing_status == QBluetoothLocalDevice.AuthorizedPaired): + or pairing_status == QBluetoothLocalDevice.AuthorizedPaired): item.setForeground(QColor(Qt.green)) else: item.setForeground(QColor(Qt.black)) @@ -123,7 +123,8 @@ class DeviceDiscoveryDialog(QDialog): items = self._ui.list.findItems(address.toString(), Qt.MatchContains) color = QColor(Qt.red) - if pairing == QBluetoothLocalDevice.Paired or pairing == QBluetoothLocalDevice.AuthorizedPaired: + if (pairing == QBluetoothLocalDevice.Paired + or pairing == QBluetoothLocalDevice.AuthorizedPaired): color = QColor(Qt.green) for item in items: item.setForeground(color) diff --git a/examples/bluetooth/heartrate_game/devicehandler.py b/examples/bluetooth/heartrate_game/devicehandler.py index 85d160c4d..ead73ecc2 100644 --- a/examples/bluetooth/heartrate_game/devicehandler.py +++ b/examples/bluetooth/heartrate_game/devicehandler.py @@ -166,7 +166,8 @@ class DeviceHandler(BluetoothBaseClass): #! [Filter HeartRate service 2] # If heartRateService found, create new service if self.m_foundHeartRateService: - self.m_service = self.m_control.createServiceObject(QBluetoothUuid(QBluetoothUuid.ServiceClassUuid.HeartRate), self) + self.m_service = self.m_control.createServiceObject( + QBluetoothUuid(QBluetoothUuid.ServiceClassUuid.HeartRate), self) if self.m_service: self.m_service.stateChanged.connect(self.serviceStateChanged) @@ -185,9 +186,11 @@ class DeviceHandler(BluetoothBaseClass): self.info = "Discovering services..." elif switch == QLowEnergyService.RemoteServiceDiscovered: self.info = "Service discovered." - hrChar = self.m_service.characteristic(QBluetoothUuid(QBluetoothUuid.CharacteristicType.HeartRateMeasurement)) + hrChar = self.m_service.characteristic( + QBluetoothUuid(QBluetoothUuid.CharacteristicType.HeartRateMeasurement)) if hrChar.isValid(): - self.m_notificationDesc = hrChar.descriptor(QBluetoothUuid.DescriptorType.ClientCharacteristicConfiguration) + self.m_notificationDesc = hrChar.descriptor( + QBluetoothUuid.DescriptorType.ClientCharacteristicConfiguration) if self.m_notificationDesc.isValid(): self.m_service.writeDescriptor(self.m_notificationDesc, QByteArray.fromHex(b"0100")) @@ -233,7 +236,7 @@ class DeviceHandler(BluetoothBaseClass): @Slot(QLowEnergyCharacteristic, QByteArray) def confirmedDescriptorWrite(self, d, value): if (d.isValid() and d == self.m_notificationDesc - and value == QByteArray.fromHex(b"0000")): + and value == QByteArray.fromHex(b"0000")): # disabled notifications . assume disconnect intent self.m_control.disconnectFromDevice() self.m_service = None @@ -244,7 +247,7 @@ class DeviceHandler(BluetoothBaseClass): # disable notifications if (self.m_notificationDesc.isValid() and self.m_service - and self.m_notificationDesc.value() == QByteArray.fromHex(b"0100")): + and self.m_notificationDesc.value() == QByteArray.fromHex(b"0100")): self.m_service.writeDescriptor(self.m_notificationDesc, QByteArray.fromHex(b"0000")) else: @@ -301,6 +304,6 @@ class DeviceHandler(BluetoothBaseClass): self.m_sum += value self.m_avg = float(self.m_sum) / len(self.m_measurements) self.m_calories = ((-55.0969 + (0.6309 * self.m_avg) + (0.1988 * 94) - + (0.2017 * 24)) / 4.184) * 60 * self.time / 3600 + + (0.2017 * 24)) / 4.184) * 60 * self.time / 3600 self.statsChanged.emit() diff --git a/examples/bluetooth/heartrate_server/heartrate_server.py b/examples/bluetooth/heartrate_server/heartrate_server.py index 801584565..abbf4eb7f 100644 --- a/examples/bluetooth/heartrate_server/heartrate_server.py +++ b/examples/bluetooth/heartrate_server/heartrate_server.py @@ -39,8 +39,8 @@ if __name__ == '__main__': char_data.setUuid(QBluetoothUuid.CharacteristicType.HeartRateMeasurement) char_data.setValue(QByteArray(2, 0)) char_data.setProperties(QLowEnergyCharacteristic.Notify) - client_config = QLowEnergyDescriptorData(QBluetoothUuid.DescriptorType.ClientCharacteristicConfiguration, - QByteArray(2, 0)) + client_config = QLowEnergyDescriptorData( + QBluetoothUuid.DescriptorType.ClientCharacteristicConfiguration, QByteArray(2, 0)) char_data.addDescriptor(client_config) service_data = QLowEnergyServiceData() @@ -66,7 +66,8 @@ if __name__ == '__main__': value = QByteArray() value.append(chr(0)) # Flags that specify the format of the value. value.append(chr(current_heart_rate)) # Actual value. - characteristic = service.characteristic(QBluetoothUuid.CharacteristicType.HeartRateMeasurement) + characteristic = service.characteristic( + QBluetoothUuid.CharacteristicType.HeartRateMeasurement) assert characteristic.isValid() # Potentially causes notification. service.writeCharacteristic(characteristic, value) diff --git a/examples/bluetooth/lowenergyscanner/characteristicinfo.py b/examples/bluetooth/lowenergyscanner/characteristicinfo.py index a0e9df77e..42bde8753 100644 --- a/examples/bluetooth/lowenergyscanner/characteristicinfo.py +++ b/examples/bluetooth/lowenergyscanner/characteristicinfo.py @@ -85,4 +85,3 @@ class CharacteristicInfo(QObject): def characteristic(self, characteristic): self._characteristic = characteristic self.characteristic_changed.emit() - diff --git a/examples/bluetooth/lowenergyscanner/device.py b/examples/bluetooth/lowenergyscanner/device.py index 95d1fe158..09108cf69 100644 --- a/examples/bluetooth/lowenergyscanner/device.py +++ b/examples/bluetooth/lowenergyscanner/device.py @@ -276,5 +276,3 @@ class Device(QObject): def stop_device_discovery(self): if self.discovery_agent.isActive(): self.discovery_agent.stop() - - diff --git a/examples/bluetooth/lowenergyscanner/deviceinfo.py b/examples/bluetooth/lowenergyscanner/deviceinfo.py index edcbef89d..35a568821 100644 --- a/examples/bluetooth/lowenergyscanner/deviceinfo.py +++ b/examples/bluetooth/lowenergyscanner/deviceinfo.py @@ -32,4 +32,3 @@ class DeviceInfo(QObject): def set_device(self, device): self._device = device self.device_changed.emit() - diff --git a/examples/bluetooth/lowenergyscanner/serviceinfo.py b/examples/bluetooth/lowenergyscanner/serviceinfo.py index 092e9898f..cddffe663 100644 --- a/examples/bluetooth/lowenergyscanner/serviceinfo.py +++ b/examples/bluetooth/lowenergyscanner/serviceinfo.py @@ -62,5 +62,3 @@ class ServiceInfo(QObject): @service.setter def service(self, service): self._service = service - - diff --git a/examples/charts/callout/callout.py b/examples/charts/callout/callout.py index 3de00b8df..59a1c3fad 100644 --- a/examples/charts/callout/callout.py +++ b/examples/charts/callout/callout.py @@ -4,8 +4,8 @@ """PySide6 port of the Callout example from Qt v5.x""" import sys -from PySide6.QtWidgets import (QApplication, QGraphicsScene, - QGraphicsView, QGraphicsSimpleTextItem, QGraphicsItem) +from PySide6.QtWidgets import (QApplication, QGraphicsScene, QGraphicsView, + QGraphicsSimpleTextItem, QGraphicsItem) from PySide6.QtCore import Qt, QPointF, QRectF, QRect from PySide6.QtCharts import QChart, QLineSeries, QSplineSeries from PySide6.QtGui import QPainter, QFont, QFontMetrics, QPainterPath, QColor @@ -42,37 +42,37 @@ class Callout(QGraphicsItem): # establish the position of the anchor point in relation to _rect above = anchor.y() <= self._rect.top() - above_center = (anchor.y() > self._rect.top() and - anchor.y() <= self._rect.center().y()) - below_center = (anchor.y() > self._rect.center().y() and - anchor.y() <= self._rect.bottom()) + above_center = (anchor.y() > self._rect.top() + and anchor.y() <= self._rect.center().y()) + below_center = (anchor.y() > self._rect.center().y() + and anchor.y() <= self._rect.bottom()) below = anchor.y() > self._rect.bottom() on_left = anchor.x() <= self._rect.left() - left_of_center = (anchor.x() > self._rect.left() and - anchor.x() <= self._rect.center().x()) - right_of_center = (anchor.x() > self._rect.center().x() and - anchor.x() <= self._rect.right()) + left_of_center = (anchor.x() > self._rect.left() + and anchor.x() <= self._rect.center().x()) + right_of_center = (anchor.x() > self._rect.center().x() + and anchor.x() <= self._rect.right()) on_right = anchor.x() > self._rect.right() # get the nearest _rect corner. x = (on_right + right_of_center) * self._rect.width() y = (below + below_center) * self._rect.height() - corner_case = ((above and on_left) or (above and on_right) or - (below and on_left) or (below and on_right)) + corner_case = ((above and on_left) or (above and on_right) + or (below and on_left) or (below and on_right)) vertical = abs(anchor.x() - x) > abs(anchor.y() - y) - x1 = (x + left_of_center * 10 - right_of_center * 20 + corner_case * - int(not vertical) * (on_left * 10 - on_right * 20)) - y1 = (y + above_center * 10 - below_center * 20 + corner_case * - vertical * (above * 10 - below * 20)) + x1 = (x + left_of_center * 10 - right_of_center * 20 + corner_case + * int(not vertical) * (on_left * 10 - on_right * 20)) + y1 = (y + above_center * 10 - below_center * 20 + corner_case + * vertical * (above * 10 - below * 20)) point1.setX(x1) point1.setY(y1) - x2 = (x + left_of_center * 20 - right_of_center * 10 + corner_case * - int(not vertical) * (on_left * 20 - on_right * 10)) - y2 = (y + above_center * 20 - below_center * 10 + corner_case * - vertical * (above * 20 - below * 10)) + x2 = (x + left_of_center * 20 - right_of_center * 10 + corner_case + * int(not vertical) * (on_left * 20 - on_right * 10)) + y2 = (y + above_center * 20 - below_center * 10 + corner_case + * vertical * (above * 20 - below * 10)) point2.setX(x2) point2.setY(y2) @@ -127,7 +127,7 @@ class View(QGraphicsView): self._chart = QChart() self._chart.setMinimumSize(640, 480) self._chart.setTitle("Hover the line to show callout. Click the line " - "to make it stay") + "to make it stay") self._chart.legend().hide() self.series = QLineSeries() self.series.append(1, 3) diff --git a/examples/charts/chartthemes/main.py b/examples/charts/chartthemes/main.py index 3a058804d..3ea7b629d 100644 --- a/examples/charts/chartthemes/main.py +++ b/examples/charts/chartthemes/main.py @@ -27,7 +27,7 @@ class ThemeWidget(QWidget): self.value_max = 10 self.value_count = 7 self.data_table = self.generate_random_data(self.list_count, - self.value_max, self.value_count) + self.value_max, self.value_count) self.ui.setupUi(self) self.populate_themebox() @@ -41,8 +41,7 @@ class ThemeWidget(QWidget): # Pie Chart chart_view = QChartView(self.create_pie_chart()) - chart_view.setSizePolicy(QSizePolicy.Ignored, - QSizePolicy.Ignored) + chart_view.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored) self.ui.gridLayout.addWidget(chart_view, 1, 1) self.charts.append(chart_view) diff --git a/examples/charts/legend/legend.py b/examples/charts/legend/legend.py index 39b9543f4..5417a940f 100644 --- a/examples/charts/legend/legend.py +++ b/examples/charts/legend/legend.py @@ -207,10 +207,8 @@ class MainWidget(QWidget): def update_legend_layout(self): legend = self.chart.legend() - rect = QRectF(self.legend_posx.value(), - self.legend_posy.value(), - self.legend_width.value(), - self.legend_height.value()) + rect = QRectF(self.legend_posx.value(), self.legend_posy.value(), + self.legend_width.value(), self.legend_height.value()) legend.setGeometry(rect) legend.update() diff --git a/examples/charts/percentbarchart/percentbarchart.py b/examples/charts/percentbarchart/percentbarchart.py index cfb11800a..9f70c0328 100644 --- a/examples/charts/percentbarchart/percentbarchart.py +++ b/examples/charts/percentbarchart/percentbarchart.py @@ -21,11 +21,11 @@ class MainWindow(QMainWindow): set3 = QBarSet("Mary") set4 = QBarSet("Samantha") - set0.append([1, 2, 3, 4, 5, 6]) - set1.append([5, 0, 0, 4, 0, 7]) + set0.append([1, 2, 3, 4, 5, 6]) + set1.append([5, 0, 0, 4, 0, 7]) set2.append([3, 5, 8, 13, 8, 5]) - set3.append([5, 6, 7, 3, 4, 5]) - set4.append([9, 7, 5, 3, 1, 2]) + set3.append([5, 6, 7, 3, 4, 5]) + set4.append([9, 7, 5, 3, 1, 2]) series = QPercentBarSeries() series.append(set0) diff --git a/examples/charts/pointconfiguration/chartwindow.py b/examples/charts/pointconfiguration/chartwindow.py index 055802b9f..36b10aa16 100644 --- a/examples/charts/pointconfiguration/chartwindow.py +++ b/examples/charts/pointconfiguration/chartwindow.py @@ -109,14 +109,14 @@ class ChartWindow(QMainWindow): self._selectedPointConfig = self._series.pointConfiguration(index) selected_point = self._series.at(index) selected_index_lineedit = self._selected_point_index_lineedit - selected_index_lineedit.setText("(" + str(selected_point.x()) + ", " + - str(selected_point.y()) + ")") + selected_index_lineedit.setText("(" + str(selected_point.x()) + ", " + + str(selected_point.y()) + ")") config = self._series.pointConfiguration(index) color = config.get(PointConfig.Color) or self._series.color() size = config.get(PointConfig.Size) or self._series.markerSize() - labelVisibility = (config.get(PointConfig.LabelVisibility) or - self._series.pointLabelsVisible()) + labelVisibility = (config.get(PointConfig.LabelVisibility) + or self._series.pointLabelsVisible()) customLabel = config.get(PointConfig.LabelFormat) or "" combobox_value_list = [ diff --git a/examples/charts/pointselectionandmarkers/pointselectionandmarkers.py b/examples/charts/pointselectionandmarkers/pointselectionandmarkers.py index 20a65bdaf..df7b61687 100644 --- a/examples/charts/pointselectionandmarkers/pointselectionandmarkers.py +++ b/examples/charts/pointselectionandmarkers/pointselectionandmarkers.py @@ -7,7 +7,8 @@ import sys from PySide6.QtCore import Slot, QPointF, Qt from PySide6.QtCharts import QChart, QChartView, QSplineSeries from PySide6.QtGui import QPainter, QImage -from PySide6.QtWidgets import QApplication, QMainWindow, QWidget, QGridLayout, QComboBox, QCheckBox, QLabel, QHBoxLayout +from PySide6.QtWidgets import (QApplication, QMainWindow, QWidget, QGridLayout, + QComboBox, QCheckBox, QLabel, QHBoxLayout) import utilities as Utilities @@ -68,7 +69,9 @@ if __name__ == "__main__": @Slot(int) def set_selected_light_marker(index): - series.setSelectedLightMarker(Utilities.get_selected_point_representation(Utilities.selected_point_type(index), marker_size)) + series.setSelectedLightMarker( + Utilities.get_selected_point_representation( + Utilities.selected_point_type(index), marker_size)) char_point_selected = QLabel("Char point selected: ") char_point_selected_combobox.addItems(["Blue triangle", "Yellow rectangle", "Lavender circle"]) @@ -85,7 +88,9 @@ if __name__ == "__main__": @Slot(int) def display_unselected_points(checkbox_state): if checkbox_state: - series.setLightMarker(Utilities.get_point_representation(Utilities.point_type(char_point_combobox.currentIndex()), marker_size)) + series.setLightMarker( + Utilities.get_point_representation( + Utilities.point_type(char_point_combobox.currentIndex()), marker_size)) else: series.setLightMarker(QImage()) diff --git a/examples/corelib/settingseditor/settingseditor.py b/examples/corelib/settingseditor/settingseditor.py index ca4369149..0a3f7748b 100644 --- a/examples/corelib/settingseditor/settingseditor.py +++ b/examples/corelib/settingseditor/settingseditor.py @@ -166,7 +166,7 @@ class MainWindow(QMainWindow): @Slot() def open_inifile(self): file_name, _ = QFileDialog.getOpenFileName(self, "Open INI File", - '', "INI Files (*.ini *.conf)") + '', "INI Files (*.ini *.conf)") if file_name: self.load_ini_file(file_name) @@ -181,7 +181,8 @@ class MainWindow(QMainWindow): @Slot() def open_property_list(self): file_name, _ = QFileDialog.getOpenFileName(self, - "Open Property List", '', "Property List Files (*.plist)") + "Open Property List", '', + "Property List Files (*.plist)") if file_name: settings = QSettings(file_name, QSettings.NativeFormat) @@ -191,8 +192,8 @@ class MainWindow(QMainWindow): @Slot() def open_registry_path(self): path, ok = QInputDialog.getText(self, "Open Registry Path", - "Enter the path in the Windows registry:", - QLineEdit.Normal, 'HKEY_CURRENT_USER\\') + "Enter the path in the Windows registry:", + QLineEdit.Normal, 'HKEY_CURRENT_USER\\') if ok and path != '': settings = QSettings(path, QSettings.NativeFormat) @@ -202,8 +203,8 @@ class MainWindow(QMainWindow): @Slot() def about(self): QMessageBox.about(self, "About Settings Editor", - "The <b>Settings Editor</b> example shows how to access " - "application settings using Qt.") + "The <b>Settings Editor</b> example shows how to access " + "application settings using Qt.") def create_actions(self): self._open_settings_act = QAction("&Open Application Settings...", @@ -217,35 +218,35 @@ class MainWindow(QMainWindow): def create_actions(self): self.open_settings_action = QAction("&Open Application Settings...", - self, shortcut="Ctrl+O", triggered=self.open_settings) + self, shortcut="Ctrl+O", triggered=self.open_settings) self.open_ini_file_action = QAction("Open I&NI File...", self, - shortcut="Ctrl+N", triggered=self.open_inifile) + shortcut="Ctrl+N", triggered=self.open_inifile) - self.open_property_list_action = QAction("Open macOS &Property List...", - self, shortcut="Ctrl+P", triggered=self.open_property_list) + self.open_property_list_action = QAction("Open macOS &Property List...", self, + shortcut="Ctrl+P", + triggered=self.open_property_list) if sys.platform != 'darwin': self.open_property_list_action.setEnabled(False) self.open_registry_path_action = QAction( - "Open Windows &Registry Path...", self, shortcut="Ctrl+G", - triggered=self.open_registry_path) + "Open Windows &Registry Path...", self, shortcut="Ctrl+G", + triggered=self.open_registry_path) if sys.platform != 'win32': self.open_registry_path_action.setEnabled(False) self.refresh_action = QAction("&Refresh", self, shortcut="Ctrl+R", - enabled=False, triggered=self.settings_tree.refresh) + enabled=False, triggered=self.settings_tree.refresh) - self.exit_action = QAction("E&xit", self, shortcut="Ctrl+Q", - triggered=self.close) + self.exit_action = QAction("E&xit", self, shortcut="Ctrl+Q", triggered=self.close) self.auto_refresh_action = QAction("&Auto-Refresh", self, - shortcut="Ctrl+A", checkable=True, enabled=False) + shortcut="Ctrl+A", checkable=True, enabled=False) self.auto_refresh_action.triggered[bool].connect(self.settings_tree.set_auto_refresh) self.auto_refresh_action.triggered[bool].connect(self.refresh_action.setDisabled) self.fallbacks_action = QAction("&Fallbacks", self, - shortcut="Ctrl+F", checkable=True, enabled=False) + shortcut="Ctrl+F", checkable=True, enabled=False) self.fallbacks_action.triggered[bool].connect(self.settings_tree.set_fallbacks_enabled) self.about_action = QAction("&About", self, triggered=self.about) diff --git a/examples/corelib/threads/mandelbrot.py b/examples/corelib/threads/mandelbrot.py index f9cc4559b..4689813d4 100644 --- a/examples/corelib/threads/mandelbrot.py +++ b/examples/corelib/threads/mandelbrot.py @@ -53,7 +53,8 @@ class RenderThread(QThread): self.abort = False for i in range(RenderThread.colormap_size): - self.colormap.append(self.rgb_from_wave_length(380.0 + (i * 400.0 / RenderThread.colormap_size))) + self.colormap.append( + self.rgb_from_wave_length(380.0 + (i * 400.0 / RenderThread.colormap_size))) def stop(self): self.mutex.lock() @@ -132,7 +133,8 @@ class RenderThread(QThread): if num_iterations < max_iterations: image.setPixel(x + half_width, y + half_height, - self.colormap[num_iterations % RenderThread.colormap_size]) + self.colormap[ + num_iterations % RenderThread.colormap_size]) all_black = False else: image.setPixel(x + half_width, y + half_height, qRgb(0, 0, 0)) @@ -221,7 +223,7 @@ class MandelbrotWidget(QWidget): if self.pixmap.isNull(): painter.setPen(Qt.white) painter.drawText(self.rect(), Qt.AlignCenter, - "Rendering initial image, please wait...") + "Rendering initial image, please wait...") return if self._cur_scale == self._pixmap_scale: @@ -250,10 +252,10 @@ class MandelbrotWidget(QWidget): painter.setPen(Qt.NoPen) painter.setBrush(QColor(0, 0, 0, 127)) painter.drawRect((self.width() - text_width) / 2 - 5, 0, text_width + 10, - metrics.lineSpacing() + 5) + metrics.lineSpacing() + 5) painter.setPen(Qt.white) painter.drawText((self.width() - text_width) / 2, - metrics.leading() + metrics.ascent(), text) + metrics.leading() + metrics.ascent(), text) def resizeEvent(self, event): self.thread.render(self._center_x, self._center_y, self._cur_scale, self.size()) @@ -317,15 +319,13 @@ class MandelbrotWidget(QWidget): def zoom(self, zoomFactor): self._cur_scale *= zoomFactor self.update() - self.thread.render(self._center_x, self._center_y, self._cur_scale, - self.size()) + self.thread.render(self._center_x, self._center_y, self._cur_scale, self.size()) def scroll(self, deltaX, deltaY): self._center_x += deltaX * self._cur_scale self._center_y += deltaY * self._cur_scale self.update() - self.thread.render(self._center_x, self._center_y, self._cur_scale, - self.size()) + self.thread.render(self._center_x, self._center_y, self._cur_scale, self.size()) if __name__ == '__main__': diff --git a/examples/datavisualization/graphgallery/bargraph.py b/examples/datavisualization/graphgallery/bargraph.py index 6c61d6708..7938a5ca1 100644 --- a/examples/datavisualization/graphgallery/bargraph.py +++ b/examples/datavisualization/graphgallery/bargraph.py @@ -8,8 +8,7 @@ from PySide6.QtGui import QFont from PySide6.QtWidgets import (QButtonGroup, QCheckBox, QComboBox, QFontComboBox, QLabel, QPushButton, QHBoxLayout, QSizePolicy, QRadioButton, QSlider, QVBoxLayout, QWidget) -from PySide6.QtDataVisualization import (QAbstract3DGraph, QAbstract3DSeries, - Q3DBars) +from PySide6.QtDataVisualization import (QAbstract3DGraph, QAbstract3DSeries, Q3DBars) class BarGraph(QObject): @@ -92,18 +91,14 @@ class BarGraph(QObject): selectionModeList.addItem("Slice into Row and Item", sel) sel = QAbstract3DGraph.SelectionSlice | QAbstract3DGraph.SelectionColumn selectionModeList.addItem("Slice into Column", sel) - sel = (QAbstract3DGraph.SelectionSlice - | QAbstract3DGraph.SelectionItemAndColumn) + sel = (QAbstract3DGraph.SelectionSlice | QAbstract3DGraph.SelectionItemAndColumn) selectionModeList.addItem("Slice into Column and Item", sel) - sel = (QAbstract3DGraph.SelectionItemRowAndColumn - | QAbstract3DGraph.SelectionMultiSeries) + sel = (QAbstract3DGraph.SelectionItemRowAndColumn | QAbstract3DGraph.SelectionMultiSeries) selectionModeList.addItem("Multi: Bar, Row, Col", sel) - sel = (QAbstract3DGraph.SelectionSlice - | QAbstract3DGraph.SelectionItemAndRow + sel = (QAbstract3DGraph.SelectionSlice | QAbstract3DGraph.SelectionItemAndRow | QAbstract3DGraph.SelectionMultiSeries) selectionModeList.addItem("Multi, Slice: Row, Item", sel) - sel = (QAbstract3DGraph.SelectionSlice - | QAbstract3DGraph.SelectionItemAndColumn + sel = (QAbstract3DGraph.SelectionSlice | QAbstract3DGraph.SelectionItemAndColumn | QAbstract3DGraph.SelectionMultiSeries) selectionModeList.addItem("Multi, Slice: Col, Item", sel) selectionModeList.setCurrentIndex(1) diff --git a/examples/datavisualization/graphgallery/main.py b/examples/datavisualization/graphgallery/main.py index 668117245..4b57b85dd 100644 --- a/examples/datavisualization/graphgallery/main.py +++ b/examples/datavisualization/graphgallery/main.py @@ -34,8 +34,8 @@ if __name__ == "__main__": surface = SurfaceGraph() if (not bars.initialize(minimum_graph_size, screen_size) - or not scatter.initialize(minimum_graph_size, screen_size) - or not surface.initialize(minimum_graph_size, screen_size)): + or not scatter.initialize(minimum_graph_size, screen_size) + or not surface.initialize(minimum_graph_size, screen_size)): QMessageBox.warning(None, "Graph Gallery", "Couldn't initialize the OpenGL context.") sys.exit(-1) diff --git a/examples/datavisualization/graphgallery/variantbardataproxy.py b/examples/datavisualization/graphgallery/variantbardataproxy.py index 2b6f5d84e..f69ebaf80 100644 --- a/examples/datavisualization/graphgallery/variantbardataproxy.py +++ b/examples/datavisualization/graphgallery/variantbardataproxy.py @@ -64,8 +64,8 @@ class VariantBarDataProxy(QBarDataProxy): # If we have no data or mapping, or the categories are not defined, # simply clear the array if (not self._dataSet or not self._mapping - or not self._mapping.rowCategories() - or not self._mapping.columnCategories()): + or not self._mapping.rowCategories() + or not self._mapping.columnCategories()): self.resetArray() return diff --git a/examples/dbus/pingpong/ping.py b/examples/dbus/pingpong/ping.py index 0fbb23ca8..d61f25499 100644 --- a/examples/dbus/pingpong/ping.py +++ b/examples/dbus/pingpong/ping.py @@ -36,4 +36,3 @@ if __name__ == "__main__": value = reply.value() print(f'ping: Reply was: {value}') sys.exit(0) - diff --git a/examples/demos/documentviewer/pdfviewer/pdfviewer.py b/examples/demos/documentviewer/pdfviewer/pdfviewer.py index 0762cfdce..63d25bf70 100644 --- a/examples/demos/documentviewer/pdfviewer/pdfviewer.py +++ b/examples/demos/documentviewer/pdfviewer/pdfviewer.py @@ -48,7 +48,7 @@ class PdfViewer(AbstractViewer): nav = self._pdfView.pageNavigator() self._pageSelector = QPdfPageSelector(self._toolBar) self._toolBar.insertWidget(self._uiAssets_forward, self._pageSelector) - self._pageSelector.setDocument(self._document); + self._pageSelector.setDocument(self._document) self._pageSelector.currentPageChanged.connect(self.pageSelected) nav.currentPageChanged.connect(self._pageSelector.setCurrentPage) nav.backAvailableChanged.connect(self._uiAssets_back.setEnabled) diff --git a/examples/demos/documentviewer/viewerfactory.py b/examples/demos/documentviewer/viewerfactory.py index 32a916be3..ecae6770b 100644 --- a/examples/demos/documentviewer/viewerfactory.py +++ b/examples/demos/documentviewer/viewerfactory.py @@ -65,7 +65,7 @@ class ViewerFactory: list = [] for name, viewer in self._viewers.items(): if ((self._defaultViewer and viewer.isDefaultViewer()) - or (not self._defaultViewer and name == "TxtViewer")): + or (not self._defaultViewer and name == "TxtViewer")): name += "(default)" list.append(name) return list diff --git a/examples/designer/taskmenuextension/tictactoe.py b/examples/designer/taskmenuextension/tictactoe.py index 9155d2309..aa1c3158c 100644 --- a/examples/designer/taskmenuextension/tictactoe.py +++ b/examples/designer/taskmenuextension/tictactoe.py @@ -89,27 +89,27 @@ class TicTacToe(QWidget): for position in range(0, 8, 3): if (self._state[position] != EMPTY - and self._state[position + 1] == self._state[position] - and self._state[position + 2] == self._state[position]): + and self._state[position + 1] == self._state[position] + and self._state[position + 2] == self._state[position]): y = self._cell_rect(position).center().y() painter.drawLine(0, y, self.width(), y) self._turn_number = 9 for position in range(3): if (self._state[position] != EMPTY - and self._state[position + 3] == self._state[position] - and self._state[position + 6] == self._state[position]): + and self._state[position + 3] == self._state[position] + and self._state[position + 6] == self._state[position]): x = self._cell_rect(position).center().x() painter.drawLine(x, 0, x, self.height()) self._turn_number = 9 if (self._state[0] != EMPTY and self._state[4] == self._state[0] - and self._state[8] == self._state[0]): + and self._state[8] == self._state[0]): painter.drawLine(0, 0, self.width(), self.height()) self._turn_number = 9 if (self._state[2] != EMPTY and self._state[4] == self._state[2] - and self._state[6] == self._state[2]): + and self._state[6] == self._state[2]): painter.drawLine(0, self.height(), self.width(), 0) self._turn_number = 9 diff --git a/examples/graphs/widgetgallery/variantbardataproxy.py b/examples/graphs/widgetgallery/variantbardataproxy.py index 743dafcca..5ab2a2cd2 100644 --- a/examples/graphs/widgetgallery/variantbardataproxy.py +++ b/examples/graphs/widgetgallery/variantbardataproxy.py @@ -64,8 +64,8 @@ class VariantBarDataProxy(QBarDataProxy): # If we have no data or mapping, or the categories are not defined, # simply clear the array if (not self._dataSet or not self._mapping - or not self._mapping.rowCategories() - or not self._mapping.columnCategories()): + or not self._mapping.rowCategories() + or not self._mapping.columnCategories()): self.resetArray() return diff --git a/examples/gui/rhiwindow/rhiwindow.py b/examples/gui/rhiwindow/rhiwindow.py index dff56fec8..b18ce700a 100644 --- a/examples/gui/rhiwindow/rhiwindow.py +++ b/examples/gui/rhiwindow/rhiwindow.py @@ -28,9 +28,9 @@ elif sys.platform == "darwin": # Y up (note clipSpaceCorrMatrix in m_viewProjection), CCW VERTEX_DATA = numpy.array([ - 0.0, 0.5, 1.0, 0.0, 0.0, - -0.5, -0.5, 0.0, 1.0, 0.0, - 0.5, -0.5, 0.0, 0.0, 1.0], dtype=numpy.float32) + 0.0, 0.5, 1.0, 0.0, 0.0, + -0.5, -0.5, 0.0, 1.0, 0.0, + 0.5, -0.5, 0.0, 0.0, 1.0], dtype=numpy.float32) UBUF_SIZE = 68 @@ -124,7 +124,8 @@ class RhiWindow(QWindow): surfaceSize = self.m_sc.surfacePixelSize() if self.m_hasSwapChain else QSize() # stop pushing frames when not exposed (or size is 0) - if (not is_exposed or (self.m_hasSwapChain and surfaceSize.isEmpty())) and self.m_initialized and not self.m_notExposed: + if ((not is_exposed or (self.m_hasSwapChain and surfaceSize.isEmpty())) + and self.m_initialized and not self.m_notExposed): self.m_notExposed = True # Continue when exposed again and the surface has a valid size. Note diff --git a/examples/multimedia/audiooutput/audiooutput.py b/examples/multimedia/audiooutput/audiooutput.py index e1b4032c6..4a3c93773 100644 --- a/examples/multimedia/audiooutput/audiooutput.py +++ b/examples/multimedia/audiooutput/audiooutput.py @@ -133,16 +133,14 @@ class AudioTest(QMainWindow): layout.addWidget(self.m_modeButton) - self.m_suspendResumeButton = QPushButton( - clicked=self.toggle_suspend_resume) + self.m_suspendResumeButton = QPushButton(clicked=self.toggle_suspend_resume) self.m_suspendResumeButton.setText(self.SUSPEND_LABEL) layout.addWidget(self.m_suspendResumeButton) volume_box = QHBoxLayout() volume_label = QLabel("Volume:") - self.m_volumeSlider = QSlider(Qt.Horizontal, minimum=0, maximum=100, - singleStep=10) + self.m_volumeSlider = QSlider(Qt.Horizontal, minimum=0, maximum=100, singleStep=10) self.m_volumeSlider.valueChanged.connect(self.volume_changed) volume_box.addWidget(volume_label) @@ -167,8 +165,8 @@ class AudioTest(QMainWindow): qWarning("Default format not supported - trying to use nearest") self.m_format = info.nearestFormat(self.m_format) - self.m_generator = Generator(self.m_format, - self.DURATION_SECONDS * 1000000, self.TONE_SAMPLE_RATE_HZ, self) + self.m_generator = Generator(self.m_format, self.DURATION_SECONDS * 1000000, + self.TONE_SAMPLE_RATE_HZ, self) self.create_audio_output() diff --git a/examples/multimedia/audiosource/audiosource.py b/examples/multimedia/audiosource/audiosource.py index c2e97c15f..0adcc7dcf 100644 --- a/examples/multimedia/audiosource/audiosource.py +++ b/examples/multimedia/audiosource/audiosource.py @@ -19,22 +19,9 @@ from typing import Optional import PySide6 from PySide6.QtCore import QByteArray, QMargins, Qt, Slot, qWarning from PySide6.QtGui import QPainter, QPalette -from PySide6.QtMultimedia import ( - QAudio, - QAudioDevice, - QAudioFormat, - QAudioSource, - QMediaDevices, -) -from PySide6.QtWidgets import ( - QApplication, - QComboBox, - QPushButton, - QSlider, - QVBoxLayout, - QWidget, - QLabel -) +from PySide6.QtMultimedia import QAudio, QAudioDevice, QAudioFormat, QAudioSource, QMediaDevices +from PySide6.QtWidgets import (QApplication, QComboBox, QPushButton, QSlider, QVBoxLayout, + QWidget, QLabel) is_android = os.environ.get('ANDROID_ARGUMENT') diff --git a/examples/multimedia/player/player.py b/examples/multimedia/player/player.py index 3124e4fff..c076b07e2 100644 --- a/examples/multimedia/player/player.py +++ b/examples/multimedia/player/player.py @@ -168,8 +168,7 @@ class MainWindow(QMainWindow): @Slot("QMediaPlayer::PlaybackState") def update_buttons(self, state): media_count = len(self._playlist) - self._play_action.setEnabled(media_count > 0 - and state != QMediaPlayer.PlayingState) + self._play_action.setEnabled(media_count > 0 and state != QMediaPlayer.PlayingState) self._pause_action.setEnabled(state == QMediaPlayer.PlayingState) self._stop_action.setEnabled(state != QMediaPlayer.StoppedState) self._previous_action.setEnabled(self._player.position() > 0) diff --git a/examples/network/blockingfortuneclient/blockingfortuneclient.py b/examples/network/blockingfortuneclient/blockingfortuneclient.py index 816ef67f5..d0dd7e0ad 100644 --- a/examples/network/blockingfortuneclient/blockingfortuneclient.py +++ b/examples/network/blockingfortuneclient/blockingfortuneclient.py @@ -110,7 +110,7 @@ class BlockingClient(QWidget): port_label.setBuddy(self._port_line_edit) self._status_label = QLabel( - "This example requires that you run the Fortune Server example as well.") + "This example requires that you run the Fortune Server example as well.") self._status_label.setWordWrap(True) self._get_fortune_button = QPushButton("Get Fortune") @@ -145,7 +145,7 @@ class BlockingClient(QWidget): def request_new_fortune(self): self._get_fortune_button.setEnabled(False) self.thread.request_new_fortune(self._host_line_edit.text(), - int(self._port_line_edit.text())) + int(self._port_line_edit.text())) def show_fortune(self, nextFortune): if nextFortune == self._current_fortune: @@ -159,22 +159,22 @@ class BlockingClient(QWidget): def display_error(self, socketError, message): if socketError == QAbstractSocket.HostNotFoundError: QMessageBox.information(self, "Blocking Fortune Client", - "The host was not found. Please check the host and port " - "settings.") + "The host was not found. Please check the host and port " + "settings.") elif socketError == QAbstractSocket.ConnectionRefusedError: QMessageBox.information(self, "Blocking Fortune Client", - "The connection was refused by the peer. Make sure the " - "fortune server is running, and check that the host name " - "and port settings are correct.") + "The connection was refused by the peer. Make sure the " + "fortune server is running, and check that the host name " + "and port settings are correct.") else: QMessageBox.information(self, "Blocking Fortune Client", - f"The following error occurred: {message}.") + f"The following error occurred: {message}.") self._get_fortune_button.setEnabled(True) def enable_get_fortune_button(self): - self._get_fortune_button.setEnabled(self._host_line_edit.text() != '' and - self._port_line_edit.text() != '') + self._get_fortune_button.setEnabled(self._host_line_edit.text() != '' + and self._port_line_edit.text() != '') if __name__ == '__main__': diff --git a/examples/network/fortuneclient/fortuneclient.py b/examples/network/fortuneclient/fortuneclient.py index b695c2ea8..e88e5e35b 100644 --- a/examples/network/fortuneclient/fortuneclient.py +++ b/examples/network/fortuneclient/fortuneclient.py @@ -31,7 +31,7 @@ class Client(QDialog): port_label.setBuddy(self._port_line_edit) self._status_label = QLabel("This examples requires that you run " - "the Fortune Server example as well.") + "the Fortune Server example as well.") self._get_fortune_button = QPushButton("Get Fortune") self._get_fortune_button.setDefault(True) @@ -40,8 +40,7 @@ class Client(QDialog): quit_button = QPushButton("Quit") button_box = QDialogButtonBox() - button_box.addButton(self._get_fortune_button, - QDialogButtonBox.ActionRole) + button_box.addButton(self._get_fortune_button, QDialogButtonBox.ActionRole) button_box.addButton(quit_button, QDialogButtonBox.RejectRole) self._tcp_socket = QTcpSocket(self) @@ -69,7 +68,7 @@ class Client(QDialog): self._block_size = 0 self._tcp_socket.abort() self._tcp_socket.connectToHost(self._host_line_edit.text(), - int(self._port_line_edit.text())) + int(self._port_line_edit.text())) def read_fortune(self): instr = QDataStream(self._tcp_socket) @@ -99,23 +98,23 @@ class Client(QDialog): pass elif socketError == QAbstractSocket.HostNotFoundError: QMessageBox.information(self, "Fortune Client", - "The host was not found. Please check the host name and " - "port settings.") + "The host was not found. Please check the host name and " + "port settings.") elif socketError == QAbstractSocket.ConnectionRefusedError: QMessageBox.information(self, "Fortune Client", - "The connection was refused by the peer. Make sure the " - "fortune server is running, and check that the host name " - "and port settings are correct.") + "The connection was refused by the peer. Make sure the " + "fortune server is running, and check that the host name " + "and port settings are correct.") else: reason = self._tcp_socket.errorString() QMessageBox.information(self, "Fortune Client", - f"The following error occurred: {reason}.") + f"The following error occurred: {reason}.") self._get_fortune_button.setEnabled(True) def enable_get_fortune_button(self): - self._get_fortune_button.setEnabled(bool(self._host_line_edit.text() and - self._port_line_edit.text())) + self._get_fortune_button.setEnabled(bool(self._host_line_edit.text() + and self._port_line_edit.text())) if __name__ == '__main__': diff --git a/examples/network/fortuneserver/fortuneserver.py b/examples/network/fortuneserver/fortuneserver.py index d84c9dcfd..a94a49f42 100644 --- a/examples/network/fortuneserver/fortuneserver.py +++ b/examples/network/fortuneserver/fortuneserver.py @@ -27,21 +27,21 @@ class Server(QDialog): if not self._tcp_server.listen(): reason = self._tcp_server.errorString() QMessageBox.critical(self, "Fortune Server", - f"Unable to start the server: {reason}.") + f"Unable to start the server: {reason}.") self.close() return port = self._tcp_server.serverPort() status_label.setText(f"The server is running on port {port}.\nRun the " - "Fortune Client example now.") + "Fortune Client example now.") self.fortunes = ( - "You've been leading a dog's life. Stay off the furniture.", - "You've got to think about tomorrow.", - "You will be surprised by a loud noise.", - "You will feel hungry again in another hour.", - "You might have mail.", - "You cannot kill time without injuring eternity.", - "Computers are not intelligent. They only think they are.") + "You've been leading a dog's life. Stay off the furniture.", + "You've got to think about tomorrow.", + "You will be surprised by a loud noise.", + "You will feel hungry again in another hour.", + "You might have mail.", + "You cannot kill time without injuring eternity.", + "Computers are not intelligent. They only think they are.") quit_button.clicked.connect(self.close) self._tcp_server.newConnection.connect(self.send_fortune) diff --git a/examples/network/threadedfortuneserver/threadedfortuneserver.py b/examples/network/threadedfortuneserver/threadedfortuneserver.py index bb86d9081..c75e2bc57 100644 --- a/examples/network/threadedfortuneserver/threadedfortuneserver.py +++ b/examples/network/threadedfortuneserver/threadedfortuneserver.py @@ -75,7 +75,7 @@ class Dialog(QDialog): if not self.server.listen(): reason = self.server.errorString() QMessageBox.critical(self, "Threaded Fortune Server", - f"Unable to start the server: {reason}.") + f"Unable to start the server: {reason}.") self.close() return @@ -89,7 +89,7 @@ class Dialog(QDialog): port = self.server.serverPort() status_label.setText(f"The server is running on\n\nIP: {ip_address}\nport: {port}\n\n" - "Run the Fortune Client example now.") + "Run the Fortune Client example now.") quit_button.clicked.connect(self.close) diff --git a/examples/opengl/contextinfo/contextinfo.py b/examples/opengl/contextinfo/contextinfo.py index 8507fd9e7..311d5b765 100644 --- a/examples/opengl/contextinfo/contextinfo.py +++ b/examples/opengl/contextinfo/contextinfo.py @@ -22,8 +22,7 @@ try: except ImportError: app = QApplication(sys.argv) message_box = QMessageBox(QMessageBox.Critical, "ContextInfo", - "PyOpenGL must be installed to run this example.", - QMessageBox.Close) + "PyOpenGL must be installed to run this example.", QMessageBox.Close) message_box.setDetailedText("Run:\npip install PyOpenGL PyOpenGL_accelerate") message_box.exec() sys.exit(1) @@ -74,7 +73,10 @@ colors = numpy.array([1, 0, 0, 0, 1, 0, 0, 0, 1], dtype=numpy.float32) def print_surface_format(surface_format): - profile_name = 'core' if surface_format.profile() == QSurfaceFormat.CoreProfile else 'compatibility' + if surface_format.profile() == QSurfaceFormat.CoreProfile: + profile_name = 'core' + else: + profile_name = 'compatibility' major = surface_format.majorVersion() minor = surface_format.minorVersion() return f"{profile_name} version {major}.{minor}" @@ -104,11 +106,13 @@ class RenderWindow(QWindow): # concept 3.2+ has. This may still fail since version 150 (3.2) is # specified in the sources but it's worth a try. if (fmt.renderableType() == QSurfaceFormat.OpenGL and fmt.majorVersion() == 3 - and fmt.minorVersion() <= 1): + and fmt.minorVersion() <= 1): use_new_style_shader = not fmt.testOption(QSurfaceFormat.DeprecatedFunctions) vertex_shader = vertex_shader_source if use_new_style_shader else vertex_shader_source_110 - fragment_shader = fragment_shader_source if use_new_style_shader else fragment_shader_source_110 + fragment_shader = (fragment_shader_source + if use_new_style_shader + else fragment_shader_source_110) if not self.program.addShaderFromSourceCode(QOpenGLShader.Vertex, vertex_shader): log = self.program.log() raise Exception("Vertex shader could not be added: {log} ({vertexShader})") diff --git a/examples/opengl/textures/textures.py b/examples/opengl/textures/textures.py index 79f7761a2..43edd4d58 100644 --- a/examples/opengl/textures/textures.py +++ b/examples/opengl/textures/textures.py @@ -32,12 +32,12 @@ class GLWidget(QOpenGLWidget): refCount = 0 coords = ( - ( ( +1, -1, -1 ), ( -1, -1, -1 ), ( -1, +1, -1 ), ( +1, +1, -1 ) ), - ( ( +1, +1, -1 ), ( -1, +1, -1 ), ( -1, +1, +1 ), ( +1, +1, +1 ) ), - ( ( +1, -1, +1 ), ( +1, -1, -1 ), ( +1, +1, -1 ), ( +1, +1, +1 ) ), - ( ( -1, -1, -1 ), ( -1, -1, +1 ), ( -1, +1, +1 ), ( -1, +1, -1 ) ), - ( ( +1, -1, +1 ), ( -1, -1, +1 ), ( -1, -1, -1 ), ( +1, -1, -1 ) ), - ( ( -1, -1, +1 ), ( +1, -1, +1 ), ( +1, +1, +1 ), ( -1, +1, +1 ) ) + ((+1, -1, -1), (-1, -1, -1), (-1, +1, -1), (+1, +1, -1)), + ((+1, +1, -1), (-1, +1, -1), (-1, +1, +1), (+1, +1, +1)), + ((+1, -1, +1), (+1, -1, -1), (+1, +1, -1), (+1, +1, +1)), + ((-1, -1, -1), (-1, -1, +1), (-1, +1, +1), (-1, +1, -1)), + ((+1, -1, +1), (-1, -1, +1), (-1, -1, -1), (+1, -1, -1)), + ((-1, -1, +1), (+1, -1, +1), (+1, +1, +1), (-1, +1, +1)) ) clicked = Signal() diff --git a/examples/qml/editingmodel/model.py b/examples/qml/editingmodel/model.py index 591497872..02a1e5717 100644 --- a/examples/qml/editingmodel/model.py +++ b/examples/qml/editingmodel/model.py @@ -2,8 +2,7 @@ # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -from PySide6.QtCore import (QAbstractListModel, QByteArray, QModelIndex, Qt, - Slot) +from PySide6.QtCore import QAbstractListModel, QByteArray, QModelIndex, Qt, Slot from PySide6.QtGui import QColor from PySide6.QtQml import QmlElement @@ -104,18 +103,18 @@ class BaseModel(QAbstractListModel): self.beginMoveRows(QModelIndex(), sourceRow, sourceRow + count, QModelIndex(), end) # start database work - pops = self.db[sourceRow : sourceRow + count + 1] + pops = self.db[sourceRow: sourceRow + count + 1] if sourceRow > dstChild: self.db = ( self.db[:dstChild] + pops + self.db[dstChild:sourceRow] - + self.db[sourceRow + count + 1 :] + + self.db[sourceRow + count + 1:] ) else: start = self.db[:sourceRow] - middle = self.db[dstChild : dstChild + 1] - endlist = self.db[dstChild + count + 1 :] + middle = self.db[dstChild: dstChild + 1] + endlist = self.db[dstChild + count + 1:] self.db = start + middle + pops + endlist # end database work @@ -136,7 +135,7 @@ class BaseModel(QAbstractListModel): self.beginRemoveRows(QModelIndex(), row, row + count) # start database work - self.db = self.db[:row] + self.db[row + count + 1 :] + self.db = self.db[:row] + self.db[row + count + 1:] # end database work self.endRemoveRows() diff --git a/examples/qml/tutorials/extending-qml-advanced/adding/person.py b/examples/qml/tutorials/extending-qml-advanced/adding/person.py index fafb9d581..526eae714 100644 --- a/examples/qml/tutorials/extending-qml-advanced/adding/person.py +++ b/examples/qml/tutorials/extending-qml-advanced/adding/person.py @@ -32,4 +32,3 @@ class Person(QObject): @shoe_size.setter def shoe_size(self, s): self._shoe_size = s - diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced1-Base-project/main.py b/examples/qml/tutorials/extending-qml-advanced/advanced1-Base-project/main.py index dc07a2a5f..85bd91ab6 100644 --- a/examples/qml/tutorials/extending-qml-advanced/advanced1-Base-project/main.py +++ b/examples/qml/tutorials/extending-qml-advanced/advanced1-Base-project/main.py @@ -1,7 +1,8 @@ # Copyright (C) 2023 The Qt Company Ltd. # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -"""PySide6 port of the qml/examples/qml/tutorials/extending-qml-advanced/advanced1-Base-project example from Qt v6.x""" +"""PySide6 port of the + qml/examples/qml/tutorials/extending-qml-advanced/advanced1-Base-project example from Qt v6.x""" from pathlib import Path import sys diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/main.py b/examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/main.py index ef4b5ac5a..bb3998030 100644 --- a/examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/main.py +++ b/examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/main.py @@ -1,10 +1,11 @@ # Copyright (C) 2022 The Qt Company Ltd. # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -"""PySide6 port of the qml/examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion example from Qt v6.x""" +"""PySide6 port of the + qml/examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion example + from Qt v6.x""" from pathlib import Path -import os import sys from PySide6.QtCore import QCoreApplication diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced3-Default-properties/main.py b/examples/qml/tutorials/extending-qml-advanced/advanced3-Default-properties/main.py index f469538b6..befb7978b 100644 --- a/examples/qml/tutorials/extending-qml-advanced/advanced3-Default-properties/main.py +++ b/examples/qml/tutorials/extending-qml-advanced/advanced3-Default-properties/main.py @@ -1,7 +1,9 @@ # Copyright (C) 2022 The Qt Company Ltd. # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -"""PySide6 port of the qml/examples/qml/tutorials/extending-qml-advanced/default advanced3-Default-properties example from Qt v6.x""" +"""PySide6 port of the + qml/examples/qml/tutorials/extending-qml-advanced/default advanced3-Default-properties example + from Qt v6.x""" from pathlib import Path import sys diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/main.py b/examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/main.py index 3cdddbd06..6f183e464 100644 --- a/examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/main.py +++ b/examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/main.py @@ -1,7 +1,9 @@ # Copyright (C) 2022 The Qt Company Ltd. # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -"""PySide6 port of the qml/examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties example from Qt v6.x""" +"""PySide6 port of the + qml/examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties example + from Qt v6.x""" from pathlib import Path import sys diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/main.py b/examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/main.py index bb607ac76..27f648642 100644 --- a/examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/main.py +++ b/examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/main.py @@ -1,7 +1,9 @@ # Copyright (C) 2022 The Qt Company Ltd. # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -"""PySide6 port of the qml/examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties example from Qt v6.x""" +"""PySide6 port of the + qml/examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties example + from Qt v6.x""" from pathlib import Path import sys diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/main.py b/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/main.py index b763a456a..d33f1e1fb 100644 --- a/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/main.py +++ b/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/main.py @@ -1,7 +1,9 @@ # Copyright (C) 2022 The Qt Company Ltd. # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -"""PySide6 port of the qml/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source example from Qt v6.x""" +"""PySide6 port of the + qml/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source example + from Qt v6.x""" from pathlib import Path import sys diff --git a/examples/qml/tutorials/extending-qml-advanced/properties/person.py b/examples/qml/tutorials/extending-qml-advanced/properties/person.py index fafb9d581..526eae714 100644 --- a/examples/qml/tutorials/extending-qml-advanced/properties/person.py +++ b/examples/qml/tutorials/extending-qml-advanced/properties/person.py @@ -32,4 +32,3 @@ class Person(QObject): @shoe_size.setter def shoe_size(self, s): self._shoe_size = s - diff --git a/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/customPropertyTypes.py b/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/customPropertyTypes.py index c70d7fc42..659850f38 100644 --- a/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/customPropertyTypes.py +++ b/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/customPropertyTypes.py @@ -1,7 +1,8 @@ # Copyright (C) 2022 The Qt Company Ltd. # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -"""PySide6 port of the qml/tutorials/extending-qml/chapter4-customPropertyTypes example from Qt v5.x""" +"""PySide6 port of the qml/tutorials/extending-qml/chapter4-customPropertyTypes example + from Qt v5.x""" import os from pathlib import Path diff --git a/examples/qml/tutorials/extending-qml/chapter5-listproperties/listproperties.py b/examples/qml/tutorials/extending-qml/chapter5-listproperties/listproperties.py index 236c487f9..98952cef1 100644 --- a/examples/qml/tutorials/extending-qml/chapter5-listproperties/listproperties.py +++ b/examples/qml/tutorials/extending-qml/chapter5-listproperties/listproperties.py @@ -54,7 +54,8 @@ class PieSlice (QQuickPaintedItem): pen = QPen(self._color, 2) painter.setPen(pen) painter.setRenderHints(QPainter.Antialiasing, True) - painter.drawPie(self.boundingRect().adjusted(1, 1, -1, -1), self._fromAngle * 16, self._angleSpan * 16) + painter.drawPie( + self.boundingRect().adjusted(1, 1, -1, -1), self._fromAngle * 16, self._angleSpan * 16) @QmlElement diff --git a/examples/quick/rendercontrol/rendercontrol_opengl/cuberenderer.py b/examples/quick/rendercontrol/rendercontrol_opengl/cuberenderer.py index ae56988aa..c1fe5c8ab 100644 --- a/examples/quick/rendercontrol/rendercontrol_opengl/cuberenderer.py +++ b/examples/quick/rendercontrol/rendercontrol_opengl/cuberenderer.py @@ -45,27 +45,27 @@ VERTEXES = numpy.array([-0.5, 0.5, 0.5, 0.5, -0.5, 0.5, -0.5, -0.5, 0.5, -0.5, 0.5, -0.5, -0.5, -0.5, 0.5, -0.5, -0.5, -0.5, -0.5, -0.5, 0.5, -0.5, 0.5, -0.5, -0.5, 0.5, 0.5, - 0.5, 0.5, -0.5, -0.5, 0.5, 0.5, -0.5, 0.5, -0.5, - -0.5, 0.5, 0.5, 0.5, 0.5, -0.5, 0.5, 0.5, 0.5, - -0.5, -0.5, -0.5, -0.5, -0.5, 0.5, 0.5, -0.5, -0.5, - 0.5, -0.5, 0.5, 0.5, -0.5, -0.5, -0.5, -0.5, 0.5], + 0.5, 0.5, -0.5, -0.5, 0.5, 0.5, -0.5, 0.5, -0.5, + -0.5, 0.5, 0.5, 0.5, 0.5, -0.5, 0.5, 0.5, 0.5, + -0.5, -0.5, -0.5, -0.5, -0.5, 0.5, 0.5, -0.5, -0.5, + 0.5, -0.5, 0.5, 0.5, -0.5, -0.5, -0.5, -0.5, 0.5], dtype=numpy.float32) -TEX_COORDS = numpy.array([0.0, 0.0, 1.0, 1.0, 1.0, 0.0, - 1.0, 1.0, 0.0, 0.0, 0.0, 1.0, - 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, - 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, +TEX_COORDS = numpy.array([0.0, 0.0, 1.0, 1.0, 1.0, 0.0, + 1.0, 1.0, 0.0, 0.0, 0.0, 1.0, + 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, + 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, - 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, - 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, - 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, - 1.0, 1.0, 0.0, 0.0, 0.0, 1.0, + 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, + 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, + 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, + 1.0, 1.0, 0.0, 0.0, 0.0, 1.0, - 0.0, 1.0, 1.0, 0.0, 1.0, 1.0, - 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, - 1.0, 0.0, 1.0, 1.0, 0.0, 0.0, - 0.0, 1.0, 0.0, 0.0, 1.0, 1.0], dtype=numpy.float32) + 0.0, 1.0, 1.0, 0.0, 1.0, 1.0, + 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, + 1.0, 0.0, 1.0, 1.0, 0.0, 0.0, + 0.0, 1.0, 0.0, 0.0, 1.0, 1.0], dtype=numpy.float32) class CubeRenderer(): diff --git a/examples/quick/rendercontrol/rendercontrol_opengl/window_singlethreaded.py b/examples/quick/rendercontrol/rendercontrol_opengl/window_singlethreaded.py index 051647696..6f1e61f94 100644 --- a/examples/quick/rendercontrol/rendercontrol_opengl/window_singlethreaded.py +++ b/examples/quick/rendercontrol/rendercontrol_opengl/window_singlethreaded.py @@ -247,7 +247,7 @@ class WindowSingleThreaded(QWindow): # If self is a resize after the scene is up and running, recreate the # texture and the Quick item and scene. if (self.texture_id() - and self.m_textureSize != self.size() * self.devicePixelRatio()): + and self.m_textureSize != self.size() * self.devicePixelRatio()): self.resizeTexture() @Slot() diff --git a/examples/quick3d/proceduraltexture/gradienttexture.py b/examples/quick3d/proceduraltexture/gradienttexture.py index 1511905cb..a577f7ebd 100644 --- a/examples/quick3d/proceduraltexture/gradienttexture.py +++ b/examples/quick3d/proceduraltexture/gradienttexture.py @@ -103,4 +103,3 @@ class GradientTexture(QQuick3DTextureData): output.setBlueF(color1.blueF() + (value * (color2.blueF() - color1.blueF()))) return output - diff --git a/examples/quickcontrols/contactslist/contactmodel.py b/examples/quickcontrols/contactslist/contactmodel.py index 313a58305..5d2746c2e 100644 --- a/examples/quickcontrols/contactslist/contactmodel.py +++ b/examples/quickcontrols/contactslist/contactmodel.py @@ -47,7 +47,7 @@ class ContactModel(QAbstractListModel): "Piobesi Torinese", "0399 2826994")) self.m_contacts.append(self.Contact("Harvey Chandler", "North Squaw Creek 11", "Madisonville", "0343 1244492")) - self.m_contacts.append(self.Contact("Miguel Gomez", "Wild Rose Street 13", "Trussville" , + self.m_contacts.append(self.Contact("Miguel Gomez", "Wild Rose Street 13", "Trussville", "0343 9826996")) self.m_contacts.append(self.Contact("Norma Rodriguez", " Glen Eagles Street 53", "Buffalo", "0241 5826596")) @@ -95,7 +95,7 @@ class ContactModel(QAbstractListModel): self.endInsertRows() @Slot(int, str, str, str, str) - def set(self, row: int, full_name: str, address: str, city: str, number: str): + def set(self, row: int, full_name: str, address: str, city: str, number: str): if row < 0 or row >= len(self.m_contacts): return diff --git a/examples/quickcontrols/filesystemexplorer/filesystemexplorer.py b/examples/quickcontrols/filesystemexplorer/filesystemexplorer.py index 90579b360..2bc733c37 100644 --- a/examples/quickcontrols/filesystemexplorer/filesystemexplorer.py +++ b/examples/quickcontrols/filesystemexplorer/filesystemexplorer.py @@ -44,7 +44,8 @@ class FileSystemModel(QFileSystemModel): file = QFile(path) mime = self.db.mimeTypeForFile(QFileInfo(file)) - if 'text' in mime.comment().lower() or any('text' in s.lower() for s in mime.parentMimeTypes()): + if ('text' in mime.comment().lower() + or any('text' in s.lower() for s in mime.parentMimeTypes())): if file.open(QFile.ReadOnly | QFile.Text): stream = QTextStream(file).readAll() return stream diff --git a/examples/serialbus/can/main.py b/examples/serialbus/can/main.py index 77d2e6012..97cdcc908 100644 --- a/examples/serialbus/can/main.py +++ b/examples/serialbus/can/main.py @@ -16,4 +16,3 @@ if __name__ == "__main__": w = MainWindow() w.show() sys.exit(QCoreApplication.exec()) - diff --git a/examples/serialbus/can/mainwindow.py b/examples/serialbus/can/mainwindow.py index e5d068e07..9167b9d00 100644 --- a/examples/serialbus/can/mainwindow.py +++ b/examples/serialbus/can/mainwindow.py @@ -109,9 +109,11 @@ class MainWindow(QMainWindow): else: self.m_model.set_queue_limit(0) - device, error_string = QCanBus.instance().createDevice(p.plugin_name, p.device_interface_name) + device, error_string = QCanBus.instance().createDevice( + p.plugin_name, p.device_interface_name) if not device: - self.m_status.setText(f"Error creating device '{p.plugin_name}', reason: '{error_string}'") + self.m_status.setText( + f"Error creating device '{p.plugin_name}', reason: '{error_string}'") return self.m_number_frames_written = 0 @@ -136,18 +138,22 @@ class MainWindow(QMainWindow): config_bit_rate = self.m_can_device.configurationParameter(QCanBusDevice.BitRateKey) if config_bit_rate > 0: is_can_fd = bool(self.m_can_device.configurationParameter(QCanBusDevice.CanFdKey)) - config_data_bit_rate = self.m_can_device.configurationParameter(QCanBusDevice.DataBitRateKey) + config_data_bit_rate = self.m_can_device.configurationParameter( + QCanBusDevice.DataBitRateKey) bit_rate = config_bit_rate / 1000 if is_can_fd and config_data_bit_rate > 0: data_bit_rate = config_data_bit_rate / 1000 - m = f"Plugin: {p.plugin_name}, connected to {p.device_interface_name} at {bit_rate} / {data_bit_rate} kBit/s" + m = (f"Plugin: {p.plugin_name}, connected to {p.device_interface_name} " + f"at {bit_rate} / {data_bit_rate} kBit/s") self.m_status.setText(m) else: - m = f"Plugin: {p.plugin_name}, connected to {p.device_interface_name} at {bit_rate} kBit/s" + m = (f"Plugin: {p.plugin_name}, connected to {p.device_interface_name} " + f"at {bit_rate} kBit/s") self.m_status.setText(m) else: - self.m_status.setText(f"Plugin: {p.plugin_name}, connected to {p.device_interface_name}") + self.m_status.setText( + f"Plugin: {p.plugin_name}, connected to {p.device_interface_name}") if self.m_can_device.hasBusStatus(): self.m_busStatusTimer.start(2000) diff --git a/examples/serialbus/can/sendframebox.py b/examples/serialbus/can/sendframebox.py index 99e4ab7c2..6472fc473 100644 --- a/examples/serialbus/can/sendframebox.py +++ b/examples/serialbus/can/sendframebox.py @@ -157,8 +157,8 @@ class SendFrameBox(QGroupBox): @Slot(bool) def _flexible_datarate(self, value): - l = MAX_PAYLOAD_FD if value else MAX_PAYLOAD - self.m_hexStringValidator.set_max_length(l) + len = MAX_PAYLOAD_FD if value else MAX_PAYLOAD + self.m_hexStringValidator.set_max_length(len) self.m_ui.bitrateSwitchBox.setEnabled(value) if not value: self.m_ui.bitrateSwitchBox.setChecked(False) diff --git a/examples/serialbus/modbus/modbusclient/mainwindow.py b/examples/serialbus/modbus/modbusclient/mainwindow.py index 99a360236..02f9d478b 100644 --- a/examples/serialbus/modbus/modbusclient/mainwindow.py +++ b/examples/serialbus/modbus/modbusclient/mainwindow.py @@ -327,5 +327,5 @@ class MainWindow(QMainWindow): # do not go beyond 10 entries number_of_entries = min(int(self.ui.writeSize.currentText()), - 10 - start_address) + 10 - start_address) return QModbusDataUnit(table, start_address, number_of_entries) diff --git a/examples/serialport/terminal/settingsdialog.py b/examples/serialport/terminal/settingsdialog.py index 57b5a6bae..c9373d5b0 100644 --- a/examples/serialport/terminal/settingsdialog.py +++ b/examples/serialport/terminal/settingsdialog.py @@ -52,7 +52,8 @@ class SettingsDialog(QDialog): self.m_ui.applyButton.clicked.connect(self.apply) self.m_ui.serialPortInfoListBox.currentIndexChanged.connect(self.show_port_info) self.m_ui.baudRateBox.currentIndexChanged.connect(self.check_custom_baud_rate_policy) - self.m_ui.serialPortInfoListBox.currentIndexChanged.connect(self.check_custom_device_path_policy) + self.m_ui.serialPortInfoListBox.currentIndexChanged.connect( + self.check_custom_device_path_policy) self.fill_ports_parameters() self.fill_ports_info() diff --git a/examples/sql/books/bookdelegate.py b/examples/sql/books/bookdelegate.py index 7015d5158..d9f4ef7e0 100644 --- a/examples/sql/books/bookdelegate.py +++ b/examples/sql/books/bookdelegate.py @@ -43,7 +43,7 @@ class BookDelegate(QSqlRelationalDelegate): if option.state & QStyle.State_Selected: painter.fillRect(option.rect, - option.palette.color(color_group, QPalette.Highlight)) + option.palette.color(color_group, QPalette.Highlight)) rating = model.data(index, Qt.DisplayRole) width = self.star.width() height = self.star.height() diff --git a/examples/sql/books/bookwindow.py b/examples/sql/books/bookwindow.py index 4acb63d44..0439ce9c7 100644 --- a/examples/sql/books/bookwindow.py +++ b/examples/sql/books/bookwindow.py @@ -2,7 +2,7 @@ # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause from PySide6.QtWidgets import (QAbstractItemView, QDataWidgetMapper, - QHeaderView, QMainWindow, QMessageBox) + QHeaderView, QMainWindow, QMessageBox) from PySide6.QtGui import QKeySequence from PySide6.QtSql import QSqlRelation, QSqlRelationalTableModel, QSqlTableModel from PySide6.QtCore import Qt, Slot @@ -58,7 +58,7 @@ class BookWindow(QMainWindow, Ui_BookWindow): # Lock and prohibit resizing of the width of the rating column: self.bookTable.horizontalHeader().setSectionResizeMode(model.fieldIndex("rating"), - QHeaderView.ResizeToContents) + QHeaderView.ResizeToContents) mapper = QDataWidgetMapper(self) mapper.setModel(model) @@ -77,7 +77,7 @@ class BookWindow(QMainWindow, Ui_BookWindow): def showError(self, err): QMessageBox.critical(self, "Unable to initialize Database", - f"Error initializing database: {err.text()}") + f"Error initializing database: {err.text()}") def create_menubar(self): file_menu = self.menuBar().addMenu(self.tr("&File")) @@ -95,4 +95,4 @@ class BookWindow(QMainWindow, Ui_BookWindow): def about(self): QMessageBox.about(self, self.tr("About Books"), self.tr("<p>The <b>Books</b> example shows how to use Qt SQL classes " - "with a model/view framework.")) + "with a model/view framework.")) diff --git a/examples/statemachine/rogue/rogue.py b/examples/statemachine/rogue/rogue.py index a43d4d1bc..9a1048af2 100644 --- a/examples/statemachine/rogue/rogue.py +++ b/examples/statemachine/rogue/rogue.py @@ -18,11 +18,11 @@ class MovementTransition(QEventTransition): self.window = window def eventTest(self, event): - if (event.type() == QEvent.StateMachineWrapped and - event.event().type() == QEvent.KeyPress): + if (event.type() == QEvent.StateMachineWrapped + and event.event().type() == QEvent.KeyPress): key = event.event().key() - return (key == Qt.Key_2 or key == Qt.Key_8 or - key == Qt.Key_6 or key == Qt.Key_4) + return (key == Qt.Key_2 or key == Qt.Key_8 + or key == Qt.Key_6 or key == Qt.Key_4) return False def onTransition(self, event): @@ -74,8 +74,8 @@ class MainWindow(QMainWindow): for x in range(self.width): column = [] for y in range(self.height): - if (x == 0 or x == self.width - 1 or y == 0 or - y == self.height - 1 or generator.bounded(0, 40) == 0): + if (x == 0 or x == self.width - 1 or y == 0 + or y == self.height - 1 or generator.bounded(0, 40) == 0): column.append('#') else: column.append('.') diff --git a/examples/utils/pyside_config.py b/examples/utils/pyside_config.py index b9f962b8d..e8333e2f9 100644 --- a/examples/utils/pyside_config.py +++ b/examples/utils/pyside_config.py @@ -78,10 +78,12 @@ options.append(("--shiboken-module-shared-libraries-cmake", options.append(("--pyside-shared-libraries-qmake", lambda: get_shared_libraries_qmake(Package.PYSIDE_MODULE), pyside_libs_error, - "Print paths of f{PYSIDE_MODULE} shared libraries (.so's, .dylib's, .dll's) for qmake")) + "Print paths of f{PYSIDE_MODULE} shared libraries (.so's, .dylib's, .dll's) " + "for qmake")) options.append(("--pyside-shared-libraries-cmake", lambda: get_shared_libraries_cmake(Package.PYSIDE_MODULE), pyside_libs_error, - f"Print paths of {PYSIDE_MODULE} shared libraries (.so's, .dylib's, .dll's) for cmake")) + f"Print paths of {PYSIDE_MODULE} shared libraries (.so's, .dylib's, .dll's) " + "for cmake")) options_usage = '' for i, (flag, _, _, description) in enumerate(options): @@ -153,11 +155,11 @@ def link_option(lib): # libraries when compiling the project baseName = os.path.basename(lib) link = ' -l' - if sys.platform in ['linux', 'linux2']: # Linux: 'libfoo.so' -> '/absolute/path/libfoo.so' + if sys.platform in ['linux', 'linux2']: # Linux: 'libfoo.so' -> '/absolute/path/libfoo.so' link = lib - elif sys.platform in ['darwin']: # Darwin: 'libfoo.so' -> '-lfoo' + elif sys.platform in ['darwin']: # Darwin: 'libfoo.so' -> '-lfoo' link += os.path.splitext(baseName[3:])[0] - else: # Windows: 'libfoo.dll' -> 'libfoo.dll' + else: # Windows: 'libfoo.dll' -> 'libfoo.dll' link += os.path.splitext(baseName)[0] return link diff --git a/examples/webenginewidgets/notifications/notificationpopup.py b/examples/webenginewidgets/notifications/notificationpopup.py index bbea86102..e68ce3d6f 100644 --- a/examples/webenginewidgets/notifications/notificationpopup.py +++ b/examples/webenginewidgets/notifications/notificationpopup.py @@ -51,8 +51,8 @@ class NotificationPopup(QWidget): self.notification.closed.connect(self.onClosed) QTimer.singleShot(10000, lambda: self.onClosed()) - self.move(self.parentWidget().mapToGlobal(self.parentWidget().rect().bottomRight() - - QPoint(self.width() + 10, self.height() + 10))) + self.move(self.parentWidget().mapToGlobal(self.parentWidget().rect().bottomRight() + - QPoint(self.width() + 10, self.height() + 10))) @Slot() def onClosed(self): diff --git a/examples/webenginewidgets/simplebrowser/browser.py b/examples/webenginewidgets/simplebrowser/browser.py index 4dc65bfa3..a124ea084 100644 --- a/examples/webenginewidgets/simplebrowser/browser.py +++ b/examples/webenginewidgets/simplebrowser/browser.py @@ -33,7 +33,8 @@ class Browser(QObject): s.setAttribute(QWebEngineSettings.DnsPrefetchEnabled, True) s.setAttribute(QWebEngineSettings.LocalContentCanAccessRemoteUrls, True) s.setAttribute(QWebEngineSettings.LocalContentCanAccessFileUrls, False) - self._profile.downloadRequested.connect(self._download_manager_widget.download_requested) + self._profile.downloadRequested.connect( + self._download_manager_widget.download_requested) profile = QWebEngineProfile.defaultProfile() if offTheRecord else self._profile main_window = BrowserWindow(self, profile, False) diff --git a/examples/webenginewidgets/simplebrowser/browserwindow.py b/examples/webenginewidgets/simplebrowser/browserwindow.py index 576865742..d5900d72e 100644 --- a/examples/webenginewidgets/simplebrowser/browserwindow.py +++ b/examples/webenginewidgets/simplebrowser/browserwindow.py @@ -84,7 +84,8 @@ class BrowserWindow(QMainWindow): if not forDevTools: self._tab_widget.link_hovered.connect(self._show_status_message) self._tab_widget.load_progress.connect(self.handle_web_view_load_progress) - self._tab_widget.web_action_enabled_changed.connect(self.handle_web_action_enabled_changed) + self._tab_widget.web_action_enabled_changed.connect( + self.handle_web_action_enabled_changed) self._tab_widget.url_changed.connect(self._url_changed) self._tab_widget.fav_icon_changed.connect(self._fav_action.setIcon) self._tab_widget.dev_tools_requested.connect(self.handle_dev_tools_requested) diff --git a/examples/webenginewidgets/simplebrowser/webview.py b/examples/webenginewidgets/simplebrowser/webview.py index 05932eec9..84d24833b 100644 --- a/examples/webenginewidgets/simplebrowser/webview.py +++ b/examples/webenginewidgets/simplebrowser/webview.py @@ -99,8 +99,10 @@ class WebView(QWebEngineView): old_page.createCertificateErrorDialog.disconnect(self.handle_certificate_error) old_page.authenticationRequired.disconnect(self.handle_authentication_required) old_page.featurePermissionRequested.disconnect(self.handle_feature_permission_requested) - old_page.proxyAuthenticationRequired.disconnect(self.handle_proxy_authentication_required) - old_page.registerProtocolHandlerRequested.disconnect(self.handle_register_protocol_handler_requested) + old_page.proxyAuthenticationRequired.disconnect( + self.handle_proxy_authentication_required) + old_page.registerProtocolHandlerRequested.disconnect( + self.handle_register_protocol_handler_requested) old_page.fileSystemAccessRequested.disconnect(self.handle_file_system_access_requested) self.create_web_action_trigger(page, QWebEnginePage.Forward) @@ -112,7 +114,8 @@ class WebView(QWebEngineView): page.authenticationRequired.connect(self.handle_authentication_required) page.featurePermissionRequested.connect(self.handle_feature_permission_requested) page.proxyAuthenticationRequired.connect(self.handle_proxy_authentication_required) - page.registerProtocolHandlerRequested.connect(self.handle_register_protocol_handler_requested) + page.registerProtocolHandlerRequested.connect( + self.handle_register_protocol_handler_requested) page.fileSystemAccessRequested.connect(self.handle_file_system_access_requested) def load_progress(self): @@ -229,8 +232,7 @@ class WebView(QWebEngineView): question = question_for_feature(feature).replace("%1", host) w = self.window() page = self.page() - if (question - and QMessageBox.question(w, title, question) == QMessageBox.Yes): + if question and QMessageBox.question(w, title, question) == QMessageBox.Yes: page.setFeaturePermission(securityOrigin, feature, QWebEnginePage.PermissionGrantedByUser) else: diff --git a/examples/widgets/animation/animatedtiles/animatedtiles.py b/examples/widgets/animation/animatedtiles/animatedtiles.py index fe524361d..1cb0ee6c8 100644 --- a/examples/widgets/animation/animatedtiles/animatedtiles.py +++ b/examples/widgets/animation/animatedtiles/animatedtiles.py @@ -123,7 +123,7 @@ if __name__ == '__main__': for i in range(64): item = Pixmap(kinetic_pix) item.pixmap_item.setOffset(-kinetic_pix.width() / 2, - -kinetic_pix.height() / 2) + -kinetic_pix.height() / 2) item.pixmap_item.setZValue(i) items.append(item) scene.addItem(item.pixmap_item) @@ -161,23 +161,25 @@ if __name__ == '__main__': for i, item in enumerate(items): # Ellipse. ellipse_state.assignProperty(item, 'pos', - QPointF(math.cos((i / 63.0) * 6.28) * 250, - math.sin((i / 63.0) * 6.28) * 250)) + QPointF(math.cos((i / 63.0) * 6.28) * 250, + math.sin((i / 63.0) * 6.28) * 250)) # Figure 8. figure_8state.assignProperty(item, 'pos', - QPointF(math.sin((i / 63.0) * 6.28) * 250, - math.sin(((i * 2) / 63.0) * 6.28) * 250)) + QPointF(math.sin((i / 63.0) * 6.28) * 250, + math.sin(((i * 2) / 63.0) * 6.28) * 250)) # Random. random_state.assignProperty(item, 'pos', - QPointF(-250 + generator.bounded(0, 500), - -250 + generator.bounded(0, 500))) + QPointF(-250 + generator.bounded(0, 500), + -250 + generator.bounded(0, 500))) # Tiled. + width = kinetic_pix.width() + height = kinetic_pix.height() tiled_state.assignProperty(item, 'pos', - QPointF(((i % 8) - 4) * kinetic_pix.width() + kinetic_pix.width() / 2, - ((i // 8) - 4) * kinetic_pix.height() + kinetic_pix.height() / 2)) + QPointF(((i % 8) - 4) * width + width / 2, + ((i // 8) - 4) * height + height / 2)) # Centered. centered_state.assignProperty(item, 'pos', QPointF()) @@ -188,8 +190,7 @@ if __name__ == '__main__': view.setViewportUpdateMode(QGraphicsView.BoundingRectViewportUpdate) view.setBackgroundBrush(QBrush(bg_pix)) view.setCacheMode(QGraphicsView.CacheBackground) - view.setRenderHints( - QPainter.Antialiasing | QPainter.SmoothPixmapTransform) + view.setRenderHints(QPainter.Antialiasing | QPainter.SmoothPixmapTransform) view.show() states = QStateMachine() diff --git a/examples/widgets/animation/easing/easing.py b/examples/widgets/animation/easing/easing.py index c8a87e8c5..ba5032458 100644 --- a/examples/widgets/animation/easing/easing.py +++ b/examples/widgets/animation/easing/easing.py @@ -143,8 +143,7 @@ class Window(QWidget): # Start point. painter.setBrush(Qt.red) - start = QPoint(y_axis, - x_axis - curve_scale * curve.valueForProgress(0)) + start = QPoint(y_axis, x_axis - curve_scale * curve.valueForProgress(0)) painter.drawRect(start.x() - 1, start.y() - 1, 3, 3) # End point. diff --git a/examples/widgets/desktop/systray/window.py b/examples/widgets/desktop/systray/window.py index c04a33e3a..19a2f22ed 100644 --- a/examples/widgets/desktop/systray/window.py +++ b/examples/widgets/desktop/systray/window.py @@ -190,8 +190,8 @@ class Window(QDialog): self._body_label = QLabel("Body:") self._body_edit = QTextEdit() - self._body_edit.setPlainText("Don't believe me. Honestly, I don't have a clue." - "\nClick this balloon for details.") + self._body_edit.setPlainText("Don't believe me. Honestly, I don't have a clue.\n" + "Click this balloon for details.") self._show_message_button = QPushButton("Show Message") self._show_message_button.setDefault(True) diff --git a/examples/widgets/dialogs/standarddialogs/standarddialogs.py b/examples/widgets/dialogs/standarddialogs/standarddialogs.py index 8a2a4426e..ef677d5a8 100644 --- a/examples/widgets/dialogs/standarddialogs/standarddialogs.py +++ b/examples/widgets/dialogs/standarddialogs/standarddialogs.py @@ -235,14 +235,14 @@ class Dialog(QDialog): @Slot() def set_integer(self): i, ok = QInputDialog.getInt(self, - "QInputDialog.getInteger()", "Percentage:", 25, 0, 100, 1) + "QInputDialog.getInteger()", "Percentage:", 25, 0, 100, 1) if ok: self._integer_label.setText(f"{i}%") @Slot() def set_double(self): d, ok = QInputDialog.getDouble(self, "QInputDialog.getDouble()", - "Amount:", 37.56, -10000, 10000, 2) + "Amount:", 37.56, -10000, 10000, 2) if ok: self._double_label.setText(f"${d:g}") @@ -250,23 +250,21 @@ class Dialog(QDialog): def set_item(self): items = ("Spring", "Summer", "Fall", "Winter") - item, ok = QInputDialog.getItem(self, "QInputDialog.getItem()", - "Season:", items, 0, False) + item, ok = QInputDialog.getItem(self, "QInputDialog.getItem()", "Season:", items, 0, False) if ok and item: self._item_label.setText(item) @Slot() def set_text(self): text, ok = QInputDialog.getText(self, "QInputDialog.getText()", - "User name:", QLineEdit.Normal, - QDir.home().dirName()) + "User name:", QLineEdit.Normal, QDir.home().dirName()) if ok and text != '': self._text_label.setText(text) @Slot() def set_multiline_text(self): text, ok = QInputDialog.getMultiLineText(self, "QInputDialog::getMultiLineText()", - "Address:", "John Doe\nFreedom Street") + "Address:", "John Doe\nFreedom Street") if ok and text != '': self._multiline_text_label.setText(text) @@ -301,9 +299,8 @@ class Dialog(QDialog): options_value = self._file_options.value() options = QFileDialog.Options(options_value) | QFileDialog.ShowDirsOnly - directory = QFileDialog.getExistingDirectory(self, - "QFileDialog.getExistingDirectory()", - self._directory_label.text(), options) + directory = QFileDialog.getExistingDirectory(self, "QFileDialog.getExistingDirectory()", + self._directory_label.text(), options) if directory: self._directory_label.setText(directory) @@ -312,10 +309,9 @@ class Dialog(QDialog): options_value = self._file_options.value() options = QFileDialog.Options(options_value) - fileName, filtr = QFileDialog.getOpenFileName(self, - "QFileDialog.getOpenFileName()", - self._open_file_name_label.text(), - "All Files (*);;Text Files (*.txt)", "", options) + fileName, _ = QFileDialog.getOpenFileName(self, "QFileDialog.getOpenFileName()", + self._open_file_name_label.text(), + "All Files (*);;Text Files (*.txt)", "", options) if fileName: self._open_file_name_label.setText(fileName) @@ -324,9 +320,9 @@ class Dialog(QDialog): options_value = self._file_options.value() options = QFileDialog.Options(options_value) - files, filtr = QFileDialog.getOpenFileNames(self, - "QFileDialog.getOpenFileNames()", self._open_files_path, - "All Files (*);;Text Files (*.txt)", "", options) + files, _ = QFileDialog.getOpenFileNames(self, "QFileDialog.getOpenFileNames()", + self._open_files_path, + "All Files (*);;Text Files (*.txt)", "", options) if files: self._open_files_path = files[0] file_list = ', '.join(files) @@ -337,10 +333,9 @@ class Dialog(QDialog): options_value = self._file_options.value() options = QFileDialog.Options(options_value) - fileName, filtr = QFileDialog.getSaveFileName(self, - "QFileDialog.getSaveFileName()", - self._save_file_name_label.text(), - "All Files (*);;Text Files (*.txt)", "", options) + fileName, _ = QFileDialog.getSaveFileName(self, "QFileDialog.getSaveFileName()", + self._save_file_name_label.text(), + "All Files (*);;Text Files (*.txt)", "", options) if fileName: self._save_file_name_label.setText(fileName) diff --git a/examples/widgets/draganddrop/draggabletext/draggabletext.py b/examples/widgets/draganddrop/draggabletext/draggabletext.py index 4b470cc9d..39a2fab82 100644 --- a/examples/widgets/draganddrop/draggabletext/draggabletext.py +++ b/examples/widgets/draganddrop/draggabletext/draggabletext.py @@ -2,7 +2,8 @@ # Copyright (C) 2022 The Qt Company Ltd. # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -"""PySide6 port of the widgets/draganddrop/draggabletext example from Qt v5.x, originating from PyQt""" +"""PySide6 port of the widgets/draganddrop/draggabletext example from Qt v5.x, + originating from PyQt""" from PySide6.QtCore import QFile, QIODevice, QMimeData, QPoint, Qt, QTextStream from PySide6.QtGui import QDrag, QPalette, QPixmap diff --git a/examples/widgets/effects/lighting/lighting.py b/examples/widgets/effects/lighting/lighting.py index fe200357d..f074813c3 100644 --- a/examples/widgets/effects/lighting/lighting.py +++ b/examples/widgets/effects/lighting/lighting.py @@ -37,8 +37,7 @@ class Lighting(QGraphicsView): def setup_scene(self): self.m_scene.setSceneRect(-300, -200, 600, 460) - linear_grad = QLinearGradient(QPointF(-100, -100), - QPointF(100, 100)) + linear_grad = QLinearGradient(QPointF(-100, -100), QPointF(100, 100)) linear_grad.setColorAt(0, QColor(255, 255, 255)) linear_grad.setColorAt(1, QColor(192, 192, 255)) self.setBackgroundBrush(linear_grad) diff --git a/examples/widgets/graphicsview/anchorlayout/anchorlayout.py b/examples/widgets/graphicsview/anchorlayout/anchorlayout.py index d6e8e57b2..9d9be041f 100644 --- a/examples/widgets/graphicsview/anchorlayout/anchorlayout.py +++ b/examples/widgets/graphicsview/anchorlayout/anchorlayout.py @@ -41,7 +41,7 @@ if __name__ == '__main__': f = create_item(QSizeF(30, 50), QSizeF(150, 50), max_size, "F") g = create_item(QSizeF(30, 50), QSizeF(30, 100), max_size, "G") - l = QGraphicsAnchorLayout() + l = QGraphicsAnchorLayout() # noqa: E741 l.setSpacing(0) w = QGraphicsWidget(None, Qt.Window) diff --git a/examples/widgets/graphicsview/collidingmice/collidingmice.py b/examples/widgets/graphicsview/collidingmice/collidingmice.py index 7cce60b22..8165335a0 100644 --- a/examples/widgets/graphicsview/collidingmice/collidingmice.py +++ b/examples/widgets/graphicsview/collidingmice/collidingmice.py @@ -5,12 +5,9 @@ import math import sys -from PySide6.QtCore import (QLineF, QPointF, QRandomGenerator, QRectF, QTimer, - Qt) -from PySide6.QtGui import (QBrush, QColor, QPainter, QPainterPath, QPixmap, - QPolygonF, QTransform) -from PySide6.QtWidgets import (QApplication, QGraphicsItem, QGraphicsScene, - QGraphicsView) +from PySide6.QtCore import (QLineF, QPointF, QRandomGenerator, QRectF, QTimer, Qt) +from PySide6.QtGui import (QBrush, QColor, QPainter, QPainterPath, QPixmap, QPolygonF, QTransform) +from PySide6.QtWidgets import (QApplication, QGraphicsItem, QGraphicsScene, QGraphicsView) import mice_rc @@ -103,7 +100,8 @@ class Mouse(QGraphicsItem): if angle_to_center < Mouse.PI and angle_to_center > Mouse.PI / 4: # Rotate left. self.angle += [-0.25, 0.25][self.angle < -Mouse.PI / 2] - elif angle_to_center >= Mouse.PI and angle_to_center < (Mouse.PI + Mouse.PI / 2 + Mouse.PI / 4): + elif (angle_to_center >= Mouse.PI + and angle_to_center < (Mouse.PI + Mouse.PI / 2 + Mouse.PI / 4)): # Rotate right. self.angle += [-0.25, 0.25][self.angle < Mouse.PI / 2] elif math.sin(self.angle) < 0: diff --git a/examples/widgets/graphicsview/diagramscene/diagramscene.py b/examples/widgets/graphicsview/diagramscene/diagramscene.py index 3348577a4..a88e030f3 100644 --- a/examples/widgets/graphicsview/diagramscene/diagramscene.py +++ b/examples/widgets/graphicsview/diagramscene/diagramscene.py @@ -30,8 +30,7 @@ class Arrow(QGraphicsLineItem): self._my_end_item = endItem self.setFlag(QGraphicsItem.ItemIsSelectable, True) self._my_color = Qt.black - self.setPen(QPen(self._my_color, 2, Qt.SolidLine, - Qt.RoundCap, Qt.RoundJoin)) + self.setPen(QPen(self._my_color, 2, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)) def set_color(self, color): self._my_color = color @@ -163,19 +162,19 @@ class DiagramItem(QGraphicsPolygonItem): self._my_polygon = path.toFillPolygon() elif self.diagram_type == self.Conditional: self._my_polygon = QPolygonF([ - QPointF(-100, 0), QPointF(0, 100), - QPointF(100, 0), QPointF(0, -100), - QPointF(-100, 0)]) + QPointF(-100, 0), QPointF(0, 100), + QPointF(100, 0), QPointF(0, -100), + QPointF(-100, 0)]) elif self.diagram_type == self.Step: self._my_polygon = QPolygonF([ - QPointF(-100, -100), QPointF(100, -100), - QPointF(100, 100), QPointF(-100, 100), - QPointF(-100, -100)]) + QPointF(-100, -100), QPointF(100, -100), + QPointF(100, 100), QPointF(-100, 100), + QPointF(-100, -100)]) else: self._my_polygon = QPolygonF([ - QPointF(-120, -80), QPointF(-70, 80), - QPointF(120, 80), QPointF(70, -80), - QPointF(-120, -80)]) + QPointF(-120, -80), QPointF(-70, 80), + QPointF(120, 80), QPointF(70, -80), + QPointF(-120, -80)]) self.setPolygon(self._my_polygon) self.setFlag(QGraphicsItem.ItemIsMovable, True) @@ -291,8 +290,7 @@ class DiagramScene(QGraphicsScene): item.setPos(mouseEvent.scenePos()) self.item_inserted.emit(item) elif self._my_mode == self.InsertLine: - self.line = QGraphicsLineItem(QLineF(mouseEvent.scenePos(), - mouseEvent.scenePos())) + self.line = QGraphicsLineItem(QLineF(mouseEvent.scenePos(), mouseEvent.scenePos())) self.line.setPen(QPen(self._my_line_color, 2)) self.addItem(self.line) elif self._my_mode == self.InsertText: @@ -484,24 +482,21 @@ class MainWindow(QMainWindow): def text_color_changed(self): self._text_action = self.sender() self._font_color_tool_button.setIcon(self.create_color_tool_button_icon( - ':/images/textpointer.png', - QColor(self._text_action.data()))) + ':/images/textpointer.png', QColor(self._text_action.data()))) self.text_button_triggered() @Slot() def item_color_changed(self): self._fill_action = self.sender() self._fill_color_tool_button.setIcon(self.create_color_tool_button_icon( - ':/images/floodfill.png', - QColor(self._fill_action.data()))) + ':/images/floodfill.png', QColor(self._fill_action.data()))) self.fill_button_triggered() @Slot() def line_color_changed(self): self._line_action = self.sender() self._line_color_tool_button.setIcon(self.create_color_tool_button_icon( - ':/images/linecolor.png', - QColor(self._line_action.data()))) + ':/images/linecolor.png', QColor(self._line_action.data()))) self.line_button_triggered() @Slot() @@ -541,7 +536,7 @@ class MainWindow(QMainWindow): @Slot() def about(self): QMessageBox.about(self, "About Diagram Scene", - "The <b>Diagram Scene</b> example shows use of the graphics framework.") + "The <b>Diagram Scene</b> example shows use of the graphics framework.") def create_tool_box(self): self._button_group = QButtonGroup() @@ -549,12 +544,9 @@ class MainWindow(QMainWindow): self._button_group.idClicked.connect(self.button_group_clicked) layout = QGridLayout() - layout.addWidget(self.create_cell_widget("Conditional", DiagramItem.Conditional), - 0, 0) - layout.addWidget(self.create_cell_widget("Process", DiagramItem.Step), 0, - 1) - layout.addWidget(self.create_cell_widget("Input/Output", DiagramItem.Io), - 1, 0) + layout.addWidget(self.create_cell_widget("Conditional", DiagramItem.Conditional), 0, 0) + layout.addWidget(self.create_cell_widget("Process", DiagramItem.Step), 0, 1) + layout.addWidget(self.create_cell_widget("Input/Output", DiagramItem.Io), 1, 0) text_button = QToolButton() text_button.setCheckable(True) @@ -580,14 +572,14 @@ class MainWindow(QMainWindow): self._background_button_group.buttonClicked.connect(self.background_button_group_clicked) background_layout = QGridLayout() - background_layout.addWidget(self.create_background_cell_widget("Blue Grid", - ':/images/background1.png'), 0, 0) - background_layout.addWidget(self.create_background_cell_widget("White Grid", - ':/images/background2.png'), 0, 1) - background_layout.addWidget(self.create_background_cell_widget("Gray Grid", - ':/images/background3.png'), 1, 0) - background_layout.addWidget(self.create_background_cell_widget("No Grid", - ':/images/background4.png'), 1, 1) + background_layout.addWidget( + self.create_background_cell_widget("Blue Grid", ':/images/background1.png'), 0, 0) + background_layout.addWidget( + self.create_background_cell_widget("White Grid", ':/images/background2.png'), 0, 1) + background_layout.addWidget( + self.create_background_cell_widget("Gray Grid", ':/images/background3.png'), 1, 0) + background_layout.addWidget( + self.create_background_cell_widget("No Grid", ':/images/background4.png'), 1, 1) background_layout.setRowStretch(2, 10) background_layout.setColumnStretch(2, 10) @@ -603,38 +595,37 @@ class MainWindow(QMainWindow): def create_actions(self): self._to_front_action = QAction( - QIcon(':/images/bringtofront.png'), "Bring to &Front", - self, shortcut="Ctrl+F", statusTip="Bring item to front", - triggered=self.bring_to_front) + QIcon(':/images/bringtofront.png'), "Bring to &Front", + self, shortcut="Ctrl+F", statusTip="Bring item to front", + triggered=self.bring_to_front) self._send_back_action = QAction( - QIcon(':/images/sendtoback.png'), "Send to &Back", self, - shortcut="Ctrl+B", statusTip="Send item to back", - triggered=self.send_to_back) + QIcon(':/images/sendtoback.png'), "Send to &Back", self, + shortcut="Ctrl+B", statusTip="Send item to back", + triggered=self.send_to_back) self._delete_action = QAction(QIcon(':/images/delete.png'), - "&Delete", self, shortcut="Delete", - statusTip="Delete item from diagram", - triggered=self.delete_item) + "&Delete", self, shortcut="Delete", + statusTip="Delete item from diagram", + triggered=self.delete_item) self._exit_action = QAction("E&xit", self, shortcut="Ctrl+X", - statusTip="Quit Scenediagram example", triggered=self.close) + statusTip="Quit Scenediagram example", triggered=self.close) self._bold_action = QAction(QIcon(':/images/bold.png'), - "Bold", self, checkable=True, shortcut="Ctrl+B", - triggered=self.handle_font_change) + "Bold", self, checkable=True, shortcut="Ctrl+B", + triggered=self.handle_font_change) self._italic_action = QAction(QIcon(':/images/italic.png'), - "Italic", self, checkable=True, shortcut="Ctrl+I", - triggered=self.handle_font_change) + "Italic", self, checkable=True, shortcut="Ctrl+I", + triggered=self.handle_font_change) self._underline_action = QAction( - QIcon(':/images/underline.png'), "Underline", self, - checkable=True, shortcut="Ctrl+U", - triggered=self.handle_font_change) + QIcon(':/images/underline.png'), "Underline", self, + checkable=True, shortcut="Ctrl+U", + triggered=self.handle_font_change) - self._about_action = QAction("A&bout", self, shortcut="Ctrl+B", - triggered=self.about) + self._about_action = QAction("A&bout", self, shortcut="Ctrl+B", triggered=self.about) def create_menus(self): self._file_menu = self.menuBar().addMenu("&File") @@ -669,32 +660,29 @@ class MainWindow(QMainWindow): self._font_color_tool_button = QToolButton() self._font_color_tool_button.setPopupMode(QToolButton.MenuButtonPopup) self._font_color_tool_button.setMenu( - self.create_color_menu(self.text_color_changed, Qt.black)) + self.create_color_menu(self.text_color_changed, Qt.black)) self._text_action = self._font_color_tool_button.menu().defaultAction() self._font_color_tool_button.setIcon( - self.create_color_tool_button_icon(':/images/textpointer.png', - Qt.black)) + self.create_color_tool_button_icon(':/images/textpointer.png', Qt.black)) self._font_color_tool_button.setAutoFillBackground(True) self._font_color_tool_button.clicked.connect(self.text_button_triggered) self._fill_color_tool_button = QToolButton() self._fill_color_tool_button.setPopupMode(QToolButton.MenuButtonPopup) self._fill_color_tool_button.setMenu( - self.create_color_menu(self.item_color_changed, Qt.white)) + self.create_color_menu(self.item_color_changed, Qt.white)) self._fill_action = self._fill_color_tool_button.menu().defaultAction() self._fill_color_tool_button.setIcon( - self.create_color_tool_button_icon(':/images/floodfill.png', - Qt.white)) + self.create_color_tool_button_icon(':/images/floodfill.png', Qt.white)) self._fill_color_tool_button.clicked.connect(self.fill_button_triggered) self._line_color_tool_button = QToolButton() self._line_color_tool_button.setPopupMode(QToolButton.MenuButtonPopup) self._line_color_tool_button.setMenu( - self.create_color_menu(self.line_color_changed, Qt.black)) + self.create_color_menu(self.line_color_changed, Qt.black)) self._line_action = self._line_color_tool_button.menu().defaultAction() self._line_color_tool_button.setIcon( - self.create_color_tool_button_icon(':/images/linecolor.png', - Qt.black)) + self.create_color_tool_button_icon(':/images/linecolor.png', Qt.black)) self._line_color_tool_button.clicked.connect(self.line_button_triggered) self._text_tool_bar = self.addToolBar("Font") @@ -719,8 +707,7 @@ class MainWindow(QMainWindow): self._pointer_type_group = QButtonGroup() self._pointer_type_group.addButton(pointer_button, DiagramScene.MoveItem) - self._pointer_type_group.addButton(line_pointer_button, - DiagramScene.InsertLine) + self._pointer_type_group.addButton(line_pointer_button, DiagramScene.InsertLine) self._pointer_type_group.idClicked.connect(self.pointer_group_clicked) self._scene_scale_combo = QComboBox() @@ -775,8 +762,7 @@ class MainWindow(QMainWindow): color_menu = QMenu(self) for color, name in zip(colors, names): - action = QAction(self.create_color_icon(color), name, self, - triggered=slot) + action = QAction(self.create_color_icon(color), name, self, triggered=slot) action.setData(QColor(color)) color_menu.addAction(action) if color == defaultColor: diff --git a/examples/widgets/graphicsview/dragdroprobot/dragdroprobot.py b/examples/widgets/graphicsview/dragdroprobot/dragdroprobot.py index 5469fc731..1896c5ab4 100644 --- a/examples/widgets/graphicsview/dragdroprobot/dragdroprobot.py +++ b/examples/widgets/graphicsview/dragdroprobot/dragdroprobot.py @@ -103,8 +103,8 @@ class RobotPart(QGraphicsItem): self.setAcceptDrops(True) def dragEnterEvent(self, event): - if (event.mimeData().hasColor() or - (isinstance(self, RobotHead) and event.mimeData().hasImage())): + if (event.mimeData().hasColor() + or (isinstance(self, RobotHead) and event.mimeData().hasImage())): event.setAccepted(True) self._drag_over = True self.update() @@ -131,8 +131,7 @@ class RobotHead(RobotPart): def paint(self, painter, option, widget=None): if not self.pixmap: - painter.setBrush(self._drag_over and self.color.lighter(130) - or self.color) + painter.setBrush(self._drag_over and self.color.lighter(130) or self.color) painter.drawRoundedRect(-10, -30, 20, 30, 25, 25, Qt.RelativeSize) painter.setBrush(Qt.white) painter.drawEllipse(-7, -3 - 20, 7, 7) @@ -177,35 +176,35 @@ class Robot(RobotPart): def __init__(self): super().__init__() - self.torsoItem = RobotTorso(self) - self.headItem = RobotHead(self.torsoItem) - self.upperLeftArmItem = RobotLimb(self.torsoItem) - self.lowerLeftArmItem = RobotLimb(self.upperLeftArmItem) + self.torsoItem = RobotTorso(self) + self.headItem = RobotHead(self.torsoItem) + self.upperLeftArmItem = RobotLimb(self.torsoItem) + self.lowerLeftArmItem = RobotLimb(self.upperLeftArmItem) self._upper_right_arm_item = RobotLimb(self.torsoItem) self._lower_right_arm_item = RobotLimb(self._upper_right_arm_item) self._upper_right_leg_item = RobotLimb(self.torsoItem) self._lower_right_leg_item = RobotLimb(self._upper_right_leg_item) - self.upperLeftLegItem = RobotLimb(self.torsoItem) - self.lowerLeftLegItem = RobotLimb(self.upperLeftLegItem) + self.upperLeftLegItem = RobotLimb(self.torsoItem) + self.lowerLeftLegItem = RobotLimb(self.upperLeftLegItem) self.timeline = QTimeLine() settings = [ - # item position rotation at - # x y time 0 / 1 - ( self.headItem, 0, -18, 20, -20 ), - ( self.upperLeftArmItem, -15, -10, 190, 180 ), - ( self.lowerLeftArmItem, 30, 0, 50, 10 ), - ( self._upper_right_arm_item, 15, -10, 300, 310 ), - ( self._lower_right_arm_item, 30, 0, 0, -70 ), - ( self._upper_right_leg_item, 10, 32, 40, 120 ), - ( self._lower_right_leg_item, 30, 0, 10, 50 ), - ( self.upperLeftLegItem, -10, 32, 150, 80 ), - ( self.lowerLeftLegItem, 30, 0, 70, 10 ), - ( self.torsoItem, 0, 0, 5, -20 ) + # item position rotation at + # x y time 0 / 1 + (self.headItem, 0, -18, 20, -20), # noqa: E241 + (self.upperLeftArmItem, -15, -10, 190, 180), # noqa: E241 + (self.lowerLeftArmItem, 30, 0, 50, 10), # noqa: E241 + (self._upper_right_arm_item, 15, -10, 300, 310), # noqa: E241 + (self._lower_right_arm_item, 30, 0, 0, -70), # noqa: E241 + (self._upper_right_leg_item, 10, 32, 40, 120), # noqa: E241 + (self._lower_right_leg_item, 30, 0, 10, 50), # noqa: E241 + (self.upperLeftLegItem, -10, 32, 150, 80), # noqa: E241 + (self.lowerLeftLegItem, 30, 0, 70, 10), # noqa: E241 + (self.torsoItem, 0, 0, 5, -20) # noqa: E241 ] self.animations = [] for item, pos_x, pos_y, rotation1, rotation2 in settings: - item.setPos(pos_x,pos_y) + item.setPos(pos_x, pos_y) animation = QGraphicsItemAnimation() animation.setItem(item) animation.setTimeLine(self.timeline) @@ -228,7 +227,7 @@ class Robot(RobotPart): pass -if __name__== '__main__': +if __name__ == '__main__': app = QApplication(sys.argv) scene = QGraphicsScene(-200, -200, 400, 400) diff --git a/examples/widgets/graphicsview/elasticnodes/elasticnodes.py b/examples/widgets/graphicsview/elasticnodes/elasticnodes.py index d77a35796..2e0581ff3 100644 --- a/examples/widgets/graphicsview/elasticnodes/elasticnodes.py +++ b/examples/widgets/graphicsview/elasticnodes/elasticnodes.py @@ -157,7 +157,7 @@ class Node(QGraphicsItem): line = QLineF(self.mapFromItem(item, 0, 0), QPointF(0, 0)) dx = line.dx() dy = line.dy() - l = 2.0 * (dx * dx + dy * dy) + l = 2.0 * (dx * dx + dy * dy) # noqa: E741 if l > 0: xvel += (dx * 150.0) / l yvel += (dy * 150.0) / l @@ -348,9 +348,9 @@ class GraphWidget(QGraphicsView): bottom_shadow = QRectF(scene_rect.left() + 5, scene_rect.bottom(), scene_rect.width(), 5) if right_shadow.intersects(rect) or right_shadow.contains(rect): - painter.fillRect(right_shadow, Qt.darkGray) + painter.fillRect(right_shadow, Qt.darkGray) if bottom_shadow.intersects(rect) or bottom_shadow.contains(rect): - painter.fillRect(bottom_shadow, Qt.darkGray) + painter.fillRect(bottom_shadow, Qt.darkGray) # Fill. gradient = QLinearGradient(scene_rect.topLeft(), scene_rect.bottomRight()) diff --git a/examples/widgets/itemviews/address_book/adddialogwidget.py b/examples/widgets/itemviews/address_book/adddialogwidget.py index 276a8d2b4..ecb853e80 100644 --- a/examples/widgets/itemviews/address_book/adddialogwidget.py +++ b/examples/widgets/itemviews/address_book/adddialogwidget.py @@ -15,8 +15,8 @@ class AddDialogWidget(QDialog): name_label = QLabel("Name") address_label = QLabel("Address") - button_box = QDialogButtonBox(QDialogButtonBox.Ok | - QDialogButtonBox.Cancel) + button_box = QDialogButtonBox(QDialogButtonBox.Ok + | QDialogButtonBox.Cancel) self._name_text = QLineEdit() self._address_text = QTextEdit() diff --git a/examples/widgets/itemviews/address_book/address_book.py b/examples/widgets/itemviews/address_book/address_book.py index 2e1f6b9b0..95f187559 100644 --- a/examples/widgets/itemviews/address_book/address_book.py +++ b/examples/widgets/itemviews/address_book/address_book.py @@ -31,10 +31,13 @@ class MainWindow(QMainWindow): exit_action = self.create_action("E&xit", file_menu, self.close) # Populate the Tools menu - add_action = self.create_action("&Add Entry...", tool_menu, self._address_widget.add_entry) - self._edit_action = self.create_action("&Edit Entry...", tool_menu, self._address_widget.edit_entry) + add_action = self.create_action( + "&Add Entry...", tool_menu, self._address_widget.add_entry) + self._edit_action = self.create_action( + "&Edit Entry...", tool_menu, self._address_widget.edit_entry) tool_menu.addSeparator() - self._remove_action = self.create_action("&Remove Entry", tool_menu, self._address_widget.remove_entry) + self._remove_action = self.create_action( + "&Remove Entry", tool_menu, self._address_widget.remove_entry) # Disable the edit and remove menu items initially, as there are # no items yet. diff --git a/examples/widgets/itemviews/address_book/addresswidget.py b/examples/widgets/itemviews/address_book/addresswidget.py index ab1330e48..cb2f46ea1 100644 --- a/examples/widgets/itemviews/address_book/addresswidget.py +++ b/examples/widgets/itemviews/address_book/addresswidget.py @@ -166,8 +166,9 @@ class AddressWidget(QTabWidget): proxy_model.setFilterKeyColumn(0) # Filter on the "name" column proxy_model.sort(0, Qt.AscendingOrder) - # This prevents an application crash (see: https://www.qtcentre.org/threads/58874-QListView-SelectionModel-selectionChanged-Crash) - viewselectionmodel = table_view.selectionModel() + # This prevents an application crash (see: + # https://www.qtcentre.org/threads/58874-QListView-SelectionModel-selectionChanged-Crash) # noqa: E501 + self.viewselectionmodel = table_view.selectionModel() table_view.selectionModel().selectionChanged.connect(self.selection_changed) self.addTab(table_view, group) diff --git a/examples/widgets/itemviews/address_book/tablemodel.py b/examples/widgets/itemviews/address_book/tablemodel.py index a0d63bbe2..3c1dbd4cc 100644 --- a/examples/widgets/itemviews/address_book/tablemodel.py +++ b/examples/widgets/itemviews/address_book/tablemodel.py @@ -105,5 +105,5 @@ class TableModel(QAbstractTableModel): """ if not index.isValid(): return Qt.ItemIsEnabled - return Qt.ItemFlags(QAbstractTableModel.flags(self, index) | - Qt.ItemIsEditable) + return Qt.ItemFlags(QAbstractTableModel.flags(self, index) + | Qt.ItemIsEditable) diff --git a/examples/widgets/itemviews/basicfiltermodel/basicsortfiltermodel.py b/examples/widgets/itemviews/basicfiltermodel/basicsortfiltermodel.py index 0071d60f3..a30b0abdf 100644 --- a/examples/widgets/itemviews/basicfiltermodel/basicsortfiltermodel.py +++ b/examples/widgets/itemviews/basicfiltermodel/basicsortfiltermodel.py @@ -147,25 +147,25 @@ def create_mail_model(parent): model.setHeaderData(2, Qt.Horizontal, "Date") add_mail(model, "Happy New Year!", "Grace K. <[email protected]>", - QDateTime(QDate(2006, 12, 31), QTime(17, 3))) + QDateTime(QDate(2006, 12, 31), QTime(17, 3))) add_mail(model, "Radically new concept", "Grace K. <[email protected]>", - QDateTime(QDate(2006, 12, 22), QTime(9, 44))) + QDateTime(QDate(2006, 12, 22), QTime(9, 44))) add_mail(model, "Accounts", "[email protected]", - QDateTime(QDate(2006, 12, 31), QTime(12, 50))) + QDateTime(QDate(2006, 12, 31), QTime(12, 50))) add_mail(model, "Expenses", "Joe Bloggs <[email protected]>", - QDateTime(QDate(2006, 12, 25), QTime(11, 39))) + QDateTime(QDate(2006, 12, 25), QTime(11, 39))) add_mail(model, "Re: Expenses", "Andy <[email protected]>", - QDateTime(QDate(2007, 1, 2), QTime(16, 5))) + QDateTime(QDate(2007, 1, 2), QTime(16, 5))) add_mail(model, "Re: Accounts", "Joe Bloggs <[email protected]>", - QDateTime(QDate(2007, 1, 3), QTime(14, 18))) + QDateTime(QDate(2007, 1, 3), QTime(14, 18))) add_mail(model, "Re: Accounts", "Andy <[email protected]>", - QDateTime(QDate(2007, 1, 3), QTime(14, 26))) + QDateTime(QDate(2007, 1, 3), QTime(14, 26))) add_mail(model, "Sports", "Linda Smith <[email protected]>", - QDateTime(QDate(2007, 1, 5), QTime(11, 33))) + QDateTime(QDate(2007, 1, 5), QTime(11, 33))) add_mail(model, "AW: Sports", "Rolf Newschweinstein <[email protected]>", - QDateTime(QDate(2007, 1, 5), QTime(12, 0))) + QDateTime(QDate(2007, 1, 5), QTime(12, 0))) add_mail(model, "RE: Sports", "Petra Schmidt <[email protected]>", - QDateTime(QDate(2007, 1, 5), QTime(12, 1))) + QDateTime(QDate(2007, 1, 5), QTime(12, 1))) return model diff --git a/examples/widgets/itemviews/dirview/dirview.py b/examples/widgets/itemviews/dirview/dirview.py index aa1e62185..d1be6958e 100644 --- a/examples/widgets/itemviews/dirview/dirview.py +++ b/examples/widgets/itemviews/dirview/dirview.py @@ -57,4 +57,3 @@ if __name__ == "__main__": tree.show() sys.exit(app.exec()) - diff --git a/examples/widgets/itemviews/stardelegate/stardelegate.py b/examples/widgets/itemviews/stardelegate/stardelegate.py index ceb7a83b4..973eb14f6 100644 --- a/examples/widgets/itemviews/stardelegate/stardelegate.py +++ b/examples/widgets/itemviews/stardelegate/stardelegate.py @@ -111,15 +111,15 @@ if __name__ == "__main__": # Create and populate the tableWidget table_widget = QTableWidget(4, 4) table_widget.setItemDelegate(StarDelegate()) - table_widget.setEditTriggers(QAbstractItemView.DoubleClicked | - QAbstractItemView.SelectedClicked) + table_widget.setEditTriggers(QAbstractItemView.DoubleClicked + | QAbstractItemView.SelectedClicked) table_widget.setSelectionBehavior(QAbstractItemView.SelectRows) table_widget.setHorizontalHeaderLabels(["Title", "Genre", "Artist", "Rating"]) - data = [ ["Mass in B-Minor", "Baroque", "J.S. Bach", 5], - ["Three More Foxes", "Jazz", "Maynard Ferguson", 4], - ["Sex Bomb", "Pop", "Tom Jones", 3], - ["Barbie Girl", "Pop", "Aqua", 5] ] + data = [["Mass in B-Minor", "Baroque", "J.S. Bach", 5], + ["Three More Foxes", "Jazz", "Maynard Ferguson", 4], + ["Sex Bomb", "Pop", "Tom Jones", 3], + ["Barbie Girl", "Pop", "Aqua", 5]] for r in range(len(data)): table_widget.setItem(r, 0, QTableWidgetItem(data[r][0])) diff --git a/examples/widgets/itemviews/stardelegate/stareditor.py b/examples/widgets/itemviews/stardelegate/stareditor.py index 1b44164a8..296afa950 100644 --- a/examples/widgets/itemviews/stardelegate/stareditor.py +++ b/examples/widgets/itemviews/stardelegate/stareditor.py @@ -55,8 +55,7 @@ class StarEditor(QWidget): """ Calculate which star the user's mouse cursor is currently hovering over. """ - star = (x / (self.star_rating.sizeHint().width() / - self.star_rating.MAX_STAR_COUNT)) + 1 + star = (x / (self.star_rating.sizeHint().width() / self.star_rating.MAX_STAR_COUNT)) + 1 if (star <= 0) or (star > self.star_rating.MAX_STAR_COUNT): return -1 diff --git a/examples/widgets/layouts/basiclayouts/basiclayouts.py b/examples/widgets/layouts/basiclayouts/basiclayouts.py index a2d29e71f..827cb7850 100644 --- a/examples/widgets/layouts/basiclayouts/basiclayouts.py +++ b/examples/widgets/layouts/basiclayouts/basiclayouts.py @@ -27,7 +27,7 @@ class Dialog(QDialog): big_editor = QTextEdit() big_editor.setPlainText("This widget takes up all the remaining space " - "in the top-level layout.") + "in the top-level layout.") button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) @@ -75,8 +75,7 @@ class Dialog(QDialog): layout.addWidget(line_edit, i + 1, 1) self._small_editor = QTextEdit() - self._small_editor.setPlainText("This widget takes up about two thirds " - "of the grid layout.") + self._small_editor.setPlainText("This widget takes up about two thirds of the grid layout.") layout.addWidget(self._small_editor, 0, 2, 4, 1) diff --git a/examples/widgets/layouts/dynamiclayouts/dynamiclayouts.py b/examples/widgets/layouts/dynamiclayouts/dynamiclayouts.py index 09f01c8cc..c9dfcc730 100644 --- a/examples/widgets/layouts/dynamiclayouts/dynamiclayouts.py +++ b/examples/widgets/layouts/dynamiclayouts/dynamiclayouts.py @@ -102,7 +102,8 @@ class Dialog(QDialog): buttons_orientation_combo_box = QComboBox() buttons_orientation_combo_box.addItem("Horizontal", Qt.Horizontal) buttons_orientation_combo_box.addItem("Vertical", Qt.Vertical) - buttons_orientation_combo_box.currentIndexChanged[int].connect(self.buttons_orientation_changed) + buttons_orientation_combo_box.currentIndexChanged[int].connect( + self.buttons_orientation_changed) self._buttons_orientation_combo_box = buttons_orientation_combo_box @@ -117,7 +118,8 @@ class Dialog(QDialog): close_button = self._button_box.addButton(QDialogButtonBox.Close) help_button = self._button_box.addButton(QDialogButtonBox.Help) - rotate_widgets_button = self._button_box.addButton("Rotate &Widgets", QDialogButtonBox.ActionRole) + rotate_widgets_button = self._button_box.addButton( + "Rotate &Widgets", QDialogButtonBox.ActionRole) rotate_widgets_button.clicked.connect(self.rotate_widgets) close_button.clicked.connect(self.close) diff --git a/examples/widgets/mainwindows/application/application.py b/examples/widgets/mainwindows/application/application.py index 320c421a6..a531c9bfb 100644 --- a/examples/widgets/mainwindows/application/application.py +++ b/examples/widgets/mainwindows/application/application.py @@ -73,9 +73,9 @@ class MainWindow(QMainWindow): @Slot() def about(self): QMessageBox.about(self, "About Application", - "The <b>Application</b> example demonstrates how to write " - "modern GUI applications using Qt, with a menu bar, " - "toolbars, and a status bar.") + "The <b>Application</b> example demonstrates how to write " + "modern GUI applications using Qt, with a menu bar, " + "toolbars, and a status bar.") @Slot() def document_was_modified(self): @@ -84,50 +84,51 @@ class MainWindow(QMainWindow): def create_actions(self): icon = QIcon.fromTheme("document-new", QIcon(':/images/new.png')) self._new_act = QAction(icon, "&New", self, shortcut=QKeySequence.New, - statusTip="Create a new file", triggered=self.new_file) + statusTip="Create a new file", triggered=self.new_file) icon = QIcon.fromTheme("document-open", QIcon(':/images/open.png')) self._open_act = QAction(icon, "&Open...", self, - shortcut=QKeySequence.Open, statusTip="Open an existing file", - triggered=self.open) + shortcut=QKeySequence.Open, statusTip="Open an existing file", + triggered=self.open) icon = QIcon.fromTheme("document-save", QIcon(':/images/save.png')) self._save_act = QAction(icon, "&Save", self, - shortcut=QKeySequence.Save, - statusTip="Save the document to disk", triggered=self.save) + shortcut=QKeySequence.Save, + statusTip="Save the document to disk", triggered=self.save) self._save_as_act = QAction("Save &As...", self, - shortcut=QKeySequence.SaveAs, - statusTip="Save the document under a new name", - triggered=self.save_as) + shortcut=QKeySequence.SaveAs, + statusTip="Save the document under a new name", + triggered=self.save_as) self._exit_act = QAction("E&xit", self, shortcut="Ctrl+Q", - statusTip="Exit the application", triggered=self.close) + statusTip="Exit the application", triggered=self.close) icon = QIcon.fromTheme("edit-cut", QIcon(':/images/cut.png')) self._cut_act = QAction(icon, "Cu&t", self, shortcut=QKeySequence.Cut, - statusTip="Cut the current selection's contents to the clipboard", - triggered=self._text_edit.cut) + statusTip="Cut the current selection's contents to the clipboard", + triggered=self._text_edit.cut) icon = QIcon.fromTheme("edit-copy", QIcon(':/images/copy.png')) self._copy_act = QAction(icon, "&Copy", - self, shortcut=QKeySequence.Copy, - statusTip="Copy the current selection's contents to the clipboard", - triggered=self._text_edit.copy) + self, shortcut=QKeySequence.Copy, + statusTip="Copy the current selection's contents to the clipboard", + triggered=self._text_edit.copy) icon = QIcon.fromTheme("edit-paste", QIcon(':/images/paste.png')) self._paste_act = QAction(icon, "&Paste", - self, shortcut=QKeySequence.Paste, - statusTip="Paste the clipboard's contents into the current selection", - triggered=self._text_edit.paste) + self, shortcut=QKeySequence.Paste, + statusTip="Paste the clipboard's contents into the current " + "selection", + triggered=self._text_edit.paste) self._about_act = QAction("&About", self, - statusTip="Show the application's About box", - triggered=self.about) + statusTip="Show the application's About box", + triggered=self.about) self._about_qt_act = QAction("About &Qt", self, - statusTip="Show the Qt library's About box", - triggered=qApp.aboutQt) + statusTip="Show the Qt library's About box", + triggered=qApp.aboutQt) self._cut_act.setEnabled(False) self._copy_act.setEnabled(False) @@ -181,10 +182,9 @@ class MainWindow(QMainWindow): def maybe_save(self): if self._text_edit.document().isModified(): ret = QMessageBox.warning(self, "Application", - "The document has been modified.\nDo you want to save " - "your changes?", - QMessageBox.Save | QMessageBox.Discard | - QMessageBox.Cancel) + "The document has been modified.\nDo you want to save " + "your changes?", + QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel) if ret == QMessageBox.Save: return self.save() elif ret == QMessageBox.Cancel: @@ -195,8 +195,7 @@ class MainWindow(QMainWindow): file = QFile(fileName) if not file.open(QFile.ReadOnly | QFile.Text): reason = file.errorString() - QMessageBox.warning(self, "Application", - f"Cannot read file {fileName}:\n{reason}.") + QMessageBox.warning(self, "Application", f"Cannot read file {fileName}:\n{reason}.") return inf = QTextStream(file) diff --git a/examples/widgets/mainwindows/dockwidgets/dockwidgets.py b/examples/widgets/mainwindows/dockwidgets/dockwidgets.py index 9b57b264b..b63edd948 100644 --- a/examples/widgets/mainwindows/dockwidgets/dockwidgets.py +++ b/examples/widgets/mainwindows/dockwidgets/dockwidgets.py @@ -2,7 +2,8 @@ # Copyright (C) 2022 The Qt Company Ltd. # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -"""PySide6 port of the widgets/mainwindows/dockwidgets example from Qt v5.x, originating from PyQt""" +"""PySide6 port of the widgets/mainwindows/dockwidgets example from Qt v5.x, + originating from PyQt""" import sys @@ -63,8 +64,7 @@ class MainWindow(QMainWindow): cursor.insertBlock() cursor.insertText("Some Country") cursor.setPosition(top_frame.lastPosition()) - cursor.insertText(QDate.currentDate().toString("d MMMM yyyy"), - text_format) + cursor.insertText(QDate.currentDate().toString("d MMMM yyyy"), text_format) cursor.insertBlock() cursor.insertBlock() cursor.insertText("Dear ", text_format) @@ -104,7 +104,7 @@ class MainWindow(QMainWindow): if not file.open(QFile.WriteOnly | QFile.Text): reason = file.errorString() QMessageBox.warning(self, "Dock Widgets", - f"Cannot write file {filename}:\n{reason}.") + f"Cannot write file {filename}:\n{reason}.") return out = QTextStream(file) @@ -153,43 +153,44 @@ class MainWindow(QMainWindow): def about(self): QMessageBox.about(self, "About Dock Widgets", - "The <b>Dock Widgets</b> example demonstrates how to use " - "Qt's dock widgets. You can enter your own text, click a " - "customer to add a customer name and address, and click " - "standard paragraphs to add them.") + "The <b>Dock Widgets</b> example demonstrates how to use " + "Qt's dock widgets. You can enter your own text, click a " + "customer to add a customer name and address, and click " + "standard paragraphs to add them.") def create_actions(self): icon = QIcon.fromTheme('document-new', QIcon(':/images/new.png')) self._new_letter_act = QAction(icon, "&New Letter", - self, shortcut=QKeySequence.New, - statusTip="Create a new form letter", triggered=self.new_letter) + self, shortcut=QKeySequence.New, + statusTip="Create a new form letter", + triggered=self.new_letter) icon = QIcon.fromTheme('document-save', QIcon(':/images/save.png')) self._save_act = QAction(icon, "&Save...", self, - shortcut=QKeySequence.Save, - statusTip="Save the current form letter", triggered=self.save) + shortcut=QKeySequence.Save, + statusTip="Save the current form letter", triggered=self.save) icon = QIcon.fromTheme('document-print', QIcon(':/images/print.png')) self._print_act = QAction(icon, "&Print...", self, - shortcut=QKeySequence.Print, - statusTip="Print the current form letter", - triggered=self.print_) + shortcut=QKeySequence.Print, + statusTip="Print the current form letter", + triggered=self.print_) icon = QIcon.fromTheme('edit-undo', QIcon(':/images/undo.png')) self._undo_act = QAction(icon, "&Undo", self, - shortcut=QKeySequence.Undo, - statusTip="Undo the last editing action", triggered=self.undo) + shortcut=QKeySequence.Undo, + statusTip="Undo the last editing action", triggered=self.undo) self._quit_act = QAction("&Quit", self, shortcut="Ctrl+Q", - statusTip="Quit the application", triggered=self.close) + statusTip="Quit the application", triggered=self.close) self._about_act = QAction("&About", self, - statusTip="Show the application's About box", - triggered=self.about) + statusTip="Show the application's About box", + triggered=self.about) self._about_qt_act = QAction("About &Qt", self, - statusTip="Show the Qt library's About box", - triggered=QApplication.instance().aboutQt) + statusTip="Show the Qt library's About box", + triggered=QApplication.instance().aboutQt) def create_menus(self): self._file_menu = self.menuBar().addMenu("&File") @@ -242,21 +243,21 @@ class MainWindow(QMainWindow): self._paragraphs_list.addItems(( "Thank you for your payment which we have received today.", "Your order has been dispatched and should be with you within " - "28 days.", + "28 days.", "We have dispatched those items that were in stock. The rest of " - "your order will be dispatched once all the remaining items " - "have arrived at our warehouse. No additional shipping " - "charges will be made.", + "your order will be dispatched once all the remaining items " + "have arrived at our warehouse. No additional shipping " + "charges will be made.", "You made a small overpayment (less than $5) which we will keep " - "on account for you, or return at your request.", + "on account for you, or return at your request.", "You made a small underpayment (less than $1), but we have sent " - "your order anyway. We'll add this underpayment to your next " - "bill.", + "your order anyway. We'll add this underpayment to your next " + "bill.", "Unfortunately you did not send enough money. Please remit an " - "additional $. Your order will be dispatched as soon as the " - "complete amount has been received.", + "additional $. Your order will be dispatched as soon as the " + "complete amount has been received.", "You made an overpayment (more than $5). Do you wish to buy more " - "items, or should we return the excess to you?")) + "items, or should we return the excess to you?")) dock.setWidget(self._paragraphs_list) self.addDockWidget(Qt.RightDockWidgetArea, dock) self._view_menu.addAction(dock.toggleViewAction()) diff --git a/examples/widgets/mainwindows/mdi/mdi.py b/examples/widgets/mainwindows/mdi/mdi.py index f55cfe17a..9649f7dac 100644 --- a/examples/widgets/mainwindows/mdi/mdi.py +++ b/examples/widgets/mainwindows/mdi/mdi.py @@ -9,10 +9,10 @@ from functools import partial import sys from PySide6.QtCore import (QByteArray, QFile, QFileInfo, QSettings, - QSaveFile, QTextStream, Qt, Slot) + QSaveFile, QTextStream, Qt, Slot) from PySide6.QtGui import QAction, QIcon, QKeySequence from PySide6.QtWidgets import (QApplication, QFileDialog, QMainWindow, - QMdiArea, QMessageBox, QTextEdit) + QMdiArea, QMessageBox, QTextEdit) import PySide6.QtExampleIcons @@ -106,7 +106,7 @@ class MdiChild(QTextEdit): f = self.user_friendly_current_file() message = f"'{f}' has been modified.\nDo you want to save your changes?" ret = QMessageBox.warning(self, "MDI", message, - QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel) + QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel) if ret == QMessageBox.Save: return self.save() @@ -208,8 +208,8 @@ class MainWindow(QMainWindow): @Slot() def about(self): QMessageBox.about(self, "About MDI", - "The <b>MDI</b> example demonstrates how to write multiple " - "document interface applications using Qt.") + "The <b>MDI</b> example demonstrates how to write multiple " + "document interface applications using Qt.") @Slot() def update_menus(self): @@ -225,8 +225,8 @@ class MainWindow(QMainWindow): self._previous_act.setEnabled(has_mdi_child) self._separator_act.setVisible(has_mdi_child) - has_selection = (self.active_mdi_child() is not None and - self.active_mdi_child().textCursor().hasSelection()) + has_selection = (self.active_mdi_child() is not None + and self.active_mdi_child().textCursor().hasSelection()) self._cut_act.setEnabled(has_selection) self._copy_act.setEnabled(has_selection) @@ -273,80 +273,81 @@ class MainWindow(QMainWindow): icon = QIcon.fromTheme("document-new") self._new_act = QAction(icon, "&New", self, - shortcut=QKeySequence.New, statusTip="Create a new file", - triggered=self.new_file) + shortcut=QKeySequence.New, statusTip="Create a new file", + triggered=self.new_file) icon = QIcon.fromTheme("document-open") self._open_act = QAction(icon, "&Open...", self, - shortcut=QKeySequence.Open, statusTip="Open an existing file", - triggered=self.open) + shortcut=QKeySequence.Open, statusTip="Open an existing file", + triggered=self.open) icon = QIcon.fromTheme("document-save") self._save_act = QAction(icon, "&Save", self, - shortcut=QKeySequence.Save, - statusTip="Save the document to disk", triggered=self.save) + shortcut=QKeySequence.Save, + statusTip="Save the document to disk", triggered=self.save) self._save_as_act = QAction("Save &As...", self, - shortcut=QKeySequence.SaveAs, - statusTip="Save the document under a new name", - triggered=self.save_as) + shortcut=QKeySequence.SaveAs, + statusTip="Save the document under a new name", + triggered=self.save_as) self._exit_act = QAction("E&xit", self, shortcut=QKeySequence.Quit, - statusTip="Exit the application", - triggered=QApplication.instance().closeAllWindows) + statusTip="Exit the application", + triggered=QApplication.instance().closeAllWindows) icon = QIcon.fromTheme("edit-cut") self._cut_act = QAction(icon, "Cu&t", self, - shortcut=QKeySequence.Cut, - statusTip="Cut the current selection's contents to the clipboard", - triggered=self.cut) + shortcut=QKeySequence.Cut, + statusTip="Cut the current selection's contents to the clipboard", + triggered=self.cut) icon = QIcon.fromTheme("edit-copy") self._copy_act = QAction(icon, "&Copy", self, - shortcut=QKeySequence.Copy, - statusTip="Copy the current selection's contents to the clipboard", - triggered=self.copy) + shortcut=QKeySequence.Copy, + statusTip="Copy the current selection's contents to the clipboard", + triggered=self.copy) icon = QIcon.fromTheme("edit-paste") self._paste_act = QAction(icon, "&Paste", self, - shortcut=QKeySequence.Paste, - statusTip="Paste the clipboard's contents into the current selection", - triggered=self.paste) + shortcut=QKeySequence.Paste, + statusTip="Paste the clipboard's contents into the current " + "selection", + triggered=self.paste) self._close_act = QAction("Cl&ose", self, - statusTip="Close the active window", - triggered=self._mdi_area.closeActiveSubWindow) + statusTip="Close the active window", + triggered=self._mdi_area.closeActiveSubWindow) self._close_all_act = QAction("Close &All", self, - statusTip="Close all the windows", - triggered=self._mdi_area.closeAllSubWindows) + statusTip="Close all the windows", + triggered=self._mdi_area.closeAllSubWindows) self._tile_act = QAction("&Tile", self, statusTip="Tile the windows", - triggered=self._mdi_area.tileSubWindows) + triggered=self._mdi_area.tileSubWindows) self._cascade_act = QAction("&Cascade", self, - statusTip="Cascade the windows", - triggered=self._mdi_area.cascadeSubWindows) + statusTip="Cascade the windows", + triggered=self._mdi_area.cascadeSubWindows) self._next_act = QAction("Ne&xt", self, shortcut=QKeySequence.NextChild, - statusTip="Move the focus to the next window", - triggered=self._mdi_area.activateNextSubWindow) + statusTip="Move the focus to the next window", + triggered=self._mdi_area.activateNextSubWindow) self._previous_act = QAction("Pre&vious", self, - shortcut=QKeySequence.PreviousChild, - statusTip="Move the focus to the previous window", - triggered=self._mdi_area.activatePreviousSubWindow) + shortcut=QKeySequence.PreviousChild, + statusTip="Move the focus to the previous window", + triggered=self._mdi_area.activatePreviousSubWindow) self._separator_act = QAction(self) self._separator_act.setSeparator(True) self._about_act = QAction("&About", self, - statusTip="Show the application's About box", - triggered=self.about) + statusTip="Show the application's About box", + triggered=self.about) self._about_qt_act = QAction("About &Qt", self, - statusTip="Show the Qt library's About box", - triggered=QApplication.instance().aboutQt) + statusTip="Show the Qt library's About box", + triggered=QApplication.instance().aboutQt) def create_menus(self): self._file_menu = self.menuBar().addMenu("&File") diff --git a/examples/widgets/painting/basicdrawing/basicdrawing.py b/examples/widgets/painting/basicdrawing/basicdrawing.py index 2af70a543..30582f9aa 100644 --- a/examples/widgets/painting/basicdrawing/basicdrawing.py +++ b/examples/widgets/painting/basicdrawing/basicdrawing.py @@ -191,12 +191,9 @@ class Window(QWidget): pen_join_label.setBuddy(self._pen_join_combo_box) self._brush_style_combo_box = QComboBox() - self._brush_style_combo_box.addItem("Linear Gradient", - Qt.LinearGradientPattern) - self._brush_style_combo_box.addItem("Radial Gradient", - Qt.RadialGradientPattern) - self._brush_style_combo_box.addItem("Conical Gradient", - Qt.ConicalGradientPattern) + self._brush_style_combo_box.addItem("Linear Gradient", Qt.LinearGradientPattern) + self._brush_style_combo_box.addItem("Radial Gradient", Qt.RadialGradientPattern) + self._brush_style_combo_box.addItem("Conical Gradient", Qt.ConicalGradientPattern) self._brush_style_combo_box.addItem("Texture", Qt.TexturePattern) self._brush_style_combo_box.addItem("Solid", Qt.SolidPattern) self._brush_style_combo_box.addItem("Horizontal", Qt.HorPattern) @@ -261,24 +258,23 @@ class Window(QWidget): self.setWindowTitle("Basic Drawing") def shape_changed(self): - shape = self._shape_combo_box.itemData(self._shape_combo_box.currentIndex(), - id_role) + shape = self._shape_combo_box.itemData(self._shape_combo_box.currentIndex(), id_role) self._render_area.set_shape(shape) def pen_changed(self): width = self._pen_width_spin_box.value() style = Qt.PenStyle(self._pen_style_combo_box.itemData( - self._pen_style_combo_box.currentIndex(), id_role)) + self._pen_style_combo_box.currentIndex(), id_role)) cap = Qt.PenCapStyle(self._pen_cap_combo_box.itemData( - self._pen_cap_combo_box.currentIndex(), id_role)) + self._pen_cap_combo_box.currentIndex(), id_role)) join = Qt.PenJoinStyle(self._pen_join_combo_box.itemData( - self._pen_join_combo_box.currentIndex(), id_role)) + self._pen_join_combo_box.currentIndex(), id_role)) self._render_area.set_pen(QPen(Qt.blue, width, style, cap, join)) def brush_changed(self): style = Qt.BrushStyle(self._brush_style_combo_box.itemData( - self._brush_style_combo_box.currentIndex(), id_role)) + self._brush_style_combo_box.currentIndex(), id_role)) if style == Qt.LinearGradientPattern: linear_gradient = QLinearGradient(0, 0, 100, 100) diff --git a/examples/widgets/painting/concentriccircles/concentriccircles.py b/examples/widgets/painting/concentriccircles/concentriccircles.py index 7b2820575..d2c60178f 100644 --- a/examples/widgets/painting/concentriccircles/concentriccircles.py +++ b/examples/widgets/painting/concentriccircles/concentriccircles.py @@ -2,7 +2,8 @@ # Copyright (C) 2022 The Qt Company Ltd. # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -"""PySide6 port of the widgets/painting/concentriccircles example from Qt v5.x, originating from PyQt""" +"""PySide6 port of the widgets/painting/concentriccircles example from Qt v5.x, originating + from PyQt""" from PySide6.QtCore import QRect, QRectF, QSize, Qt, QTimer from PySide6.QtGui import QColor, QPainter, QPalette, QPen @@ -52,10 +53,10 @@ class CircleWidget(QWidget): if self._float_based: painter.drawEllipse(QRectF(-diameter / 2.0, - -diameter / 2.0, diameter, diameter)) + -diameter / 2.0, diameter, diameter)) else: painter.drawEllipse(QRect(-diameter / 2, - -diameter / 2, diameter, diameter)) + -diameter / 2, diameter, diameter)) class Window(QWidget): diff --git a/examples/widgets/richtext/orderform/orderform.py b/examples/widgets/richtext/orderform/orderform.py index dea856a72..9725624c3 100644 --- a/examples/widgets/richtext/orderform/orderform.py +++ b/examples/widgets/richtext/orderform/orderform.py @@ -89,8 +89,7 @@ class MainWindow(QMainWindow): body_frame_format.setWidth(QTextLength(QTextLength.PercentageLength, 100)) cursor.insertFrame(body_frame_format) - cursor.insertText("I would like to place an order for the following " - "items:", text_format) + cursor.insertText("I would like to place an order for the following items:", text_format) cursor.insertBlock() cursor.insertBlock() @@ -121,17 +120,17 @@ class MainWindow(QMainWindow): cursor.insertBlock() cursor.insertText("Please update my records to take account of the " - "following privacy information:") + "following privacy information:") cursor.insertBlock() offers_table = cursor.insertTable(2, 2) cursor = offers_table.cellAt(0, 1).firstCursorPosition() cursor.insertText("I want to receive more information about your " - "company's products and special offers.", text_format) + "company's products and special offers.", text_format) cursor = offers_table.cellAt(1, 1).firstCursorPosition() cursor.insertText("I do not want to receive any promotional " - "information from your company.", text_format) + "information from your company.", text_format) if sendOffers: cursor = offers_table.cellAt(0, 0).firstCursorPosition() @@ -193,8 +192,7 @@ class DetailsDialog(QDialog): self._name_edit = QLineEdit() self._address_edit = QTextEdit() - self._offers_check_box = QCheckBox("Send information about " - "products and special offers:") + self._offers_check_box = QCheckBox("Send information about products and special offers:") self.setup_items_table() @@ -250,9 +248,9 @@ class DetailsDialog(QDialog): return answer = QMessageBox.warning(self, "Incomplete Form", - "The form does not contain all the necessary information.\n" - "Do you want to discard it?", - QMessageBox.Yes, QMessageBox.No) + "The form does not contain all the necessary information.\n" + "Do you want to discard it?", + QMessageBox.Yes, QMessageBox.No) if answer == QMessageBox.Yes: self.reject() diff --git a/examples/widgets/richtext/textedit/textedit.py b/examples/widgets/richtext/textedit/textedit.py index 4f4146d34..0f7cfdbb7 100644 --- a/examples/widgets/richtext/textedit/textedit.py +++ b/examples/widgets/richtext/textedit/textedit.py @@ -621,7 +621,7 @@ class TextEdit(QMainWindow): above = QTextCursor(cursor) above.movePosition(QTextCursor.Up) if (above.currentList() - and list_fmt.indent() + amount == above.currentList().format().indent()): + and list_fmt.indent() + amount == above.currentList().format().indent()): above.currentList().add(cursor.block()) else: list_fmt.setIndent(list_fmt.indent() + amount) diff --git a/examples/widgets/tools/regularexpression/regularexpressiondialog.py b/examples/widgets/tools/regularexpression/regularexpressiondialog.py index ab48fa517..2d2bb2bb7 100644 --- a/examples/widgets/tools/regularexpression/regularexpressiondialog.py +++ b/examples/widgets/tools/regularexpression/regularexpressiondialog.py @@ -87,7 +87,7 @@ class PatternLineEdit(QLineEdit): t = ( t[: selection_start] + escapedSelection - + t[selection_start + len(selection) :] + + t[selection_start + len(selection):] ) self.setText(t) @@ -329,23 +329,20 @@ class RegularExpressionDialog(QDialog): self.patternOptionsCheckBoxLayout = QGridLayout() gridRow = 0 - self.patternOptionsCheckBoxLayout.addWidget(self.caseInsensitiveOptionCheckBox, gridRow, \ - 1) - self.patternOptionsCheckBoxLayout.addWidget(self.dotMatchesEverythingOptionCheckBox, gridRow\ - ,2) + self.patternOptionsCheckBoxLayout.addWidget(self.caseInsensitiveOptionCheckBox, gridRow, 1) + self.patternOptionsCheckBoxLayout.addWidget( + self.dotMatchesEverythingOptionCheckBox, gridRow, 2) gridRow = gridRow + 1 - self.patternOptionsCheckBoxLayout.addWidget(self.multilineOptionCheckBox, gridRow, \ - 1) - self.patternOptionsCheckBoxLayout.addWidget(self.extendedPatternSyntaxOptionCheckBox, gridRow \ - , 2) + self.patternOptionsCheckBoxLayout.addWidget(self.multilineOptionCheckBox, gridRow, 1) + self.patternOptionsCheckBoxLayout.addWidget( + self.extendedPatternSyntaxOptionCheckBox, gridRow, 2) gridRow = gridRow + 1 - self.patternOptionsCheckBoxLayout.addWidget(self.invertedGreedinessOptionCheckBox, gridRow,\ - 1) - self.patternOptionsCheckBoxLayout.addWidget(self.dontCaptureOptionCheckBox, gridRow,\ - 2) + self.patternOptionsCheckBoxLayout.addWidget( + self.invertedGreedinessOptionCheckBox, gridRow, 1) + self.patternOptionsCheckBoxLayout.addWidget(self.dontCaptureOptionCheckBox, gridRow, 2) gridRow = gridRow + 1 - self.patternOptionsCheckBoxLayout.addWidget(self.useUnicodePropertiesOptionCheckBox, gridRow,\ - 1) + self.patternOptionsCheckBoxLayout.addWidget( + self.useUnicodePropertiesOptionCheckBox, gridRow, 1) form_layout.addRow("Pattern options:", self.patternOptionsCheckBoxLayout) diff --git a/examples/widgets/tutorials/addressbook/part2.py b/examples/widgets/tutorials/addressbook/part2.py index 89c813006..3c0eb451d 100644 --- a/examples/widgets/tutorials/addressbook/part2.py +++ b/examples/widgets/tutorials/addressbook/part2.py @@ -102,17 +102,16 @@ class AddressBook(QWidget): address = self._address_text.toPlainText() if name == "" or address == "": - QMessageBox.information(self, "Empty Field", - "Please enter a name and address.") + QMessageBox.information(self, "Empty Field", "Please enter a name and address.") return if name not in self.contacts: self.contacts[name] = address QMessageBox.information(self, "Add Successful", - f'"{name}" has been added to your address book.') + f'"{name}" has been added to your address book.') else: QMessageBox.information(self, "Add Unsuccessful", - f'Sorry, "{name}" is already in your address book.') + f'Sorry, "{name}" is already in your address book.') return if not self.contacts: diff --git a/examples/widgets/tutorials/addressbook/part3.py b/examples/widgets/tutorials/addressbook/part3.py index 571a96a48..611796f5e 100644 --- a/examples/widgets/tutorials/addressbook/part3.py +++ b/examples/widgets/tutorials/addressbook/part3.py @@ -116,17 +116,16 @@ class AddressBook(QWidget): address = self._address_text.toPlainText() if name == "" or address == "": - QMessageBox.information(self, "Empty Field", - "Please enter a name and address.") + QMessageBox.information(self, "Empty Field", "Please enter a name and address.") return if name not in self.contacts: self.contacts[name] = address QMessageBox.information(self, "Add Successful", - f'"{name}" has been added to your address book.') + f'"{name}" has been added to your address book.') else: QMessageBox.information(self, "Add Unsuccessful", - f'Sorry, "{name}" is already in your address book.') + f'Sorry, "{name}" is already in your address book.') return if not self.contacts: diff --git a/examples/widgets/tutorials/addressbook/part4.py b/examples/widgets/tutorials/addressbook/part4.py index 505fe4db9..535e3929f 100644 --- a/examples/widgets/tutorials/addressbook/part4.py +++ b/examples/widgets/tutorials/addressbook/part4.py @@ -128,34 +128,34 @@ class AddressBook(QWidget): address = self._address_text.toPlainText() if name == "" or address == "": - QMessageBox.information(self, "Empty Field", - "Please enter a name and address.") + QMessageBox.information(self, "Empty Field", "Please enter a name and address.") return if self._current_mode == self.AddingMode: if name not in self.contacts: self.contacts[name] = address QMessageBox.information(self, "Add Successful", - f'"{name}" has been added to your address book.') + f'"{name}" has been added to your address book.') else: QMessageBox.information(self, "Add Unsuccessful", - f'Sorry, "{name}" is already in your address book.') + f'Sorry, "{name}" is already in your address book.') return elif self._current_mode == self.EditingMode: if self._old_name != name: if name not in self.contacts: QMessageBox.information(self, "Edit Successful", - f'"{self.oldName}" has been edited in your address book.') + f'"{self.oldName}" has been edited in your ' + 'address book.') del self.contacts[self._old_name] self.contacts[name] = address else: QMessageBox.information(self, "Edit Unsuccessful", - f'Sorry, "{name}" is already in your address book.') + f'Sorry, "{name}" is already in your address book.') return elif self._old_address != address: QMessageBox.information(self, "Edit Successful", - f'"{name}" has been edited in your address book.') + f'"{name}" has been edited in your address book.') self.contacts[name] = address self.update_interface(self.NavigationMode) @@ -173,15 +173,15 @@ class AddressBook(QWidget): if name in self.contacts: button = QMessageBox.question(self, "Confirm Remove", - f'Are you sure you want to remove "{name}"?', - QMessageBox.Yes | QMessageBox.No) + f'Are you sure you want to remove "{name}"?', + QMessageBox.Yes | QMessageBox.No) if button == QMessageBox.Yes: self.previous() del self.contacts[name] QMessageBox.information(self, "Remove Successful", - f'"{name}" has been removed from your address book.') + f'"{name}" has been removed from your address book.') self.update_interface(self.NavigationMode) diff --git a/examples/widgets/tutorials/addressbook/part5.py b/examples/widgets/tutorials/addressbook/part5.py index 72245703f..921c210d4 100644 --- a/examples/widgets/tutorials/addressbook/part5.py +++ b/examples/widgets/tutorials/addressbook/part5.py @@ -134,34 +134,34 @@ class AddressBook(QWidget): address = self._address_text.toPlainText() if name == "" or address == "": - QMessageBox.information(self, "Empty Field", - "Please enter a name and address.") + QMessageBox.information(self, "Empty Field", "Please enter a name and address.") return if self._current_mode == self.AddingMode: if name not in self.contacts: self.contacts[name] = address QMessageBox.information(self, "Add Successful", - f'"{name}" has been added to your address book.') + f'"{name}" has been added to your address book.') else: QMessageBox.information(self, "Add Unsuccessful", - f'Sorry, "{name}" is already in your address book.') + f'Sorry, "{name}" is already in your address book.') return elif self._current_mode == self.EditingMode: if self._old_name != name: if name not in self.contacts: QMessageBox.information(self, "Edit Successful", - f'"{self.oldName}" has been edited in your address book.') + f'"{self.oldName}" has been edited in your ' + 'address book.') del self.contacts[self._old_name] self.contacts[name] = address else: QMessageBox.information(self, "Edit Unsuccessful", - f'Sorry, "{name}" is already in your address book.') + f'Sorry, "{name}" is already in your address book.') return elif self._old_address != address: QMessageBox.information(self, "Edit Successful", - f'"{name}" has been edited in your address book.') + f'"{name}" has been edited in your address book.') self.contacts[name] = address self.update_interface(self.NavigationMode) @@ -179,15 +179,15 @@ class AddressBook(QWidget): if name in self.contacts: button = QMessageBox.question(self, "Confirm Remove", - f'Are you sure you want to remove "{name}"?', - QMessageBox.Yes | QMessageBox.No) + f'Are you sure you want to remove "{name}"?', + QMessageBox.Yes | QMessageBox.No) if button == QMessageBox.Yes: self.previous() del self.contacts[name] QMessageBox.information(self, "Remove Successful", - f'"{name}" has been removed from your address book.') + f'"{name}" has been removed from your address book.') self.update_interface(self.NavigationMode) @@ -243,7 +243,7 @@ class AddressBook(QWidget): self._address_text.setText(self.contacts[contact_name]) else: QMessageBox.information(self, "Contact Not Found", - f'Sorry, "{contact_name}" is not in your address book.') + f'Sorry, "{contact_name}" is not in your address book.') return self.update_interface(self.NavigationMode) @@ -311,8 +311,7 @@ class FindDialog(QDialog): text = self._line_edit.text() if not text: - QMessageBox.information(self, "Empty Field", - "Please enter a name.") + QMessageBox.information(self, "Empty Field", "Please enter a name.") return else: self._find_text = text diff --git a/examples/widgets/tutorials/addressbook/part6.py b/examples/widgets/tutorials/addressbook/part6.py index f75fbf44f..af68412b1 100644 --- a/examples/widgets/tutorials/addressbook/part6.py +++ b/examples/widgets/tutorials/addressbook/part6.py @@ -145,34 +145,34 @@ class AddressBook(QWidget): address = self._address_text.toPlainText() if name == "" or address == "": - QMessageBox.information(self, "Empty Field", - "Please enter a name and address.") + QMessageBox.information(self, "Empty Field", "Please enter a name and address.") return if self._current_mode == self.AddingMode: if name not in self.contacts: self.contacts[name] = address QMessageBox.information(self, "Add Successful", - f'"{name}" has been added to your address book.') + f'"{name}" has been added to your address book.') else: QMessageBox.information(self, "Add Unsuccessful", - f'Sorry, "{name}" is already in your address book.') + f'Sorry, "{name}" is already in your address book.') return elif self._current_mode == self.EditingMode: if self._old_name != name: if name not in self.contacts: QMessageBox.information(self, "Edit Successful", - f'"{self.oldName}" has been edited in your address book.') + f'"{self.oldName}" has been edited in your ' + 'address book.') del self.contacts[self._old_name] self.contacts[name] = address else: QMessageBox.information(self, "Edit Unsuccessful", - f'Sorry, "{name}" is already in your address book.') + f'Sorry, "{name}" is already in your address book.') return elif self._old_address != address: QMessageBox.information(self, "Edit Successful", - f'"{name}" has been edited in your address book.') + f'"{name}" has been edited in your address book.') self.contacts[name] = address self.update_interface(self.NavigationMode) @@ -190,15 +190,15 @@ class AddressBook(QWidget): if name in self.contacts: button = QMessageBox.question(self, "Confirm Remove", - f'Are you sure you want to remove "{name}"?', - QMessageBox.Yes | QMessageBox.No) + f'Are you sure you want to remove "{name}"?', + QMessageBox.Yes | QMessageBox.No) if button == QMessageBox.Yes: self.previous() del self.contacts[name] QMessageBox.information(self, "Remove Successful", - f'"{name}" has been removed from your address book.') + f'"{name}" has been removed from your address book.') self.update_interface(self.NavigationMode) @@ -254,7 +254,7 @@ class AddressBook(QWidget): self._address_text.setText(self.contacts[contact_name]) else: QMessageBox.information(self, "Contact Not Found", - f'Sorry, "{contact_name}" is not in your address book.') + f'Sorry, "{contact_name}" is not in your address book.') return self.update_interface(self.NavigationMode) @@ -304,8 +304,8 @@ class AddressBook(QWidget): def save_to_file(self): fileName, _ = QFileDialog.getSaveFileName(self, - "Save Address Book", '', - "Address Book (*.abk);;All Files (*)") + "Save Address Book", '', + "Address Book (*.abk);;All Files (*)") if not fileName: return @@ -314,7 +314,7 @@ class AddressBook(QWidget): out_file = open(str(fileName), 'wb') except IOError: QMessageBox.information(self, "Unable to open file", - f'There was an error opening "{fileName}"') + f'There was an error opening "{fileName}"') return pickle.dump(self.contacts, out_file) @@ -322,8 +322,8 @@ class AddressBook(QWidget): def load_from_file(self): fileName, _ = QFileDialog.getOpenFileName(self, - "Open Address Book", '', - "Address Book (*.abk);;All Files (*)") + "Open Address Book", '', + "Address Book (*.abk);;All Files (*)") if not fileName: return @@ -332,7 +332,7 @@ class AddressBook(QWidget): in_file = open(str(fileName), 'rb') except IOError: QMessageBox.information(self, "Unable to open file", - f'There was an error opening "{fileName}"') + f'There was an error opening "{fileName}"') return self.contacts = pickle.load(in_file) @@ -340,8 +340,7 @@ class AddressBook(QWidget): if len(self.contacts) == 0: QMessageBox.information(self, "No contacts in file", - "The file you are attempting to open contains no " - "contacts.") + "The file you are attempting to open contains no contacts.") else: for name, address in self.contacts: self._name_line.setText(name) @@ -375,8 +374,7 @@ class FindDialog(QDialog): text = self._line_edit.text() if not text: - QMessageBox.information(self, "Empty Field", - "Please enter a name.") + QMessageBox.information(self, "Empty Field", "Please enter a name.") return self._find_text = text diff --git a/examples/widgets/tutorials/addressbook/part7.py b/examples/widgets/tutorials/addressbook/part7.py index 2f874f9bd..35a7d1728 100644 --- a/examples/widgets/tutorials/addressbook/part7.py +++ b/examples/widgets/tutorials/addressbook/part7.py @@ -151,34 +151,34 @@ class AddressBook(QWidget): address = self._address_text.toPlainText() if name == "" or address == "": - QMessageBox.information(self, "Empty Field", - "Please enter a name and address.") + QMessageBox.information(self, "Empty Field", "Please enter a name and address.") return if self._current_mode == self.AddingMode: if name not in self.contacts: self.contacts[name] = address QMessageBox.information(self, "Add Successful", - f'"{name}" has been added to your address book.') + f'"{name}" has been added to your address book.') else: QMessageBox.information(self, "Add Unsuccessful", - f'Sorry, "{name}" is already in your address book.') + f'Sorry, "{name}" is already in your address book.') return elif self._current_mode == self.EditingMode: if self._old_name != name: if name not in self.contacts: QMessageBox.information(self, "Edit Successful", - f'"{self.oldName}" has been edited in your address book.') + f'"{self.oldName}" has been edited in your ' + 'address book.') del self.contacts[self._old_name] self.contacts[name] = address else: QMessageBox.information(self, "Edit Unsuccessful", - f'Sorry, "{name}" is already in your address book.') + f'Sorry, "{name}" is already in your address book.') return elif self._old_address != address: QMessageBox.information(self, "Edit Successful", - f'"{name}" has been edited in your address book.') + f'"{name}" has been edited in your address book.') self.contacts[name] = address self.update_interface(self.NavigationMode) @@ -196,15 +196,15 @@ class AddressBook(QWidget): if name in self.contacts: button = QMessageBox.question(self, "Confirm Remove", - f'Are you sure you want to remove "{name}"?', - QMessageBox.Yes | QMessageBox.No) + f'Are you sure you want to remove "{name}"?', + QMessageBox.Yes | QMessageBox.No) if button == QMessageBox.Yes: self.previous() del self.contacts[name] QMessageBox.information(self, "Remove Successful", - f'"{name}" has been removed from your address book.') + f'"{name}" has been removed from your address book.') self.update_interface(self.NavigationMode) @@ -260,7 +260,7 @@ class AddressBook(QWidget): self._address_text.setText(self.contacts[contact_name]) else: QMessageBox.information(self, "Contact Not Found", - f'Sorry, "{contact_name}" is not in your address book.') + f'Sorry, "{contact_name}" is not in your address book.') return self.update_interface(self.NavigationMode) @@ -313,8 +313,8 @@ class AddressBook(QWidget): def save_to_file(self): fileName, _ = QFileDialog.getSaveFileName(self, - "Save Address Book", '', - "Address Book (*.abk);;All Files (*)") + "Save Address Book", '', + "Address Book (*.abk);;All Files (*)") if not fileName: return @@ -323,7 +323,7 @@ class AddressBook(QWidget): out_file = open(str(fileName), 'wb') except IOError: QMessageBox.information(self, "Unable to open file", - f'There was an error opening "{fileName}"') + f'There was an error opening "{fileName}"') return pickle.dump(self.contacts, out_file) @@ -331,8 +331,8 @@ class AddressBook(QWidget): def load_from_file(self): fileName, _ = QFileDialog.getOpenFileName(self, - "Open Address Book", '', - "Address Book (*.abk);;All Files (*)") + "Open Address Book", '', + "Address Book (*.abk);;All Files (*)") if not fileName: return @@ -341,7 +341,7 @@ class AddressBook(QWidget): in_file = open(str(fileName), 'rb') except IOError: QMessageBox.information(self, "Unable to open file", - f'There was an error opening "{fileName}"') + f'There was an error opening "{fileName}"') return self.contacts = pickle.load(in_file) @@ -349,8 +349,7 @@ class AddressBook(QWidget): if len(self.contacts) == 0: QMessageBox.information(self, "No contacts in file", - "The file you are attempting to open contains no " - "contacts.") + "The file you are attempting to open contains no contacts.") else: for name, address in self.contacts: self._name_line.setText(name) @@ -372,7 +371,7 @@ class AddressBook(QWidget): last_name = '' file_name = QFileDialog.getSaveFileName(self, "Export Contact", - '', "vCard Files (*.vcf);;All Files (*)")[0] + '', "vCard Files (*.vcf);;All Files (*)")[0] if not file_name: return @@ -380,8 +379,7 @@ class AddressBook(QWidget): out_file = QFile(file_name) if not out_file.open(QIODevice.WriteOnly): - QMessageBox.information(self, "Unable to open file", - out_file.errorString()) + QMessageBox.information(self, "Unable to open file", out_file.errorString()) return out_s = QTextStream(out_file) @@ -399,7 +397,7 @@ class AddressBook(QWidget): out_s << 'END:VCARD' << '\n' QMessageBox.information(self, "Export Successful", - f'"{name}" has been exported as a vCard.') + f'"{name}" has been exported as a vCard.') class FindDialog(QDialog): @@ -427,8 +425,7 @@ class FindDialog(QDialog): text = self._line_edit.text() if not text: - QMessageBox.information(self, "Empty Field", - "Please enter a name.") + QMessageBox.information(self, "Empty Field", "Please enter a name.") return self._find_text = text diff --git a/examples/widgets/tutorials/cannon/t11.py b/examples/widgets/tutorials/cannon/t11.py index 997eecbd1..10afea90c 100644 --- a/examples/widgets/tutorials/cannon/t11.py +++ b/examples/widgets/tutorials/cannon/t11.py @@ -45,8 +45,8 @@ class LCDRange(QWidget): def set_range(self, minValue, maxValue): if minValue < 0 or maxValue > 99 or minValue > maxValue: qWarning(f"LCDRange::setRange({minValue}, {maxValue})\n" - "\tRange must be 0..99\n" - "\tand minValue must not be greater than maxValue") + "\tRange must be 0..99\n" + "\tand minValue must not be greater than maxValue") return self.slider.setRange(minValue, maxValue) diff --git a/examples/widgets/tutorials/cannon/t14.py b/examples/widgets/tutorials/cannon/t14.py index 5e74443ed..88babe9ea 100644 --- a/examples/widgets/tutorials/cannon/t14.py +++ b/examples/widgets/tutorials/cannon/t14.py @@ -174,7 +174,8 @@ class CannonField(QWidget): self._auto_shoot_timer.stop() self.hit.emit() self.can_shoot.emit(True) - elif shot_r.x() > self.width() or shot_r.y() > self.height() or shot_r.intersects(self.barrier_rect()): + elif (shot_r.x() > self.width() or shot_r.y() > self.height() + or shot_r.intersects(self.barrier_rect())): self._auto_shoot_timer.stop() self.missed.emit() self.can_shoot.emit(True) diff --git a/examples/widgets/tutorials/modelview/2_formatting.py b/examples/widgets/tutorials/modelview/2_formatting.py index 73c993e5f..f39ec462c 100644 --- a/examples/widgets/tutorials/modelview/2_formatting.py +++ b/examples/widgets/tutorials/modelview/2_formatting.py @@ -32,7 +32,7 @@ class MyModel(QAbstractTableModel): return "<--left" if row == 1 and col == 1: return "right-->" - return f"Row{row}, Column{col+1}" + return f"Row{row}, Column{col + 1}" elif role == Qt.FontRole: if row == 0 and col == 0: # change font only for cell(0,0) diff --git a/examples/widgets/widgets/charactermap/characterwidget.py b/examples/widgets/widgets/charactermap/characterwidget.py index 1df2a3b74..0f01f9684 100644 --- a/examples/widgets/widgets/charactermap/characterwidget.py +++ b/examples/widgets/widgets/charactermap/characterwidget.py @@ -127,7 +127,7 @@ class CharacterWidget(QWidget): self._square_size, self._square_size, QBrush(Qt.red)) text = chr(key) - painter.drawText(column * self._square_size + (self._square_size / 2) - - font_metrics.horizontalAdvance(text) / 2, + painter.drawText(column * self._square_size + (self._square_size / 2) + - font_metrics.horizontalAdvance(text) / 2, row * self._square_size + 4 + font_metrics.ascent(), text) diff --git a/examples/widgets/widgets/tetrix/tetrix.py b/examples/widgets/widgets/tetrix/tetrix.py index 062629d46..cb126ee6d 100644 --- a/examples/widgets/widgets/tetrix/tetrix.py +++ b/examples/widgets/widgets/tetrix/tetrix.py @@ -134,11 +134,11 @@ class TetrixBoard(QFrame): def sizeHint(self): return QSize(TetrixBoard.board_width * 15 + self.frameWidth() * 2, - TetrixBoard.board_height * 15 + self.frameWidth() * 2) + TetrixBoard.board_height * 15 + self.frameWidth() * 2) def minimum_size_hint(self): return QSize(TetrixBoard.board_width * 5 + self.frameWidth() * 2, - TetrixBoard.board_height * 5 + self.frameWidth() * 2) + TetrixBoard.board_height * 5 + self.frameWidth() * 2) @Slot() def start(self): @@ -190,16 +190,17 @@ class TetrixBoard(QFrame): shape = self.shape_at(j, TetrixBoard.board_height - i - 1) if shape != Piece.NoShape: self.draw_square(painter, - rect.left() + j * self.square_width(), - board_top + i * self.square_height(), shape) + rect.left() + j * self.square_width(), + board_top + i * self.square_height(), shape) if self._cur_piece.shape() != Piece.NoShape: for i in range(4): x = self._cur_x + self._cur_piece.x(i) y = self._cur_y - self._cur_piece.y(i) self.draw_square(painter, rect.left() + x * self.square_width(), - board_top + (TetrixBoard.board_height - y - 1) * self.square_height(), - self._cur_piece.shape()) + board_top + + (TetrixBoard.board_height - y - 1) * self.square_height(), + self._cur_piece.shape()) def keyPressEvent(self, event): if not self._is_started or self._is_paused or self._cur_piece.shape() == Piece.NoShape: @@ -234,7 +235,8 @@ class TetrixBoard(QFrame): super(TetrixBoard, self).timerEvent(event) def clear_board(self): - self.board = [Piece.NoShape for i in range(TetrixBoard.board_height * TetrixBoard.board_width)] + self.board = [ + Piece.NoShape for _ in range(TetrixBoard.board_height * TetrixBoard.board_width)] def drop_down(self): drop_height = 0 @@ -328,7 +330,7 @@ class TetrixBoard(QFrame): x = self._next_piece.x(i) - self._next_piece.min_x() y = self._next_piece.y(i) - self._next_piece.min_y() self.draw_square(painter, x * self.square_width(), - y * self.square_height(), self._next_piece.shape()) + y * self.square_height(), self._next_piece.shape()) self.nextPieceLabel.setPixmap(pixmap) @@ -352,8 +354,7 @@ class TetrixBoard(QFrame): 0xCCCC66, 0xCC66CC, 0x66CCCC, 0xDAAA00] color = QColor(color_table[shape]) - painter.fillRect(x + 1, y + 1, self.square_width() - 2, - self.square_height() - 2, color) + painter.fillRect(x + 1, y + 1, self.square_width() - 2, self.square_height() - 2, color) painter.setPen(color.lighter()) painter.drawLine(x, y + self.square_height() - 1, x, y) @@ -361,21 +362,21 @@ class TetrixBoard(QFrame): painter.setPen(color.darker()) painter.drawLine(x + 1, y + self.square_height() - 1, - x + self.square_width() - 1, y + self.square_height() - 1) + x + self.square_width() - 1, y + self.square_height() - 1) painter.drawLine(x + self.square_width() - 1, - y + self.square_height() - 1, x + self.square_width() - 1, y + 1) + y + self.square_height() - 1, x + self.square_width() - 1, y + 1) class TetrixPiece(object): coords_table = ( - ((0, 0), (0, 0), (0, 0), (0, 0)), - ((0, -1), (0, 0), (-1, 0), (-1, 1)), - ((0, -1), (0, 0), (1, 0), (1, 1)), - ((0, -1), (0, 0), (0, 1), (0, 2)), - ((-1, 0), (0, 0), (1, 0), (0, 1)), - ((0, 0), (1, 0), (0, 1), (1, 1)), - ((-1, -1), (0, -1), (0, 0), (0, 1)), - ((1, -1), (0, -1), (0, 0), (0, 1)) + ((0, 0), (0, 0), (0, 0), (0, 0)), + ((0, -1), (0, 0), (-1, 0), (-1, 1)), + ((0, -1), (0, 0), (1, 0), (1, 1)), + ((0, -1), (0, 0), (0, 1), (0, 2)), + ((-1, 0), (0, 0), (1, 0), (0, 1)), + ((0, 0), (1, 0), (0, 1), (1, 1)), + ((-1, -1), (0, -1), (0, 0), (0, 1)), + ((1, -1), (0, -1), (0, 0), (0, 1)) ) def __init__(self): diff --git a/examples/widgets/widgetsgallery/widgetgallery.py b/examples/widgets/widgetsgallery/widgetgallery.py index bf1f523e2..d43ab26a5 100644 --- a/examples/widgets/widgetsgallery/widgetgallery.py +++ b/examples/widgets/widgetsgallery/widgetgallery.py @@ -164,8 +164,8 @@ class WidgetGallery(QDialog): top_layout.addStretch(1) top_layout.addWidget(disable_widgets_checkbox) - dialog_buttonbox = QDialogButtonBox(QDialogButtonBox.Help | - QDialogButtonBox.Close) + dialog_buttonbox = QDialogButtonBox(QDialogButtonBox.Help + | QDialogButtonBox.Close) init_widget(dialog_buttonbox, "dialogButtonBox") dialog_buttonbox.helpRequested.connect(launch_module_help) dialog_buttonbox.rejected.connect(self.reject) diff --git a/examples/xml/dombookmarks/dombookmarks.py b/examples/xml/dombookmarks/dombookmarks.py index 4fbc843e1..85e423ef5 100644 --- a/examples/xml/dombookmarks/dombookmarks.py +++ b/examples/xml/dombookmarks/dombookmarks.py @@ -30,8 +30,8 @@ class MainWindow(QMainWindow): def open(self): file_name = QFileDialog.getOpenFileName(self, - "Open Bookmark File", QDir.currentPath(), - "XBEL Files (*.xbel *.xml)")[0] + "Open Bookmark File", QDir.currentPath(), + "XBEL Files (*.xbel *.xml)")[0] if not file_name: return @@ -40,7 +40,7 @@ class MainWindow(QMainWindow): if not in_file.open(QFile.ReadOnly | QFile.Text): reason = in_file.errorString() QMessageBox.warning(self, "DOM Bookmarks", - f"Cannot read file {file_name}:\n{reason}.") + f"Cannot read file {file_name}:\n{reason}.") return if self._xbel_tree.read(in_file): @@ -48,8 +48,8 @@ class MainWindow(QMainWindow): def save_as(self): file_name = QFileDialog.getSaveFileName(self, - "Save Bookmark File", QDir.currentPath(), - "XBEL Files (*.xbel *.xml)")[0] + "Save Bookmark File", QDir.currentPath(), + "XBEL Files (*.xbel *.xml)")[0] if not file_name: return @@ -58,7 +58,7 @@ class MainWindow(QMainWindow): if not out_file.open(QFile.WriteOnly | QFile.Text): reason = out_file.errorString() QMessageBox.warning(self, "DOM Bookmarks", - "Cannot write file {fileName}:\n{reason}.") + f"Cannot write file {file_name}:\n{reason}.") return if self._xbel_tree.write(out_file): @@ -66,25 +66,26 @@ class MainWindow(QMainWindow): def about(self): QMessageBox.about(self, "About DOM Bookmarks", - "The <b>DOM Bookmarks</b> example demonstrates how to use Qt's " - "DOM classes to read and write XML documents.") + "The <b>DOM Bookmarks</b> example demonstrates how to use Qt's " + "DOM classes to read and write XML documents.") def create_menus(self): self._file_menu = self.menuBar().addMenu("&File") self._file_menu.addAction(QAction("&Open...", self, - shortcut=QKeySequence(Qt.CTRL | Qt.Key_O), triggered=self.open)) + shortcut=QKeySequence( + Qt.CTRL | Qt.Key_O), triggered=self.open)) self._file_menu.addAction(QAction("&Save As...", self, - shortcut=QKeySequence(Qt.CTRL | Qt.Key_S), triggered=self.save_as)) + shortcut=QKeySequence( + Qt.CTRL | Qt.Key_S), triggered=self.save_as)) self._file_menu.addAction(QAction("E&xit", self, - shortcut=QKeySequence(Qt.CTRL | Qt.Key_Q), triggered=self.close)) + shortcut=QKeySequence( + Qt.CTRL | Qt.Key_Q), triggered=self.close)) self.menuBar().addSeparator() self._help_menu = self.menuBar().addMenu("&Help") - self._help_menu.addAction(QAction("&About", self, - triggered=self.about)) - self._help_menu.addAction(QAction("About &Qt", self, - triggered=qApp.aboutQt)) + self._help_menu.addAction(QAction("&About", self, triggered=self.about)) + self._help_menu.addAction(QAction("About &Qt", self, triggered=qApp.aboutQt)) class XbelTree(QTreeWidget): @@ -102,26 +103,27 @@ class XbelTree(QTreeWidget): self._bookmark_icon = QIcon() self._folder_icon.addPixmap(self.style().standardPixmap(QStyle.SP_DirClosedIcon), - QIcon.Normal, QIcon.Off) + QIcon.Normal, QIcon.Off) self._folder_icon.addPixmap(self.style().standardPixmap(QStyle.SP_DirOpenIcon), - QIcon.Normal, QIcon.On) + QIcon.Normal, QIcon.On) self._bookmark_icon.addPixmap(self.style().standardPixmap(QStyle.SP_FileIcon)) def read(self, device): ok, errorStr, errorLine, errorColumn = self._dom_document.setContent(device, True) if not ok: QMessageBox.information(self.window(), "DOM Bookmarks", - f"Parse error at line {errorLine}, column {errorColumn}:\n{errorStr}") + f"Parse error at line {errorLine}, " + f"column {errorColumn}:\n{errorStr}") return False root = self._dom_document.documentElement() if root.tagName() != 'xbel': QMessageBox.information(self.window(), "DOM Bookmarks", - "The file is not an XBEL file.") + "The file is not an XBEL file.") return False elif root.hasAttribute('version') and root.attribute('version') != '1.0': QMessageBox.information(self.window(), "DOM Bookmarks", - "The file is not an XBEL version 1.0 file.") + "The file is not an XBEL version 1.0 file.") return False self.clear() |