change/fix long name of 'qrun' to 'qrun-on-ui-thread' (erroneously called 'qrun-in-gui-thread')
This commit is contained in:
parent
0f1ae2cc07
commit
36232f6d37
11 changed files with 33 additions and 32 deletions
|
|
@ -27,7 +27,7 @@
|
|||
|
||||
;; in some ECL thread
|
||||
(let (values)
|
||||
(run-in-gui-thread
|
||||
(run-on-ui-thread
|
||||
|
||||
;; in ECL main/GUI thread
|
||||
(lambda ()
|
||||
|
|
@ -36,14 +36,14 @@
|
|||
;; back in some ECL thread
|
||||
(values-list values))
|
||||
</pre>
|
||||
<p>Here the implementation of the ECL function <code>run-in-gui-thread</code> (embedded in Qt):</p>
|
||||
<p>Here the implementation of the ECL function <code>run-on-ui-thread</code> (embedded in Qt):</p>
|
||||
<pre>
|
||||
|
||||
cl_object run_in_gui_thread(cl_object closure) // define ECL function
|
||||
cl_object run_on_ui_thread(cl_object closure) // define ECL function
|
||||
{
|
||||
QMetaObject::invokeMethod(
|
||||
object, // any QObject from GUI thread
|
||||
"runInGuiThread", // see Q_INVOKABLE
|
||||
"runOnUiThread", // see Q_INVOKABLE
|
||||
Qt::BlockingQueuedConnection, // blocking for return values
|
||||
Q_ARG(void*, closure)); // 'closure' is just a pointer
|
||||
|
||||
|
|
@ -53,7 +53,7 @@
|
|||
<p>Now the Lisp closure will run in the GUI/main thread, and the implementation of the Qt function <code>runInGuiThread</code> is as simple as:</p>
|
||||
<pre>
|
||||
|
||||
Q_INVOKABLE void runInGuiThread(void* closure) // note Q_INVOKABLE
|
||||
Q_INVOKABLE void runOnUiThread(void* closure) // note Q_INVOKABLE
|
||||
{
|
||||
cl_funcall(1, (cl_object)closure); // ECL function call
|
||||
}
|
||||
|
|
|
|||
|
|
@ -463,17 +463,17 @@ Loads an EQL module, corresponding to a Qt module.<br>Returns the module name if
|
|||
Constructs a <code>(unsigned-byte 32)</code> value that represents a 32 bit pixel color specified by the red, green, blue and alpha values.
|
||||
<br>
|
||||
<br><br>
|
||||
<b>QRUN-IN-GUI-THREAD (function &optional (blocking t))</b>
|
||||
<b>QRUN-ON-UI-THREAD (function &optional (blocking t))</b>
|
||||
<br>
|
||||
<b>QRUN</b>
|
||||
<br><br>
|
||||
Runs <code>function</code> in GUI thread while (by default) blocking the calling thread (if called from main thread, <code>function</code> will simply be called directly).<br>This is needed to run GUI code from ECL threads other than the main thread.<br>Returns <code>T</code> on success.<br><br>There are 2 reasons to always wrap any EQL function like this, if called from another ECL thread:<ul><li>Qt GUI methods always need to run in the GUI thread<li>EQL functions are not designed to be reentrant (not needed for GUI code)</ul>See also macro <code>qrun*</code>.
|
||||
Runs <code>function</code> on the UI thread while (by default) blocking the calling thread (if called from main thread, <code>function</code> will simply be called directly).<br>This is needed to run GUI code from ECL threads other than the main thread.<br>Returns <code>T</code> on success.<br><br>There are 2 reasons to always wrap any EQL function like this, if called from another ECL thread:<ul><li>Qt UI methods always need to run on the UI thread<li>EQL functions are not designed to be reentrant (not needed for UI code)</ul>See also macro <code>qrun*</code>.
|
||||
<br>
|
||||
<pre>
|
||||
(qrun 'update-view-data)
|
||||
</pre>
|
||||
<br><br>
|
||||
<b>QRUN-IN-GUI-THREAD* (&body body)</b>
|
||||
<b>QRUN-ON-UI-THREAD* (&body body)</b>
|
||||
<br>
|
||||
<b>QRUN*</b>
|
||||
<br><br>
|
||||
|
|
|
|||
|
|
@ -66,9 +66,9 @@
|
|||
"qrequire"
|
||||
"qrgb"
|
||||
"qrun"
|
||||
"qrun-in-gui-thread"
|
||||
"qrun-on-ui-thread"
|
||||
"qrun*"
|
||||
"qrun-in-gui-thread*"
|
||||
"qrun-on-ui-thread*"
|
||||
"qsel"
|
||||
"qselect"
|
||||
"qsender"
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
;;;
|
||||
;;; A simple demo for macro QRUN-IN-GUI-THREAD* / QRUN*
|
||||
;;; A simple demo for macro QRUN-ON-UI-THREAD* / QRUN*
|
||||
;;;
|
||||
;;; Calculate primes in threads and update QTreeWidget directly from threads.
|
||||
;;;
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
(defun %qeval (form)
|
||||
(multiple-value-bind (values package)
|
||||
(qrun-in-gui-thread*
|
||||
(qrun-on-ui-thread*
|
||||
(values (multiple-value-list
|
||||
(with-simple-restart (abort "Return to SLIME's top level.")
|
||||
(eval (subst 'identity 'qeval form))))
|
||||
|
|
|
|||
|
|
@ -145,7 +145,7 @@ void iniCLFunctions() {
|
|||
DEFUN ("qproperty", qproperty, 2)
|
||||
DEFUN ("%qrequire", qrequire2, 2)
|
||||
DEFUN ("qremove-event-filter", qremove_event_filter, 1)
|
||||
DEFUN ("%qrun-in-gui-thread", qrun_in_gui_thread2, 2)
|
||||
DEFUN ("%qrun-on-ui-thread", qrun_on_ui_thread2, 2)
|
||||
DEFUN ("qsender", qsender, 0)
|
||||
DEFUN ("%qset-gc", qset_gc, 1)
|
||||
DEFUN ("qset-property", qset_property, 3)
|
||||
|
|
@ -2958,26 +2958,26 @@ cl_object qversion() {
|
|||
l_env->values[1] = from_cstring(qVersion());
|
||||
return l_env->values[0]; }
|
||||
|
||||
cl_object qrun_in_gui_thread2(cl_object l_function_or_closure, cl_object l_blocking) {
|
||||
cl_object qrun_on_ui_thread2(cl_object l_function_or_closure, cl_object l_blocking) {
|
||||
/// args: (function &optional (blocking t))
|
||||
/// alias: qrun
|
||||
/// Runs <code>function</code> in GUI thread while (by default) blocking the calling thread (if called from main thread, <code>function</code> will simply be called directly).<br>This is needed to run GUI code from ECL threads other than the main thread.<br>Returns <code>T</code> on success.<br><br>There are 2 reasons to always wrap any EQL function like this, if called from another ECL thread:<ul><li>Qt GUI methods always need to run in the GUI thread<li>EQL functions are not designed to be reentrant (not needed for GUI code)</ul>See also macro <code>qrun*</code>.
|
||||
/// Runs <code>function</code> on the UI thread while (by default) blocking the calling thread (if called from main thread, <code>function</code> will simply be called directly).<br>This is needed to run GUI code from ECL threads other than the main thread.<br>Returns <code>T</code> on success.<br><br>There are 2 reasons to always wrap any EQL function like this, if called from another ECL thread:<ul><li>Qt UI methods always need to run on the UI thread<li>EQL functions are not designed to be reentrant (not needed for UI code)</ul>See also macro <code>qrun*</code>.
|
||||
/// (qrun 'update-view-data)
|
||||
ecl_process_env()->nvalues = 1;
|
||||
if(l_function_or_closure != Cnil) {
|
||||
QObject o;
|
||||
if(o.thread() == QApplication::instance()->thread()) {
|
||||
// direct call
|
||||
LObjects::eql->runInGuiThread(l_function_or_closure);
|
||||
LObjects::eql->runOnUiThread(l_function_or_closure);
|
||||
return Ct; }
|
||||
else {
|
||||
// queued call in main event loop (GUI thread)
|
||||
QMetaObject::invokeMethod(LObjects::eql,
|
||||
"runInGuiThread",
|
||||
"runOnUiThread",
|
||||
(l_blocking != Cnil) ? Qt::BlockingQueuedConnection : Qt::QueuedConnection,
|
||||
Q_ARG(void*, l_function_or_closure));
|
||||
return Ct; }}
|
||||
error_msg("QRUN-IN-GUI-THREAD", LIST1(l_function_or_closure));
|
||||
error_msg("QRUN-ON-UI-THREAD", LIST1(l_function_or_closure));
|
||||
return Cnil; }
|
||||
|
||||
cl_object qlog2(cl_object l_msg) {
|
||||
|
|
|
|||
|
|
@ -272,7 +272,7 @@ cl_object qprocess_events ();
|
|||
cl_object qproperty (cl_object, cl_object);
|
||||
cl_object qremove_event_filter (cl_object);
|
||||
cl_object qrequire2 (cl_object, cl_object);
|
||||
cl_object qrun_in_gui_thread2 (cl_object, cl_object);
|
||||
cl_object qrun_on_ui_thread2 (cl_object, cl_object);
|
||||
cl_object qsender ();
|
||||
cl_object qset_gc (cl_object);
|
||||
cl_object qset_property (cl_object, cl_object, cl_object);
|
||||
|
|
|
|||
|
|
@ -179,11 +179,12 @@ void EQL::exec(QWidget* widget, const QString& lispFile, const QString& slimeHoo
|
|||
if(exec_with_simple_restart) {
|
||||
eval("(eql::exec-with-simple-restart)"); }}
|
||||
|
||||
void EQL::runInGuiThread(void* function_or_closure) {
|
||||
void EQL::runOnUiThread(void* function_or_closure) {
|
||||
const cl_env_ptr l_env = ecl_process_env();
|
||||
CL_CATCH_ALL_BEGIN(l_env) {
|
||||
CL_UNWIND_PROTECT_BEGIN(l_env) {
|
||||
cl_funcall(1, (cl_object)function_or_closure); }
|
||||
cl_object l_fun = (cl_object)function_or_closure;
|
||||
cl_funcall(1, l_fun); }
|
||||
CL_UNWIND_PROTECT_EXIT {}
|
||||
CL_UNWIND_PROTECT_END; }
|
||||
CL_CATCH_ALL_END; }
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ public:
|
|||
" (eql:qversion)"
|
||||
" (format t \"EQL5 ~A (ECL ~A, Qt ~A)~%\" eql (lisp-implementation-version) qt))"); }
|
||||
|
||||
Q_INVOKABLE void runInGuiThread(void*);
|
||||
Q_INVOKABLE void runOnUiThread(void*);
|
||||
|
||||
public Q_SLOTS:
|
||||
void exitEventLoop() { eventLoop->exit(); }
|
||||
|
|
|
|||
|
|
@ -328,7 +328,7 @@
|
|||
(unless (find-package :ecl-readline)
|
||||
(princ "> "))
|
||||
(let ((form (si::%tpl-read)))
|
||||
(qrun-in-gui-thread (lambda () (eval-top-level form)) nil))
|
||||
(qrun-on-ui-thread (lambda () (eval-top-level form)) nil))
|
||||
(values))
|
||||
|
||||
(defun start-read-thread ()
|
||||
|
|
@ -690,13 +690,13 @@
|
|||
(funcall ,reloaded ',variable ,library-name)))))
|
||||
(defvar ,reloaded nil))))
|
||||
|
||||
(defun qrun-in-gui-thread (function &optional (blocking t))
|
||||
(%qrun-in-gui-thread function blocking))
|
||||
(defun qrun-on-ui-thread (function &optional (blocking t))
|
||||
(%qrun-on-ui-thread function blocking))
|
||||
|
||||
#+threads
|
||||
(defvar *gui-thread* mp:*current-process*)
|
||||
|
||||
(defmacro qrun-in-gui-thread* (&body body)
|
||||
(defmacro qrun-on-ui-thread* (&body body)
|
||||
"args: (&body body)
|
||||
alias: qrun*
|
||||
Convenience macro for <code>qrun</code>, wrapping <code>body</code> in a closure (passing arguments, return values).
|
||||
|
|
@ -722,7 +722,7 @@
|
|||
(first body)))
|
||||
|
||||
(defmacro qrun* (&body body) ; alias
|
||||
`(qrun-in-gui-thread* ,@body))
|
||||
`(qrun-on-ui-thread* ,@body))
|
||||
|
||||
(defun qload (file-name)
|
||||
"args: (file-name)
|
||||
|
|
@ -772,7 +772,7 @@
|
|||
(alias qfun+ qinvoke-method+)
|
||||
(alias qmsg qmessage-box)
|
||||
(alias qnull qnull-object)
|
||||
(alias qrun qrun-in-gui-thread)
|
||||
(alias qrun qrun-on-ui-thread)
|
||||
(alias qsel qselect)
|
||||
(alias qq qquit)
|
||||
|
||||
|
|
@ -834,9 +834,9 @@
|
|||
(cons 'qrequire '(module &optional quiet))
|
||||
(cons 'qrgb '(red green blue &optional (alpha 255)))
|
||||
(cons 'qrun '(function))
|
||||
(cons 'qrun-in-gui-thread '(function))
|
||||
(cons 'qrun-on-ui-thread '(function))
|
||||
(cons 'qrun* '(&body body))
|
||||
(cons 'qrun-in-gui-thread* '(&body body))
|
||||
(cons 'qrun-on-ui-thread* '(&body body))
|
||||
(cons 'qset-null '(object))
|
||||
(cons 'qset '(object name value))
|
||||
(cons 'qset-color '(widget color-role color))
|
||||
|
|
|
|||
|
|
@ -77,9 +77,9 @@
|
|||
#:qrequire
|
||||
#:qrgb
|
||||
#:qrun
|
||||
#:qrun-in-gui-thread
|
||||
#:qrun-on-ui-thread
|
||||
#:qrun*
|
||||
#:qrun-in-gui-thread*
|
||||
#:qrun-on-ui-thread*
|
||||
#:qsel
|
||||
#:qselect
|
||||
#:qsender
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue