diff options
Diffstat (limited to 'sources/pyside6/doc/tutorials')
17 files changed, 55 insertions, 56 deletions
diff --git a/sources/pyside6/doc/tutorials/datavisualize/datavisualize3/main_window.py b/sources/pyside6/doc/tutorials/datavisualize/datavisualize3/main_window.py index 8ce8f9ace..6ee8fa61b 100644 --- a/sources/pyside6/doc/tutorials/datavisualize/datavisualize3/main_window.py +++ b/sources/pyside6/doc/tutorials/datavisualize/datavisualize3/main_window.py @@ -2,7 +2,6 @@ # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause from __future__ import annotations -from PySide6.QtCore import Slot from PySide6.QtGui import QAction, QKeySequence from PySide6.QtWidgets import QMainWindow diff --git a/sources/pyside6/doc/tutorials/datavisualize/datavisualize5/main_widget.py b/sources/pyside6/doc/tutorials/datavisualize/datavisualize5/main_widget.py index 40954ea34..77ea4e776 100644 --- a/sources/pyside6/doc/tutorials/datavisualize/datavisualize5/main_widget.py +++ b/sources/pyside6/doc/tutorials/datavisualize/datavisualize5/main_widget.py @@ -2,11 +2,10 @@ # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause from __future__ import annotations -from PySide6.QtCore import QDateTime, Qt from PySide6.QtGui import QPainter from PySide6.QtWidgets import (QWidget, QHeaderView, QHBoxLayout, QTableView, QSizePolicy) -from PySide6.QtCharts import QChart, QChartView, QLineSeries, QDateTimeAxis, QValueAxis +from PySide6.QtCharts import QChart, QChartView from table_model import CustomTableModel @@ -41,12 +40,12 @@ class Widget(QWidget): self.main_layout = QHBoxLayout() size = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) - ## Left layout + # Left layout size.setHorizontalStretch(1) self.table_view.setSizePolicy(size) self.main_layout.addWidget(self.table_view) - ## Right Layout + # Right Layout size.setHorizontalStretch(4) self.chart_view.setSizePolicy(size) self.main_layout.addWidget(self.chart_view) diff --git a/sources/pyside6/doc/tutorials/datavisualize/datavisualize6/main_window.py b/sources/pyside6/doc/tutorials/datavisualize/datavisualize6/main_window.py index 21842cff1..f37268df8 100644 --- a/sources/pyside6/doc/tutorials/datavisualize/datavisualize6/main_window.py +++ b/sources/pyside6/doc/tutorials/datavisualize/datavisualize6/main_window.py @@ -2,8 +2,7 @@ # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause from __future__ import annotations -from PySide6.QtCore import Slot -from PySide6.QtGui import QAction, QKeySequence, QScreen +from PySide6.QtGui import QAction, QKeySequence from PySide6.QtWidgets import QMainWindow diff --git a/sources/pyside6/doc/tutorials/expenses/main_snake_prop.py b/sources/pyside6/doc/tutorials/expenses/main_snake_prop.py index 0817fae25..f074ce27d 100644 --- a/sources/pyside6/doc/tutorials/expenses/main_snake_prop.py +++ b/sources/pyside6/doc/tutorials/expenses/main_snake_prop.py @@ -10,7 +10,7 @@ from PySide6.QtWidgets import (QAction, QApplication, QHeaderView, QHBoxLayout, QVBoxLayout, QWidget) from PySide6.QtCharts import QtCharts -from __feature__ import snake_case, true_property +from __feature__ import snake_case, true_property # noqa: F401 class Widget(QWidget): diff --git a/sources/pyside6/doc/tutorials/expenses/steps/01-expenses.py b/sources/pyside6/doc/tutorials/expenses/steps/01-expenses.py index 917d069bd..c661aca1d 100644 --- a/sources/pyside6/doc/tutorials/expenses/steps/01-expenses.py +++ b/sources/pyside6/doc/tutorials/expenses/steps/01-expenses.py @@ -11,6 +11,7 @@ class MainWindow(QMainWindow): super().__init__() self.setWindowTitle("Tutorial") + if __name__ == "__main__": # Qt Application app = QApplication(sys.argv) diff --git a/sources/pyside6/doc/tutorials/modelviewprogramming/qlistview-dnd.py b/sources/pyside6/doc/tutorials/modelviewprogramming/qlistview-dnd.py index 15e9c81dc..4b2300b1e 100644 --- a/sources/pyside6/doc/tutorials/modelviewprogramming/qlistview-dnd.py +++ b/sources/pyside6/doc/tutorials/modelviewprogramming/qlistview-dnd.py @@ -14,7 +14,7 @@ class DragDropListModel(QStringListModel): """A simple model that uses a QStringList as its data source.""" def __init__(self, strings, parent=None): - super().__init__(strings, parent) + super().__init__(strings, parent) #! [0] @@ -27,6 +27,7 @@ class DragDropListModel(QStringListModel): return True #! [0] + #! [1] def dropMimeData(self, data, action, row, column, parent): if not self.canDropMimeData(data, action, row, column, parent): diff --git a/sources/pyside6/doc/tutorials/modelviewprogramming/stringlistmodel.py b/sources/pyside6/doc/tutorials/modelviewprogramming/stringlistmodel.py index 6818c1aa3..46f2eb964 100644 --- a/sources/pyside6/doc/tutorials/modelviewprogramming/stringlistmodel.py +++ b/sources/pyside6/doc/tutorials/modelviewprogramming/stringlistmodel.py @@ -5,7 +5,7 @@ from __future__ import annotations import sys from PySide6.QtWidgets import (QApplication, QListView) -from PySide6.QtCore import QAbstractListModel, QStringListModel, QModelIndex, Qt +from PySide6.QtCore import QAbstractListModel, QModelIndex, Qt #! [0] @@ -117,7 +117,7 @@ if __name__ == '__main__': model.insertRows(5, 7, QModelIndex()) for row in range(5, 12): index = model.index(row, 0, QModelIndex()) - model.setData(index, f"{row+1}") + model.setData(index, f"{row + 1}") #! [main5] view.show() diff --git a/sources/pyside6/doc/tutorials/portingguide/chapter1/createdb.py b/sources/pyside6/doc/tutorials/portingguide/chapter1/createdb.py index 46b5c312a..b3834edb2 100644 --- a/sources/pyside6/doc/tutorials/portingguide/chapter1/createdb.py +++ b/sources/pyside6/doc/tutorials/portingguide/chapter1/createdb.py @@ -2,7 +2,7 @@ # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause from __future__ import annotations -from PySide6.QtSql import QSqlDatabase, QSqlError, QSqlQuery +from PySide6.QtSql import QSqlDatabase, QSqlQuery from datetime import date @@ -27,6 +27,7 @@ def add_author(q, name, birthdate): q.exec_() return q.lastInsertId() + BOOKS_SQL = """ create table books(id integer primary key, title varchar, author integer, genre integer, year integer, rating integer) @@ -48,6 +49,7 @@ INSERT_BOOK_SQL = """ values(?, ?, ?, ?, ?) """ + def init_db(): """ init_db() @@ -74,12 +76,12 @@ def init_db(): greeneId = add_author(q, "Graham Greene", date(1904, 10, 2)) pratchettId = add_author(q, "Terry Pratchett", date(1948, 4, 28)) - check(q.prepare,INSERT_GENRE_SQL) + check(q.prepare, INSERT_GENRE_SQL) sfiction = add_genre(q, "Science Fiction") fiction = add_genre(q, "Fiction") fantasy = add_genre(q, "Fantasy") - check(q.prepare,INSERT_BOOK_SQL) + check(q.prepare, INSERT_BOOK_SQL) add_book(q, "Foundation", 1951, asimovId, sfiction, 3) add_book(q, "Foundation and Empire", 1952, asimovId, sfiction, 4) add_book(q, "Second Foundation", 1953, asimovId, sfiction, 3) diff --git a/sources/pyside6/doc/tutorials/portingguide/chapter2/bookdelegate.py b/sources/pyside6/doc/tutorials/portingguide/chapter2/bookdelegate.py index 5e926baca..d83312e91 100644 --- a/sources/pyside6/doc/tutorials/portingguide/chapter2/bookdelegate.py +++ b/sources/pyside6/doc/tutorials/portingguide/chapter2/bookdelegate.py @@ -3,14 +3,12 @@ from __future__ import annotations import copy -import os from pathlib import Path from PySide6.QtSql import QSqlRelationalDelegate -from PySide6.QtWidgets import (QItemDelegate, QSpinBox, QStyledItemDelegate, - QStyle, QStyleOptionViewItem) -from PySide6.QtGui import QMouseEvent, QPixmap, QPalette, QImage -from PySide6.QtCore import QEvent, QSize, Qt, QUrl +from PySide6.QtWidgets import QSpinBox, QStyle +from PySide6.QtGui import QPixmap, QPalette +from PySide6.QtCore import QEvent, QSize, Qt class BookDelegate(QSqlRelationalDelegate): @@ -49,7 +47,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/sources/pyside6/doc/tutorials/portingguide/chapter2/createdb.py b/sources/pyside6/doc/tutorials/portingguide/chapter2/createdb.py index 46b5c312a..b3834edb2 100644 --- a/sources/pyside6/doc/tutorials/portingguide/chapter2/createdb.py +++ b/sources/pyside6/doc/tutorials/portingguide/chapter2/createdb.py @@ -2,7 +2,7 @@ # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause from __future__ import annotations -from PySide6.QtSql import QSqlDatabase, QSqlError, QSqlQuery +from PySide6.QtSql import QSqlDatabase, QSqlQuery from datetime import date @@ -27,6 +27,7 @@ def add_author(q, name, birthdate): q.exec_() return q.lastInsertId() + BOOKS_SQL = """ create table books(id integer primary key, title varchar, author integer, genre integer, year integer, rating integer) @@ -48,6 +49,7 @@ INSERT_BOOK_SQL = """ values(?, ?, ?, ?, ?) """ + def init_db(): """ init_db() @@ -74,12 +76,12 @@ def init_db(): greeneId = add_author(q, "Graham Greene", date(1904, 10, 2)) pratchettId = add_author(q, "Terry Pratchett", date(1948, 4, 28)) - check(q.prepare,INSERT_GENRE_SQL) + check(q.prepare, INSERT_GENRE_SQL) sfiction = add_genre(q, "Science Fiction") fiction = add_genre(q, "Fiction") fantasy = add_genre(q, "Fantasy") - check(q.prepare,INSERT_BOOK_SQL) + check(q.prepare, INSERT_BOOK_SQL) add_book(q, "Foundation", 1951, asimovId, sfiction, 3) add_book(q, "Foundation and Empire", 1952, asimovId, sfiction, 4) add_book(q, "Second Foundation", 1953, asimovId, sfiction, 3) diff --git a/sources/pyside6/doc/tutorials/portingguide/chapter2/main.py b/sources/pyside6/doc/tutorials/portingguide/chapter2/main.py index 735d8e021..e125314de 100644 --- a/sources/pyside6/doc/tutorials/portingguide/chapter2/main.py +++ b/sources/pyside6/doc/tutorials/portingguide/chapter2/main.py @@ -4,7 +4,6 @@ from __future__ import annotations import sys -from PySide6.QtCore import Qt from PySide6.QtSql import QSqlQueryModel from PySide6.QtWidgets import QTableView, QApplication diff --git a/sources/pyside6/doc/tutorials/portingguide/chapter3/bookdelegate-old.py b/sources/pyside6/doc/tutorials/portingguide/chapter3/bookdelegate-old.py index cfe52bba8..ecd0afd1f 100644 --- a/sources/pyside6/doc/tutorials/portingguide/chapter3/bookdelegate-old.py +++ b/sources/pyside6/doc/tutorials/portingguide/chapter3/bookdelegate-old.py @@ -3,14 +3,12 @@ from __future__ import annotations import copy -import os from pathlib import Path from PySide6.QtSql import QSqlRelationalDelegate -from PySide6.QtWidgets import (QItemDelegate, QSpinBox, QStyledItemDelegate, - QStyle, QStyleOptionViewItem) -from PySide6.QtGui import QMouseEvent, QPixmap, QPalette, QImage -from PySide6.QtCore import QEvent, QSize, Qt, QUrl +from PySide6.QtWidgets import QSpinBox, QStyle +from PySide6.QtGui import QPixmap, QPalette +from PySide6.QtCore import QEvent, QSize, Qt class BookDelegate(QSqlRelationalDelegate): @@ -49,7 +47,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/sources/pyside6/doc/tutorials/portingguide/chapter3/bookdelegate.py b/sources/pyside6/doc/tutorials/portingguide/chapter3/bookdelegate.py index 6aba9dd93..6abbc3343 100644 --- a/sources/pyside6/doc/tutorials/portingguide/chapter3/bookdelegate.py +++ b/sources/pyside6/doc/tutorials/portingguide/chapter3/bookdelegate.py @@ -2,12 +2,12 @@ # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause from __future__ import annotations -import copy, os +import copy from PySide6.QtSql import QSqlRelationalDelegate -from PySide6.QtWidgets import (QItemDelegate, QSpinBox, QStyledItemDelegate, - QStyle, QStyleOptionViewItem) -from PySide6.QtGui import QMouseEvent, QPixmap, QPalette, QImage -from PySide6.QtCore import QEvent, QSize, Qt, QUrl +from PySide6.QtWidgets import QSpinBox, QStyle +from PySide6.QtGui import QPixmap, QPalette +from PySide6.QtCore import QEvent, QSize, Qt + class BookDelegate(QSqlRelationalDelegate): """Books delegate to rate the books""" @@ -44,7 +44,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/sources/pyside6/doc/tutorials/portingguide/chapter3/bookwindow.py b/sources/pyside6/doc/tutorials/portingguide/chapter3/bookwindow.py index e115c321d..907af92c5 100644 --- a/sources/pyside6/doc/tutorials/portingguide/chapter3/bookwindow.py +++ b/sources/pyside6/doc/tutorials/portingguide/chapter3/bookwindow.py @@ -2,13 +2,11 @@ # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause from __future__ import annotations -from PySide6.QtGui import QAction from PySide6.QtWidgets import (QAbstractItemView, QDataWidgetMapper, - QHeaderView, QMainWindow, QMessageBox) + QHeaderView, QMainWindow, QMessageBox) from PySide6.QtGui import QKeySequence -from PySide6.QtSql import (QSqlRelation, QSqlRelationalTableModel, QSqlTableModel, - QSqlError) -from PySide6.QtCore import QAbstractItemModel, QObject, QSize, Qt, Slot +from PySide6.QtSql import QSqlRelation, QSqlRelationalTableModel, QSqlTableModel +from PySide6.QtCore import Qt import createdb from ui_bookwindow import Ui_BookWindow from bookdelegate import BookDelegate @@ -60,8 +58,8 @@ class BookWindow(QMainWindow, Ui_BookWindow): self.genreEdit.setModelColumn(model.relationModel(genre_idx).fieldIndex("name")) # Lock and prohibit resizing of the width of the rating column: - self.bookTable.horizontalHeader().setSectionResizeMode(model.fieldIndex("rating"), - QHeaderView.ResizeToContents) + header = self.bookTable.horizontalHeader() + header.setSectionResizeMode(model.fieldIndex("rating"), QHeaderView.ResizeToContents) mapper = QDataWidgetMapper(self) mapper.setModel(model) @@ -78,23 +76,23 @@ class BookWindow(QMainWindow, Ui_BookWindow): self.bookTable.setCurrentIndex(model.index(0, 0)) self.create_menubar() - def showError(err): + def showError(self, err): QMessageBox.critical(self, "Unable to initialize Database", - "Error initializing database: " + err.text()) + "Error initializing database: " + err.text()) def create_menubar(self): file_menu = self.menuBar().addMenu(self.tr("&File")) quit_action = file_menu.addAction(self.tr("&Quit")) - quit_action.triggered.connect(qApp.quit) + quit_action.triggered.connect(qApp.quit) # noqa: F821 help_menu = self.menuBar().addMenu(self.tr("&Help")) about_action = help_menu.addAction(self.tr("&About")) about_action.setShortcut(QKeySequence.HelpContents) about_action.triggered.connect(self.about) aboutQt_action = help_menu.addAction("&About Qt") - aboutQt_action.triggered.connect(qApp.aboutQt) + aboutQt_action.triggered.connect(qApp.aboutQt) # noqa: F821 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.")) + message = self.tr("<p>The <b>Books</b> example shows how to use Qt SQL classes " + "with a model/view framework.") + QMessageBox.about(self, self.tr("About Books"), message) diff --git a/sources/pyside6/doc/tutorials/portingguide/chapter3/createdb.py b/sources/pyside6/doc/tutorials/portingguide/chapter3/createdb.py index 46b5c312a..b3834edb2 100644 --- a/sources/pyside6/doc/tutorials/portingguide/chapter3/createdb.py +++ b/sources/pyside6/doc/tutorials/portingguide/chapter3/createdb.py @@ -2,7 +2,7 @@ # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause from __future__ import annotations -from PySide6.QtSql import QSqlDatabase, QSqlError, QSqlQuery +from PySide6.QtSql import QSqlDatabase, QSqlQuery from datetime import date @@ -27,6 +27,7 @@ def add_author(q, name, birthdate): q.exec_() return q.lastInsertId() + BOOKS_SQL = """ create table books(id integer primary key, title varchar, author integer, genre integer, year integer, rating integer) @@ -48,6 +49,7 @@ INSERT_BOOK_SQL = """ values(?, ?, ?, ?, ?) """ + def init_db(): """ init_db() @@ -74,12 +76,12 @@ def init_db(): greeneId = add_author(q, "Graham Greene", date(1904, 10, 2)) pratchettId = add_author(q, "Terry Pratchett", date(1948, 4, 28)) - check(q.prepare,INSERT_GENRE_SQL) + check(q.prepare, INSERT_GENRE_SQL) sfiction = add_genre(q, "Science Fiction") fiction = add_genre(q, "Fiction") fantasy = add_genre(q, "Fantasy") - check(q.prepare,INSERT_BOOK_SQL) + check(q.prepare, INSERT_BOOK_SQL) add_book(q, "Foundation", 1951, asimovId, sfiction, 3) add_book(q, "Foundation and Empire", 1952, asimovId, sfiction, 4) add_book(q, "Second Foundation", 1953, asimovId, sfiction, 3) diff --git a/sources/pyside6/doc/tutorials/portingguide/chapter3/main.py b/sources/pyside6/doc/tutorials/portingguide/chapter3/main.py index 9af868772..4b4aee1a3 100644 --- a/sources/pyside6/doc/tutorials/portingguide/chapter3/main.py +++ b/sources/pyside6/doc/tutorials/portingguide/chapter3/main.py @@ -5,7 +5,7 @@ from __future__ import annotations import sys from PySide6.QtWidgets import QApplication from bookwindow import BookWindow -import rc_books +import rc_books # noqa: F401 if __name__ == "__main__": app = QApplication([]) diff --git a/sources/pyside6/doc/tutorials/portingguide/hello_world_ex.py b/sources/pyside6/doc/tutorials/portingguide/hello_world_ex.py index 3b234bdf8..c4df30060 100644 --- a/sources/pyside6/doc/tutorials/portingguide/hello_world_ex.py +++ b/sources/pyside6/doc/tutorials/portingguide/hello_world_ex.py @@ -5,10 +5,10 @@ from __future__ import annotations import sys import random -from PySide6.QtWidgets import (QApplication, QLabel, - QPushButton, QVBoxLayout, QWidget) +from PySide6.QtWidgets import QApplication, QLabel, QPushButton, QVBoxLayout, QWidget from PySide6.QtCore import Qt, Slot + class MyWidget(QWidget): def __init__(self): super().__init__() @@ -30,6 +30,7 @@ class MyWidget(QWidget): def magic(self): self.text.setText(random.choice(self.hello)) + if __name__ == "__main__": app = QApplication(sys.argv) |
