Exemple #1
0
    def add(self, func):
        func_id = get_id()

        event_wrapper = u"window[{storage_name}].add(event)".format(
            storage_name=escape_js(self.events_storage.name), )
        js_func = u"window[{storage_name}][{func_id}] = " \
                  u"function(event) {{ window[{storage_name}].run({func_id}, {event}, event) }}"\
            .format(
                storage_name=escape_js(self.name),
                func_id=escape_js(func_id),
                event=event_wrapper
            )

        escape_and_evaljs(self.parent().web_page.mainFrame(), js_func)

        self.storage[func_id] = func
        return func_id
Exemple #2
0
    def __init__(self,
                 parent,
                 callback,
                 errback,
                 logger: SplashLogger,
                 timeout=0):
        self.name = get_id()
        self._used_up = False
        self._callback = callback
        self._errback = errback
        self.logger = logger

        if timeout < 0:
            raise ValueError('OneShotCallbackProxy timeout must be >= 0.')
        elif timeout == 0:
            self._timer = None
        elif timeout > 0:
            self._timer = QTimer()
            self._timer.setSingleShot(True)
            self._timer.timeout.connect(self._timed_out)
            self._timer.start(timeout * 1000)

        super(OneShotCallbackProxy, self).__init__(parent)
Exemple #3
0
 def get_id(self):
     return get_id()
Exemple #4
0
 def __init__(self, parent):
     self.name = get_id()
     super(EventsStorage, self).__init__(parent)
Exemple #5
0
 def __init__(self, parent, events_storage):
     self.name = get_id()
     self.events_storage = events_storage
     self.storage = {}
     super(EventHandlersStorage, self).__init__(parent)