aboutsummaryrefslogtreecommitdiffstats
path: root/examples/dialogs/findfiles.py
diff options
context:
space:
mode:
Diffstat (limited to 'examples/dialogs/findfiles.py')
-rwxr-xr-xexamples/dialogs/findfiles.py91
1 files changed, 66 insertions, 25 deletions
diff --git a/examples/dialogs/findfiles.py b/examples/dialogs/findfiles.py
index c3b01ee..cc41033 100755
--- a/examples/dialogs/findfiles.py
+++ b/examples/dialogs/findfiles.py
@@ -1,11 +1,52 @@
#!/usr/bin/env python
-"""PyQt4 port of the dialogs/findfiles example from Qt v4.x"""
-
-from PySide2 import QtCore, QtGui
-
-
-class Window(QtGui.QDialog):
+#############################################################################
+##
+## Copyright (C) 2013 Riverbank Computing Limited.
+## Copyright (C) 2016 The Qt Company Ltd.
+## Contact: http://www.qt.io/licensing/
+##
+## This file is part of the PySide 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$
+##
+#############################################################################
+
+"""PySide2 port of the widgets/dialogs/findfiles example from Qt v5.x"""
+
+from PySide2 import QtCore, QtGui, QtWidgets
+
+
+class Window(QtWidgets.QDialog):
def __init__(self, parent=None):
super(Window, self).__init__(parent)
@@ -16,18 +57,18 @@ class Window(QtGui.QDialog):
self.textComboBox = self.createComboBox()
self.directoryComboBox = self.createComboBox(QtCore.QDir.currentPath())
- fileLabel = QtGui.QLabel("Named:")
- textLabel = QtGui.QLabel("Containing text:")
- directoryLabel = QtGui.QLabel("In directory:")
- self.filesFoundLabel = QtGui.QLabel()
+ fileLabel = QtWidgets.QLabel("Named:")
+ textLabel = QtWidgets.QLabel("Containing text:")
+ directoryLabel = QtWidgets.QLabel("In directory:")
+ self.filesFoundLabel = QtWidgets.QLabel()
self.createFilesTable()
- buttonsLayout = QtGui.QHBoxLayout()
+ buttonsLayout = QtWidgets.QHBoxLayout()
buttonsLayout.addStretch()
buttonsLayout.addWidget(self.findButton)
- mainLayout = QtGui.QGridLayout()
+ mainLayout = QtWidgets.QGridLayout()
mainLayout.addWidget(fileLabel, 0, 0)
mainLayout.addWidget(self.fileComboBox, 0, 1, 1, 2)
mainLayout.addWidget(textLabel, 1, 0)
@@ -44,7 +85,7 @@ class Window(QtGui.QDialog):
self.resize(500, 300)
def browse(self):
- directory = QtGui.QFileDialog.getExistingDirectory(self, "Find Files",
+ directory = QtWidgets.QFileDialog.getExistingDirectory(self, "Find Files",
QtCore.QDir.currentPath())
if directory:
@@ -80,7 +121,7 @@ class Window(QtGui.QDialog):
self.showFiles(files)
def findFiles(self, files, text):
- progressDialog = QtGui.QProgressDialog(self)
+ progressDialog = QtWidgets.QProgressDialog(self)
progressDialog.setCancelButtonText("&Cancel")
progressDialog.setRange(0, len(files))
@@ -91,7 +132,7 @@ class Window(QtGui.QDialog):
for i in range(len(files)):
progressDialog.setValue(i)
progressDialog.setLabelText("Searching file number %d of %d..." % (i, len(files)))
- QtGui.qApp.processEvents()
+ QtCore.qApp.processEvents()
if progressDialog.wasCanceled():
break
@@ -117,9 +158,9 @@ class Window(QtGui.QDialog):
file = QtCore.QFile(self.currentDir.absoluteFilePath(fn))
size = QtCore.QFileInfo(file).size()
- fileNameItem = QtGui.QTableWidgetItem(fn)
+ fileNameItem = QtWidgets.QTableWidgetItem(fn)
fileNameItem.setFlags(fileNameItem.flags() ^ QtCore.Qt.ItemIsEditable)
- sizeItem = QtGui.QTableWidgetItem("%d KB" % (int((size + 1023) / 1024)))
+ sizeItem = QtWidgets.QTableWidgetItem("%d KB" % (int((size + 1023) / 1024)))
sizeItem.setTextAlignment(QtCore.Qt.AlignVCenter | QtCore.Qt.AlignRight)
sizeItem.setFlags(sizeItem.flags() ^ QtCore.Qt.ItemIsEditable)
@@ -131,24 +172,24 @@ class Window(QtGui.QDialog):
self.filesFoundLabel.setText("%d file(s) found (Double click on a file to open it)" % len(files))
def createButton(self, text, member):
- button = QtGui.QPushButton(text)
+ button = QtWidgets.QPushButton(text)
button.clicked.connect(member)
return button
def createComboBox(self, text=""):
- comboBox = QtGui.QComboBox()
+ comboBox = QtWidgets.QComboBox()
comboBox.setEditable(True)
comboBox.addItem(text)
- comboBox.setSizePolicy(QtGui.QSizePolicy.Expanding,
- QtGui.QSizePolicy.Preferred)
+ comboBox.setSizePolicy(QtWidgets.QSizePolicy.Expanding,
+ QtWidgets.QSizePolicy.Preferred)
return comboBox
def createFilesTable(self):
- self.filesTable = QtGui.QTableWidget(0, 2)
- self.filesTable.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
+ self.filesTable = QtWidgets.QTableWidget(0, 2)
+ self.filesTable.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows)
self.filesTable.setHorizontalHeaderLabels(("File Name", "Size"))
- self.filesTable.horizontalHeader().setResizeMode(0, QtGui.QHeaderView.Stretch)
+ self.filesTable.horizontalHeader().setSectionResizeMode(0, QtWidgets.QHeaderView.Stretch)
self.filesTable.verticalHeader().hide()
self.filesTable.setShowGrid(False)
@@ -164,7 +205,7 @@ if __name__ == '__main__':
import sys
- app = QtGui.QApplication(sys.argv)
+ app = QtWidgets.QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec_())