Пример #1
0
 def __init__(self, event_id=1000, name="", data=None):
     '''after id 1000 starts custom_user_event'''
     self.idType = QEvent.registerEventType(event_id)
     self.name = name
     self.data = data
     QEvent.__init__(self, self.idType)
     print("Created CustomEvent with id: ", self.idType)
Пример #2
0
 def __init__(self, tag: str):
     """
     Args:
         tag (str): Тег статьи.
     """
     # noinspection PyTypeChecker
     QEvent.__init__(self, DeleteArticleTagEvent.idType)
     self.tag = tag
Пример #3
0
 def __init__(self, etype, key, value=None, oldValue=None):
     """
     Initialize the event instance
     """
     QEvent.__init__(self, etype)
     self.__key = key
     self.__value = value
     self.__oldValue = oldValue
Пример #4
0
 def __init__(self, function, args, kwargs, semaphore=None):
     QEvent.__init__(self, QueuedCallEvent.QueuedCall)
     self.function = function
     self.args = args
     self.kwargs = kwargs
     self.semaphore = semaphore
     self._result = None
     self._exc_info = None
     self._state = 0
Пример #5
0
 def __init__(self, queue, exceptions_in_main, fn, *args, **kwargs):
     QEvent.__init__(self, self.EVENT_TYPE)
     self.fn = fn
     self.args = args
     self.kwargs = kwargs
     self._returnval = queue
     # Whether to raise exceptions in the main thread or store them
     # for raising in the calling thread:
     self._exceptions_in_main = exceptions_in_main
Пример #6
0
 def __init__(self, callback, response):
     """ A WorkerEvent encapsulates a function to be called in the main ui loop and its argument
         :param callback: The function to be called when the event gets processed
         :type callback: function
         :param response: Response message from the worker, passed as argument to the callback function
         :type response: str
     """
     QEvent.__init__(self, WorkerEvent.EVENT_TYPE)
     self.callback = callback
     self.response = response
Пример #7
0
 def __init__(self, callback, response):
     """ A WorkerEvent encapsulates a function to be called in the main ui loop and its argument
         :param callback: The function to be called when the event gets processed
         :type callback: function
         :param response: Response message from the worker, passed as argument to the callback function
         :type response: str
     """
     QEvent.__init__(self, WorkerEvent.EVENT_TYPE)
     self.callback = callback
     self.response = response
Пример #8
0
    def processEvents(self):
        # Process incoming data, and send to sim
        while self.connection.poll():
            (eventtype, event) = self.connection.recv()
            if eventtype == SetNodeIdType:
                self.nodeid = event
            elif eventtype == SetActiveNodeType:
                self.active = event
            else:
                # Data over pipes is pickled/unpickled, this causes problems with
                # inherited classes. Solution is to call the ancestor's init
                QEvent.__init__(event, eventtype)
                self.sim.event(event)

        # Process timers
        Timer.updateTimers()
Пример #9
0
    def processEvents(self):
        # Process incoming data, and send to sim
        while self.connection.poll():
            (eventtype, event) = self.connection.recv()
            if eventtype == SetNodeIdType:
                self.nodeid = event
            elif eventtype == SetActiveNodeType:
                self.active = event
            else:
                # Data over pipes is pickled/unpickled, this causes problems with
                # inherited classes. Solution is to call the ancestor's init
                QEvent.__init__(event, eventtype)
                self.sim.event(event)

        # Process timers
        Timer.updateTimers()
Пример #10
0
 def __init__(self, id, data=None, *args):
     # Invoke parent init
     QEvent.__init__(self, id)
     self.data = data
     self.id = id
Пример #11
0
 def __init__(self, error, data):
     QEvent.__init__(self, self.TYPE)
     self.error = error
     self.data = data
Пример #12
0
 def __init__(self):
     QEvent.__init__(self, 2001)
     self.registerEventType(self.event_type)
Пример #13
0
 def __init__(self, reference, *args, **kwargs):
     QEvent.__init__(self, QSlotEvent.EVENT_TYPE)
     self.reference = reference
     self.args = args
     self.kwargs = kwargs
Пример #14
0
 def __init__(self, data):
     QEvent.__init__(self, MyEvent.idType)
     self.data = data
Пример #15
0
 def __init__(self, _, event):
     QEvent.__init__(self, _)
     self.event = event
