I am kind of new to Python and especially new to PyQT. I Used PyQT5 to create a very simple gui. Now, I would like to upgrade it to involve something more real then to calculate number operations.
I want a user to choose a directory with images. After that and some other small operations like ticking some check boxes I want to run an algorithm of mine in the background and in the mean while to show him/her the progress via a progressBar.
This is my code right now:
import sys
from os.path import expanduser
from PyQt5.QtWidgets import QMainWindow, QApplication
from PyQt5 import uic, QtGui
Ui_MainWindow, QtBaseClass = uic.loadUiType("mainGui_3A.ui")
class MyApp(QMainWindow):
def __init__(self):
super(MyApp, self).__init__()
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.ui.pushButton_Directory.clicked.connect(self.choose_directory)
self.ui.pushButton_CreateAlbum.clicked.connect(self.create_album)
def choose_directory(self):
my_dir = QtGui.QFileDialog.getExistingDirectory(
self,
"Open a folder",
expanduser("~"),
QtGui.QFileDialog.ShowDirsOnly
)
self.ui.lineEdit_Directory.setText(my_dir)
def create_album(self):
current_dir = self.ui.lineEdit_Directory.toPlainText()
check1 = self.ui.checkBox_1.value()
check2 = self.ui.checkBox_2.value()
return current_dir, check1, check2
if __name__ == "__main__":
app = QApplication(sys.argv)
window = MyApp()
window.show()
sys.exit(app.exec_())
I have looked at :
PYQT - How to open a directory folder?
PyQt: QFileDialog.getExistingDirectory using a default directory, user independant
as you can see I still didn't add the last bit since the error below but I think I need to look into:
Example of the right way to use QThread in PyQt?
Change the value of the progress bar from a class other than my GUI class PyQt4
There is no error at first. the ui is loaded currectly I believe but as soon as I click one of my buttons the program stop running.. what did I do wrong? do I need to use threads to choose the directory?
Any tips for the future would be welcomed!
Thanks in advance!