mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[apps][python] ExecutionEnvironment handles hide sand display of sandbox
and plot controller the same way
This commit is contained in:
@@ -28,7 +28,7 @@ static size_t extract_and_validate_plot_input(mp_obj_t x, mp_obj_t y, mp_obj_t *
|
||||
|
||||
mp_obj_t modpyplot___init__() {
|
||||
static Matplotlib::PlotStore plotStore;
|
||||
static Matplotlib::PlotController plotController(&plotStore);
|
||||
static Matplotlib::PlotController plotController(&plotStore, MicroPython::ExecutionEnvironment::currentExecutionEnvironment());
|
||||
sPlotStore = &plotStore;
|
||||
sPlotController = &plotController;
|
||||
sPlotStore->flush();
|
||||
|
||||
@@ -3,14 +3,18 @@
|
||||
|
||||
#include <apps/shared/simple_interactive_curve_view_controller.h>
|
||||
#include <apps/shared/curve_view_cursor.h>
|
||||
#include <python/port/port.h>
|
||||
#include "plot_view.h"
|
||||
#include "plot_store.h"
|
||||
|
||||
namespace Matplotlib {
|
||||
|
||||
class PlotController : public Shared::SimpleInteractiveCurveViewController {
|
||||
class PlotController : public Shared::SimpleInteractiveCurveViewController, public MicroPython::ExecutionViewControllerHelper {
|
||||
public:
|
||||
PlotController(PlotStore * store) : Shared::SimpleInteractiveCurveViewController(nullptr, &m_cursor), m_store(store), m_view(m_store) {}
|
||||
PlotController(PlotStore * store, MicroPython::ExecutionEnvironment * executiveEnvironment) : Shared::SimpleInteractiveCurveViewController(nullptr, &m_cursor), ExecutionViewControllerHelper(executiveEnvironment), m_store(store), m_view(m_store) {}
|
||||
|
||||
void viewWillAppear() override { MicroPython::ExecutionViewControllerHelper::viewWillAppear(this); }
|
||||
void viewDidDisappear() override { MicroPython::ExecutionViewControllerHelper::viewDidDisappear(this); }
|
||||
|
||||
float cursorBottomMarginRatio() override {
|
||||
return 0.0f;
|
||||
@@ -33,5 +37,4 @@ private:
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -95,11 +95,21 @@ void MicroPython::ExecutionEnvironment::interrupt() {
|
||||
mp_keyboard_interrupt();
|
||||
}
|
||||
|
||||
void MicroPython::ExecutionEnvironment::setSandboxIsDisplayed(bool display) {
|
||||
if (m_sandboxIsDisplayed && !display) {
|
||||
void MicroPython::ExecutionEnvironment::viewControllerDidDisappear(ViewController * vc) {
|
||||
if (vc == sandbox()) {
|
||||
modturtle_view_did_disappear();
|
||||
}
|
||||
m_sandboxIsDisplayed = display;
|
||||
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" {
|
||||
|
||||
@@ -15,22 +15,37 @@ public:
|
||||
|
||||
class ExecutionEnvironment {
|
||||
public:
|
||||
ExecutionEnvironment() : m_sandboxIsDisplayed(false) {}
|
||||
ExecutionEnvironment() : m_displayedViewController(nullptr) {}
|
||||
static ExecutionEnvironment * currentExecutionEnvironment();
|
||||
void runCode(const char * );
|
||||
virtual const char * inputText(const char * prompt) { return nullptr; }
|
||||
virtual void displaySandbox() {}
|
||||
virtual void hideSandbox() {}
|
||||
|
||||
// Sandbox
|
||||
void displaySandbox() { displayViewController(sandbox()); }
|
||||
virtual ViewController * sandbox() { return nullptr; }
|
||||
virtual void resetSandbox() {}
|
||||
|
||||
// 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();
|
||||
void setSandboxIsDisplayed(bool display);
|
||||
protected:
|
||||
bool sandboxIsDisplayed() const { return m_sandboxIsDisplayed; }
|
||||
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:
|
||||
bool m_sandboxIsDisplayed;
|
||||
ExecutionEnvironment * m_executionEnvironment;
|
||||
};
|
||||
|
||||
void init(void * heapStart, void * heapEnd);
|
||||
@@ -38,6 +53,6 @@ void deinit();
|
||||
void registerScriptProvider(ScriptProvider * s);
|
||||
void collectRootsAtAddress(char * address, int len);
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user