def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.ui = Ui_dirSettingsDialog() self.ui.setupUi(self) # 信号绑定 self.ui.okButton.clicked.connect(self.getLocation) self.ui.cancelButton.clicked.connect(self.Close) self.ui.mp3LocationButton.clicked.connect(self.getMp3FileLocation) self.ui.lrcLocationButton.clicked.connect(self.getLrcFileLocation)
class dirSettingsDialog(QtGui.QDialog): def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.ui = Ui_dirSettingsDialog() self.ui.setupUi(self) # 信号绑定 self.ui.okButton.clicked.connect(self.getLocation) self.ui.cancelButton.clicked.connect(self.Close) self.ui.mp3LocationButton.clicked.connect(self.getMp3FileLocation) self.ui.lrcLocationButton.clicked.connect(self.getLrcFileLocation) def getFileLocation(self,dirtype): """Open a FileDialog and choose an existing directory.""" fd = QtGui.QFileDialog(self) dirname = fd.getExistingDirectory() if dirtype == 'mp3': self.ui.mp3LocationEdit.setText(dirname) elif dirtype == 'lrc': self.ui.lrcLocationEdit.setText(dirname) return def getMp3FileLocation(self): return self.getFileLocation('mp3') def getLrcFileLocation(self): return self.getFileLocation('lrc') def getLocation(self): """Get mp3 & lrc dirname from dirSettingsDialog.""" self.mp3Location = self.ui.mp3LocationEdit.text() self.lrcLocation = self.ui.lrcLocationEdit.text() self.done(1) # return 1 and close dirSettingsDialog def Close(self): self.done(0)