Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions guide/ch_scripting.tex
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,17 @@ \subsection{Pause/Resume}
\label{sec:scripting:differences:pause}

The Qt6-based builds (version 1.0 and later) do not offer a way to pause and resume a script as was available in the Qt5-based builds (0.10 to 0.22).
However, \texttt{core.waitForKeypress()} can be used to pause a script until a key is pressed,
which is particularly useful for planetarium presentations with a Bluetooth or wireless remote clicker.
A visual indicator \emph{``Press any key to continue...''} will be displayed on screen while the script is paused.

Example usage:
\begin{script}
core.goToObject("Orion");
core.waitForKeypress();
core.goToObject("Sirius");
core.waitForKeypress();
\end{script}

\subsection{The Vec3f problem}
\label{sec:scripting:differences:Vec3f}
Expand Down
4 changes: 4 additions & 0 deletions src/scripting/StelMainScriptAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1024,10 +1024,14 @@ void StelMainScriptAPI::waitForKeypress()
QEventLoop* loop = scriptMgr->getWaitEventLoop();
KeypressFilter filter(loop);
qApp->installEventFilter(&filter);
LabelMgr* labelMgr = GETSTELMODULE(LabelMgr);
int labelId = labelMgr->labelScreen(q_("Press any key to continue..."),
30, 30, true, 20, "#ffffff", false, 0);
if( loop->exec() != 0 )
{
emit requestExit();
}
labelMgr->deleteLabel(labelId);
qApp->removeEventFilter(&filter);
}

Expand Down
11 changes: 8 additions & 3 deletions src/scripting/StelScriptMgr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <QFile>
#include <QTimer>
#include <QEventLoop>
#include <QKeyEvent>
#include <QMap>
#include <QPair>
#include <QSet>
Expand All @@ -51,9 +52,13 @@ class KeypressFilter : public QObject {
public:
KeypressFilter(QEventLoop* l) : loop(l) {}
bool eventFilter(QObject* obj, QEvent* event) override {
if (event->type() == QEvent::KeyPress) {
loop->quit();
return true;
if(event->type() == QEvent::KeyPress) {
QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
if (!keyEvent->isAutoRepeat()) {
loop->quit();
keyEvent->accept();
return true;
}
}
return QObject::eventFilter(obj, event);
}
Expand Down
Loading