File: backends.py

package info (click to toggle)
glueviz 0.9.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 17,180 kB
  • ctags: 6,728
  • sloc: python: 37,111; makefile: 134; sh: 60
file content (62 lines) | stat: -rw-r--r-- 1,174 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
61
62
"""
A common interface for accessing backend UI functionality.

At the moment, the only backend is Qt
"""
from __future__ import absolute_import, division, print_function

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