This repository has been archived by the owner on May 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#------------------------------------------------------------------------------ | ||
# Copyright (c) 2012, Enthought, Inc. | ||
# All rights reserved. | ||
#------------------------------------------------------------------------------ | ||
from .qt.QtCore import QUrl | ||
from .qt.QtWebKit import QWebView | ||
from .qt_control import QtControl | ||
|
||
|
||
class QtWebView(QtControl): | ||
""" A Qt implementation of an Enaml WebView. | ||
""" | ||
def create_widget(self, parent, tree): | ||
""" Create the underlying QWebView control. | ||
""" | ||
return QWebView(parent) | ||
|
||
def create(self, tree): | ||
""" Create and initialize the underlying control. | ||
""" | ||
super(QtWebView, self).create(tree) | ||
html = tree['html'] | ||
if html: | ||
self.set_html(html) | ||
else: | ||
self.set_url(tree['url']) | ||
|
||
#-------------------------------------------------------------------------- | ||
# Message Handling | ||
#-------------------------------------------------------------------------- | ||
def on_action_set_url(self, content): | ||
""" Handle the 'set_url' action from the Enaml widget. | ||
""" | ||
self.set_url(content['url']) | ||
|
||
def on_action_set_html(self, content): | ||
""" Handle the 'set_html' action from the Enaml widget. | ||
""" | ||
self.set_html(content['html']) | ||
|
||
#-------------------------------------------------------------------------- | ||
# Widget Update Methods | ||
#-------------------------------------------------------------------------- | ||
def set_url(self, url): | ||
""" Set the url for the underlying control. | ||
""" | ||
self.widget().setUrl(QUrl(url)) | ||
|
||
def set_html(self, html): | ||
""" Set the html source for the underlying control. | ||
""" | ||
self.widget().setHtml(html, 'c:/') | ||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#------------------------------------------------------------------------------ | ||
# Copyright (c) 2012, Enthought, Inc. | ||
# All rights reserved. | ||
#------------------------------------------------------------------------------ | ||
from traits.api import Unicode | ||
|
||
from .control import Control | ||
|
||
|
||
class WebView(Control): | ||
""" A widget which displays a web page. | ||
Unlike the simpler `Html` widget, this widget supports the features | ||
of a full web browser. | ||
""" | ||
#: The URL to load in the web view. This can be a path to a remote | ||
#: resource or a path to a file on the local filesystem. This value | ||
#: is mutually exclusive of `html`. | ||
url = Unicode | ||
|
||
#: The html to load into the web view. This value is mutually | ||
#: exclusive of `url`. | ||
html = Unicode | ||
|
||
#: A web view expands freely in height and width by default. | ||
hug_width = 'ignore' | ||
hug_height = 'ignore' | ||
|
||
#-------------------------------------------------------------------------- | ||
# Initialization | ||
#-------------------------------------------------------------------------- | ||
def snapshot(self): | ||
""" Create the snapshot for the widget. | ||
""" | ||
snap = super(WebView, self).snapshot() | ||
snap['url'] = self.url | ||
snap['html'] = self.html | ||
return snap | ||
|
||
def bind(self): | ||
""" Bind the change handlers for the widget. | ||
""" | ||
super(WebView, self).bind() | ||
self.publish_attributes('url', 'html') | ||
|