mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[python] Stub a matplotlib module
This commit is contained in:
committed by
Émilie Feral
parent
2b73c4c9aa
commit
c99bed6922
@@ -134,6 +134,11 @@ port_src += $(addprefix python/port/,\
|
||||
mod/ion/modion_table.cpp \
|
||||
mod/kandinsky/modkandinsky.cpp \
|
||||
mod/kandinsky/modkandinsky_table.c \
|
||||
mod/matplotlib/modpyplot.cpp \
|
||||
mod/matplotlib/modpyplot_table.c \
|
||||
mod/matplotlib/plot_controller.cpp \
|
||||
mod/matplotlib/plot_store.cpp \
|
||||
mod/matplotlib/plot_view.cpp \
|
||||
mod/time/modtime.c \
|
||||
mod/time/modtime_table.c \
|
||||
mod/turtle/modturtle.cpp \
|
||||
|
||||
@@ -73,6 +73,12 @@ Q(fill_rect)
|
||||
Q(get_pixel)
|
||||
Q(set_pixel)
|
||||
|
||||
// Matplotlib QSTRs
|
||||
Q(plot)
|
||||
Q(pyplot)
|
||||
Q(show)
|
||||
|
||||
|
||||
// Turtle QSTRs
|
||||
Q(turtle)
|
||||
Q(forward)
|
||||
|
||||
17
python/port/mod/matplotlib/modpyplot.cpp
Normal file
17
python/port/mod/matplotlib/modpyplot.cpp
Normal file
@@ -0,0 +1,17 @@
|
||||
extern "C" {
|
||||
#include "modpyplot.h"
|
||||
}
|
||||
#include "port.h"
|
||||
#include "plot_controller.h"
|
||||
|
||||
Matplotlib::PlotController sPlotController;
|
||||
|
||||
mp_obj_t modpyplot_plot(mp_obj_t x, mp_obj_t y) {
|
||||
// Ensure x and y are arrays
|
||||
// "Push" x and y on bigger arrays
|
||||
}
|
||||
|
||||
mp_obj_t modpyplot_show() {
|
||||
MicroPython::ExecutionEnvironment * env = MicroPython::ExecutionEnvironment::currentExecutionEnvironment();
|
||||
env->displayViewController(&sPlotController);
|
||||
}
|
||||
10
python/port/mod/matplotlib/modpyplot.h
Normal file
10
python/port/mod/matplotlib/modpyplot.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#include <py/obj.h>
|
||||
|
||||
mp_obj_t modpyplot_plot(mp_obj_t x, mp_obj_t y);
|
||||
//mp_obj_t grid();
|
||||
//mp_obj_t scatter(mp_obj_t x, mp_obj_t y);
|
||||
//mp_obj_t bar();
|
||||
//mp_obj_t hist();
|
||||
//mp_obj_t axis(mp_obj_t v);
|
||||
//mp_obj_t text(mp_obj_t x, mp_obj_t y, mp_obj_t text);
|
||||
mp_obj_t modpyplot_show();
|
||||
17
python/port/mod/matplotlib/modpyplot_table.c
Normal file
17
python/port/mod/matplotlib/modpyplot_table.c
Normal file
@@ -0,0 +1,17 @@
|
||||
#include "modpyplot.h"
|
||||
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(modpyplot_plot_obj, modpyplot_plot);
|
||||
MP_DEFINE_CONST_FUN_OBJ_0(modpyplot_show_obj, modpyplot_show);
|
||||
|
||||
STATIC const mp_rom_map_elem_t modpyplot_module_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_pyplot) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_plot), MP_ROM_PTR(&modpyplot_plot_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_show), MP_ROM_PTR(&modpyplot_show_obj) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(modpyplot_module_globals, modpyplot_module_globals_table);
|
||||
|
||||
const mp_obj_module_t modpyplot_module = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t*)&modpyplot_module_globals,
|
||||
};
|
||||
0
python/port/mod/matplotlib/plot_controller.cpp
Normal file
0
python/port/mod/matplotlib/plot_controller.cpp
Normal file
47
python/port/mod/matplotlib/plot_controller.h
Normal file
47
python/port/mod/matplotlib/plot_controller.h
Normal file
@@ -0,0 +1,47 @@
|
||||
#ifndef PYTHON_MATPLOTLIB_PLOT_CONTROLLER_H
|
||||
#define PYTHON_MATPLOTLIB_PLOT_CONTROLLER_H
|
||||
|
||||
//#include <escher/view_controller.h>
|
||||
#include <apps/shared/simple_interactive_curve_view_controller.h>
|
||||
#include <apps/shared/curve_view_cursor.h>
|
||||
#include "plot_view.h"
|
||||
#include "plot_store.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
namespace Matplotlib {
|
||||
|
||||
class PlotController : public Shared::SimpleInteractiveCurveViewController {
|
||||
public:
|
||||
PlotController() : Shared::SimpleInteractiveCurveViewController(nullptr, &m_cursor), m_store(), m_view(&m_store) {}
|
||||
//virtual View * view() override { return &m_view; }
|
||||
|
||||
float cursorBottomMarginRatio() override {
|
||||
return 0.0f;
|
||||
}
|
||||
virtual void reloadBannerView() override {
|
||||
}
|
||||
|
||||
bool handleEvent(Ion::Events::Event event) override {
|
||||
printf("EVENT!!\n");
|
||||
return Shared::SimpleInteractiveCurveViewController::handleEvent(event);
|
||||
}
|
||||
|
||||
virtual bool handleEnter() override {
|
||||
printf("ENTER !!\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
protected:
|
||||
Shared::CurveView * curveView() override { return &m_view; }
|
||||
Shared::InteractiveCurveViewRange * interactiveCurveViewRange() override { return &m_store; }
|
||||
private:
|
||||
Shared::CurveViewCursor m_cursor;
|
||||
PlotStore m_store;
|
||||
PlotView m_view;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
1
python/port/mod/matplotlib/plot_store.cpp
Normal file
1
python/port/mod/matplotlib/plot_store.cpp
Normal file
@@ -0,0 +1 @@
|
||||
#include "plot_store.h"
|
||||
33
python/port/mod/matplotlib/plot_store.h
Normal file
33
python/port/mod/matplotlib/plot_store.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#ifndef PYTHON_MATPLOTLIB_PLOT_STORE_H
|
||||
#define PYTHON_MATPLOTLIB_PLOT_STORE_H
|
||||
|
||||
//#include <apps/shared/curve_view_range.h>
|
||||
#include <apps/shared/interactive_curve_view_range.h>
|
||||
|
||||
namespace Matplotlib {
|
||||
|
||||
class PlotStore : public Shared::InteractiveCurveViewRange {
|
||||
public:
|
||||
PlotStore() : Shared::InteractiveCurveViewRange() {}
|
||||
/*
|
||||
float xMin() const override { return 0.0f; }
|
||||
float xMax() const override { return 1.0f; }
|
||||
float yMin() const override { return 0.0f; }
|
||||
float yMax() const override { return 1.0f; }
|
||||
*/
|
||||
private:
|
||||
/*
|
||||
mp_obj_array_t * m_plots;
|
||||
mp_obj_array_t * m_arrows;
|
||||
mp_obj_array_t * m_scatters;
|
||||
mp_obj_array_t * m_texts;
|
||||
mp_obj_array_t * m_rects;
|
||||
|
||||
bool m_grid;
|
||||
*/
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
13
python/port/mod/matplotlib/plot_view.cpp
Normal file
13
python/port/mod/matplotlib/plot_view.cpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#include "plot_view.h"
|
||||
|
||||
namespace Matplotlib {
|
||||
|
||||
void PlotView::drawRect(KDContext * ctx, KDRect rect) const {
|
||||
ctx->fillRect(rect, KDColorWhite);
|
||||
drawGrid(ctx, rect);
|
||||
drawAxes(ctx, rect);
|
||||
drawLabelsAndGraduations(ctx, rect, Axis::Vertical, true);
|
||||
drawLabelsAndGraduations(ctx, rect, Axis::Horizontal, true);
|
||||
}
|
||||
|
||||
}
|
||||
18
python/port/mod/matplotlib/plot_view.h
Normal file
18
python/port/mod/matplotlib/plot_view.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef PYTHON_MATPLOTLIB_PLOT_VIEW_H
|
||||
#define PYTHON_MATPLOTLIB_PLOT_VIEW_H
|
||||
|
||||
#include <apps/shared/labeled_curve_view.h>
|
||||
#include "plot_store.h"
|
||||
|
||||
namespace Matplotlib {
|
||||
|
||||
class PlotView : public Shared::LabeledCurveView {
|
||||
public:
|
||||
PlotView(PlotStore * s) : Shared::LabeledCurveView(s) {}
|
||||
void drawRect(KDContext * ctx, KDRect rect) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
@@ -130,12 +130,14 @@ typedef long mp_off_t;
|
||||
|
||||
extern const struct _mp_obj_module_t modion_module;
|
||||
extern const struct _mp_obj_module_t modkandinsky_module;
|
||||
extern const struct _mp_obj_module_t modpyplot_module;
|
||||
extern const struct _mp_obj_module_t modtime_module;
|
||||
extern const struct _mp_obj_module_t modturtle_module;
|
||||
|
||||
#define MICROPY_PORT_BUILTIN_MODULES \
|
||||
{ MP_ROM_QSTR(MP_QSTR_ion), MP_ROM_PTR(&modion_module) }, \
|
||||
{ MP_ROM_QSTR(MP_QSTR_kandinsky), MP_ROM_PTR(&modkandinsky_module) }, \
|
||||
{ MP_ROM_QSTR(MP_QSTR_pyplot), MP_ROM_PTR(&modpyplot_module) }, \
|
||||
{ MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&modtime_module) }, \
|
||||
{ MP_ROM_QSTR(MP_QSTR_turtle), MP_ROM_PTR(&modturtle_module) }, \
|
||||
|
||||
|
||||
Reference in New Issue
Block a user