Commit ae59a3de authored by Dan Pascu's avatar Dan Pascu

Do not schedule to the GUI thread when already in the GUI thread

parent 8f5fdf50
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
__all__ = ['QSingleton', 'call_in_gui_thread', 'call_later', 'run_in_gui_thread'] __all__ = ['QSingleton', 'call_in_gui_thread', 'call_later', 'run_in_gui_thread']
from PyQt4.QtCore import QObject, QTimer from PyQt4.QtCore import QObject, QThread, QTimer
from PyQt4.QtGui import QApplication from PyQt4.QtGui import QApplication
from application.python.decorator import decorator, preserve_signature from application.python.decorator import decorator, preserve_signature
from application.python.types import Singleton from application.python.types import Singleton
...@@ -17,6 +17,9 @@ class QSingleton(Singleton, type(QObject)): ...@@ -17,6 +17,9 @@ class QSingleton(Singleton, type(QObject)):
def call_in_gui_thread(function, *args, **kw): def call_in_gui_thread(function, *args, **kw):
application = QApplication.instance() application = QApplication.instance()
if application.thread() is QThread.currentThread():
function(*args, **kw)
else:
application.postEvent(application, CallFunctionEvent(function, args, kw)) application.postEvent(application, CallFunctionEvent(function, args, kw))
...@@ -26,11 +29,14 @@ def call_later(interval, function, *args, **kw): ...@@ -26,11 +29,14 @@ def call_later(interval, function, *args, **kw):
@decorator @decorator
def run_in_gui_thread(func): def run_in_gui_thread(function):
@preserve_signature(func) @preserve_signature(function)
def wrapper(*args, **kw): def wrapper(*args, **kw):
application = QApplication.instance() application = QApplication.instance()
application.postEvent(application, CallFunctionEvent(func, args, kw)) if application.thread() is QThread.currentThread():
function(*args, **kw)
else:
application.postEvent(application, CallFunctionEvent(function, args, kw))
return wrapper return wrapper
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment