Results 1 to 11 of 11

Thread: unfreezing GUI

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Default unfreezing GUI

    Is it true that to unfreeze a GUI one should use qthread whlie working in a pyqt framework ?

    If that is true then when a user clicks "OK" control should go to another thread passing a def from GUI. ( in the script attached )

    and ok button change to "processing"

    Googling for qthreads has helped build code to this level. However, my code does not work as required.

    I have tried two ways. One is while the GUI freezes to display "processing " on ok button so that user knows something is going on.

    Best would be to pass the task that takes time to another thread. None work .

    Kindly suggest what I am missing.



    Qt Code:
    1. #!/usr/bin/env python
    2. import sys
    3. import os, time
    4. from PyQt4 import QtCore, QtGui
    5. from backUpUi import Ui_MainWindow
    6.  
    7. class setText01Thread(QtCore.QThread):
    8.  
    9. def __init__(self, mw):
    10. super(setText01Thread, self).__init__(mw)
    11.  
    12. def run(self):
    13. self.emit(QtCore.SIGNAL('setStatus'))
    14.  
    15. class backUpMain(QtGui.QMainWindow):
    16.  
    17. """UI functionality to pack stuff for client"""
    18. def __init__(self,parent=None):
    19. super(backUpMain, self).__init__(parent)
    20. self.ui = Ui_MainWindow()
    21. self.ui.setupUi(self)
    22.  
    23. self.connect(self.ui.okButton, QtCore.SIGNAL("clicked()"), self._handlebackUp)
    24. self.ui.cancelButton.released.connect(self.close)
    25. self.statusTh = setText01Thread(self)
    26. self.connect(self.statusTh, QtCore.SIGNAL('setStatus'), self.updateText_01,QtCore.Qt.QueuedConnection)
    27.  
    28. def updateText_01(self):
    29. self.ui.okButton.setText("Processing Started")
    30.  
    31. def _handlebackUp(self):
    32.  
    33. self.statusTh.start()
    34. self.ui.logEdit.clear()
    35. .
    36. .
    37. outPutFileName = self.ui.outEdit.text()
    38. inputData = self.getInputContent(self.ui.filePathEdit.text())
    39.  
    40. # indPath = self.getIndPathFromShotgun(projectId,"sg_ind_path_to_frames")
    41. # the above line takes a long time to execute. Can this def be executed in another
    42. # thread
    43. .
    44. .
    45. .
    46.  
    47. def main():
    48. app = QtGui.QApplication(sys.argv)
    49. dialog = backUpMain()
    50. dialog.show()
    51. sys.exit(app.exec_())
    52.  
    53. if __name__ == '__main__':
    54. main()
    To copy to clipboard, switch view to plain text mode 
    Last edited by anda_skoa; 24th January 2015 at 09:57. Reason: missing [code] tags

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.