def moveToNextStep(self): if self.currentStep == len(self.lesson.steps): dlg = LessonFinishedDialog(self.lesson) dlg.exec_() if dlg.nextLesson is not None: self.init(dlg.nextLesson) else: self.finishLesson() else: step = self.lesson.steps[self.currentStep] if step.endsignal is not None: step.endsignal.connect(self.endSignalEmitted) item = self.listSteps.item(self.currentStep) item.setBackground(Qt.green) if os.path.exists(step.description): with open(step.description) as f: html = "".join(f.readlines()) self.webView.document().setMetaInformation(QTextDocument.DocumentUrl, QUrl.fromUserInput(step.description).toString()) self.webView.setHtml(html) else: self.webView.setHtml(step.description) QCoreApplication.processEvents() if step.prestep is not None: execute(step.prestep) if step.function is not None: self.btnRunStep.setEnabled(step.steptype != Step.AUTOMATEDSTEP) self.btnMove.setEnabled(step.steptype != Step.AUTOMATEDSTEP and step.endsignal is None) if step.steptype == Step.AUTOMATEDSTEP: self.runCurrentStepFunction() else: self.btnRunStep.setEnabled(False) self.btnMove.setEnabled(step.endsignal is None)
def getInfo(self, gebouwnummer): qurl = QUrl.fromUserInput(self.basewfs) qurl.addQueryItem('typeName', 'geo:fund_verseon') qurl.addQueryItem('filter', "<PropertyIsEqualTo><PropertyName>gebouwnummer</PropertyName><Literal>" + unicode(gebouwnummer) + "</Literal></PropertyIsEqualTo>") request = QNetworkRequest(qurl) reply = self.manager.get(request) reply.finished.connect(self.handleInfo)
def requester_send_button_clicked(self): """ Make a request from the Request tab """ if 'Cancel' == self.mainWindow.requesterSendButton.text() and self.pending_request is not None: self.pending_request.cancel() self.pending_request = None self.mainWindow.requesterSendButton.setText('Send') return qurl = QUrl.fromUserInput(self.mainWindow.requesterUrlEdit.text()) url = qurl.toEncoded().data().decode('utf-8') self.mainWindow.requesterUrlEdit.setText(url) self.framework.set_raft_config_value('requesterUrlEdit', url) templateText = str(self.mainWindow.requesterTemplateEdit.toPlainText()) method = str(self.mainWindow.requesterRequestMethod.currentText()) use_global_cookie_jar = self.mainWindow.requesterUseGlobalCookieJar.isChecked() replacements = self.build_replacements(method, url) (method, url, headers, body) = self.process_template(url, templateText, replacements) sequenceId = None if self.mainWindow.requesterSequenceCheckBox.isChecked(): sequenceId = str(self.mainWindow.requesterSequenceComboBox.itemData(self.mainWindow.requesterSequenceComboBox.currentIndex())) self.requestRunner = RequestRunner(self.framework, self) if use_global_cookie_jar: self.requesterCookieJar = self.framework.get_global_cookie_jar() else: self.requesterCookieJar = InMemoryCookieJar(self.framework, self) self.requestRunner.setup(self.requester_response_received, self.requesterCookieJar, sequenceId) self.pending_request = self.requestRunner.queue_request(method, url, headers, body) self.mainWindow.requesterSendButton.setText('Cancel') self.miniResponseRenderWidget.clear_response_render()
def onChangeWebLocation(self): """ On change web location """ self.webCounter.setText("(1%)") url = QUrl.fromUserInput(self.locationEdit.text()) self.webView.load(url) self.webView.setFocus()
def getAkrInfo(self, id): qurl = QUrl.fromUserInput(self.basewfs) qurl.addQueryItem('typeName', 'geo:brk_zak_recht') qurl.addQueryItem('cql_filter', "rust_op_kadastraalobject_id='" + id + "'") print qurl request = QNetworkRequest(qurl) reply = self.manager.get(request) reply.finished.connect(self.handleAkrInfo)
def getLkiInfo(self, wkt): #geom_ogr = ogr.CreateGeometryFromWkt(wkt) #gml = geom_wkt.ExportToGML() qurl = QUrl.fromUserInput(self.basewfs) qurl.addQueryItem('typeName', 'geo:brk_perceel') qurl.addQueryItem('cql_filter', "CONTAINS(geom," + wkt + ")") request = QNetworkRequest(qurl) reply = self.manager.get(request) reply.finished.connect(self.handleLkiInfo)
def currentItemChanged(self): item = self.lessonsTree.currentItem() if item: if hasattr(item, "lesson"): self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(True) if os.path.exists(item.lesson.description): with open(item.lesson.description) as f: html = "".join(f.readlines()) self.webView.document().setMetaInformation(QTextDocument.DocumentUrl, QUrl.fromUserInput(item.lesson.description).toString()) self.webView.setHtml(html) else: self.webView.setHtml("<p>%s</p>" % item.lesson.description) else: self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False) self.webView.setHtml("")
def accept(self): if self.txtName.text().strip() == "": QMessageBox.information(self, self.windowTitle(), self.trUtf8("请填写网络链接的名称。")) self.txtName.setFocus(Qt.OtherFocusReason) return if self.txtLink.text().strip() == "": QMessageBox.information(self, self.windowTitle(), self.trUtf8("请填写网络链接的地址。")) self.txtLink.setFocus(Qt.OtherFocusReason) return url = QUrl.fromUserInput(self.txtLink.text().strip()) if not url.isValid(): QMessageBox.information(self, self.windowTitle(), self.trUtf8("您填写的似乎不是正确的网络链接地址。")) self.txtLink.setFocus(Qt.OtherFocusReason) self.txtLink.selectAll() return QDialog.accept(self)
def runShortcut(self, index): if not index.isValid(): return False shortcut = self.shortcuts[index.row()] if shortcut["path"].startswith("special://"): if shortcut["path"] == COMPUTER_PATH: if os.name == "nt": explorer = os.path.join(os.environ["SystemRoot"], "explorer.exe") return QProcess.startDetached(explorer, ["::{20D04FE0-3AEA-1069-A2D8-08002B30309D}"]) else: path = "/" elif shortcut["path"] == DOCUMENTS_PATH: path = QDesktopServices.storageLocation(QDesktopServices.DocumentsLocation) elif shortcut["path"] == MUSIC_PATH: path = QDesktopServices.storageLocation(QDesktopServices.MusicLocation) elif shortcut["path"] == PICTURES_PATH: path = QDesktopServices.storageLocation(QDesktopServices.PicturesLocation) else: return False if os.name == "nt": #针对windows进行优化 explorer = os.path.join(os.environ["SystemRoot"], "explorer.exe") return QProcess.startDetached(explorer, [path]) else: return QDesktopServices.openUrl(QUrl.fromLocalFile(path)) else: currentDirectory = os.getcwd() try: if shortcut["dir"] is not None and shortcut["dir"] != "": os.chdir(shortcut["dir"]) if shortcut["openwith"] is not None and shortcut["openwith"] != "": if not os.path.exists(shortcut["openwith"]): return False return QProcess.startDetached(shortcut["openwith"], [shortcut["path"]]) else: url = QUrl.fromUserInput(shortcut["path"]) if not url.isValid(): return False if url.scheme() == "file" and not os.path.exists(url.toLocalFile()): return False return QDesktopServices.openUrl(url) except OSError: #raised by chdir() pass finally: os.chdir(currentDirectory) return False
def request(self, gebouwnummer): qurl = QUrl.fromUserInput(self.basewfs) qurl.addQueryItem('typeName', 'geo:bag_verblijfsobject') qurl.addQueryItem('filter', "<PropertyIsEqualTo><PropertyName>gebouwnummer</PropertyName><Literal>" + unicode(gebouwnummer) + "</Literal></PropertyIsEqualTo>") request = QNetworkRequest(qurl) self.reply = self.manager.get(request) self.reply.finished.connect(self.loop.quit) self.timer.start(5000) self.loop.exec_() if self.timer.isActive(): self.timer.stop() r = self.handleReply() else: raise Exception("Timeout error.") return r
def editShortcut(self): index = self.listView.currentIndex() if not index.isValid(): return shortcut = self.quickDesktopModel.shortcutAt(index) url = QUrl.fromUserInput(shortcut["path"]) if not url.isValid(): return if url.scheme() == "special": QMessageBox.information(self, self.trUtf8("编辑快捷方式"), self.trUtf8("不能编辑特殊图标。")) return elif url.scheme() == "file": d = ShortcutDialog(self) else: d = BookmarkDialog(self) if self.window().runDialog(d.edit, shortcut) == QDialog.Accepted: shortcut.update(d.getResult()) self.quickDesktopModel.updateShortcut(shortcut, index) d.deleteLater()
def requester_send_button_clicked(self): """ Make a request from the Request tab """ if 'Cancel' == self.mainWindow.requesterSendButton.text( ) and self.pending_request is not None: self.pending_request.cancel() self.pending_request = None self.mainWindow.requesterSendButton.setText('Send') return qurl = QUrl.fromUserInput(self.mainWindow.requesterUrlEdit.text()) url = qurl.toEncoded().data().decode('utf-8') self.mainWindow.requesterUrlEdit.setText(url) self.framework.set_raft_config_value('requesterUrlEdit', url) templateText = str(self.mainWindow.requesterTemplateEdit.toPlainText()) method = str(self.mainWindow.requesterRequestMethod.currentText()) use_global_cookie_jar = self.mainWindow.requesterUseGlobalCookieJar.isChecked( ) replacements = self.build_replacements(method, url) (method, url, headers, body) = self.process_template(url, templateText, replacements) sequenceId = None if self.mainWindow.requesterSequenceCheckBox.isChecked(): sequenceId = str( self.mainWindow.requesterSequenceComboBox.itemData( self.mainWindow.requesterSequenceComboBox.currentIndex())) self.requestRunner = RequestRunner(self.framework, self) if use_global_cookie_jar: self.requesterCookieJar = self.framework.get_global_cookie_jar() else: self.requesterCookieJar = InMemoryCookieJar(self.framework, self) self.requestRunner.setup(self.requester_response_received, self.requesterCookieJar, sequenceId) self.pending_request = self.requestRunner.queue_request( method, url, headers, body) self.mainWindow.requesterSendButton.setText('Cancel') self.miniResponseRenderWidget.clear_response_render()
def fix_url(url): """ entra string, sale QUrl """ if not url: return QUrl() if url.split(':')[0] == "about": return QUrl(url) search = False if url[:4] in ['http', 'file']: return QUrl(url) else: try: # ingenioso pero feo; con 'bind' local es barato socket.gethostbyname(url.split('/')[0]) except (UnicodeEncodeError, socket.error): search = True if search: #return QUrl("http://localhost:8000/?q=%s" % (url.replace(" ", "+"))) return QUrl( "http://duckduckgo.com/html/?q=%s" % (url.replace(" ", "+"))) else: return QUrl.fromUserInput(url)
def getShortcutIcon(shortcut): if shortcut["icon"]: icon = QIcon(shortcut["icon"]) if not icon.isNull(): return icon iconProvider = QFileIconProvider() if shortcut["path"] == COMPUTER_PATH: return QIcon(":/images/user-home.png") elif shortcut["path"] == DOCUMENTS_PATH: documentsIcon = iconProvider.icon(QFileInfo(QDesktopServices.storageLocation(QDesktopServices.DocumentsLocation))) if documentsIcon.isNull(): return QIcon(":/images/folder-documents.png") else: return documentsIcon elif shortcut["path"] == MUSIC_PATH: musicIcon = iconProvider.icon(QFileInfo(QDesktopServices.storageLocation(QDesktopServices.MusicLocation))) if musicIcon.isNull(): return QIcon(":/images/folder-sound.png") else: return musicIcon elif shortcut["path"] == PICTURES_PATH: picturesIcon = iconProvider.icon(QFileInfo(QDesktopServices.storageLocation(QDesktopServices.PicturesLocation))) if picturesIcon.isNull(): return QIcon(":/images/folder-image.png") else: return picturesIcon else: url = QUrl.fromUserInput(shortcut["path"]) if url.scheme() == "file": if os.path.exists(shortcut["path"]): icon = iconProvider.icon(QFileInfo(url.toLocalFile())) if not icon.isNull(): return icon return QIcon(":/images/unknown.png") else: return QIcon(":/images/httpurl.png") return QIcon(":/images/unknown.png")
def showItem(self, item): row = item.row() qurl = QUrl.fromUserInput(self.tableWidget.item(row, 2).text()) QDesktopServices.openUrl(qurl)
def update_storage_entry(self, domain, name, value): base_path = self.get_base_path() self.localstorage_files = [] for dirpath, dirnames, filenames in os.walk(base_path): self.visit_localstorage_files(None, dirpath, filenames) found = False for item in self.localstorage_files: scheme, domain_name, filename = item if domain == urlparse.urlunsplit( (scheme, domain_name, '', '', '')): found = True found_filename = filename break if found: filename = found_filename else: qurl = QUrl.fromUserInput(domain) splitted = urlparse.urlsplit( qurl.toEncoded().data().decode('utf-8')) scheme = splitted.scheme or 'http' domain_name = splitted.hostname or splitted.path filename = os.path.join( self.get_base_path(), '%s_%s_0.localstorage' % (scheme, domain_name)) localstorage_db, cursor = None, None try: localstorage_db = sqlite.connect(filename) cursor = localstorage_db.cursor() cursor.execute( """CREATE TABLE IF NOT EXISTS ItemTable (key TEXT UNIQUE ON CONFLICT REPLACE, value TEXT NOT NULL ON CONFLICT FAIL)""" ) localstorage_db.commit() cursor.close() cursor = None localstorage_db.close() localstorage_db = None except Exception as error: self.framework.report_exception(error) finally: if cursor: cursor.close() cursor = None if localstorage_db: localstorage_db.close() localstorage_db = None localstorage_db, cursor = None, None try: localstorage_db = sqlite.connect(filename) cursor = localstorage_db.cursor() cursor.execute("""SELECT count(1) FROM ItemTable WHERE key=?""", [name]) rcount = int(cursor.fetchone()[0]) if 0 == rcount: cursor.execute( """INSERT INTO ItemTable (key, value) VALUES (?,?)""", [name, value]) else: cursor.execute("""UPDATE ItemTable SET value=? WHERE key=?""", [value, name]) localstorage_db.commit() cursor.close() cursor = None localstorage_db.close() localstorage_db = None except Exception as error: self.framework.report_exception(error) finally: if cursor: cursor.close() cursor = None if localstorage_db: localstorage_db.close() localstorage_db = None
def updateWeb(self, url=None): if url != None: self.mdiArea.currentSubWindow().widget().load(QUrl.fromUserInput(url))
def handle_testerClickjackingGenerateButton_clicked(self): entry = self.mainWindow.testerClickjackingTargetURL.text() url = QUrl.fromUserInput(entry).toEncoded().data().decode("utf-8") self.setup_clickjacking_url(url)
def handle_testerClickjackingGenerateButton_clicked(self): entry = self.mainWindow.testerClickjackingTargetURL.text() url = QUrl.fromUserInput(entry).toEncoded().data().decode('utf-8') self.setup_clickjacking_url(url)
def update_storage_entry(self, domain, name, value): base_path = self.get_base_path() self.localstorage_files = [] for dirpath, dirnames, filenames in os.walk(base_path): self.visit_localstorage_files(None, dirpath, filenames) found = False for item in self.localstorage_files: scheme, domain_name, filename = item if domain == urlparse.urlunsplit((scheme, domain_name, "", "", "")): found = True found_filename = filename break if found: filename = found_filename else: qurl = QUrl.fromUserInput(domain) splitted = urlparse.urlsplit(qurl.toEncoded().data().decode("utf-8")) scheme = splitted.scheme or "http" domain_name = splitted.hostname or splitted.path filename = os.path.join(self.get_base_path(), "%s_%s_0.localstorage" % (scheme, domain_name)) localstorage_db, cursor = None, None try: localstorage_db = sqlite.connect(filename) cursor = localstorage_db.cursor() cursor.execute( """CREATE TABLE IF NOT EXISTS ItemTable (key TEXT UNIQUE ON CONFLICT REPLACE, value TEXT NOT NULL ON CONFLICT FAIL)""" ) localstorage_db.commit() cursor.close() cursor = None localstorage_db.close() localstorage_db = None except Exception as error: self.framework.report_exception(error) finally: if cursor: cursor.close() cursor = None if localstorage_db: localstorage_db.close() localstorage_db = None localstorage_db, cursor = None, None try: localstorage_db = sqlite.connect(filename) cursor = localstorage_db.cursor() cursor.execute("""SELECT count(1) FROM ItemTable WHERE key=?""", [name]) rcount = int(cursor.fetchone()[0]) if 0 == rcount: cursor.execute("""INSERT INTO ItemTable (key, value) VALUES (?,?)""", [name, value]) else: cursor.execute("""UPDATE ItemTable SET value=? WHERE key=?""", [value, name]) localstorage_db.commit() cursor.close() cursor = None localstorage_db.close() localstorage_db = None except Exception as error: self.framework.report_exception(error) finally: if cursor: cursor.close() cursor = None if localstorage_db: localstorage_db.close() localstorage_db = None