aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorDavid Shah <dave@ds0.me>2019-04-03 16:08:33 +0100
committerDavid Shah <dave@ds0.me>2019-04-03 16:08:33 +0100
commit6fffe24177f9b99d6c332c18e343648cf33d4397 (patch)
treea75edfc7a224b588af0d7d7656915db8246d4506 /common
parenta05593da624d08e6b5c0356448238639479dd250 (diff)
downloadnextpnr-6fffe24177f9b99d6c332c18e343648cf33d4397.tar.gz
nextpnr-6fffe24177f9b99d6c332c18e343648cf33d4397.tar.bz2
nextpnr-6fffe24177f9b99d6c332c18e343648cf33d4397.zip
generic: GUI Python bindings
Signed-off-by: David Shah <dave@ds0.me>
Diffstat (limited to 'common')
-rw-r--r--common/nextpnr.cc8
-rw-r--r--common/nextpnr.h6
-rw-r--r--common/pybindings.cc22
3 files changed, 34 insertions, 2 deletions
diff --git a/common/nextpnr.cc b/common/nextpnr.cc
index 54333b15..daaadf28 100644
--- a/common/nextpnr.cc
+++ b/common/nextpnr.cc
@@ -444,5 +444,13 @@ void BaseCtx::constrainCellToRegion(IdString cell, IdString region_name)
{
cells[cell]->region = region[region_name].get();
}
+DecalXY BaseCtx::constructDecalXY(DecalId decal, float x, float y)
+{
+ DecalXY dxy;
+ dxy.decal = decal;
+ dxy.x = x;
+ dxy.y = y;
+ return dxy;
+}
NEXTPNR_NAMESPACE_END
diff --git a/common/nextpnr.h b/common/nextpnr.h
index 5967ecee..79dbbaca 100644
--- a/common/nextpnr.h
+++ b/common/nextpnr.h
@@ -181,6 +181,9 @@ struct GraphicElement
float x1 = 0, y1 = 0, x2 = 0, y2 = 0, z = 0;
std::string text;
+ GraphicElement() {};
+ GraphicElement(type_t type, style_t style, float x1, float y1, float x2, float y2, float z) : type(type),
+ style(style), x1(x1), y1(y1), x2(x2), y2(y2), z(z) {};
};
struct Loc
@@ -640,6 +643,9 @@ struct BaseCtx
void createRectangularRegion(IdString name, int x0, int y0, int x1, int y1);
void addBelToRegion(IdString name, BelId bel);
void constrainCellToRegion(IdString cell, IdString region_name);
+
+ // Workaround for lack of wrappable constructors
+ DecalXY constructDecalXY(DecalId decal, float x, float y);
};
NEXTPNR_NAMESPACE_END
diff --git a/common/pybindings.cc b/common/pybindings.cc
index bf5382eb..e1fc8534 100644
--- a/common/pybindings.cc
+++ b/common/pybindings.cc
@@ -87,7 +87,26 @@ BOOST_PYTHON_MODULE(MODULE_NAME)
using namespace PythonConversion;
+ enum_<GraphicElement::type_t>("GraphicElementType")
+ .value("TYPE_NONE", GraphicElement::TYPE_NONE)
+ .value("TYPE_LINE", GraphicElement::TYPE_LINE)
+ .value("TYPE_ARROW", GraphicElement::TYPE_ARROW)
+ .value("TYPE_BOX", GraphicElement::TYPE_BOX)
+ .value("TYPE_CIRCLE", GraphicElement::TYPE_CIRCLE)
+ .value("TYPE_LABEL", GraphicElement::TYPE_LABEL)
+ .export_values();
+
+ enum_<GraphicElement::style_t>("GraphicElementStyle")
+ .value("STYLE_GRID", GraphicElement::STYLE_GRID)
+ .value("STYLE_FRAME", GraphicElement::STYLE_FRAME)
+ .value("STYLE_HIDDEN", GraphicElement::STYLE_HIDDEN)
+ .value("STYLE_INACTIVE", GraphicElement::STYLE_INACTIVE)
+ .value("STYLE_ACTIVE", GraphicElement::STYLE_ACTIVE)
+ .export_values();
+
class_<GraphicElement>("GraphicElement")
+ .def(init<GraphicElement::type_t, GraphicElement::style_t, float, float, float, float, float>(
+ (args("type"), "style", "x1", "y1", "x2", "y2", "z")))
.def_readwrite("type", &GraphicElement::type)
.def_readwrite("x1", &GraphicElement::x1)
.def_readwrite("y1", &GraphicElement::y1)
@@ -214,8 +233,7 @@ void init_python(const char *executable, bool first)
PyImport_AppendInittab(TOSTRING(MODULE_NAME), PYINIT_MODULE_NAME);
Py_SetProgramName(program);
Py_Initialize();
- if (first)
- PyImport_ImportModule(TOSTRING(MODULE_NAME));
+ PyImport_ImportModule(TOSTRING(MODULE_NAME));
PyRun_SimpleString("from " TOSTRING(MODULE_NAME) " import *");
} catch (boost::python::error_already_set const &) {
// Parse and output the exception