class AddNotepadDlg(QDialog): def __init__(self, parentWidget, settings): QDialog.__init__(self, parentWidget) self.settings = settings self.ui = Ui_AddNotepadDlg() self.ui.setupUi(self) self.ui.buttonBox.clicked.connect(self.applyAuth) # TODO self.ui.storageTypeUI.setCurrentIndex(0) self.ui.dropboxPages.setCurrentIndex(0) self.ui.localPath.setFocus() self.ui.selectDirectory.clicked.connect(self.choosePath) self.ui.storageType.activated.connect(self.changeStorage) def choosePath(self): pathName = QFileDialog.getExistingDirectory(self, caption='Select Notepad to add') self.ui.localPath.setText(pathName) def changeStorage(self, index): if index == 0: self.ui.buttonBox.setStandardButtons(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) elif index == 1: if len(self.settings.getDropboxToken()) == 0: # No authentication token available self.ui.dropboxPages.setCurrentIndex(0) self.ui.buttonBox.setStandardButtons(QDialogButtonBox.Apply| QDialogButtonBox.Cancel) self.flow = dropbox.client.DropboxOAuth2FlowNoRedirect('9tuq93gk3wkq242','4au1g1d5vp6phq3') authorize_url = self.flow.start() self.ui.authUrl.setText('<a href="{0}">{0}</a>'.format(authorize_url)) self.ui.authCode.setFocus() else: self.ui.buttonBox.setStandardButtons(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) self.ui.dropboxPages.setCurrentIndex(1) client = dropbox.client.DropboxClient(self.settings.getDropboxToken()) info = client.account_info() self.ui.userName.setText('{} <{}>'.format(info['display_name'], info['email'])) self.ui.notepadName.setFocus() def applyAuth(self, button): if button.text() == "Apply": # TODO!!!! authCode = self.ui.authCode.text() try: accessToken, user_id = self.flow.finish(authCode) self.settings.setDropboxToken(accessToken) self.changeStorage(1) except ErrorResponse as rsp: self.ui.errorMessage.setText('Error: {}'.format(rsp))
def __init__(self, parentWidget, settings): QDialog.__init__(self, parentWidget) self.settings = settings self.ui = Ui_AddNotepadDlg() self.ui.setupUi(self) self.ui.buttonBox.clicked.connect(self.applyAuth) # TODO self.ui.storageTypeUI.setCurrentIndex(0) self.ui.dropboxPages.setCurrentIndex(0) self.ui.localPath.setFocus() self.ui.selectDirectory.clicked.connect(self.choosePath) self.ui.storageType.activated.connect(self.changeStorage)
class AddNotepadDlg(QDialog): def __init__(self, parentWidget, settings): QDialog.__init__(self, parentWidget) self.settings = settings self.ui = Ui_AddNotepadDlg() self.ui.setupUi(self) self.ui.buttonBox.clicked.connect(self.applyAuth) # TODO self.ui.storageTypeUI.setCurrentIndex(0) self.ui.dropboxPages.setCurrentIndex(0) self.ui.localPath.setFocus() self.ui.selectDirectory.clicked.connect(self.choosePath) self.ui.storageType.activated.connect(self.changeStorage) def choosePath(self): pathName = QFileDialog.getExistingDirectory( self, caption='Select Notepad to add') self.ui.localPath.setText(pathName) def changeStorage(self, index): if index == 0: self.ui.buttonBox.setStandardButtons(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) elif index == 1: if len(self.settings.getDropboxToken()) == 0: # No authentication token available self.ui.dropboxPages.setCurrentIndex(0) self.ui.buttonBox.setStandardButtons(QDialogButtonBox.Apply | QDialogButtonBox.Cancel) self.flow = dropbox.client.DropboxOAuth2FlowNoRedirect( '9tuq93gk3wkq242', '4au1g1d5vp6phq3') authorize_url = self.flow.start() self.ui.authUrl.setText( '<a href="{0}">{0}</a>'.format(authorize_url)) self.ui.authCode.setFocus() else: self.ui.buttonBox.setStandardButtons(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) self.ui.dropboxPages.setCurrentIndex(1) client = dropbox.client.DropboxClient( self.settings.getDropboxToken()) info = client.account_info() self.ui.userName.setText('{} <{}>'.format( info['display_name'], info['email'])) self.ui.notepadName.setFocus() def applyAuth(self, button): if button.text() == "Apply": # TODO!!!! authCode = self.ui.authCode.text() try: accessToken, user_id = self.flow.finish(authCode) self.settings.setDropboxToken(accessToken) self.changeStorage(1) except ErrorResponse as rsp: self.ui.errorMessage.setText('Error: {}'.format(rsp))