[code] Fixed the wait for user input after drawing using Python.

A SandboxController is now pushed on the StackViewController and sets the
KDIonContext::sharedContext before drawing, sets a white background and handles
user input after the Python computation to dismiss the drawing screen.

Change-Id: I51b0474365a85e845227379a16d090541fa8ded7
This commit is contained in:
Léa Saviot
2017-11-27 14:09:49 +01:00
parent 9a9ccc7a8c
commit 1ce6f36651
11 changed files with 98 additions and 110 deletions

View File

@@ -13,20 +13,6 @@ extern "C" {
namespace Code {
ConsoleController::ContentView::ContentView(SelectableTableView * selectabletableView) :
m_selectableTableView(selectabletableView)
{
}
void ConsoleController::ContentView::layoutSubviews() {
m_selectableTableView->setFrame(bounds());
}
void ConsoleController::ContentView::markAsDirty() {
markRectAsDirty(bounds());
}
ConsoleController::ConsoleController(Responder * parentResponder, ScriptStore * scriptStore) :
ViewController(parentResponder),
SelectableTableViewDataSource(),
@@ -37,7 +23,7 @@ ConsoleController::ConsoleController(Responder * parentResponder, ScriptStore *
m_editCell(this, this),
m_pythonHeap(nullptr),
m_scriptStore(scriptStore),
m_view(&m_selectableTableView)
m_sandboxController(this)
{
for (int i = 0; i < k_numberOfLineCells; i++) {
m_cells[i].setParentResponder(&m_selectableTableView);
@@ -90,14 +76,9 @@ 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();
}
void ConsoleController::removeExtensionIfAny(char * name) {
@@ -112,41 +93,18 @@ void ConsoleController::removeExtensionIfAny(char * name) {
void ConsoleController::viewWillAppear() {
assert(pythonEnvironmentIsLoaded());
#ifdef __EMSCRIPTEN__
if (isFramebufferModified()) {
return;
}
#endif
m_sandboxIsDisplayed = false;
m_selectableTableView.reloadData();
m_selectableTableView.selectCellAtLocation(0, m_consoleStore.numberOfLines());
m_editCell.setEditing(true);
m_editCell.setText("");
}
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);
@@ -269,11 +227,9 @@ 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()) {
if (m_sandboxIsDisplayed) {
return true;
}
#endif
m_selectableTableView.reloadData();
m_editCell.setEditing(true);
textField->setText("");
@@ -292,6 +248,14 @@ bool ConsoleController::textFieldDidAbortEditing(TextField * textField, const ch
return codeApp->pythonToolbox();
}
void ConsoleController::displaySandbox() {
if (m_sandboxIsDisplayed) {
return;
}
m_sandboxIsDisplayed = true;
stackViewController()->push(&m_sandboxController);
}
/* printText is called by the Python machine.
* The text argument is not always null-terminated. */
void ConsoleController::printText(const char * text, size_t length) {
@@ -317,10 +281,6 @@ void ConsoleController::printText(const char * text, size_t length) {
}
}
void ConsoleController::redraw() {
m_view.markAsDirty();
}
void ConsoleController::autoImportScriptAtIndex(int index) {
const char * importCommand1 = "from ";
const char * importCommand2 = " import *";
@@ -390,5 +350,4 @@ bool ConsoleController::copyCurrentLineToClipboard() {
return false;
}
}