File tree Expand file tree Collapse file tree 16 files changed +66
-36
lines changed
eval-file-pyqt5-set-value Expand file tree Collapse file tree 16 files changed +66
-36
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ The pybind11 authors prefer adding pybind11 as a git sub-project: you can of cou
2323## Links
2424
2525- and HN thread: < https://news.ycombinator.com/item?id=15095757 >
26+ - how to use cmake with pybind11 < https://github.com/pybind/pybind11/pull/1098 >
2627
2728## Notes
2829
Original file line number Diff line number Diff line change 11cmake_minimum_required (VERSION 3.4)
22project (scripting)
33
4- set (PYBIND11_PYTHON_VERSION 3.6 )
4+ set (PYBIND11_PYTHON_VERSION 3.4 )
55
66FIND_PACKAGE (pybind11 CONFIG)
77
Original file line number Diff line number Diff line change 22
33~~~ .sh
44$ mkdir build
5- $ cmake -Dpybind11_DIR=/home/ale/bin/pybind11/share/cmake/pybind11
5+ $ cmake -Dpybind11_DIR=/home/ale/bin/pybind11/share/cmake/pybind11 ..
66$ make
77$ ./scripting
88~~~
Original file line number Diff line number Diff line change 33
44namespace py = pybind11;
55
6+ class Dog
7+ {
8+ public:
9+ void setName (std::string n) { name = n; }
10+ std::string getName () { return name; }
11+ private:
12+ std::string name;
13+ };
14+
615int main ()
716{
817 // http://pybind11.readthedocs.io/en/latest/advanced/embedding.html#getting-started
Original file line number Diff line number Diff line change 11cmake_minimum_required (VERSION 3.4)
22project (scripting)
33
4- set (PYBIND11_PYTHON_VERSION 3.6 )
4+ set (PYBIND11_PYTHON_VERSION 3.4 )
55
66FIND_PACKAGE (pybind11 CONFIG)
77
Original file line number Diff line number Diff line change 88print ("python document.margin.top " + str (document .margin .top ))
99Sample .document .margin .top = 21
1010print ("python document.margin.top " + str (document .margin .top ))
11+ Sample .document .getPage (1 ).margin .top = 21
12+ print ("python page 1 margin.top " + str (document .getPage (1 ).margin .top ))
13+ Sample .document .getPage (1 ).margin .top = 42
14+ print ("python page 1 margin.top " + str (document .getPage (1 ).margin .top ))
Original file line number Diff line number Diff line change 33#include < pybind11/embed.h>
44
55#include " sample/document.h"
6- // #include "sample/margin.h"
7- //
6+ #include " sample/page.h"
7+ #include " sample/margin.h"
8+
89#include " scripter.h"
910
1011namespace py = pybind11;
1112
1213int main ()
1314{
1415 Sample::Document document;
16+ Sample::Page page;
17+ document.page .push_back (page);
1518
1619 Scripter scripter{&document};
17- std::cout << " c++ document top " << document.margin . top << std::endl;
20+ std::cout << " c++ document top " << document.margin -> top << std::endl;
1821 scripter.runFile (" ../python/set-bar.py" );
19- std::cout << " c++ document top " << document.margin . top << std::endl;
20- // std::cout << "document page 1 top" document.page.at(0).margin. top << std::endl;
22+ std::cout << " c++ document top " << document.margin -> top << std::endl;
23+ std::cout << " c++ document page 1 top " << document.page .at (0 ).margin -> top << std::endl;
2124}
22-
Original file line number Diff line number Diff line change @@ -8,7 +8,13 @@ namespace Sample
88 class Document
99 {
1010 public:
11- Margin margin;
11+ Document () {
12+ margin = new Margin ();
13+ }
14+ ~Document () {
15+ delete margin;
16+ }
17+ Margin* margin;
1218 std::vector<Page> page;
1319 };
1420
Original file line number Diff line number Diff line change @@ -6,7 +6,13 @@ namespace Sample
66 class Page
77 {
88 public:
9- Margin margin;
9+ Page () {
10+ margin = new Margin ();
11+ }
12+ ~Page () {
13+ delete margin;
14+ }
15+ Margin* margin;
1016 };
1117
1218}
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ namespace py = pybind11;
77void init_DocumentAPI (py::module &m) {
88 py::class_<ScripterAPI::Document>(m, " Document" )
99 .def (py::init<>())
10+ .def (" getPage" , &ScripterAPI::Document::getPage)
1011 .def_property_readonly (" margin" , &ScripterAPI::Document::getMargin)
1112 ;
1213}
You can’t perform that action at this time.
0 commit comments