Skip to content

Instantly share code, notes, and snippets.

@tbnorth
Last active December 20, 2015 16:59
Show Gist options
  • Save tbnorth/6165576 to your computer and use it in GitHub Desktop.
Save tbnorth/6165576 to your computer and use it in GitHub Desktop.
Webkit free-layout pane provider for Leo (http://leoeditor.com/)
from PyQt4 import QtGui, QtWebKit, QtCore, Qt
from PyQt4.QtCore import Qt as QtConst
class WebKitPaneProvider:
ns_id = '_add_tmce_pane'
def __init__(self, c):
self.c = c
# Careful: we may be unit testing.
if hasattr(c, 'free_layout'):
splitter = c.free_layout.get_top_splitter()
if splitter:
splitter.register_provider(self)
def ns_provides(self):
return[('WebKit browser', self.ns_id)]
def ns_provide(self, id_):
if id_ != self.ns_id:
return
w = QtGui.QWidget()
w.setLayout(QtGui.QVBoxLayout())
location = QtGui.QLineEdit("http://www.google.com/")
w.layout().addWidget(location)
web_browser = QtWebKit.QWebView()
w.layout().addWidget(web_browser)
QtWebKit.QWebSettings.globalSettings().setAttribute(
QtWebKit.QWebSettings.DeveloperExtrasEnabled, True)
location.returnPressed.connect(
lambda: web_browser.setUrl(QtCore.QUrl(location.text())))
location.returnPressed.emit()
web_browser.urlChanged.connect(
lambda url: location.setText(url.toString()))
return w
def ns_provider_id(self):
return self.ns_id
WebKitPaneProvider(c)
if hasattr(c, 'free_layout'):
splitter = c.free_layout.get_top_splitter()
if splitter:
splitter.open_window(action=WebKitPaneProvider.ns_id)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment