diff options
Diffstat (limited to 'examples/widgets/mainwindows/dockwidgets/dockwidgets.py')
-rw-r--r-- | examples/widgets/mainwindows/dockwidgets/dockwidgets.py | 125 |
1 files changed, 44 insertions, 81 deletions
diff --git a/examples/widgets/mainwindows/dockwidgets/dockwidgets.py b/examples/widgets/mainwindows/dockwidgets/dockwidgets.py index 61b1dd781..83487ee58 100644 --- a/examples/widgets/mainwindows/dockwidgets/dockwidgets.py +++ b/examples/widgets/mainwindows/dockwidgets/dockwidgets.py @@ -1,57 +1,21 @@ +# Copyright (C) 2013 Riverbank Computing Limited. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -############################################################################# -## -## Copyright (C) 2013 Riverbank Computing Limited. -## Copyright (C) 2021 The Qt Company Ltd. -## Contact: http://www.qt.io/licensing/ -## -## This file is part of the Qt for Python examples of the Qt Toolkit. -## -## $QT_BEGIN_LICENSE:BSD$ -## You may use this file under the terms of the BSD license as follows: -## -## "Redistribution and use in source and binary forms, with or without -## modification, are permitted provided that the following conditions are -## met: -## * Redistributions of source code must retain the above copyright -## notice, this list of conditions and the following disclaimer. -## * Redistributions in binary form must reproduce the above copyright -## notice, this list of conditions and the following disclaimer in -## the documentation and/or other materials provided with the -## distribution. -## * Neither the name of The Qt Company Ltd nor the names of its -## contributors may be used to endorse or promote products derived -## from this software without specific prior written permission. -## -## -## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -## -## $QT_END_LICENSE$ -## -############################################################################# - -"""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 from PySide6.QtCore import QDate, QFile, Qt, QTextStream from PySide6.QtGui import (QAction, QFont, QIcon, QKeySequence, - QTextCharFormat, QTextCursor, QTextTableFormat) + QTextCharFormat, QTextCursor, QTextTableFormat) from PySide6.QtPrintSupport import QPrintDialog, QPrinter from PySide6.QtWidgets import (QApplication, QDialog, QDockWidget, - QFileDialog, QListWidget, QMainWindow, QMessageBox, QTextEdit) + QFileDialog, QListWidget, QMainWindow, + QMessageBox, QTextEdit) -import dockwidgets_rc +import dockwidgets_rc # noqa: F401 class MainWindow(QMainWindow): @@ -100,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) @@ -141,13 +104,12 @@ class MainWindow(QMainWindow): if not file.open(QFile.WriteOnly | QFile.Text): reason = file.errorString() QMessageBox.warning(self, "Dock Widgets", - "Cannot write file {filename}:\n{reason}.") + f"Cannot write file {filename}:\n{reason}.") return out = QTextStream(file) - QApplication.setOverrideCursor(Qt.WaitCursor) - out << self._text_edit.toHtml() - QApplication.restoreOverrideCursor() + with QApplication.setOverrideCursor(Qt.WaitCursor): + out << self._text_edit.toHtml() self.statusBar().showMessage(f"Saved '{filename}'", 2000) @@ -182,8 +144,8 @@ class MainWindow(QMainWindow): if cursor.isNull(): return cursor.beginEditBlock() - cursor.movePosition(QTextCursor.PreviousBlock, QTextCursor.MoveAnchor, - 2) + cursor.movePosition(QTextCursor.PreviousBlock, + QTextCursor.MoveAnchor, 2) cursor.insertBlock() cursor.insertText(paragraph) cursor.insertBlock() @@ -191,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") @@ -280,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()) |