HAL  v4.5.0-83-g30c8f0afc
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
python_bindings.cpp
Go to the documentation of this file.
2 
7 #include "pybind11/operators.h"
8 #include "pybind11/pybind11.h"
9 #include "pybind11/stl.h"
10 #include "pybind11/stl_bind.h"
11 
12 namespace py = pybind11;
13 namespace hal
14 {
15 #ifdef PYBIND11_MODULE
16  PYBIND11_MODULE(gui_extension_demo, m)
17  {
18  m.doc() = "hal GuiExtensionDemoPlugin python bindings";
19 #else
20  PYBIND11_PLUGIN(gui_extension_demo)
21  {
22  py::module m("gui_extension_demo", "hal GuiExtensionDemoPlugin python bindings");
23 #endif // ifdef PYBIND11_MODULE
24  py::class_<GuiExtensionDemoPlugin, RawPtrWrapper<GuiExtensionDemoPlugin>, BasePluginInterface>(m, "GuiExtensionDemoPlugin")
25  .def_property_readonly("name", &GuiExtensionDemoPlugin::get_name, R"(
26  The name of the plugin.
27 
28  :type: str
29  )")
30  .def("get_name", &GuiExtensionDemoPlugin::get_name, R"(
31  Get the name of the plugin.
32 
33  :returns: Plugin name.
34  :rtype: str
35  )")
36  .def_property_readonly("version", &GuiExtensionDemoPlugin::get_version, R"(
37  The version of the plugin.
38 
39  :type: str
40  )")
41  .def("get_version", &GuiExtensionDemoPlugin::get_version, R"(
42  Get the version of the plugin.
43 
44  :returns: Plugin version.
45  :rtype: str
46  )");
47 
48  py::enum_<PluginParameter::ParameterType>(m, "ParameterType", R"(
49  Defines the type of a gui input parameter.
50  )")
51  .value("Absent", PluginParameter::Absent, R"(Indicate not used.)")
52  .value("Boolean", PluginParameter::Boolean, R"(``True`` or ``False``.)")
53  .value("Color", PluginParameter::Color, R"(Color value like '#ffe080'.)")
54  .value("ComboBox", PluginParameter::ComboBox, R"(Combo box to select string from semicolon separated input list.)")
55  .value("Dictionary", PluginParameter::Dictionary, R"(Key value pairs (string).)")
56  .value("ExistingDir", PluginParameter::ExistingDir, R"(Existing directory.)")
57  .value("ExistingFile",PluginParameter::ExistingFile,R"(Existing file.)")
58  .value("Float", PluginParameter::Float, R"(Floating point number.)")
59  .value("Gate", PluginParameter::Gate, R"(Gate ID.)")
60  .value("Integer", PluginParameter::Integer, R"(Integer number.)")
61  .value("Module", PluginParameter::Gate, R"(Module ID.)")
62  .value("NewFile", PluginParameter::NewFile, R"(New file name.)")
63  .value("PushButton", PluginParameter::PushButton, R"(Push Button.)")
64  .value("Label", PluginParameter::Label, R"(Text Label.)")
65  .value("String", PluginParameter::String, R"(String value.)")
66  .value("TabName", PluginParameter::TabName, R"(Tab name for structuring other elements.)")
67  .export_values();
68 
69  py::class_<PluginParameter>(m,"PluginParameter")
70  .def(py::init<PluginParameter::ParameterType,std::string,std::string,std::string>())
71  .def("get_tagname", &PluginParameter::get_tagname, R"(
72  Get tag name of parameter.
73 
74  :returns: Tag name.
75  :rtype: str
76  )")
77  .def("get_label", &PluginParameter::get_label, R"(
78  Get labl of parameter.
79 
80  :returns: Parameter label.
81  :rtype: str
82  )")
83  .def("get_value", &PluginParameter::get_value, R"(
84  Get text value parameter.
85 
86  :returns: Parameter value.
87  :rtype: str
88  )")
89  .def("get_type", &PluginParameter::get_type, R"(
90  Get labl of parameter.
91 
92  :returns: Parameter type.
93  :rtype: ParameterType
94  )")
95  .def("set_tagname", &PluginParameter::set_tagname, py::arg("tagname"), R"(
96  Set new tag name.
97  :param str tagname: Tag name for parameter.
98  )")
99  .def("set_value", &PluginParameter::set_value, py::arg("value"), R"(
100  Set parameter value.
101 
102  :param str value: Value for parameter.
103  )");
104 
105  py::class_<GuiExtensionPythonBase>(m,"GuiExtensionPythonBase")
106  .def(py::init<std::string,std::string>())
107  .def("add_main_menu", &GuiExtensionPythonBase::add_main_menu, py::arg("params"), R"(
108  Add form to main menu comprising parameter and push button (special parameter).
109  :param list[hal_py.PluginParameter] params: Parameter to be added.
110  )")
111  .def("add_module_context", &GuiExtensionPythonBase::add_module_context, py::arg("tagname"), py::arg("label"), R"(
112  Add context extension if single module selected.
113  :param str tagname: Tagname of function called from context menu.
114  :param str label: Entry for context menu.
115  )")
116  .def("add_gate_context", &GuiExtensionPythonBase::add_gate_context, py::arg("tagname"), py::arg("label"), R"(
117  Add context extension if single gate selected.
118  :param str tagname: Tagname of function called from context menu.
119  :param str label: Entry for context menu.
120  )")
121  .def("add_net_context", &GuiExtensionPythonBase::add_net_context, py::arg("tagname"), py::arg("label"), R"(
122  Add context extension if single net selected.
123  :param str tagname: Tagname of function called from context menu.
124  :param str label: Entry for context menu.
125  )")
126  .def("get_parameter", &GuiExtensionPythonBase::get_parameter, R"(
127  Get parameter list.
128  :returns: List of parameter.
129  :rtype: list[hal_py.PluginParameter]
130  )")
131  .def("get_selected_modules", &GuiExtensionPythonBase::get_selected_modules, R"(
132  Get IDs of selected modules.
133 
134  :returns: List of module IDs.
135  :rtype: list[int]
136  )")
137  .def("get_selected_gates", &GuiExtensionPythonBase::get_selected_gates, R"(
138  Get IDs of selected gates.
139 
140  :returns: List of gate IDs.
141  :rtype: list[int]
142  )")
143  .def("get_selected_nets", &GuiExtensionPythonBase::get_selected_nets, R"(
144  Get IDs of selected nets.
145 
146  :returns: List of net IDs.
147  :rtype: list[int]
148  )")
149  .def("get_function_call", &GuiExtensionPythonBase::get_function_call, R"(
150  Get tag name of function triggered by GUI
151 
152  :returns: Function tag name.
153  :rtype: str
154  )")
155  .def("clear", &GuiExtensionPythonBase::clear, R"(
156  Clear all registered callbacks and function tags.
157  )");
158 
159 #ifndef PYBIND11_MODULE
160  return m.ptr();
161 #endif // PYBIND11_MODULE
162  }
163 } // namespace hal
std::string get_name() const override
std::string get_version() const override
std::vector< PluginParameter > get_parameter() const
virtual void add_main_menu(const std::vector< PluginParameter > &params)
std::vector< u32 > get_selected_modules() const
virtual void add_gate_context(const std::string tagname, const std::string label)
std::vector< u32 > get_selected_gates() const
virtual void add_module_context(const std::string tagname, const std::string label)
std::vector< u32 > get_selected_nets() const
virtual void add_net_context(const std::string tagname, const std::string label)
void set_value(const std::string &v)
std::string get_label() const
std::string get_value() const
std::string get_tagname() const
void set_tagname(const std::string &tg)
ParameterType get_type() const
const Module * module(const Gate *g, const NodeBoxes &boxes)
Definition: defines.h:45
PYBIND11_PLUGIN(hal_py)