aboutsummaryrefslogtreecommitdiffstats
path: root/examples/widgets/dialogs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/widgets/dialogs')
-rw-r--r--examples/widgets/dialogs/classwizard/classwizard.py6
-rw-r--r--examples/widgets/dialogs/classwizard/classwizard.pyproject3
-rw-r--r--examples/widgets/dialogs/classwizard/listchooser.py2
-rw-r--r--examples/widgets/dialogs/findfiles/findfiles.py184
-rw-r--r--examples/widgets/dialogs/findfiles/findfiles.pyproject3
-rw-r--r--examples/widgets/dialogs/standarddialogs/standarddialogs.py122
-rw-r--r--examples/widgets/dialogs/trivialwizard/trivialwizard.py2
7 files changed, 78 insertions, 244 deletions
diff --git a/examples/widgets/dialogs/classwizard/classwizard.py b/examples/widgets/dialogs/classwizard/classwizard.py
index b657308e0..0efbde69f 100644
--- a/examples/widgets/dialogs/classwizard/classwizard.py
+++ b/examples/widgets/dialogs/classwizard/classwizard.py
@@ -13,9 +13,9 @@ from PySide6.QtWidgets import (QApplication, QComboBox, QCheckBox, QFormLayout,
QMessageBox, QToolButton, QVBoxLayout, QWizard,
QWizardPage)
-from listchooser import ListChooser, PropertyChooser, SignalChooser
+from listchooser import PropertyChooser, SignalChooser
-import classwizard_rc
+import classwizard_rc # noqa: F401
BASE_CLASSES = ['<None>', 'PySide6.QtCore.QObject',
@@ -333,7 +333,7 @@ class OutputFilesPage(QWizardPage):
def _choose_output_dir(self):
directory = QFileDialog.getExistingDirectory(self, "Output Directory",
- self.output_dir())
+ self.output_dir())
if directory:
self.set_output_dir(directory)
diff --git a/examples/widgets/dialogs/classwizard/classwizard.pyproject b/examples/widgets/dialogs/classwizard/classwizard.pyproject
index 6086099b8..fcc96ef28 100644
--- a/examples/widgets/dialogs/classwizard/classwizard.pyproject
+++ b/examples/widgets/dialogs/classwizard/classwizard.pyproject
@@ -1,4 +1,3 @@
{
- "files": ["classwizard.qrc", "classwizard.py", "classwizard_rc.py",
- "listchooser.py", "classwizard_rc.pyc"]
+ "files": ["classwizard.qrc", "classwizard.py", "listchooser.py"]
}
diff --git a/examples/widgets/dialogs/classwizard/listchooser.py b/examples/widgets/dialogs/classwizard/listchooser.py
index bf15be88c..6bf47c6d1 100644
--- a/examples/widgets/dialogs/classwizard/listchooser.py
+++ b/examples/widgets/dialogs/classwizard/listchooser.py
@@ -27,7 +27,7 @@ class ValidatingInputDialog(QDialog):
self._lineedit = QLineEdit()
self._lineedit.setClearButtonEnabled(True)
re = QRegularExpression(pattern)
- assert(re.isValid())
+ assert re.isValid()
self._validator = QRegularExpressionValidator(re, self)
self._lineedit.setValidator(self._validator)
self._form_layout.addRow(label, self._lineedit)
diff --git a/examples/widgets/dialogs/findfiles/findfiles.py b/examples/widgets/dialogs/findfiles/findfiles.py
deleted file mode 100644
index 7f2093c42..000000000
--- a/examples/widgets/dialogs/findfiles/findfiles.py
+++ /dev/null
@@ -1,184 +0,0 @@
-# Copyright (C) 2013 Riverbank Computing Limited.
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-"""PySide6 port of the widgets/dialogs/findfiles example from Qt v5.x"""
-
-import sys
-
-from PySide6.QtCore import (QCoreApplication, QDir, QFile, QFileInfo,
- QIODevice, QTextStream, QUrl, Qt)
-from PySide6.QtGui import QDesktopServices
-from PySide6.QtWidgets import (QAbstractItemView, QApplication, QComboBox,
- QDialog, QFileDialog, QGridLayout, QHBoxLayout,
- QHeaderView, QLabel, QProgressDialog,
- QPushButton, QSizePolicy, QTableWidget,
- QTableWidgetItem)
-
-
-class Window(QDialog):
- def __init__(self, parent=None):
- super().__init__(parent)
-
- self._browse_button = self.create_button("&Browse...", self.browse)
- self._find_button = self.create_button("&Find", self.find)
-
- self._file_combo_box = self.create_combo_box("*")
- self._text_combo_box = self.create_combo_box()
- self._directory_combo_box = self.create_combo_box(QDir.currentPath())
-
- file_label = QLabel("Named:")
- text_label = QLabel("Containing text:")
- directory_label = QLabel("In directory:")
- self._files_found_label = QLabel()
-
- self.create_files_table()
-
- buttons_layout = QHBoxLayout()
- buttons_layout.addStretch()
- buttons_layout.addWidget(self._find_button)
-
- main_layout = QGridLayout()
- main_layout.addWidget(file_label, 0, 0)
- main_layout.addWidget(self._file_combo_box, 0, 1, 1, 2)
- main_layout.addWidget(text_label, 1, 0)
- main_layout.addWidget(self._text_combo_box, 1, 1, 1, 2)
- main_layout.addWidget(directory_label, 2, 0)
- main_layout.addWidget(self._directory_combo_box, 2, 1)
- main_layout.addWidget(self._browse_button, 2, 2)
- main_layout.addWidget(self._files_table, 3, 0, 1, 3)
- main_layout.addWidget(self._files_found_label, 4, 0)
- main_layout.addLayout(buttons_layout, 5, 0, 1, 3)
- self.setLayout(main_layout)
-
- self.setWindowTitle("Find Files")
- self.resize(500, 300)
-
- def browse(self):
- directory = QFileDialog.getExistingDirectory(self, "Find Files",
- QDir.currentPath())
-
- if directory:
- if self._directory_combo_box.findText(directory) == -1:
- self._directory_combo_box.addItem(directory)
-
- self._directory_combo_box.setCurrentIndex(self._directory_combo_box.findText(directory))
-
- @staticmethod
- def update_combo_box(comboBox):
- if comboBox.findText(comboBox.currentText()) == -1:
- comboBox.addItem(comboBox.currentText())
-
- def find(self):
- self._files_table.setRowCount(0)
-
- file_name = self._file_combo_box.currentText()
- text = self._text_combo_box.currentText()
- path = self._directory_combo_box.currentText()
-
- self.update_combo_box(self._file_combo_box)
- self.update_combo_box(self._text_combo_box)
- self.update_combo_box(self._directory_combo_box)
-
- self._current_dir = QDir(path)
- if not file_name:
- file_name = "*"
- files = self._current_dir.entryList([file_name],
- QDir.Files | QDir.NoSymLinks)
-
- if text:
- files = self.find_files(files, text)
- self.show_files(files)
-
- def find_files(self, files, text):
- progress_dialog = QProgressDialog(self)
-
- progress_dialog.setCancelButtonText("&Cancel")
- progress_dialog.setRange(0, len(files))
- progress_dialog.setWindowTitle("Find Files")
-
- found_files = []
-
- for i in range(len(files)):
- progress_dialog.setValue(i)
- n = len(files)
- progress_dialog.setLabelText(f"Searching file number {i} of {n}...")
- QCoreApplication.processEvents()
-
- if progress_dialog.wasCanceled():
- break
-
- in_file = QFile(self._current_dir.absoluteFilePath(files[i]))
-
- if in_file.open(QIODevice.ReadOnly):
- stream = QTextStream(in_file)
- while not stream.atEnd():
- if progress_dialog.wasCanceled():
- break
- line = stream.readLine()
- if text in line:
- found_files.append(files[i])
- break
-
- progress_dialog.close()
-
- return found_files
-
- def show_files(self, files):
- for fn in files:
- file = QFile(self._current_dir.absoluteFilePath(fn))
- size = QFileInfo(file).size()
-
- file_name_item = QTableWidgetItem(fn)
- file_name_item.setFlags(file_name_item.flags() ^ Qt.ItemIsEditable)
- size_kb = int((size + 1023) / 1024)
- size_item = QTableWidgetItem(f"{size_kb} KB")
- size_item.setTextAlignment(Qt.AlignVCenter | Qt.AlignRight)
- size_item.setFlags(size_item.flags() ^ Qt.ItemIsEditable)
-
- row = self._files_table.rowCount()
- self._files_table.insertRow(row)
- self._files_table.setItem(row, 0, file_name_item)
- self._files_table.setItem(row, 1, size_item)
-
- n = len(files)
- self._files_found_label.setText(f"{n} file(s) found (Double click on a file to open it)")
-
- def create_button(self, text, member):
- button = QPushButton(text)
- button.clicked.connect(member)
- return button
-
- def create_combo_box(self, text=""):
- combo_box = QComboBox()
- combo_box.setEditable(True)
- combo_box.addItem(text)
- combo_box.setSizePolicy(QSizePolicy.Expanding,
- QSizePolicy.Preferred)
- return combo_box
-
- def create_files_table(self):
- self._files_table = QTableWidget(0, 2)
- self._files_table.setSelectionBehavior(QAbstractItemView.SelectRows)
-
- self._files_table.setHorizontalHeaderLabels(("File Name", "Size"))
- self._files_table.horizontalHeader().setSectionResizeMode(0, QHeaderView.Stretch)
- self._files_table.verticalHeader().hide()
- self._files_table.setShowGrid(False)
-
- self._files_table.cellActivated.connect(self.open_file_of_item)
-
- def open_file_of_item(self, row, column):
- item = self._files_table.item(row, 0)
-
- QDesktopServices.openUrl(QUrl(self._current_dir.absoluteFilePath(item.text())))
-
-
-if __name__ == '__main__':
-
- import sys
-
- app = QApplication(sys.argv)
- window = Window()
- window.show()
- sys.exit(app.exec())
diff --git a/examples/widgets/dialogs/findfiles/findfiles.pyproject b/examples/widgets/dialogs/findfiles/findfiles.pyproject
deleted file mode 100644
index c2fae6dff..000000000
--- a/examples/widgets/dialogs/findfiles/findfiles.pyproject
+++ /dev/null
@@ -1,3 +0,0 @@
-{
- "files": ["findfiles.py"]
-}
diff --git a/examples/widgets/dialogs/standarddialogs/standarddialogs.py b/examples/widgets/dialogs/standarddialogs/standarddialogs.py
index 94a5eec52..ef677d5a8 100644
--- a/examples/widgets/dialogs/standarddialogs/standarddialogs.py
+++ b/examples/widgets/dialogs/standarddialogs/standarddialogs.py
@@ -5,6 +5,8 @@
"""PySide6 port of the widgets/dialogs/standarddialogs example from Qt v5.x"""
import sys
+from textwrap import dedent
+
from PySide6.QtCore import QDir, Qt, Slot
from PySide6.QtGui import QFont, QPalette
from PySide6.QtWidgets import (QApplication, QColorDialog, QCheckBox, QDialog,
@@ -37,10 +39,6 @@ class DialogOptionsWidget(QGroupBox):
class Dialog(QDialog):
- MESSAGE = ("<p>Message boxes have a caption, a text, and up to three "
- "buttons, each with standard or custom texts.</p>"
- "<p>Click a button to close the message box. Pressing the Esc "
- "button will activate the detected escape button (if any).</p>")
def __init__(self, parent=None):
super().__init__(parent)
@@ -143,8 +141,6 @@ class Dialog(QDialog):
self._warning_label.setFrameStyle(frame_style)
self._warning_button = QPushButton("QMessageBox.&warning()")
- self._error_label = QLabel()
- self._error_label.setFrameStyle(frame_style)
self._error_button = QPushButton("QErrorMessage.showM&essage()")
self._integer_button.clicked.connect(self.set_integer)
@@ -230,7 +226,6 @@ class Dialog(QDialog):
layout.addWidget(self._warning_button, 3, 0)
layout.addWidget(self._warning_label, 3, 1)
layout.addWidget(self._error_button, 4, 0)
- layout.addWidget(self._error_label, 4, 1)
spacer = QSpacerItem(0, 0, QSizePolicy.Ignored, QSizePolicy.MinimumExpanding)
layout.addItem(spacer, 5, 0)
toolbox.addItem(page, "Message Boxes")
@@ -240,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}")
@@ -255,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)
@@ -306,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)
@@ -317,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)
@@ -329,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)
@@ -342,18 +333,24 @@ 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)
@Slot()
def critical_message(self):
- reply = QMessageBox.critical(self, "QMessageBox.critical()",
- Dialog.MESSAGE,
- QMessageBox.Abort | QMessageBox.Retry | QMessageBox.Ignore)
+ m = dedent("""\
+ Activating the liquid oxygen stirring fans caused an
+ explosion in one of the tanks. Liquid oxygen levels
+ are getting low. This may jeopardize the moon landing mission.""")
+ msg_box = QMessageBox(QMessageBox.Critical, "QMessageBox.critical()",
+ "Houston, we have a problem",
+ QMessageBox.Abort | QMessageBox.Retry | QMessageBox.Ignore,
+ self)
+ msg_box.setInformativeText(m)
+ reply = msg_box.exec()
if reply == QMessageBox.Abort:
self._critical_label.setText("Abort")
elif reply == QMessageBox.Retry:
@@ -363,8 +360,16 @@ class Dialog(QDialog):
@Slot()
def information_message(self):
- reply = QMessageBox.information(self,
- "QMessageBox.information()", Dialog.MESSAGE)
+ m = dedent("""\
+ This phrase was often used by public address announcers at
+ the conclusion of Elvis Presley concerts in order to
+ disperse audiences who lingered in hopes of an encore.
+ It has since become a catchphrase and punchline.""")
+ msg_box = QMessageBox(QMessageBox.Information, "QMessageBox.information()",
+ "Elvis has left the building.",
+ QMessageBox.Ok, self)
+ msg_box.setInformativeText(m)
+ reply = msg_box.exec()
if reply == QMessageBox.Ok:
self._information_label.setText("OK")
else:
@@ -372,9 +377,17 @@ class Dialog(QDialog):
@Slot()
def question_message(self):
- reply = QMessageBox.question(self, "QMessageBox.question()",
- Dialog.MESSAGE,
- QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel)
+ m = dedent("""\
+ A cheeseburger is a hamburger topped with cheese.
+ Traditionally, the slice of cheese is placed on top of the
+ meat patty. The cheese is usually added to the cooking
+ hamburger patty shortly before serving, which allows the
+ cheese to melt.""")
+ msg_box = QMessageBox(QMessageBox.Question, "QMessageBox.question()",
+ "Would you like cheese with that?",
+ QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel)
+ msg_box.setInformativeText(m)
+ reply = msg_box.exec()
if reply == QMessageBox.Yes:
self._question_label.setText("Yes")
elif reply == QMessageBox.No:
@@ -384,25 +397,34 @@ class Dialog(QDialog):
@Slot()
def warning_message(self):
- msg_box = QMessageBox(QMessageBox.Warning,
- "QMessageBox.warning()", Dialog.MESSAGE,
- QMessageBox.NoButton, self)
- msg_box.addButton("Save &Again", QMessageBox.AcceptRole)
- msg_box.addButton("&Continue", QMessageBox.RejectRole)
+ msg_box = QMessageBox(QMessageBox.Warning, "QMessageBox.warning()",
+ "Delete the only copy of your movie manuscript?",
+ QMessageBox.NoButton, self)
+ m = "You've been working on this manuscript for 738 days now. Hang in there!"
+ msg_box.setInformativeText(m)
+ msg_box.setDetailedText('"A long time ago in a galaxy far, far away...."')
+ msg_box.addButton("&Keep", QMessageBox.AcceptRole)
+ msg_box.addButton("Delete", QMessageBox.RejectRole)
if msg_box.exec() == QMessageBox.AcceptRole:
- self._warning_label.setText("Save Again")
+ self._warning_label.setText("Keep")
else:
- self._warning_label.setText("Continue")
+ self._warning_label.setText("Delete")
@Slot()
def error_message(self):
- self._error_message_dialog.showMessage("This dialog shows and remembers "
- "error messages. If the checkbox is checked (as it is by "
- "default), the shown message will be shown again, but if the "
- "user unchecks the box the message will not appear again if "
- "QErrorMessage.showMessage() is called with the same message.")
- self._error_label.setText("If the box is unchecked, the message won't "
- "appear again.")
+ m = dedent("""\
+ This dialog shows and remembers error messages. If the
+ user chooses to not show the dialog again, the dialog
+ will not appear again if QErrorMessage.showMessage()
+ is called with the same message.""")
+ self._error_message_dialog.showMessage(m)
+ m = dedent("""\
+ You can queue up error messages, and they will be
+ shown one after each other. Each message maintains
+ its own state for whether it will be shown again
+ the next time QErrorMessage::showMessage() is called
+ with the same message.""")
+ self._error_message_dialog.showMessage(m)
if __name__ == '__main__':
diff --git a/examples/widgets/dialogs/trivialwizard/trivialwizard.py b/examples/widgets/dialogs/trivialwizard/trivialwizard.py
index 0eb9fb567..2e551ae19 100644
--- a/examples/widgets/dialogs/trivialwizard/trivialwizard.py
+++ b/examples/widgets/dialogs/trivialwizard/trivialwizard.py
@@ -15,7 +15,7 @@ def create_intro_page():
page.setTitle("Introduction")
label = QLabel("This wizard will help you register your copy of "
- "Super Product Two.")
+ "Super Product Two.")
label.setWordWrap(True)
layout = QVBoxLayout(page)