aboutsummaryrefslogtreecommitdiffstats
path: root/examples/widgetbinding/doc/widgetbinding.md
blob: 6355ea3112f7949645bce4e4a83d24655e508c70 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
(widgetbinding-example)=
# WigglyWidget Example

This example shows how to interact with a custom widget from two
different ways:

 * A full Python translation from a C++ example,
 * A Python binding generated from the C++ file.


The original example contained three different files:
 * `main.cpp/h`, which was translated to `main.py`,
 * `dialog.cpp/h`, which was translated to `dialog.py`,
 * `wigglywidget.cpp/h`, which was translated to `wigglywidget.py`,
   but also remains as is, to enable the binding generation through
   Shiboken.

In the `dialog.py` file you will find two imports that will be related
to each of the two approaches described before::


    # Python translated file
    from wigglywidget import WigglyWidget

    # Binding module create with Shiboken
    from wiggly import WigglyWidget


## Steps to build the bindings

The most important files are:
 * `bindings.xml`, to specify the class that we want to expose from C++
   to Python,
 * `bindings.h` to include the header of the classes we want to expose
 * `CMakeList.txt`, with all the instructions to build the shared libraries
   (DLL, or dylib)
 * `pyside_config.py` which is located in the utils directory, one level
   up, to get the path for Shiboken and PySide.

Now create a `build/` directory, and from inside run `cmake` to use
the provided `CMakeLists.txt`:

macOS/Linux:
```bash
cd ~/pyside-setup/examples/widgetbinding
```

On Windows:
```bash
cd C:\pyside-setup\examples\widgetbinding
```

```bash
mkdir build
cd build
cmake -S.. -B. -G Ninja -DCMAKE_BUILD_TYPE=Release
ninja
ninja install
cd ..
```

The final example can then be run by:
```bash
python main.py
```

You should see two identical custom widgets, one being the
Python translation, and the other one being the C++ one.

## Final words

Since this example originated by mixing the concepts of the `scriptableapplication`
and `samplebinding` examples, you can complement this README with the ones in
those directories.