mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[code/emscripten] On emscripten, fixed waiting after a Python drawing.
The user can now push OK or Back to remove a Python drawing. Change-Id: I293064a9458f8c0c6d0da5351500600fd9e82706
This commit is contained in:
@@ -88,6 +88,12 @@ void ConsoleController::runAndPrintForCommand(const char * command) {
|
||||
m_consoleStore.pushCommand(command, strlen(command));
|
||||
assert(m_outputAccumulationBuffer[0] == '\0');
|
||||
runCode(command);
|
||||
#ifdef __EMSCRIPTEN__
|
||||
if (isFramebufferModified()) {
|
||||
app()->setFirstResponder(this);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
flushOutputAccumulationBufferToStore();
|
||||
m_consoleStore.deleteLastLineIfEmpty();
|
||||
}
|
||||
@@ -104,16 +110,41 @@ void ConsoleController::removeExtensionIfAny(char * name) {
|
||||
|
||||
void ConsoleController::viewWillAppear() {
|
||||
assert(pythonEnvironmentIsLoaded());
|
||||
#ifdef __EMSCRIPTEN__
|
||||
if (isFramebufferModified()) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
m_selectableTableView.reloadData();
|
||||
m_selectableTableView.selectCellAtLocation(0, m_consoleStore.numberOfLines());
|
||||
m_editCell.setEditing(true);
|
||||
}
|
||||
|
||||
void ConsoleController::didBecomeFirstResponder() {
|
||||
#ifdef __EMSCRIPTEN__
|
||||
if (isFramebufferModified()) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
app()->setFirstResponder(&m_editCell);
|
||||
}
|
||||
|
||||
bool ConsoleController::handleEvent(Ion::Events::Event event) {
|
||||
#ifdef __EMSCRIPTEN__
|
||||
if (isFramebufferModified()) {
|
||||
if (event == Ion::Events::OK || event == Ion::Events::Back) {
|
||||
didCleanFramebuffer(),
|
||||
m_view.markAsDirty();
|
||||
flushOutputAccumulationBufferToStore();
|
||||
m_consoleStore.deleteLastLineIfEmpty();
|
||||
m_selectableTableView.reloadData();
|
||||
m_selectableTableView.selectCellAtLocation(0, m_consoleStore.numberOfLines());
|
||||
m_editCell.setEditing(true);
|
||||
m_editCell.setText("");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
if (event == Ion::Events::Up) {
|
||||
if (m_consoleStore.numberOfLines() > 0 && m_selectableTableView.selectedRow() == m_consoleStore.numberOfLines()) {
|
||||
m_editCell.setEditing(false);
|
||||
@@ -227,6 +258,11 @@ bool ConsoleController::textFieldDidReceiveEvent(TextField * textField, Ion::Eve
|
||||
|
||||
bool ConsoleController::textFieldDidFinishEditing(TextField * textField, const char * text, Ion::Events::Event event) {
|
||||
runAndPrintForCommand(text);
|
||||
#ifdef __EMSCRIPTEN__
|
||||
if (isFramebufferModified()) {
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
m_selectableTableView.reloadData();
|
||||
m_editCell.setEditing(true);
|
||||
textField->setText("");
|
||||
|
||||
@@ -28,7 +28,7 @@ def fibo2(n):
|
||||
return fibo2(n-1)+fibo2(n-2))");
|
||||
|
||||
constexpr ScriptTemplate mandelbrotScriptTemplate("mandelbrot.py", R"(# This script draws a Mandelbrot fractal set
|
||||
# N_iteration: degree of precision
|
||||
#N_iteration: degree of precision
|
||||
import kandinsky
|
||||
def mandelbrot(N_iteration):
|
||||
for x in range(320):
|
||||
|
||||
@@ -41,6 +41,10 @@ void MicroPython::ExecutionEnvironment::didModifyFramebuffer() {
|
||||
m_framebufferHasBeenModified = true;
|
||||
}
|
||||
|
||||
void MicroPython::ExecutionEnvironment::didCleanFramebuffer() {
|
||||
m_framebufferHasBeenModified = false;
|
||||
}
|
||||
|
||||
void MicroPython::ExecutionEnvironment::runCode(const char * str) {
|
||||
assert(sCurrentExecutionEnvironment == nullptr);
|
||||
sCurrentExecutionEnvironment = this;
|
||||
@@ -93,6 +97,8 @@ void MicroPython::ExecutionEnvironment::runCode(const char * str) {
|
||||
/* End of mp_obj_print_exception. */
|
||||
}
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#else
|
||||
while (m_framebufferHasBeenModified) {
|
||||
int timeout = 3000;
|
||||
Ion::Events::Event event = Ion::Events::getEvent(&timeout);
|
||||
@@ -101,6 +107,7 @@ void MicroPython::ExecutionEnvironment::runCode(const char * str) {
|
||||
redraw();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
assert(sCurrentExecutionEnvironment == this);
|
||||
sCurrentExecutionEnvironment = nullptr;
|
||||
|
||||
@@ -13,6 +13,8 @@ public:
|
||||
ExecutionEnvironment();
|
||||
static ExecutionEnvironment * currentExecutionEnvironment();
|
||||
void didModifyFramebuffer();
|
||||
bool isFramebufferModified() const { return m_framebufferHasBeenModified; }
|
||||
void didCleanFramebuffer();
|
||||
void runCode(const char * );
|
||||
virtual void printText(const char * text, size_t length) {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user