diff options
Diffstat (limited to 'sources/pyside6/doc/tutorials/portingguide')
10 files changed, 45 insertions, 45 deletions
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) |