Пример #16
0
    def __init__(self, func, *args, **kwargs):
        QEvent.__init__(self, self.EVENT_TYPE)

        self.func = func
        self.args = args
        self.kwargs = kwargs
Пример #17
0
 def __init__(self, point):
     QEvent.__init__(self, ReleasePosEvent.EventType)
     self.point = point
Пример #18
0
    def receiveFromNodes(self):
        # Only look for incoming data if we're not quitting
        if self.stopping:
            return

        # First look for new connections
        r, w, e = select.select((self.listener, ), (), (), 0)
        if self.listener in r:
            conn = self.listener.accept()
            address = self.listener.last_accepted[0]
            if address in self.hosts:
                nodeid = self.hosts[address]
            else:
                nodeid = (len(self.hosts), 0)
            # Store host number and its number of nodes
            self.hosts[address] = (nodeid[0], nodeid[1] + 1)
            # Send the node information about its nodeid
            connidx = len(self.connections)
            conn.send((SetNodeIdType, nodeid))
            self.connections.append([conn, nodeid, 0])
            self.nodes_changed.emit(address, nodeid, connidx)
            self.setActiveNode(connidx)

        # Then process any data in the active connections
        for idx, conn in enumerate(self.connections):
            if conn[0] is None or conn[0].closed:
                continue

            # Check for incoming events with poll
            while conn[0].poll():
                # Receive events that are waiting in the conn
                try:
                    (eventtype, event) = conn[0].recv()
                except:
                    continue

                # Sender id is connection index and node id
                self.sender_id = (idx, conn[1])

                if eventtype == AddNodeType:
                    # This event only consists of an int: the number of nodes to add
                    for i in range(event):
                        self.addNode()
                    continue
                # Data over connections is pickled/unpickled, this causes problems with
                # inherited classes. Solution is to call the ancestor's init
                QEvent.__init__(event, eventtype)

                # First check if this event is meant for the manager
                if event.type() == SimStateEventType:
                    # Save the state together with the connection object
                    conn[2] = event.state
                    if event.state == event.end:
                        # Quit the main loop. Afterwards, manager will also quit
                        qapp.instance().quit()

                    elif event.state == event.init or event.state == event.hold:
                        if len(self.scenarios) > 0:
                            self.sendScenario(conn)

                elif event.type() == BatchEventType:
                    self.scenarios = [scen for scen in split_scenarios(event.scentime, event.scencmd)]
                    # Check if the batch list contains scenarios
                    if len(self.scenarios) == 0:
                        qapp.sendEvent(qapp.instance(), StackTextEvent(disptext='No scenarios defined in batch file!'))

                    else:
                        qapp.sendEvent(qapp.instance(), StackTextEvent(disptext='Found %d scenarios in batch' % len(self.scenarios)))
                        # Available nodes (nodes that are in init or hold mode):
                        av_nodes = [n for n, conn in enumerate(self.connections) if conn[2] in [0, 2]]
                        for i in range(min(len(av_nodes), len(self.scenarios))):
                            self.sendScenario(self.connections[i])
                        # If there are still scenarios left, determine and start the required number of local nodes
                        reqd_nnodes = min(len(self.scenarios), max(0, self.max_nnodes - len(self.localnodes)))
                        for n in range(reqd_nnodes):
                            self.addNode()

                elif event.type() == StackTextEventType:
                    self.telnet_in.sendReply(event)

                    if not event.disptext == MSG_OK:
                        qapp.sendEvent(qapp.instance(), event)

                else:
                    # The event is meant for the gui
                    qapp.sendEvent(qapp.instance(), event)

        # To avoid giving wrong information with sender() when it is called outside
        # of this function, set sender_id to None
        self.sender_id = None
Пример #19
0
 def __init__(self, callback):
     # Thread-safe
     QEvent.__init__(self, _Event.EVENT_TYPE)
     self.callback = callback
Пример #20
0
 def __init__(self, reference, *args, **kwargs):
     QEvent.__init__(self, QSlotEvent.EVENT_TYPE)
     self.reference = reference
     self.args = args
     self.kwargs = kwargs
Пример #21
0
 def __init__(self, data):
     #thread-safe
     QEvent.__init__(self, Event.EVENT_TYPE)
     self.data = data
Пример #22
0
 def __init__(self, data):
     QEvent.__init__(self, NotifyParent.idType)
     self.data = data
