本文整理汇总了Python中PySide.QtWebKit.QWebView类的典型用法代码示例。如果您正苦于以下问题:Python QWebView类的具体用法?Python QWebView怎么用?Python QWebView使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QWebView类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, parent=None, userData=None,inspector = True):
QWebView.__init__(self, parent)
settings = QWebSettings.globalSettings()
settings.setFontFamily(QWebSettings.StandardFont, 'Helvetica')
settings.setFontSize(QWebSettings.DefaultFontSize, 12)
self.webpage = page = PtWebPage(self)
self.setPage(page)
self.connect(self, SIGNAL('loadFinished(bool)'), self.onLoadFinished)
self.settings().setAttribute(
QWebSettings.WebAttribute.DeveloperExtrasEnabled, True)
#path = os.getcwd()
#self.settings().setUserStyleSheetUrl(QUrl.fromLocalFile(path + "/myCustom.css"))
font = QFont("Helvetica")
font.setPixelSize(12)
self.setFont(font)
# or globally:
# QWebSettings.globalSettings().setAttribute(
# QWebSettings.WebAttribute.DeveloperExtrasEnabled, True)
if inspector:
self.inspector = QWebInspector()
self.inspector.setPage(self.page())
self.inspector.hide()
self.page().setLinkDelegationPolicy(QWebPage.DelegateAllLinks)
self.page().linkClicked.connect(self._on_page_link_clicked)
示例2: testBug899
def testBug899(self):
html = '''
<html><body>
<script type="text/javascript">
document.write("<p>"+py_obj.list1+"</p>")
document.write("<p>"+py_obj.list2+"</p>")
</script>
</body></html>
'''
class Obj(object):
list1 = ['foo', 'bar', 'baz']
list2 = ['fi', 'fo', 'fum']
obj = Obj()
wrapper_dict = {}
for name in ('list1', 'list2'):
getter = lambda arg=None, name=name: getattr(obj, name)
wrapper_dict[name] = Property('QVariantList', getter)
wrapper = type('PyObj', (QObject,), wrapper_dict)
view = QWebView()
view.page().mainFrame().addToJavaScriptWindowObject('py_obj', wrapper())
view.setHtml(html)
示例3: BaseWindow
class BaseWindow(QtGui.QMainWindow):
def __init__(self, parent = None):
QtGui.QMainWindow.__init__(self, parent)
self.centralWidget = QtGui.QWidget()
self.resize(800, 500)
self.setWindowTitle('Test')
self.tabs = QTabWidget()
self.tabs.blockSignals(True) #just for not showing the initial message
self.tabs.currentChanged.connect(self.onChange) #changed!
self.webview = QWebView()
self.webview.load(QUrl("http://gmx.de"))
self.webview2 = QWebView()
self.webview2.load(QUrl("http://web.de"))
centralLayout = QtGui.QVBoxLayout()
centralLayout.addWidget(self.tabs, 1)
self.tabs.addTab(self.webview, "gmx")
self.tabs.addTab(self.webview2, "web")
self.centralWidget.setLayout(centralLayout)
self.setCentralWidget(self.centralWidget)
self.tabs.blockSignals(False) #now listen the currentChanged signal
#@pyqtSlot()
def onChange(self,i): #changed!
QtGui.QMessageBox.information(self,
"Tab Index Changed!",
"Current Tab Index: %d" % i ) #changed!
示例4: __init__
def __init__(self, parent=None):
super(Text, self).__init__(parent)
# Sentence view
self.view, self.page = QWebView(), QWebPage()
self.view.setPage(self.page)
# TODO: update dynamically on parent widget resize events (somehow?)
self.view.setMinimumSize(parent.width(), parent.height() / 2)
# Info view
self.infoView, self.infoPage = QWebView(), QWebPage()
self.infoView.setPage(self.infoPage)
self.infoView.setMaximumSize(parent.width() / 2, parent.height())
# Active terms and sentence
self.terms, self.example = {}, u''
# Default style
self.css = 'solarized-light'
# Composition
self.compose({
QHBoxLayout(): [self.infoView, self.view]
})
# Initialize events
self.page.linkHovered.connect(self.showInfo)
self.page.setLinkDelegationPolicy(QWebPage.DelegateExternalLinks)
self.page.linkClicked.connect(self.queryServer)
# Initialize style
self.clearPages()
示例5: AssistantWindow
class AssistantWindow(QtGui.QDialog):
def __init__(self, *args, **kwargs):
super(AssistantWindow, self).__init__(*args, **kwargs)
self.smap = QWebView()
self.lattitude = QtGui.QLineEdit()
self.longitude = QtGui.QLineEdit()
self.get_map_button = QtGui.QPushButton('Get map')
self.get_map_button.clicked.connect(self.get_map)
self.zoom_level = QtGui.QLineEdit()
self.zoom_level.setText('18')
self.flayout = QtGui.QFormLayout()
self.setLayout(self.flayout)
self.flayout.addRow('Lattitude:', self.lattitude)
self.flayout.addRow('Longitude:', self.longitude)
self.flayout.addRow('Zoom level:', self.zoom_level)
self.flayout.addRow(self.get_map_button)
self.flayout.addRow(self.smap)
def get_map(self):
lt = int(self.lattitude.text())
ln = int(self.longitude.text())
lt_g = coord_conv(lt)
ln_g = coord_conv(ln)
url = (ST_MAPS_API + 'center=%s,%s' % (lt_g, ln_g) +
'&zoom=%s' % self.zoom_level.text() +
'&size=400x400&sensor=false&maptype=hybrid' +
'&markers=%s,%s' % (lt_g, ln_g))
self.smap.load(url)
示例6: HtmlFavoritePage
class HtmlFavoritePage():
def __init__(self, page, layout, parent):
self.page = page
self.parent = parent
container = QVBoxLayout()
# actions section
actionsContainer = QHBoxLayout()
self.saveButton = QPushButton('Save')
self.saveButton.clicked.connect(lambda: save_clicked(self))
actionsContainer.addWidget(QLabel('Link: '))
self.linkText = QLineEdit(page.url)
label = QLabel('<a href="' + page.url + '">Open Externally</a>')
label.setOpenExternalLinks(True)
actionsContainer.addWidget(self.linkText)
actionsContainer.addWidget(self.saveButton)
actionsContainer.addWidget(label)
container.addLayout(actionsContainer)
# content
self.view = QWebView()
self.view.setUrl(page.url)
container.addWidget(self.view)
layout.addLayout(container)
示例7: Event
class Event(QWidget):
def __init__(self, parent=None):
super(Event, self).__init__(parent)
self.setWindowTitle('loadFinished Event')
url = QUrl('https://www.torproject.org/')
self.webView = QWebView()
self.webView.setUrl(url)
page = self.webView.page()
frame = page.mainFrame()
frame.loadFinished.connect(self.load_finished)
self.mainLayout = QGridLayout()
self.mainLayout.addWidget(self.webView)
self.setLayout(self.mainLayout)
def load_finished(self):
print 'load has finished'
示例8: webkit_download
def webkit_download(url):
app = QApplication([])
webview = QWebView()
webview.loadFinished.connect(app.quit)
webview.load(url)
app.exec_() # delay here until download finished
return webview.page().mainFrame().toHtml()
示例9: HTMLApplication
class HTMLApplication(object):
def show(self):
#It is IMPERATIVE that all forward slashes are scrubbed out, otherwise QTWebKit seems to be
# easily confused
kickOffHTML = join(dirname(__file__).replace('\\', '/'), "templates/index.html").replace('\\', '/')
#This is basically a browser instance
self.web = QWebView()
#Unlikely to matter but prefer to be waiting for callback then try to catch
# it in time.
self.web.loadFinished.connect(self.onLoad)
self.web.load(kickOffHTML)
self.web.show()
def onLoad(self):
#This is the body of a web browser tab
self.myPage = self.web.page()
self.myPage.settings().setAttribute(QWebSettings.DeveloperExtrasEnabled, True)
#This is the actual context/frame a webpage is running in.
# Other frames could include iframes or such.
self.myFrame = self.myPage.mainFrame()
# ATTENTION here's the magic that sets a bridge between Python to HTML
self.myFrame.addToJavaScriptWindowObject("eth", self.ethclient)
#Tell the HTML side, we are open for business
self.myFrame.evaluateJavaScript("ApplicationIsReady()")
示例10: _show_timeline
def _show_timeline(self, start_time_attr, display_abnormal_source=True):
conclusions = set()
for _, row in self.entries.iterrows():
for c in row.conclusions:
conclusions.add(c)
conclusions = list(conclusions)
conclusions.append('无可用结论')
groups, c_id = [], {}
for i, c in enumerate(conclusions):
groups.append({'id': i, 'content': c})
c_id[c] = i
def _gen_item(item, group_id=len(conclusions) - 1):
content = '#%s' % item.id
if display_abnormal_source:
if item.abnormal_src:
content += '<br />%s' % ', '.join(item.abnormal_src)
_ = {'start': item[start_time_attr].timestamp() * 1000,
'content': content,
'group': group_id}
if item.abnormal:
_['className'] = 'red'
return _
items = []
for i, (_t, item) in enumerate(self.entries.iterrows()):
if item.conclusions:
for c in item.conclusions:
_ = _gen_item(item, c_id[c])
items.append(_)
else:
_ = _gen_item(item)
items.append(_)
html = self.timeline_template.render(
groups=groups,
items=items,
start=self.summary_widget.start_time.timestamp() * 1000,
end=self.summary_widget.end_time.timestamp() * 1000
)
if self.USE_QT_WEBKIT:
view = QWebView(self)
view.setHtml(html, self.timeline_base_url)
self.figures_widget.addTab(view, '时间线')
else:
info_box(self, '将会打开外部浏览器查看时间线')
path = os.path.join(self.template_path, 'r.html')
print(html, file=open(path, 'w', encoding='utf-8'))
webbrowser.open(QUrl.fromLocalFile(path).toString())
示例11: browse
def browse(url, name='', icon=''):
from PySide.QtGui import QApplication, QIcon
from PySide.QtCore import QUrl
from PySide.QtWebKit import QWebView
for try_ in range(10):
try:
assert urllib2.urlopen(url).code == 200
except (AssertionError, urllib2.URLError):
time.sleep(0.25)
else:
print "Started Qt Web View after %i ticks." % try_
break
else:
sys.exit("Error initializing Qt Web View.")
qtapp = QApplication(name)
web = QWebView()
web.load(QUrl(url))
if icon:
print "Setting Icon to", icon
web.setWindowIcon(QIcon(icon))
else:
print "WARNING: No icon found in settings.py"
web.setWindowTitle(name)
web.show()
qtapp.exec_()
示例12: __init__
def __init__(self, app):
QWebView.__init__(self)
# By storing a reference to the application which started this
# instance, we will be able to close the application once we get what
# we want
self.parent_app = app
# connect the loadFinished signal to a method defined by us.
# loadFinished is the signal which is triggered when a page is loaded
self.loadFinished.connect(self._load_finished)
示例13: new_tab
def new_tab(self):
"""Open new tab."""
tasklist = QTreeView()
tasklist.hide()
tasklist.setObjectName('taskList')
tasklist.setMinimumWidth(100)
tasklist.setMaximumWidth(250)
new_tab = QWebView()
new_tab.setObjectName('webView')
inspector = QWebInspector(self)
inspector.setObjectName('webInspector')
inspector.hide()
page_layout = QVBoxLayout()
page_layout.setSpacing(0)
page_layout.setContentsMargins(0, 0, 0, 0)
page_layout.addWidget(new_tab)
page_layout.addWidget(inspector)
page_widget = QFrame()
page_widget.setObjectName('pageWidget')
page_widget.setLayout(page_layout)
complete_tab_layout = QHBoxLayout()
complete_tab_layout.setSpacing(0)
complete_tab_layout.setContentsMargins(0, 0, 0, 0)
complete_tab_layout.addWidget(tasklist)
complete_tab_layout.addWidget(page_widget)
complete_tab_widget = QFrame()
complete_tab_widget.setLayout(complete_tab_layout)
new_tab.load(QUrl(self.startpage))
self.tabs.setUpdatesEnabled(False)
if self.new_tab_behavior == "insert":
self.tabs.insertTab(self.tabs.currentIndex()+1, complete_tab_widget,
unicode(new_tab.title()))
elif self.new_tab_behavior == "append":
self.tabs.appendTab(complete_tab_widget, unicode(new_tab.title()))
self.tabs.setCurrentWidget(complete_tab_widget)
self.tabs.setTabText(self.tabs.currentIndex(),
unicode(self.tabs.currentWidget().findChild(QFrame, unicode('pageWidget')).findChild(QWebView, unicode('webView')).title()))
self.tabs.setUpdatesEnabled(True)
# tab.page().mainFrame().setScrollBarPolicy(Qt.Horizontal, Qt.ScrollBarAlwaysOff)
# tab.page().mainFrame().setScrollBarPolicy(Qt.Vertical, Qt.ScrollBarAlwaysOff)
new_tab.titleChanged.connect(self.change_tab)
new_tab.urlChanged.connect(self.change_tab)
new_tab.loadStarted.connect(self.load_start)
new_tab.loadFinished.connect(self.load_finish)
new_tab.loadProgress.connect(self.pbar.setValue)
new_tab.page().linkHovered.connect(self.linkHover)
inspector.setPage(new_tab.page())
示例14: __init__
def __init__(self):
super(Browser, self).__init__()
self.layout = QStackedLayout(self)
self.frontView = QWebView(self)
self.backView = QWebView(self)
self.frontView.page().networkAccessManager().sslErrors.connect(self.onSslErrors)
self.backView.page().networkAccessManager().sslErrors.connect(self.onSslErrors)
self.hostname = os.uname()[1]
self.layout.setStackingMode(QStackedLayout.StackAll)
self.layout.addWidget(self.frontView)
self.layout.addWidget(self.backView)
self.commands = {
'help' : self.cmdHelp,
'refresh' : self.cmdRefresh,
'add' : self.cmdAdd,
'del' : self.cmdDel,
'list' : self.cmdList,
'zoom' : self.cmdZoom,
'fs' : self.cmdFs,
'exit' : self.cmdExit,
'next' : self.cmdNext,
'restart' : self.cmdRestart,
'upgrade' : self.cmdUpgrade,
}
self.timer = QTimer()
self.timer.setSingleShot(False)
self.sites = list()
self.siteId = -1
self.socket = False
url = QUrl("http://dmr.tokiogroup.com/rrs.php")
self.sites.append(Site(url, 10, 1))
url = QUrl("http://dmr.tokiogroup.com/lastheard.php")
self.sites.append(Site(url, 10, 1))
self.server = QTcpServer()
self.server.listen(QHostAddress.Any, 4242)
self.connect(self.server, SIGNAL("newConnection()"), self, SLOT("onConnection()"));
self.connect(self.timer, SIGNAL("timeout()"), self, SLOT("goNext()"));
self.goNext()
self.goNext()
示例15: about_license
def about_license(self):
try:
f = open(get_file("GNU_HTML"))
license = QtGui.QDialog()
license.resize(650, 480)
license.setWindowTitle("SynchroniZeRD License")
licenseText = QWebView()
licenseText.setHtml(f.read())
layout = QtGui.QGridLayout(license)
layout.addWidget(licenseText)
license.exec_()
except:
QMessageBox.critical(self, "Error", "Unable to open GNU_HTML License file.")