File: backends.py

package info (click to toggle)
glueviz 1.0.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 30,340 kB
  • sloc: python: 44,462; makefile: 138; sh: 70
file content (60 lines) | stat: -rw-r--r-- 1,108 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"""
A common interface for accessing backend UI functionality.

At the moment, the only backend is Qt
"""
from abc import abstractmethod
_backend = None


class TimerBase(object):

    @abstractmethod
    def __init__(self, interval, callback):
        pass

    @abstractmethod
    def stop(self):
        pass

    @abstractmethod
    def start(self):
        pass


class QtTimer(TimerBase):

    def __init__(self, interval, callback):
        from qtpy import QtCore
        self._timer = QtCore.QTimer()
        self._timer.setInterval(interval)
        self._timer.timeout.connect(callback)

    def start(self):
        self._timer.start()

    def stop(self):
        self._timer.stop()


def get_timer(backend='qt'):

    if backend == 'qt':
        return QtTimer
    else:
        raise ValueError("Only QT Backend supported")


def get_backend(backend='qt'):
    global _backend

    if _backend is not None:
        return _backend

    if backend != 'qt':
        raise ValueError("Only QT Backend supported")

    from glue.qt import qt_backend

    _backend = qt_backend
    return _backend