Here is an example using signals/slots
On 11/12/13 09:56, Janwillem van Dijk wrote:
Here is the snippet: It reads the filenames in a folder and determines
new names for photo's based on the exif info.
I apreciate that threading might be a solution but the problem seems
too simple for that. Can you give an example on how to use the signal
concept?
self.outFolder = QFileDialog.getExistingDirectory(
caption='Destination folder', dir=self.defOutFolder)
self.outFiles = []
if self.outFolder:
self.outFolder = self.outFolder.replace('\\', '/')
self.lineEdit_dest.setText(self.outFolder)
self.progressBar.setRange(0, self.numFiles)
for i, fname in enumerate(self.inFiles):
self.progressBar.setValue(i + 1)
newpath, newfname = rename_photo(self.inFolder, fname)
newpath = path.join(self.outFolder, newpath)
self.outFiles.append([fname, newpath, newfname])
s = fname + ' --> ' + self.outFolder + '\n'
s += path.join(newpath, newfname).replace(self.outFolder, '')
self.plainTextEdit_dest.appendPlainText(s)
On 10/12/13 21:35, Sean Fisk wrote:
Hi Janwillem,
Are you running the “lengthy part that processes a files list” within
the GUI thread? If so, you will probably see your GUI hang while this
is happening (you won’t be able to click or do anything). In this
case, you should consider running the processing in a different
thread using QThread
<http://seanfisk.github.io/pyside-docs/pyside/PySide/QtCore/QThread.html>
or QThreadPool
<http://seanfisk.github.io/pyside-docs/pyside/PySide/QtCore/QThreadPool.html>.
Can you post the relevant part of the code?
Thanks,
--
Sean Fisk
On Tue, Dec 10, 2013 at 3:17 PM, Janwillem van Dijk
<[email protected] <mailto:[email protected]>> wrote:
Hi, I have a PySide script that uses
QFileDialog.getExistingDirectory(). After clicking the Open
button the script proceeds with a lengthy part that processes a
files list and writes to a QPlainTextEdit. Unfortunately the
QFileDialog widget does only disappear after this processing is
finished, hiding the QPlainTextEdit.
How can I make that the QFileDialog widget is gone before the
processing starts?
Cheers, Janwillem
_______________________________________________
PySide mailing list
[email protected] <mailto:[email protected]>
http://lists.qt-project.org/mailman/listinfo/pyside
from PySide import QtGui
import time
import os
class MyWidget(QtGui.QWidget):
def __init__(self, parent=None):
super(MyWidget, self).__init__(parent)
self.defOutFolder = os.getcwd()
self.setupUI()
self.connectSignalsAndSlots()
def setupUI(self):
self.setLayout(QtGui.QVBoxLayout())
self.btn = QtGui.QPushButton('get output directory')
self.progressbar = QtGui.QProgressBar()
self.progressbar.setMaximum(10)
self.layout().addWidget(self.btn)
self.layout().addWidget(self.progressbar)
self.fileBrowser = QtGui.QFileDialog()
self.fileBrowser.setFileMode(QtGui.QFileDialog.Directory)
def getOutDir(self):
self.fileBrowser.exec_()
def connectSignalsAndSlots(self):
self.btn.clicked.connect(self.getOutDir)
self.fileBrowser.finished.connect(self.processFiles)
def processFiles(self):
'''put file processing here'''
for i in xrange(10):
print i
self.progressbar.setValue(i + 1)
time.sleep(.5)
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
w = MyWidget()
w.show()
sys.exit(app.exec_())_______________________________________________
PySide mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/pyside