Skip to content

Commit 7cf5707

Browse files
committed
now it ssets the page margins from python
1 parent 3e44b9d commit 7cf5707

File tree

16 files changed

+66
-36
lines changed

16 files changed

+66
-36
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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

eval-file-pyqt5-set-value/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cmake_minimum_required(VERSION 3.4)
22
project(scripting)
33

4-
set(PYBIND11_PYTHON_VERSION 3.6)
4+
set(PYBIND11_PYTHON_VERSION 3.4)
55

66
FIND_PACKAGE(pybind11 CONFIG)
77

eval-file-pyqt5-set-value/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
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
~~~

eval-file-pyqt5-set-value/src/main.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
33

44
namespace 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+
615
int main()
716
{
817
// http://pybind11.readthedocs.io/en/latest/advanced/embedding.html#getting-started

eval-file-pyqt5/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cmake_minimum_required(VERSION 3.4)
22
project(scripting)
33

4-
set(PYBIND11_PYTHON_VERSION 3.6)
4+
set(PYBIND11_PYTHON_VERSION 3.4)
55

66
FIND_PACKAGE(pybind11 CONFIG)
77

scripter-api/python/set-bar.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@
88
print("python document.margin.top "+str(document.margin.top))
99
Sample.document.margin.top = 21
1010
print("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))

scripter-api/src/main.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,22 @@
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

1011
namespace py = pybind11;
1112

1213
int 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-

scripter-api/src/sample/document.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff 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

scripter-api/src/sample/page.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff 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
}

scripter-api/src/scripterAPI/document.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace py = pybind11;
77
void 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
}

0 commit comments

Comments
 (0)