Skip to content
Snippets Groups Projects
Commit 1f0f36db authored by Paul McCarthy's avatar Paul McCarthy
Browse files

Async.run does not create a separate thread if wx is not

running. GLModel has to implement GLObject.ready() method.
parent 952e6cae
No related branches found
No related tags found
No related merge requests found
......@@ -165,7 +165,10 @@ def runTool(toolName, args, **kwargs):
"""
args = [toolName] + args
if log.getEffectiveLevel() == logging.DEBUG:
args = ['-vvv'] + args
# If we are running from a compiled fsleyes
# executable, we need to prepend command line
# arguments with 'cmd' - see the wrapper script
......
......@@ -106,6 +106,12 @@ class GLModel(globject.GLObject):
self.opts = None
def ready(self):
"""Overrides :meth:`.GLObject.ready`. Always returns ``True``.
"""
return True
def addListeners(self):
"""Called by :meth:`__init__`. Adds some property listeners to the
:class:`.Display` and :class:`.ModelOpts` instances so the OpenGL
......
......@@ -59,13 +59,18 @@ def run(task, onFinish=None, name=None):
:arg name: An optional name to use for this task in log statements.
.. note:: If a ``wx`` application is not running, the ``onFinish``
function is called directly from the task thread.
:returns: A reference to the ``Thread`` that was created.
.. note:: If a ``wx`` application is not running, the ``task`` and
``onFinish`` functions will simply be called directly, and
the return value will be ``None``.
"""
if name is None:
name = 'async task'
haveWX = _haveWX()
def wrapper():
log.debug('Running task "{}"...'.format(name))
......@@ -73,24 +78,26 @@ def run(task, onFinish=None, name=None):
log.debug('Task "{}" finished'.format(name))
if onFinish is not None:
if _haveWX():
import wx
if (onFinish is not None):
log.debug('Scheduling task "{}" finish handler '
'on wx.MainLoop'.format(name))
import wx
wx.CallAfter(onFinish)
else:
log.debug('Running task "{}" finish handler'.format(name))
onFinish()
log.debug('Scheduling task "{}" finish handler '
'on wx.MainLoop'.format(name))
thread = threading.Thread(target=wrapper)
thread.start()
wx.CallAfter(onFinish)
return thread
if haveWX:
thread = threading.Thread(target=wrapper)
thread.start()
return thread
else:
log.debug('Running task "{}" directly'.format(name))
task()
log.debug('Running task "{}" finish handler'.format(name))
onFinish()
return None
_idleRegistered = False
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment