def __init__(self): super(FileChooser, self).__init__() # Setup ui self.ui = Ui_FileChooser() self.ui.setupUi(self) self.path = QtCore.QString() self.mode = self.DIR # Connect signals and slots #self.connect(self.ui.browseButton, QtCore.SIGNAL('clicked()'), self.chooseFile) self.ui.browseButton.clicked.connect(self.chooseFile)
class FileChooser(QtGui.QWidget): DIR = 0 FILE = 1 pathChanged = QtCore.pyqtSignal() def __init__(self): super(FileChooser, self).__init__() # Setup ui self.ui = Ui_FileChooser() self.ui.setupUi(self) self.path = QtCore.QString() self.mode = self.DIR # Connect signals and slots #self.connect(self.ui.browseButton, QtCore.SIGNAL('clicked()'), self.chooseFile) self.ui.browseButton.clicked.connect(self.chooseFile) def get_path(self): return self.__path def set_path(self, value): self.__path = value self.pathChanged.emit() path = QtCore.pyqtProperty(QtCore.QString, get_path, set_path) @QtCore.pyqtSlot() def chooseFile(self): if self.mode == self.DIR: self.path = QtGui.QFileDialog.getExistingDirectory(self) else: self.path = QtGui.QFileDialog.getOpenFileName(self) if self.path: self.ui.pathLine.setText(self.path)