Skip to content
This repository has been archived by the owner on Aug 24, 2021. It is now read-only.

[WIP] try to fix for use with PyQt5 #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions examples/simple/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
class ExampleSynopticWidget(SynopticWidget):

"A custom subclass of the synoptic widget."

def on_click(self, kind, name):
# Overriding the click event handler to print information
print "click", kind, name
def __init__(self, url=None, parent=None, *args, **kwargs):
super(ExampleSynopticWidget, self).__init__(url=None, parent=None, *args, **kwargs)

#def on_click(self, kind, name):
# # Overriding the click event handler to print information
# print("click", kind, name)


def main():
Expand Down
26 changes: 19 additions & 7 deletions examples/tango/example.svg → examples/simple_tango/example.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions examples/simple_tango/models.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"value1" : "sys/tg_test/1/double_scalar",
"value2" : "sys/tg_test/1/ampli",
"value3" : "sys/tg_test/1/ampli"
}
5 changes: 0 additions & 5 deletions examples/tango/models.json

This file was deleted.

2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ requires = python-fandango
python-pytango
qtwebkit

release = 1%{?dist}.maxlab
release = maxlab
8 changes: 4 additions & 4 deletions svgsynoptic2/caseless.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class CaselessDictionary(MutableMapping):
def __init__(self, *args, **kwargs):
self.__dict__["_dict"] = {}
temp_dict = dict(*args, **kwargs)
for key, value in temp_dict.iteritems():
if isinstance(key, basestring):
for key, value in temp_dict.items():
if isinstance(key, str):
key = CaselessString.make_caseless(key)
self._dict[key] = value

Expand Down Expand Up @@ -90,7 +90,7 @@ def __cmp__(self, other):

@classmethod
def make_caseless(cls, string):
if isinstance(string, unicode):
if isinstance(string, str):
return CaselessUnicode(string)
return CaselessStr(string)

Expand All @@ -99,5 +99,5 @@ class CaselessStr(CaselessString, str):
pass


class CaselessUnicode(CaselessString, unicode):
class CaselessUnicode(CaselessString, str):
pass
4 changes: 2 additions & 2 deletions svgsynoptic2/jsinterface.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from threading import Lock

from PyQt4 import QtCore
from PyQt5 import QtCore


class JSInterface(QtCore.QObject):
Expand Down Expand Up @@ -65,7 +65,7 @@ def setup(self):

@QtCore.pyqtSlot(str, str, str)
def run_plugin_command(self, plugin, cmd, args):
print "run_plugin_command", plugin, cmd, args
print("run_plugin_command", plugin, cmd, args)
# Note: since we're using signals to loosely connect with the widget
# it's not possible to get a return value. But we probably don't
# want that anyway since it might block..?
Expand Down
26 changes: 14 additions & 12 deletions svgsynoptic2/synopticwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
import os
import json

from PyQt4 import Qt, QtCore, QtGui
from PyQt4.QtWebKit import QWebPage, QWebView, QWebSettings, QWebInspector
from PyQt5 import Qt, QtCore, QtGui, QtWidgets
from PyQt5.QtWebKitWidgets import QWebView, QWebPage, QWebInspector
from PyQt5.QtWebKit import QWebSettings

from jsinterface import JSInterface
from .jsinterface import JSInterface


class LoggingWebPage(QWebPage):
Expand All @@ -27,10 +28,10 @@ def __init__(self, logger=None, parent=None):

def javaScriptConsoleMessage(self, msg, lineNumber, sourceID):
# don't use the logger for now; too verbose :)
print "JsConsole(%s:%d):\n\t%s" % (sourceID, lineNumber, msg)
print("JsConsole(%s:%d):\n\t%s" % (sourceID, lineNumber, msg))


class SynopticWidget(QtGui.QWidget):
class SynopticWidget(QtWidgets.QWidget):

