[python] modpyplot: show() does nothing when the store is empty

This commit is contained in:
Émilie Feral
2020-03-30 16:41:25 +02:00
parent ce33faad11
commit b3b6565410
3 changed files with 8 additions and 0 deletions

View File

@@ -342,6 +342,9 @@ mp_obj_t modpyplot_text(mp_obj_t x, mp_obj_t y, mp_obj_t s) {
}
mp_obj_t modpyplot_show() {
if (sPlotStore->isEmpty()) {
return mp_const_none;
}
MicroPython::ExecutionEnvironment * env = MicroPython::ExecutionEnvironment::currentExecutionEnvironment();
env->displayViewController(sPlotController);
return mp_const_none;

View File

@@ -20,6 +20,10 @@ void PlotStore::flush() {
m_gridRequested = false;
}
bool PlotStore::isEmpty() {
return MP_OBJ_SMALL_INT_VALUE(mp_obj_len(m_dots)) == 0 && MP_OBJ_SMALL_INT_VALUE(mp_obj_len(m_segments)) == 0 && MP_OBJ_SMALL_INT_VALUE(mp_obj_len(m_rects)) == 0 && MP_OBJ_SMALL_INT_VALUE(mp_obj_len(m_labels)) == 0;
}
// Iterators
template <class T>

View File

@@ -13,6 +13,7 @@ class PlotStore : public Shared::InteractiveCurveViewRange {
public:
PlotStore();
void flush();
bool isEmpty();
// Iterators