diff -r 6c4509eceea2 -r 128d9567a533 WebBrowser/JavaScript/ExternalJsObject.py --- a/WebBrowser/JavaScript/ExternalJsObject.py Fri Feb 09 19:44:25 2018 +0100 +++ b/WebBrowser/JavaScript/ExternalJsObject.py Sat Feb 10 17:24:42 2018 +0100 @@ -27,6 +27,8 @@ """ Class implementing the endpoint of our web channel. """ + extraObjects = {} + def __init__(self, page): """ Constructor @@ -89,3 +91,41 @@ self.__startPage = StartPageJsObject(self) return self.__startPage + + @classmethod + def setupWebChannel(cls, channel, page): + """ + Class method to setup the web channel. + + @param channel reference to the channel + @type QWebChannel + @param page reference to the web page + @type QWebEnginePage + """ + channel.registerObject("eric_object", ExternalJsObject(page)) + for jsObject in cls.extraObjects: + channel.registerObject("eric_{0}".forma(jsObject), + cls.extraObjects[jsObject]) + + @classmethod + def registerExtraObject(cls, name, jsObject): + """ + Class method to register extra JavaScript objects. + + @param name name for the object + @type str + @param jsObject reference to the JavaScript object to be registered + @type QObject + """ + cls.extraObjects[id] = jsObject + + @classmethod + def unregisterExtraObject(cls, name): + """ + Class method to unregister extra JavaScript objects. + + @param name name of the object + @type str + """ + if name in cls.extraObjects: + del cls.extraObjects[name]