"""
A Qt widget displaying a SVG synoptic in a webview.
Expand All @@ -50,7 +51,7 @@ def __init__(self, url=None, parent=None, *args, **kwargs):
self._modelNames = None

def _setup_ui(self, url=None, section=None):
self.hbox = hbox = QtGui.QHBoxLayout(self)
self.hbox = hbox = QtWidgets.QHBoxLayout(self)
self.hbox.setContentsMargins(0, 0, 0, 0)
self.hbox.layout().setContentsMargins(0, 0, 0, 0)
self.setLayout(self.hbox)
Expand All @@ -60,13 +61,13 @@ def _setup_ui(self, url=None, section=None):
def set_url(self, url, section=None):
# TODO: probably breaks things if the url is already set
self._url = url
self.splitter = QtGui.QSplitter(self)
self.splitter = QtWidgets.QSplitter(self)
self.splitter.setOrientation(QtCore.Qt.Vertical)
self.hbox.addWidget(self.splitter)
view = self._create_view(url, section)
self._setup_inspector(view)
self.splitter.addWidget(view)
print "set_url", url
print("set_url", url)

def setConfig(self, configFile):
abspath = os.path.dirname(os.path.abspath(configFile))
Expand Down Expand Up @@ -110,7 +111,8 @@ def _create_view(self, html=None, section=None):
# Inject JSInterface into the JS global namespace as "Backend"
def addBackend():
frame.addToJavaScriptWindowObject('QtBackend', self.js)
view.connect(frame, QtCore.SIGNAL("javaScriptWindowObjectCleared()"), addBackend)
#view.connect(frame, QtCore.SIGNAL("javaScriptWindowObjectCleared()"), addBackend)
frame.javaScriptWindowObjectCleared.connect(addBackend)

# load the page
# need to set the "base URL" for the webview to find the
Expand Down Expand Up @@ -152,7 +154,7 @@ def toggle_inspector():
self._inspector.setPage(page)
self.splitter.addWidget(self._inspector)

shortcut = QtGui.QShortcut(self)
shortcut = QtWidgets.QShortcut(self)
shortcut.setKey(QtCore.Qt.Key_F12)
shortcut.activated.connect(toggle_inspector)

Expand Down Expand Up @@ -218,7 +220,7 @@ def select(self, kind, names, replace=True):
"""Set a list of items as 'selected'. By default unselects all
previously selected things first.
"""
print "select", kind, names
print("select", kind, names)
if replace:
self.js.evaluate("synoptic.unselectAll()")
if names:
Expand All @@ -234,7 +236,7 @@ def unselect_all(self):

if __name__ == '__main__':
import sys
print sys.argv[1]
print(sys.argv[1])
qapp = Qt.QApplication([])
sw = SynopticWidget(sys.argv[1])
sw.show()
Expand Down
20 changes: 10 additions & 10 deletions svgsynoptic2/taurusregistry.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from threading import Lock, Event
from time import sleep

from PyQt4 import QtCore
from PyQt5 import QtCore
from taurus import Attribute
from taurus.core import TaurusException
try:
Expand All @@ -18,9 +18,9 @@

# We can't use pytango's CaselessDict since it does not keep the original
# case of the keys :(
from caseless import CaselessDictionary as CaselessDict
from .caseless import CaselessDictionary as CaselessDict

from ttldict import TTLDict
from .ttldict import TTLDict


class Registry(QtCore.QThread):
Expand Down Expand Up @@ -77,19 +77,19 @@ def subscribe(self, models=[]):
try:
taurusattrs[modelstate] = Attribute(modelstate)
except TaurusException as e:
print "Failed to create Taurus Attribute for model %s! %s" % (model, e)
print("Failed to create Taurus Attribute for model %s! %s" % (model, e))
elif (self.attribute_validator.isValid(model) or
self.eval_validator.isValid(model)):
attrs[model] = True
if model not in taurusattrs.keys():
try:
taurusattrs[model] = Attribute(model)
except TaurusException as e:
print "Failed to create Taurus Attribute for model %s! %s" % (model, e)
print("Failed to create Taurus Attribute for model %s! %s" % (model, e))
except Exception as e:
print "Failed to create Taurus Attribute for model %s!" % (model)
print("Failed to create Taurus Attribute for model %s!" % (model))
else:
print "Invalid Taurus model %s!?" % model
print("Invalid Taurus model %s!?" % model)
self._attributes = attrs
self._taurus_attributes = taurusattrs

Expand Down Expand Up @@ -129,7 +129,7 @@ def _update(self, attributes=CaselessDict()):
try:
self._add_listener(attr)
except (TypeError, PyTango.DevFailed) as e:
print "Failed to setup listener for", attr, e
print("Failed to setup listener for", attr, e)

self.unsubscribe_callback(old_attrs)

Expand All @@ -147,9 +147,9 @@ def _add_listener(self, model):
listener.addListener(self.handle_event)
return listener
except (TaurusException, AttributeError) as e:
print "Failed to subscribe to model %s! %s" % (model, e)
print("Failed to subscribe to model %s! %s" % (model, e))
except Exception:
print "Failed to subscribe to model %s!" % (model)
print("Failed to subscribe to model %s!" % (model))

def _remove_listener(self, model):
listener = self.listeners.pop(model)
Expand Down
24 changes: 12 additions & 12 deletions svgsynoptic2/taurussynopticwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import json

import numpy as np
from PyQt4 import QtCore
from PyQt5 import QtCore
import PyTango
from synopticwidget import SynopticWidget
from .synopticwidget import SynopticWidget
from taurus import Attribute, Manager, Release
from taurus.core.taurusbasetypes import (
AttrQuality, TaurusEventType, TaurusSerializationMode)
Expand Down Expand Up @@ -47,7 +47,7 @@ def run(self):
% value.value)
self.finished.emit(self.model, html)
except PyTango.DevFailed as e:
print e
print(e)


def getStateClasses(state=None):
Expand Down Expand Up @@ -110,13 +110,13 @@ def run_plugin_command(self, plugin, cmd, args):
plugins = __import__("plugins.%s" % plugin, globals(),
locals(), [cmd], -1)
except ImportError as e:
print "Could not initialize plugin '%s'!" % plugin
print e
print("Could not initialize plugin '%s'!" % plugin)
print(e)
return ""
return getattr(plugins, cmd)(self, args)

def handle_subscriptions(self, models=[]):
print "handle_subscriptions ", models
print("handle_subscriptions ", models)
if self.registry:
self.registry.subscribe(models)

Expand Down Expand Up @@ -246,7 +246,7 @@ def on_click(self, kind, name):
clicked section. Override this function if you need something
else.
"""
print "on_click", kind, name
print("on_click", kind, name)
if kind == "model" and self.registry.device_validator.isValid(name):
self.select(kind, [name])
self.emit(Qt.SIGNAL("graphicItemSelected(QString)"), name)
Expand All @@ -269,7 +269,7 @@ def on_rightclick(self, kind, name):
if name.lower() in self._panels:

widget = self._panels[name.lower()]
print "Found existing panel for %s:" % name, widget
print("Found existing panel for %s:" % name, widget)
if not widget.isVisible():
widget.show()
widget.activateWindow()
Expand Down Expand Up @@ -305,10 +305,10 @@ def _cleanup_panel(self, w):
become pretty bogged down."""
if self.registry:
with self.registry.lock:
print "cleaning up panel for", w.getModel(), "..."
print("cleaning up panel for", w.getModel(), "...")
self._panels.pop(str(w.getModel()).lower(), None)
w.setModel(None)
print "done!"
print("done!")

# Note: the tooltip stuff is broken and not currently in use.
# Currently there is only the default tooltip which displays the
Expand Down Expand Up @@ -365,13 +365,13 @@ def closeEvent(self, event):
# not exit cleanly.
super(TaurusSynopticWidget, self).closeEvent(event)
for model, panel in self._panels.items():
print "closing panel for", model
print("closing panel for", model)
panel.close()


if __name__ == '__main__':
import sys
print sys.argv[1]
print(sys.argv[1])
# qapp = Qt.QApplication([])
app = TaurusApplication()
sw = TaurusSynopticWidget()
Expand Down