diff options
Diffstat (limited to 'sources/pyside6/doc/tutorials')
4 files changed, 28 insertions, 13 deletions
diff --git a/sources/pyside6/doc/tutorials/portingguide/chapter2/bookdelegate.py b/sources/pyside6/doc/tutorials/portingguide/chapter2/bookdelegate.py index d6c16972b..bebb40f50 100644 --- a/sources/pyside6/doc/tutorials/portingguide/chapter2/bookdelegate.py +++ b/sources/pyside6/doc/tutorials/portingguide/chapter2/bookdelegate.py @@ -38,20 +38,24 @@ ## ############################################################################# -import copy, os +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 + class BookDelegate(QSqlRelationalDelegate): """Books delegate to rate the books""" def __init__(self, parent=None): QSqlRelationalDelegate.__init__(self, parent) - star_png = os.path.dirname(__file__) + "\images\star.png" - self.star = QPixmap(star_png) + star_png = Path(__file__).parent / "images" / "star.png" + self.star = QPixmap(os.fspath(star_png)) def paint(self, painter, option, index): """ Paint the items in the table. diff --git a/sources/pyside6/doc/tutorials/portingguide/chapter3/bookdelegate-old.py b/sources/pyside6/doc/tutorials/portingguide/chapter3/bookdelegate-old.py index 0c0f1ee69..4b5009b32 100644 --- a/sources/pyside6/doc/tutorials/portingguide/chapter3/bookdelegate-old.py +++ b/sources/pyside6/doc/tutorials/portingguide/chapter3/bookdelegate-old.py @@ -38,20 +38,24 @@ ## ############################################################################# -import copy, os +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 + class BookDelegate(QSqlRelationalDelegate): """Books delegate to rate the books""" def __init__(self, star_png, parent=None): QSqlRelationalDelegate.__init__(self, parent) - star_png = os.path.dirname(__file__) + "\images\star.png" - self.star = QPixmap(star_png) + star_png = Path(__file__).parent / "images" / "star.png" + self.star = QPixmap(os.fspath(star_png)) def paint(self, painter, option, index): """ Paint the items in the table. diff --git a/sources/pyside6/doc/tutorials/qmlapp/main.py b/sources/pyside6/doc/tutorials/qmlapp/main.py index 5946538d9..c1c941835 100644 --- a/sources/pyside6/doc/tutorials/qmlapp/main.py +++ b/sources/pyside6/doc/tutorials/qmlapp/main.py @@ -41,12 +41,18 @@ #!/usr/bin/env python # -*- conding: utf-8 -*- -import os, sys, urllib.request, json +import os +import sys +import urllib.request +import json +from pathlib import Path + import PySide6.QtQml from PySide6.QtQuick import QQuickView from PySide6.QtCore import QStringListModel, Qt, QUrl from PySide6.QtGui import QGuiApplication + if __name__ == '__main__': #get our data @@ -66,11 +72,11 @@ if __name__ == '__main__': #Expose the list to the Qml code my_model = QStringListModel() my_model.setStringList(data_list) - view.rootContext().setContextProperty("myModel",my_model) + view.rootContext().setContextProperty("myModel", my_model) #Load the QML file - qml_file = os.path.join(os.path.dirname(__file__),"view.qml") - view.setSource(QUrl.fromLocalFile(os.path.abspath(qml_file))) + qml_file = Path(__file__).parent / "view.qml" + view.setSource(QUrl.fromLocalFile(os.fspath(qml_file.resolve()))) #Show the window if view.status() == QQuickView.Error: diff --git a/sources/pyside6/doc/tutorials/qmlintegration/main.py b/sources/pyside6/doc/tutorials/qmlintegration/main.py index 884d239b3..24a801851 100644 --- a/sources/pyside6/doc/tutorials/qmlintegration/main.py +++ b/sources/pyside6/doc/tutorials/qmlintegration/main.py @@ -39,7 +39,8 @@ ############################################################################# import sys -from os.path import abspath, dirname, join +import os +from pathlib import Path from PySide6.QtCore import QObject, Slot from PySide6.QtGui import QGuiApplication @@ -104,8 +105,8 @@ if __name__ == '__main__': # Get the path of the current directory, and then add the name # of the QML file, to load it. - qmlFile = join(dirname(__file__), 'view.qml') - engine.load(abspath(qmlFile)) + qmlFile = Path(__file__).parent / 'view.qml' + engine.load(os.fspath(qmlFile.resolve())) if not engine.rootObjects(): sys.exit(-1) |
