def runConfigWizard(self): try: api = InstagramAPI( client_id=self.options_string['hidden_client_id'], client_secret=self.options_string['hidden_client_secret'], redirect_uri=self.options_string['redirect_uri']) url = api.get_authorize_login_url() self.wizard.setWindowTitle('Instagram plugin configuration wizard') page1 = QWizardPage() layout1 = QVBoxLayout() txtArea = QLabel() txtArea.setText( 'Please copy the following link to your browser window. \n ' + 'Once you authenticate with Instagram you will be redirected to ' + 'www.geocreepy.com and get your token. Copy the token to the input field below:' ) urlArea = QLineEdit() urlArea.setObjectName('urlArea') urlArea.setText(url) inputLink = QLineEdit() inputLink.setObjectName('inputLink') labelLink = QLabel('Your token value:') openInBrowserButton = QPushButton('Open in browser') openInBrowserButton.clicked.connect( functools.partial(self.openLinkInBrowser, url)) layout1.addWidget(txtArea) layout1.addWidget(urlArea) layout1.addWidget(openInBrowserButton) layout1.addWidget(labelLink) layout1.addWidget(inputLink) page1.setLayout(layout1) self.wizard.addPage(page1) self.wizard.resize(600, 400) if self.wizard.exec_(): c = str(inputLink.text()) if c: try: access_token = api.exchange_code_for_access_token( code=c) self.options_string[ 'hidden_access_token'] = access_token[0] self.saveConfiguration(self.config) except Exception, err: logger.error(err) self.showWarning( 'Error Getting Access Token', 'Please verify that the link you pasted was correct. ' 'Try running the wizard again.') else: self.showWarning( 'Error Getting Access Token', 'Please verify that the link you pasted was correct. Try running the wizard again.' ) except Exception, err: logger.error(err) self.showWarning('Error', 'Error was {0}'.format(err))
def _create_page_id_files(self): """Creates a page for selecting student id files.""" page = QWizardPage(self) page.setTitle(_('Student id files')) page.setSubTitle(_('You can select zero, one or more files with the ' 'list of student ids. Go to the user manual ' 'if you don\'t know the format of the files.')) self.files_w = widgets.MultipleFilesWidget( _('Select student list files'), file_name_filter=FileNameFilters.student_list, check_file_function=self._check_student_ids_file) layout = QVBoxLayout() page.setLayout(layout) layout.addWidget(self.files_w) return page
def runConfigWizard(self): try: oAuthHandler = tweepy.OAuthHandler( self.options_string['hidden_application_key'], self.options_string['hidden_application_secret']) authorizationURL = oAuthHandler.get_authorization_url(True) self.wizard.setWindowTitle("Twitter plugin configuration wizard") page1 = QWizardPage() page2 = QWizardPage() layout1 = QVBoxLayout() layout2 = QVBoxLayout() layoutInputPin = QHBoxLayout() label1a = QLabel( "Click next to connect to twitter.com . Please login with your account and follow the instructions in order to authorize creepy" ) label2a = QLabel( "Copy the PIN that you will receive once you authorize cree.py in the field below and click finish" ) pinLabel = QLabel("PIN") inputPin = QLineEdit() inputPin.setObjectName("inputPin") html = QWebView() html.load(QUrl(authorizationURL)) layout1.addWidget(label1a) layout2.addWidget(html) layout2.addWidget(label2a) layoutInputPin.addWidget(pinLabel) layoutInputPin.addWidget(inputPin) layout2.addLayout(layoutInputPin) page1.setLayout(layout1) page2.setLayout(layout2) page2.registerField("inputPin*", inputPin) self.wizard.addPage(page1) self.wizard.addPage(page2) self.wizard.resize(800, 600) if self.wizard.exec_(): try: oAuthHandler.get_access_token( str(self.wizard.field("inputPin").toString()).strip()) self.options_string[ 'hidden_access_token'] = oAuthHandler.access_token self.options_string[ 'hidden_access_token_secret'] = oAuthHandler.access_token_secret self.config.write() except Exception, err: logger.error(err) self.showWarning( "Error completing the wizard", "We were unable to obtain the access token for your account, please try to run the wizard again. Error was {0}" .format(err.message)) except Exception, err: logger.error(err) self.showWarning('Error completing the wizard', 'Error was: {0}'.format(err.message))