event.py 920 Bytes
Newer Older
1

Dan Pascu's avatar
Dan Pascu committed
2
from PyQt5.QtCore import QEvent
3

4
from application.python.descriptor import classproperty
5 6


7 8 9
__all__ = ['CallFunctionEvent']


10 11 12 13 14 15
class EventMeta(type(QEvent)):
    def __init__(cls, name, bases, dct):
        super(EventMeta, cls).__init__(name, bases, dct)
        cls.id = QEvent.registerEventType() if name != 'EventBase' else None


Adrian Georgescu's avatar
Adrian Georgescu committed
16
class EventBase(QEvent, metaclass=EventMeta):
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
    def __new__(cls, *args, **kw):
        if cls is EventBase:
            raise TypeError("EventBase cannot be directly instantiated")
        return super(EventBase, cls).__new__(cls)

    def __init__(self):
        super(EventBase, self).__init__(self.id)

    @classproperty
    def name(cls):
        return cls.__name__


class CallFunctionEvent(EventBase):
    def __init__(self, function, args, kw):
        super(CallFunctionEvent, self).__init__()
        self.function = function
        self.args = args
        self.kw = kw