[apps/code][python] ConsoleController doesn't keep any pointer/boolean to know

if the sandbox/matplotlib view controller is displayed. Its state won't be
always right; instead, use the StackViewController depth.

This fixes the following bug: when popping the sandbox/matplotlib view
controller, the first responder token was not given to the console
controller!
This commit is contained in:
Émilie Feral
2020-03-26 09:42:36 +01:00
parent d0c5ac0343
commit fb3f6ab6f3
9 changed files with 35 additions and 54 deletions

View File

@@ -28,7 +28,7 @@ static size_t extractAndValidatePlotInput(mp_obj_t x, mp_obj_t y, mp_obj_t ** xI
mp_obj_t modpyplot___init__() {
static Matplotlib::PlotStore plotStore;
static Matplotlib::PlotController plotController(&plotStore, MicroPython::ExecutionEnvironment::currentExecutionEnvironment());
static Matplotlib::PlotController plotController(&plotStore);
sPlotStore = &plotStore;
sPlotController = &plotController;
sPlotStore->flush();

View File

@@ -3,12 +3,10 @@
namespace Matplotlib {
void PlotController::viewWillAppear() {
MicroPython::ExecutionViewControllerHelper::viewWillAppear(this);
curveView()->reload();
}
void PlotController::viewDidDisappear() {
MicroPython::ExecutionViewControllerHelper::viewDidDisappear(this);
m_store->flush();
}

View File

@@ -2,15 +2,14 @@
#define PYTHON_MATPLOTLIB_PLOT_CONTROLLER_H
#include <apps/shared/zoom_and_pan_curve_view_controller.h>
#include <python/port/port.h>
#include "plot_view.h"
#include "plot_store.h"
namespace Matplotlib {
class PlotController : public Shared::ZoomAndPanCurveViewController, public MicroPython::ExecutionViewControllerHelper {
class PlotController : public Shared::ZoomAndPanCurveViewController {
public:
PlotController(PlotStore * store, MicroPython::ExecutionEnvironment * executiveEnvironment) : Shared::ZoomAndPanCurveViewController(nullptr), ExecutionViewControllerHelper(executiveEnvironment), m_store(store), m_view(m_store) {}
PlotController(PlotStore * store) : Shared::ZoomAndPanCurveViewController(nullptr), m_store(store), m_view(m_store) {}
void viewWillAppear() override;
void viewDidDisappear() override;

View File

@@ -95,23 +95,6 @@ void MicroPython::ExecutionEnvironment::interrupt() {
mp_keyboard_interrupt();
}
void MicroPython::ExecutionEnvironment::viewControllerDidDisappear(ViewController * vc) {
if (vc == sandbox()) {
modturtle_view_did_disappear();
}
m_displayedViewController = nullptr;
}
void MicroPython::ExecutionViewControllerHelper::viewWillAppear(ViewController * vc) {
assert(m_executionEnvironment != nullptr);
m_executionEnvironment->viewControllerWillAppear(vc);
}
void MicroPython::ExecutionViewControllerHelper::viewDidDisappear(ViewController * vc) {
assert(m_executionEnvironment != nullptr);
m_executionEnvironment->viewControllerDidDisappear(vc);
}
extern "C" {
extern const void * _stack_start;
extern const void * _stack_end;

View File

@@ -15,7 +15,7 @@ public:
class ExecutionEnvironment {
public:
ExecutionEnvironment() : m_displayedViewController(nullptr) {}
ExecutionEnvironment() {}
static ExecutionEnvironment * currentExecutionEnvironment();
void runCode(const char * );
virtual const char * inputText(const char * prompt) { return nullptr; }
@@ -28,24 +28,10 @@ public:
// Generic View Controller
virtual void displayViewController(ViewController * controller) {}
virtual void hideAnyDisplayedViewController() {}
void viewControllerWillAppear(ViewController * vc) { m_displayedViewController = vc; }
void viewControllerDidDisappear(ViewController * vc);
virtual void printText(const char * text, size_t length) {}
virtual void refreshPrintOutput() {}
void interrupt();
protected:
bool viewControllerIsDisplayed(ViewController * vc) const { return m_displayedViewController == vc; }
ViewController * m_displayedViewController;
};
class ExecutionViewControllerHelper {
public:
ExecutionViewControllerHelper(ExecutionEnvironment * executionEnvironment) : m_executionEnvironment(executionEnvironment) {}
void viewWillAppear(ViewController * vc);
void viewDidDisappear(ViewController * vc);
private:
ExecutionEnvironment * m_executionEnvironment;
};
void init(void * heapStart, void * heapEnd);