本文整理汇总了Python中PySide.QtCore.QUrl类的典型用法代码示例。如果您正苦于以下问题:Python QUrl类的具体用法?Python QUrl怎么用?Python QUrl使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QUrl类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parseMarkdown
def parseMarkdown(self):
"""
Parse the Markdown stuff.
"""
self.updateStructure()
if self.sync is False:
return
y = self.web.page().mainFrame().scrollPosition().y()
txt = self.editor.toPlainText().encode('utf-8')
if txt is '' or None:
return
p = Popen([self.parser], stdout=PIPE, stdin=PIPE, stderr=STDOUT,
shell=False)
grep_stdout = p.communicate(input=txt)[0].decode('utf-8')
path = QUrl.fromUserInput(os.getcwd() + os.sep)
grep_stdout = grep_stdout.replace('img src=\"', 'img src=\"' +
path.toString())
# Can't use baseUrl=path because external img will not be loaded
# than :-/
self.web.setHtml(grep_stdout)
self.web.settings().setUserStyleSheetUrl(QUrl.fromLocalFile(os.getcwd()
+ os.sep + "/style.css"))
if y:
self.web.scroll(0, y)
self.web.page().mainFrame().scroll(0, y)
self.web.page().mainFrame().setScrollPosition(QPoint(0, y))
示例2: _urlencode_request_data
def _urlencode_request_data(self, raw_data):
# the data which we want to send to the server must be urlencoded
request_data = QUrl()
for (name, value) in raw_data.items():
request_data.addQueryItem(name, unicode(value))
return request_data.encodedQuery()
示例3: testSetQueryItems
def testSetQueryItems(self):
#QUrl.setQueryItems
urla = QUrl('http://www.google.com/search?q=python&hl=en')
urlb = QUrl('http://www.google.com/search')
urlb.setQueryItems(urla.queryItems())
self.assertEqual(urla, urlb)
示例4: email_note
def email_note(self):
body = self.page.mainFrame().toPlainText()[
len(self.title):
].strip()
url = QUrl("mailto:")
url.addQueryItem("subject", self.title)
url.addQueryItem("body", body)
QDesktopServices.openUrl(url)
示例5: testAllEncodedQueryItemsValues
def testAllEncodedQueryItemsValues(self):
#QUrl.allEncodedQueryItemValues
url = QUrl()
key = 'key'
valid_data = ['data', 'valid', 'test']
for i, data in enumerate(valid_data):
url.addQueryItem(key, data)
self.assertEqual(url.allEncodedQueryItemValues(key),
list(valid_data[:i+1]))
示例6: download_file
def download_file(self, path, setting):
version_file = self.settings['base_url'].format(self.selected_version())
location = self.get_setting('download_dir').value
versions = re.findall('v(\d+)\.(\d+)\.(\d+)', path)[0]
minor = int(versions[1])
if minor >= 12:
path = path.replace('node-webkit', 'nwjs')
self.progress_text = 'Downloading {}'.format(path.replace(version_file, ''))
url = QUrl(path)
file_name = setting.save_file_path(self.selected_version(), location)
archive_exists = QFile.exists(file_name)
#dest_files_exist = False
# for dest_file in setting.dest_files:
# dest_file_path = os.path.join('files', setting.name, dest_file)
# dest_files_exist &= QFile.exists(dest_file_path)
forced = self.get_setting('force_download').value
if archive_exists and not forced:
self.continue_downloading_or_extract()
return
self.out_file = QFile(file_name)
if not self.out_file.open(QIODevice.WriteOnly):
error = self.out_file.error().name
self.show_error('Unable to save the file {}: {}.'.format(file_name,
error))
self.out_file = None
self.enable_ui()
return
mode = QHttp.ConnectionModeHttp
port = url.port()
if port == -1:
port = 0
self.http.setHost(url.host(), mode, port)
self.http_request_aborted = False
path = QUrl.toPercentEncoding(url.path(), "!$&'()*+,;=:@/")
if path:
path = str(path)
else:
path = '/'
# Download the file.
self.http_get_id = self.http.get(path, self.out_file)
示例7: __init__
def __init__(self):
QApplication.__init__(self, sys.argv)
self.setOrganizationName("Khertan Software")
self.setOrganizationDomain("khertan.net")
self.setApplicationName("KhtNotes")
self.settings = Settings()
self.view = FilteredDeclarativeView(settings=self.settings)
if os.path.exists('/etc/mer-release'):
fullscreen = True
elif os.path.exists('/etc/aegis'):
fullscreen = True
self.glformat = QGLFormat().defaultFormat()
self.glformat.setSampleBuffers(False)
self.glw = QGLWidget(self.glformat)
self.glw.setAutoFillBackground(False)
self.view.setViewport(self.glw)
else:
fullscreen = False
self.notesModel = NotesModel()
self.note = Note(settings=self.settings)
self.conboyImporter = TomboyImporter()
self.syncer = Sync()
self.rootContext = self.view.rootContext()
self.rootContext.setContextProperty("argv", sys.argv)
self.rootContext.setContextProperty("__version__", __version__)
self.rootContext.setContextProperty("__upgrade__", __upgrade__
.replace('\n', '<br />'))
self.rootContext.setContextProperty("Settings", self.settings)
self.rootContext.setContextProperty("Sync", self.syncer)
self.rootContext.setContextProperty("Importer", self.conboyImporter)
self.rootContext.setContextProperty('notesModel', self.notesModel)
self.rootContext.setContextProperty('Note', self.note)
try:
self.view.setSource(QUrl.fromLocalFile(
os.path.join(os.path.dirname(__file__),
'qml', 'Harmattan_main.qml')))
except:
self.view.setSource(QUrl.fromLocalFile(
os.path.join(os.path.dirname(__file__),
'qml', 'Desktop_main.qml')))
self.rootObject = self.view.rootObject()
if fullscreen:
self.view.showFullScreen()
else:
self.view.show()
self.note.on_error.connect(self.rootObject.onError)
self.syncer.on_error.connect(self.rootObject.onError)
self.syncer.on_finished.connect(self.rootObject.refresh)
self.conboyImporter.on_finished.connect(self.notesModel.reload)
示例8: serve_forever
def serve_forever(self):
self.jid = '[email protected]'
self.connect() # be sure we are "connected" before the first command
self.connect_callback() # notify that the connection occured
# create window and components
app = QtGui.QApplication(sys.argv)
self.mainW = QtGui.QWidget()
self.mainW.setWindowTitle('Err...')
icon_path = os.path.dirname(errbot.__file__) + os.sep + 'err.svg'
bg_path = os.path.dirname(errbot.__file__) + os.sep + 'err-bg.svg'
self.mainW.setWindowIcon(QtGui.QIcon(icon_path))
vbox = QtGui.QVBoxLayout()
help = QtGui.QLabel("CTRL+Space to autocomplete -- CTRL+Enter to send your message")
self.input = CommandBox(self.cmd_history, self.commands)
self.output = QtWebKit.QWebView()
# init webpage
self.buffer = """<html>
<head>
<link rel="stylesheet" type="text/css" href="%s/style/style.css" />
</head>
<body style=" background-image: url('%s'); background-repeat: no-repeat; background-position:center center; background-attachment:fixed; background-size: contain; margin:0;">
""" % (QUrl.fromLocalFile(BOT_DATA_DIR).toString(), QUrl.fromLocalFile(bg_path).toString())
self.output.setHtml(self.buffer)
# layout
vbox.addWidget(self.output)
vbox.addWidget(self.input)
vbox.addWidget(help)
self.mainW.setLayout(vbox)
# setup web view to open liks in external browser
self.output.page().setLinkDelegationPolicy(QtWebKit.QWebPage.DelegateAllLinks)
# connect signals/slots
self.output.page().mainFrame().contentsSizeChanged.connect(self.scroll_output_to_bottom)
self.output.page().linkClicked.connect(QtGui.QDesktopServices.openUrl)
self.input.newCommand.connect(self.send_command)
self.conn.newAnswer.connect(self.new_message)
self.mainW.show()
try:
app.exec_()
finally:
self.disconnect_callback()
self.shutdown()
exit(0)
示例9: __init__
def __init__(self):
QApplication.__init__(self, sys.argv)
self.setOrganizationName("Khertan Software")
self.setOrganizationDomain("khertan.net")
self.setApplicationName("KhtNotes")
self.view = QtDeclarative.QDeclarativeView()
self.glw = QGLWidget()
self.view.setViewport(self.glw)
self.notesModel = NotesModel()
self.note = Note()
self.conboyImporter = TomboyImporter()
self.syncer = Sync()
self.rootContext = self.view.rootContext()
self.rootContext.setContextProperty("argv", sys.argv)
self.rootContext.setContextProperty("__version__", __version__)
self.rootContext.setContextProperty("__upgrade__", __upgrade__
.replace('\n', '<br>'))
self.rootContext.setContextProperty("Settings", Settings())
self.rootContext.setContextProperty("Sync", self.syncer)
self.rootContext.setContextProperty("Importer", self.conboyImporter)
self.rootContext.setContextProperty("QmlDirReaderWriter",
QmlDirReaderWriter())
self.rootContext.setContextProperty('notesModel', self.notesModel)
self.rootContext.setContextProperty('Note', self.note)
self.view.setSource(QUrl.fromLocalFile(
os.path.join(os.path.dirname(__file__),
'qml', 'Harmattan_main.qml')))
self.rootObject = self.view.rootObject()
self.view.showFullScreen()
self.note.on_error.connect(self.rootObject.onError)
self.syncer.on_error.connect(self.rootObject.onError)
self.syncer.on_finished.connect(self.notesModel.reload)
self.conboyImporter.on_finished.connect(self.notesModel.reload)
示例10: testAbstractItemModelTransferToQML
def testAbstractItemModelTransferToQML(self):
view = QDeclarativeView()
view.setSource(QUrl.fromLocalFile(adjust_filename('bug_814.qml', __file__)))
root = view.rootObject()
model = ListModel()
root.setProperty('model', model)
view.show()
示例11: testMetaData
def testMetaData(self):
self.view = QWebView()
QObject.connect(self.view, SIGNAL('loadFinished(bool)'),
self.load_finished)
url = QUrl.fromLocalFile(adjust_filename('fox.html', __file__))
self.view.setUrl(url)
self.app.exec_()
示例12: __init__
def __init__(self, url, image_path):
QObject.__init__(self)
self.url = QUrl(url)
self.image_path = image_path
self.webpage = QWebPage(self)
self.webpage.loadFinished.connect(self.render)
self.webpage.mainFrame().load(self.url)
示例13: __init__
def __init__(self):
QApplication.__init__(self, sys.argv)
self.setOrganizationName("Khertan Software")
self.setOrganizationDomain("khertan.net")
self.setApplicationName("KhtSimpleText")
self.view = QtDeclarative.QDeclarativeView()
#Are we on mer ? So don't use opengl
#As it didn't works on all devices
if not os.path.exists('/etc/mer-release'):
self.glformat = QGLFormat().defaultFormat()
self.glformat.setSampleBuffers(False)
self.glw = QGLWidget(self.glformat)
self.glw.setAutoFillBackground(False)
self.view.setViewport(self.glw)
self.document = Document('~')
self.documentsModel= DocumentsModel(currentDoc=self.document)
self.rootContext = self.view.rootContext()
self.rootContext.setContextProperty("argv", sys.argv)
self.rootContext.setContextProperty("__version__", __version__)
self.rootContext.setContextProperty("__upgrade__", __upgrade__
.replace('\n', '<br>'))
self.rootContext.setContextProperty("Settings", Settings())
self.rootContext.setContextProperty("DocumentsModel",
self.documentsModel)
self.rootContext.setContextProperty("Document",
self.document)
self.view.setSource(QUrl.fromLocalFile(
os.path.join(os.path.dirname(__file__), 'qml', 'main.qml')))
self.rootObject = self.view.rootObject()
self.view.showFullScreen()
示例14: __init__
def __init__(self):
self.network_manager = CustomNetworkAccessManager.getInstance()
self.axis = []
self.human_events = {}
self.node_collected_data = {}
self.last_url = None
self.current_url = QUrl()
self.current_axis_id = None
self.crossed_axis_method = None
self.crossed_axes = []
self.crossed_axes_string = ''
self.cross_axis_delay = QTimer()
self.cross_axis_delay.setSingleShot(True)
self.cross_axis_delay.timeout.connect(self.crossedAxis)
self.cross_axis_params = None
self.loading_timeout = QTimer()
self.loading_timeout.setSingleShot(True)
self.loading_timeout.setInterval(30000)
self.loading_timeout.timeout.connect(self.loadingTimeoutAction)
self.inactivity_timeout = QTimer()
self.inactivity_timeout.setSingleShot(True)
self.inactivity_timeout.setInterval(10000)
self.inactivity_timeout.timeout.connect(self.inactivityTimeoutAction)
self.page_reloads = 0
Logger.getLoggerFor(self.__class__)
示例15: ImageRenderer
class ImageRenderer(QObject):
def __init__(self, url, image_path):
QObject.__init__(self)
self.url = QUrl(url)
self.image_path = image_path
self.webpage = QWebPage(self)
self.webpage.loadFinished.connect(self.render)
self.webpage.mainFrame().load(self.url)
def render(self, ok):
if ok:
print('Loaded {0}'.format(self.url.toString()))
self.webpage.setViewportSize(
self.webpage.mainFrame().contentsSize())
image = QImage(self.webpage.viewportSize(),
QImage.Format_ARGB32)
painter = QPainter(image)
self.webpage.mainFrame().render(painter)
painter.end()
if image.save(self.image_path):
print('Saved image to {0}'.format(self.image_path))
else:
print('Could not save to {0}'.format(self.image_path))
else:
print('Could not load {0.toString()}'.format(self.url))
QApplication.instance().quit()