Skip to content

Commit

Permalink
Make sure that get_timer works if Qt is not installed
Browse files Browse the repository at this point in the history
  • Loading branch information
astrofrog committed Aug 15, 2023
1 parent dc30657 commit cb691a1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
24 changes: 19 additions & 5 deletions glue/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ def start(self):
pass


class SimpleTimer(TimerBase):

def __init__(self, interval, callback):
from threading import Timer
self._timer = Timer(interval / 1000., callback)

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

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


class QtTimer(TimerBase):

def __init__(self, interval, callback):
Expand All @@ -37,12 +50,13 @@ def stop(self):
self._timer.stop()


def get_timer(backend='qt'):

if backend == 'qt':
return QtTimer
def get_timer():
try:
from qtpy import QtCore
except ImportError:
return SimpleTimer
else:
raise ValueError("Only QT Backend supported")
return QtTimer


def get_backend(backend='qt'):
Expand Down
3 changes: 0 additions & 3 deletions glue/core/data_factories/tests/test_data_factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,6 @@ def test_data_reload_shape_change():
assert d.coords is coords_old


# TODO: this doesn't belong in the core since it relies on Qt
@requires_qt
def test_file_watch():
cb = MagicMock()
with make_file(b'test', 'csv') as fname:
Expand All @@ -232,7 +230,6 @@ def test_file_watch():
assert cb.call_count == 1


@requires_qt
@pytest.mark.skipif(sys.platform.startswith('win'), reason='file deletion doesn\'t work on Windows')
def test_file_watch_os_error():
cb = MagicMock()
Expand Down

0 comments on commit cb691a1

Please sign in to comment.