Пример #23
0
 def __init__(self, func, *args):
     QEvent.__init__(self, self.EventType)
     if len(args) > 0:
         self.thunk = partial(func, *args)
     else:
         self.thunk = func
Пример #24
0
 def __init__(self, func, *args, **kwargs):
     QEvent.__init__(self, QEvent.User)
     self.func = func
     self.args = args
     self.kwargs = kwargs
Пример #25
0
    def receiveFromNodes(self):
        # Only look for incoming data if we're not quitting
        if self.stopping:
            return

        # First look for new connections
        r, w, e = select.select((self.listener, ), (), (), 0)
        if self.listener in r:
            conn = self.listener.accept()
            address = self.listener.last_accepted[0]
            if address in self.hosts:
                nodeid = self.hosts[address]
            else:
                nodeid = (len(self.hosts), 0)
            # Store host number and its number of nodes
            self.hosts[address] = (nodeid[0], nodeid[1] + 1)
            # Send the node information about its nodeid
            connidx = len(self.connections)
            conn.send((SetNodeIdType, nodeid))
            self.connections.append([conn, nodeid, 0])
            self.nodes_changed.emit(address, nodeid, connidx)
            self.setActiveNode(connidx)

        # Then process any data in the active connections
        for connidx in range(len(self.connections)):
            conn = self.connections[connidx]
            if conn[0] is None or conn[0].closed:
                continue

            # Check for incoming events with poll
            while conn[0].poll():
                # Receive events that are waiting in the conn
                try:
                    (eventtype, event) = conn[0].recv()
                except:
                    continue

                # Sender id is connection index and node id
                self.sender_id = (connidx, conn[1])

                if eventtype == AddNodeType:
                    # This event only consists of an int: the number of nodes to add
                    for i in range(event):
                        self.addNode()
                    continue
                # Data over connections is pickled/unpickled, this causes problems with
                # inherited classes. Solution is to call the ancestor's init
                QEvent.__init__(event, eventtype)

                # First check if this event is meant for the manager
                if event.type() == SimStateEventType:
                    # Save the state together with the connection object
                    conn[2] = event.state
                    if event.state == event.end:
                        # Quit the main loop. Afterwards, manager will also quit
                        qapp.instance().quit()

                    elif event.state == event.init or event.state == event.hold:
                        if len(self.scenarios) > 0:
                            self.sendScenario(conn)

                elif event.type() == BatchEventType:
                    self.scenarios = [scen for scen in split_scenarios(event.scentime, event.scencmd)]
                    # Check if the batch list contains scenarios
                    if len(self.scenarios) == 0:
                        qapp.sendEvent(qapp.instance(), StackTextEvent(disptext='No scenarios defined in batch file!'))

                    else:
                        qapp.sendEvent(qapp.instance(), StackTextEvent(disptext='Found %d scenarios in batch' % len(self.scenarios)))
                        # Available nodes (nodes that are in init or hold mode):
                        av_nodes = [n for n in range(len(self.connections)) if self.connections[n][2] in [0, 2]]
                        for i in range(min(len(av_nodes), len(self.scenarios))):
                            self.sendScenario(self.connections[i])
                        # If there are still scenarios left, determine and start the required number of local nodes
                        reqd_nnodes = min(len(self.scenarios), max(0, self.max_nnodes - len(self.localnodes)))
                        for n in range(reqd_nnodes):
                            self.addNode()

                else:
                    # The event is meant for the gui
                    qapp.sendEvent(qapp.instance(), event)

        # To avoid giving wrong information with sender() when it is called outside
        # of this function, set sender_id to None
        self.sender_id = None
Пример #26
0
 def __init__(self, initstate):
     QEvent.__init__(self, WidgetManager.WidgetInitEvent.DelayedInit)
     self._initstate = initstate
Пример #27
0
 def __init__(self, id, data=None, *args):
     # Invoke parent init
     QEvent.__init__(self, id)
     self.data = data
     self.id = id
Пример #28
0
 def __init__(self, etype):
     QEvent.__init__(self, etype)
Пример #29
0
 def __init__(self, func, *args, **kwargs):
     QEvent.__init__(self, QEvent.User)
     self.func = func
     self.args = args
     self.kwargs = kwargs
Пример #30
0
 def __init__(self, func, *args):
     QEvent.__init__(self, self.EventType)
     if len(args) > 0:
         self.thunk = partial(func, *args)
     else:
         self.thunk = func