GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

qtsass.watchers.qt   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 97
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 49
dl 0
loc 97
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A QtWatcher.on_change() 0 12 2
A QtWatcher.setup() 0 4 1
A QtWatcher.qtdispatcher() 0 7 2
1
# -*- coding: utf-8 -*-
2
# -----------------------------------------------------------------------------
3
# Copyright (c) 2015 Yann Lanthony
4
# Copyright (c) 2017-2018 Spyder Project Contributors
5
#
6
# Licensed under the terms of the MIT License
7
# (See LICENSE.txt for details)
8
# -----------------------------------------------------------------------------
9
"""Contains the Qt implementation of the Watcher api."""
10
11
# yapf: disable
12
13
from __future__ import absolute_import
14
15
# Local imports
16
from qtsass.watchers.polling import PollingWatcher
17
18
19
# We cascade through Qt bindings here rather than relying on a comprehensive
20
# Qt compatability library like qtpy or Qt.py. This prevents us from forcing a
21
# specific compatability library on users.
22
QT_BINDING = None
23
if not QT_BINDING:
24
    try:
25
        from PySide2.QtWidgets import QApplication
26
        from PySide2.QtCore import QObject, Signal
27
        QT_BINDING = 'pyside2'
28
    except ImportError:
29
        pass
30
if not QT_BINDING:
31
    try:
32
        from PyQt5.QtWidgets import QApplication
33
        from PyQt5.QtCore import QObject
34
        from PyQt5.QtCore import pyqtSignal as Signal
35
        QT_BINDING = 'pyqt5'
36
    except ImportError:
37
        pass
38
if not QT_BINDING:
39
    try:
40
        from PySide.QtGui import QApplication
41
        from PySide2.QtCore import QObject, Signal
42
        QT_BINDING == 'pyside'
43
    except ImportError:
44
        pass
45
if not QT_BINDING:
46
    from PyQt4.QtGui import QApplication
47
    from PyQt4.QtCore import QObject
48
    from PyQt4.QtCore import pyqtSignal as Signal
49
    QT_BINDING == 'pyqt4'
50
51
52
# yapf: enable
53
54
55
class QtDispatcher(QObject):
0 ignored issues
show
introduced by
The variable QObject does not seem to be defined in case BooleanNotNode on line 23 is False. Are you sure this can never be the case?
Loading history...
56
    """Used by QtWatcher to dispatch callbacks in the main ui thread."""
57
58
    signal = Signal()
0 ignored issues
show
introduced by
The variable Signal does not seem to be defined in case BooleanNotNode on line 23 is False. Are you sure this can never be the case?
Loading history...
59
60
61
class QtWatcher(PollingWatcher):
62
    """The Qt implementation of the Watcher api.
63
64
    Subclasses PollingWatcher but dispatches :meth:`compile_and_dispatch`
65
    using a Qt Signal to ensure that these calls are executed in the main ui
66
    thread. We aren't using a QFileSystemWatcher because it fails to report
67
    changes in certain circumstances.
68
    """
69
70
    _qt_binding = QT_BINDING
71
72
    def setup(self):
73
        """Set up QtWatcher."""
74
        super(QtWatcher, self).setup()
75
        self._qtdispatcher = None
76
77
    @property
78
    def qtdispatcher(self):
79
        """Get the QtDispatcher."""
80
        if self._qtdispatcher is None:
81
            self._qtdispatcher = QtDispatcher()
82
            self._qtdispatcher.signal.connect(self.compile_and_dispatch)
83
        return self._qtdispatcher
84
85
    def on_change(self):
86
        """Call when a change is detected."""
87
        self._log.debug('Change detected...')
88
89
        # If a QApplication event loop has not been started
90
        # call compile_and_dispatch in the current thread.
91
        if not QApplication.instance():
0 ignored issues
show
introduced by
The variable QApplication does not seem to be defined in case BooleanNotNode on line 23 is False. Are you sure this can never be the case?
Loading history...
92
            return super(PollingWatcher, self).compile_and_dispatch()
93
94
        # Create and use a QtDispatcher to ensure compile and any
95
        # connected callbacks get executed in the main gui thread.
96
        self.qtdispatcher.signal.emit()
97