Created
April 9, 2014 15:15
-
-
Save albop/10281951 to your computer and use it in GitHub Desktop.
Browser with tabs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
from __future__ import print_function | |
import sys | |
from PySide.QtCore import * | |
from PySide.QtGui import * | |
from PySide import QtGui | |
from PySide.QtWebKit import * | |
from PySide import QtWebKit | |
class Form(QDialog): | |
def __init__(self, parent=None): | |
super(Form, self).__init__(parent) | |
self.tabWidget = QtGui.QTabWidget() | |
web = QWebView() | |
web.setUrl(QUrl("http://www.google.fr/")) | |
self.webviews = [web] | |
# web.reload() | |
self.button = QPushButton("Show Greetings") | |
self.url = QTextEdit() | |
layout = QVBoxLayout() | |
layout.addWidget(self.tabWidget) | |
layout.addWidget(self.button) | |
layout.addWidget(self.url) | |
self.setLayout(layout) | |
self.tabWidget.addTab(self.webviews[0], "General") | |
self.setWindowTitle("My Form") | |
self.button.clicked.connect(self.load_url) | |
web.page().setLinkDelegationPolicy(QtWebKit.QWebPage.DelegateAllLinks) | |
web.linkClicked.connect(lambda x: self.open_link(x)) | |
def open_link(self, arg__1): | |
web = QWebView() | |
self.webviews.append(web) | |
self.tabWidget.addTab(web, str(arg__1)) | |
web.setUrl(QUrl(arg__1)) | |
print("Clicked") | |
def load_url(self): | |
txt = self.url.toPlainText() | |
self.webviews[0].setUrl(QUrl(txt)) | |
if __name__ == '__main__': | |
# Create the Qt Application | |
app = QApplication(sys.argv) | |
# Create and show the form | |
form = Form() | |
form.show() | |
# Run the main Qt loop | |
sys.exit(app.exec_()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment