class FileSelector(QWidget): def __init__(self, title="Select file", filter="All files (*.*)", parent=None): """If filter contains a pair of parentheses containing one or more of anything*something, separated by spaces, then only the text contained in the parentheses is used as the filter. Equivalent filters: "All C++ files (*.cpp *.cc *.C *.cxx *.c++)" "*.cpp *.cc *.C *.cxx *.c++" filter can also be a set, tuple or list """ QWidget.__init__(self, parent) self.filter = filter self.title = title box = QHBoxLayout(self) self.edit = QLineEdit() self.edit.setMinimumWidth(self.edit.fontMetrics().averageCharWidth() * 15) box.addWidget(self.edit) button = QPushButton(tr("Browse")) self.connect(button, SIGNAL('clicked()'), self.openFileDialog) box.addWidget(button) box.addStretch() def openFileDialog(self): selected = self.edit.text() filename = QFileDialog.getOpenFileName(self, self.title, selected, self.filter) if filename: self.edit.setText(filename) self.emit(SIGNAL('modified'), filename)