I am building a tiny tool that does file operations at session startup. In order to make sure the user has a visual feedback, I want to associate it with a progress bar.
Here I am so far:
import sys
import time
from PySide.QtGui import *
class ProgressWindowWidget(QWidget):
def __init__(self, parent=None):
super(ProgressWindowWidget, self).__init__()
self.init_ui()
def init_ui(self):
self.setGeometry(500, 500, 600, 100)
self.setWindowTitle('Progress')
self.layout_ = QGridLayout()
self.setLayout(self.layout_)
self.progress_bar = QProgressBar()
self.layout_.addWidget(self.progress_bar, 0, 0, 1, 1)
def my_operations(self):
print('do something 1')
time.sleep(2)
print('do something 2')
time.sleep(2)
print('do something 3')
time.sleep(2)
def main():
app = QApplication(sys.argv)
progress_window = ProgressWindowWidget()
progress_window.show()
progress_window.my_operations()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
My problem is that my_operations
is executed first and then my GUI is loaded. I'd like to execute my_operations
only when the progress bar is loaded, so I can update it.
According to this, it has something to do with the exec_ main
loop, but there's obviously something I don't understand here because I am calling my_operations
after show
.
Needless to say, I'm a beginner. Does anyone have an idea? Cheers