Python qtpy.QtCore.QObject() Examples

The following are 9 code examples of qtpy.QtCore.QObject(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module qtpy.QtCore , or try the search function .
Example #1
Source File: threading.py    From napari with BSD 3-Clause "New" or "Revised" License 7 votes vote down vote up
def __init__(
        self,
        func: Callable,
        *args,
        SignalsClass: Type[QObject] = GeneratorWorkerSignals,
        **kwargs,
    ):
        if not inspect.isgeneratorfunction(func):
            raise TypeError(
                f"Regular function {func} cannot be used with "
                "GeneratorWorker, use FunctionWorker instead"
            )
        super().__init__(SignalsClass=SignalsClass)

        self._gen = func(*args, **kwargs)
        self._incoming_value = None
        self._pause_requested = False
        self._resume_requested = False
        self._paused = False
        # polling interval: ONLY relevant if the user paused a running worker
        self._pause_interval = 0.01 
Example #2
Source File: threading.py    From napari with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def __getattr__(self, name):
        """Pass through attr requests to signals to simplify connection API.

        The goal is to enable ``worker.signal.connect`` instead of
        ``worker.signals.yielded.connect``. Because multiple inheritance of Qt
        classes is not well supported in PyQt, we have to use composition here
        (signals are provided by QObjects, and QRunnable is not a QObject). So
        this passthrough allows us to connect to signals on the ``_signals``
        object.
        """
        # the Signal object is actually a class attribute
        attr = getattr(self._signals.__class__, name, None)
        if isinstance(attr, Signal):
            # but what we need to connect to is the instantiated signal
            # (which is of type `SignalInstance` in PySide and
            # `pyqtBoundSignal` in PyQt)
            return getattr(self._signals, name) 
Example #3
Source File: zmqstream.py    From spyder-unittest with MIT License 5 votes vote down vote up
def __init__(self):
        """Constructor; also constructs ZMQ stream."""
        super(QObject, self).__init__()
        self.context = zmq.Context()
        self.socket = self.context.socket(zmq.PAIR)
        self.port = self.socket.bind_to_random_port('tcp://*')
        fid = self.socket.getsockopt(zmq.FD)
        self.notifier = QSocketNotifier(fid, QSocketNotifier.Read, self)
        self.notifier.activated.connect(self.received_message) 
Example #4
Source File: threading.py    From napari with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __init__(
        self, *args, SignalsClass: Type[QObject] = WorkerBaseSignals, **kwargs
    ) -> None:
        super().__init__()
        self._abort_requested = False
        self._running = False
        self._signals = SignalsClass() 
Example #5
Source File: util.py    From qtconsole with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def superQ(QClass):
    """ Permits the use of super() in class hierarchies that contain Qt classes.

    Unlike QObject, SuperQObject does not accept a QObject parent. If it did,
    super could not be emulated properly (all other classes in the heierarchy
    would have to accept the parent argument--they don't, of course, because
    they don't inherit QObject.)

    This class is primarily useful for attaching signals to existing non-Qt
    classes. See QtKernelManagerMixin for an example.
    """
    class SuperQClass(QClass):

        def __new__(cls, *args, **kw):
            # We initialize QClass as early as possible. Without this, Qt complains
            # if SuperQClass is not the first class in the super class list.
            inst = QClass.__new__(cls)
            QClass.__init__(inst)
            return inst

        def __init__(self, *args, **kw):
            # Emulate super by calling the next method in the MRO, if there is one.
            mro = self.__class__.mro()
            for qt_class in QClass.mro():
                mro.remove(qt_class)
            next_index = mro.index(SuperQClass) + 1
            if next_index < len(mro):
                mro[next_index].__init__(self, *args, **kw)

    return SuperQClass 
Example #6
Source File: test_qtcore.py    From qtpy with MIT License 5 votes vote down vote up
def test_QtCore_SignalInstance():
    class ClassWithSignal(QtCore.QObject):
        signal = QtCore.Signal()

    instance = ClassWithSignal()

    assert isinstance(instance.signal, QtCore.SignalInstance) 
Example #7
Source File: pyrpl_widget.py    From pyrpl with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self):
        """
        Initialize the handler
        """
        logging.Handler.__init__(self)
        QtCore.QObject.__init__(self)
        # set format of logged messages
        self.setFormatter(logging.Formatter('%(levelname)s (%(name)s): %(message)s')) 
Example #8
Source File: client_api.py    From conda-manager with MIT License 5 votes vote down vote up
def __init__(self):
        """Anaconda Client API wrapper."""
        super(QObject, self).__init__()
        self._anaconda_client_api = binstar_client.utils.get_server_api(
            log_level=logging.NOTSET)
        self._queue = deque()
        self._threads = []
        self._workers = []
        self._timer = QTimer()
        self._conda_api = CondaAPI()

        self._timer.setInterval(1000)
        self._timer.timeout.connect(self._clean) 
Example #9
Source File: download_api.py    From conda-manager with MIT License 5 votes vote down vote up
def __init__(self, load_rc_func=None):
        """Download API based on requests."""
        super(QObject, self).__init__()
        self._conda_api = CondaAPI()
        self._queue = deque()
        self._threads = []
        self._workers = []
        self._timer = QTimer()

        self._load_rc_func = load_rc_func
        self._chunk_size = 1024
        self._timer.setInterval(1000)
        self._timer.timeout.connect(self._clean)