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 /examples/widgets | |
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]>
Diffstat (limited to 'examples/widgets')
41 files changed, 392 insertions, 424 deletions
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) |