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
274 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ui version="4.0"> | ||
<class>ILineEdit</class> | ||
<widget class="QWidget" name="ILineEdit"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>406</width> | ||
<height>187</height> | ||
</rect> | ||
</property> | ||
<property name="windowTitle"> | ||
<string>LineEdit preferences</string> | ||
</property> | ||
<layout class="QVBoxLayout" name="verticalLayout"> | ||
<item> | ||
<widget class="GroupBox" name="groupBox"> | ||
<property name="title"> | ||
<string>Basic settings</string> | ||
</property> | ||
<property name="template" stdset="0"> | ||
<string>inspector-groupbox-roomandpath</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item> | ||
<widget class="GroupBox" name="groupBox_3"> | ||
<property name="title"> | ||
<string>Triggered pillows</string> | ||
</property> | ||
<property name="template" stdset="0"> | ||
<string>inspector-groupbox-triggeredpillows</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item> | ||
<widget class="GroupBox" name="groupBox_2"> | ||
<property name="title"> | ||
<string>Enable logic</string> | ||
</property> | ||
<property name="template" stdset="0"> | ||
<string>inspector-groupbox-enablelogic</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item> | ||
<spacer name="verticalSpacer"> | ||
<property name="orientation"> | ||
<enum>Qt::Vertical</enum> | ||
</property> | ||
<property name="sizeHint" stdset="0"> | ||
<size> | ||
<width>20</width> | ||
<height>40</height> | ||
</size> | ||
</property> | ||
</spacer> | ||
</item> | ||
</layout> | ||
</widget> | ||
<customwidgets> | ||
<customwidget> | ||
<class>GroupBox</class> | ||
<extends>QGroupBox</extends> | ||
<header>wallaby.frontends.qt.widgets.containers.groupBox</header> | ||
<container>1</container> | ||
</customwidget> | ||
</customwidgets> | ||
<resources/> | ||
<connections/> | ||
</ui> |
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,58 @@ | ||
# Copyright (c) by it's authors. | ||
# Some rights reserved. See LICENSE, AUTHORS. | ||
|
||
import wallaby.FXUI as FXUI | ||
|
||
from wallaby.qt_combat import * | ||
|
||
from wallaby.frontends.qt.widgets.labels.extendedWebView import ExtendedWebView | ||
|
||
#============================================================================# | ||
# The group name in designer widgetbox # | ||
#----------------------------------------------------------------------------# | ||
DESIGNER_GROUP_NAME = "wallaby@fX" | ||
|
||
#============================================================================# | ||
# Plugin for CTLiveView # | ||
#----------------------------------------------------------------------------# | ||
class ExtendedWebViewPlugin(QtDesigner.QPyDesignerCustomWidgetPlugin): | ||
|
||
def __init__(self, parent=None): | ||
super(ExtendedWebViewPlugin, self).__init__(parent) | ||
|
||
self.initialized = False | ||
|
||
def initialize(self, formEditor): | ||
if self.initialized: | ||
return | ||
self.initialized = True | ||
|
||
def isInitialized(self): | ||
return self.initialized | ||
|
||
def isContainer(self): | ||
return False | ||
|
||
def icon(self): | ||
return FXUI.icon() | ||
|
||
def domXml(self): | ||
return '<widget class="ExtendedWebView" name="extendedWebView">\n</widget>\n' | ||
|
||
def group(self): | ||
return DESIGNER_GROUP_NAME | ||
|
||
def includeFile(self): | ||
return "wallaby.frontends.qt.widgets.labels.extendedWebView" | ||
|
||
def name(self): | ||
return "ExtendedWebView" | ||
|
||
def toolTip(self): | ||
return "" | ||
|
||
def whatsThis(self): | ||
return "" | ||
|
||
def createWidget(self, parent): | ||
return ExtendedWebView(parent) |
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,117 @@ | ||
# Copyright (c) by it's authors. | ||
# Some rights reserved. See LICENSE, AUTHORS. | ||
|
||
import codecs | ||
import wallaby.FX as FX | ||
import wallaby.FXUI as FXUI | ||
|
||
from wallaby.qt_combat import * | ||
|
||
from ..baseWidget import * | ||
from ..logics import * | ||
|
||
from wallaby.pf.peer.viewer import * | ||
from webRoom import WebRoom | ||
|
||
import copy | ||
|
||
class ExtendedWebView(QtWebKit.QWebView, BaseWidget, EnableLogic, ViewLogic, TriggeredPillowsLogic): | ||
__metaclass__ = QWallabyMeta | ||
|
||
triggers = Meta.property("list", readOnly=True, default=["", "clicked"]) | ||
templateName = Meta.property("string") | ||
|
||
def __init__(self, *args): | ||
QtWebKit.QWebView.__init__(self, *args) | ||
BaseWidget.__init__(self, QtWebKit.QWebView, *args) | ||
EnableLogic.__init__(self) | ||
ViewLogic.__init__(self, Viewer, self._setData) | ||
TriggeredPillowsLogic.__init__(self) | ||
|
||
self.setContextMenuPolicy(QtCore.Qt.DefaultContextMenu) | ||
|
||
self.linkClicked.connect(self._linkActivated) | ||
|
||
self._webRoom = WebRoom(self) | ||
|
||
self.page().mainFrame().javaScriptWindowObjectCleared.connect(self._registerObjects) | ||
self._registerObjects() | ||
|
||
palette = self.palette() | ||
palette.setBrush(QtGui.QPalette.Base, QtCore.Qt.transparent) | ||
self.page().setPalette(palette) | ||
self.setAttribute(QtCore.Qt.WA_OpaquePaintEvent, False) | ||
|
||
self._index = "<html><body>Template not found</body></html>" | ||
self._content = "" | ||
self._scripts = {} | ||
self._styles = {} | ||
|
||
self.page().setLinkDelegationPolicy(QtWebKit.QWebPage.DelegateAllLinks) | ||
self.page().settings().setAttribute(QtWebKit.QWebSettings.JavascriptEnabled, True) | ||
self.page().settings().setAttribute(QtWebKit.QWebSettings.DeveloperExtrasEnabled, True) | ||
self.page().settings().setAttribute(QtWebKit.QWebSettings.XSSAuditingEnabled, False) | ||
|
||
def _registerObjects(self): | ||
self.page().mainFrame().addToJavaScriptWindowObject("wallaby", self._webRoom) | ||
|
||
def _linkActivated(self, url): | ||
link = unicode(url.toString()) | ||
if link.startswith('wlby://'): | ||
link = link.replace('wlby://', '') | ||
args = None | ||
if '/' in link: | ||
args = link.split('/') | ||
cmd = args.pop(0) | ||
self._triggeredValue = args | ||
self.trigger("clicked") | ||
|
||
def deregister(self, remove=False): | ||
EnableLogic.deregister(self, remove) | ||
ViewLogic.deregister(self, remove) | ||
TriggeredPillowsLogic.deregister(self, remove) | ||
|
||
# Proxy for webRoom | ||
def catch(self, pillow, cb): | ||
House.get(self.room).catch(pillow, cb) | ||
|
||
def throw(self, pillow, feathers): | ||
House.get(self.room).throw(pillow, feathers) | ||
|
||
def roomName(self): | ||
return self.room | ||
|
||
def register(self): | ||
EnableLogic.register(self) | ||
ViewLogic.register(self, raw=True) | ||
TriggeredPillowsLogic.register(self) | ||
|
||
import os.path | ||
if self.templateName is not None and FXUI.app is not None and os.path.exists(os.path.join(FX.appPath, "templates", self.templateName, "index.html")): | ||
self._index = codecs.open(os.path.join(FX.appPath, "templates", self.templateName, "index.html"), "r", "utf-8").read() | ||
|
||
if os.path.exists(os.path.join(FX.appPath, "templates", self.templateName, "content.html")): | ||
self._content = codecs.open(os.path.join(FX.appPath, "templates", self.templateName, "content.html"), "r", "utf-8").read() | ||
|
||
import glob | ||
for js in glob.glob(os.path.join(FX.appPath, "templates", self.templateName, "*.js")): | ||
name, _ = os.path.splitext(os.path.basename(js)) | ||
script = codecs.open(js, "r", "utf-8").read() | ||
self._scripts[name] = script | ||
|
||
for css in glob.glob(os.path.join(FX.appPath, "templates", self.templateName, "*.css")): | ||
name, _ = os.path.splitext(os.path.basename(css)) | ||
style = codecs.open(css, "r", "utf-8").read() | ||
self._styles[name] = style | ||
|
||
import pystache | ||
self._index = pystache.render(unicode(self._index), {"scripts": self._scripts, "styles": self._styles}) | ||
|
||
self.setHtml(unicode(self._index)) | ||
|
||
def _setData(self, data): | ||
import pystache | ||
page = pystache.render(unicode(self._content), {"data": data}) | ||
|
||
e = self.page().mainFrame().findFirstElement('#content') | ||
e.setInnerXml(page) |
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,27 @@ | ||
from wallaby.qt_combat import * | ||
|
||
class WebRoom(QtCore.QObject): | ||
pillow = Signal('QString', 'QVariant') | ||
|
||
def __init__(self, room): | ||
QtCore.QObject.__init__(self) | ||
self._room = room | ||
|
||
@Property("QString") | ||
def room(self): | ||
return self._room.roomName() | ||
|
||
@Slot("QString") | ||
def _catch(self, pillow): | ||
self._room.catch(pillow, self.__catch) | ||
|
||
def __catch(self, pillow, feathers): | ||
from wallaby.common.document import Document | ||
if isinstance(feathers, Document): | ||
self.pillow.emit( pillow, feathers._data) | ||
else: | ||
self.pillow.emit( pillow, feathers) | ||
|
||
@Slot("QString", "QVariant") | ||
def _throw(self, pillow, feathers): | ||
self._room.throw(pillow, feathers) |