|
1 | 1 | # pythreejs |
2 | 2 |
|
3 | | - |
4 | | -[](https://pythreejs.readthedocs.io/en/stable/?badge=stable) |
5 | | - |
6 | | - |
7 | | -A Python / ThreeJS bridge utilizing the Jupyter widget infrastructure. |
| 3 | +[![Install from PyPI][pypi-badge]][pypi] |
| 4 | +[![Install from conda-forge][cf-badge]][cf] |
| 5 | +[![Documentation Status][docs-badge]][docs] |
| 6 | +[![Build Status][ci-badge]][ci] |
| 7 | + |
| 8 | +A Python / ThreeJS bridge for [Jupyter Widgets][widgets]. |
| 9 | + |
| 10 | +[pypi-badge]: https://img.shields.io/pypi/v/pythreejs?logo=pypi |
| 11 | +[pypi]: https://pypi.org/project/pythreejs |
| 12 | +[cf-badge]: https://img.shields.io/conda/vn/conda-forge/pythreejs?logo=conda-forge |
| 13 | +[cf]: https://anaconda.org/conda-forge/pythreejs |
| 14 | +[docs-badge]: https://readthedocs.org/projects/pythreejs/badge/?version=stable |
| 15 | +[docs]: https://pythreejs.readthedocs.io/en/stable |
| 16 | +[ci-badge]: https://github.com/jupyter-widgets/pythreejs/actions/workflows/ci.yml/badge.svg |
| 17 | +[ci]: https://github.com/jupyter-widgets/pythreejs/actions/workflows/ci.yml?query=branch%3Amaster |
| 18 | +[widgets]: https://jupyter.org/widgets |
8 | 19 |
|
9 | 20 |  |
10 | 21 |
|
11 | | -## Getting Started |
| 22 | +## Installation |
12 | 23 |
|
13 | | -### Installation |
14 | | - |
15 | | -Using pip: |
| 24 | +Using `pip`: |
16 | 25 |
|
17 | 26 | ```bash |
18 | 27 | pip install pythreejs |
19 | 28 | ``` |
20 | 29 |
|
21 | | -And then install the extension for jupyter notebooks |
| 30 | +or `conda`: |
| 31 | + |
| 32 | +```bash |
| 33 | +conda install -c conda-forge pythreejs |
22 | 34 | ``` |
| 35 | + |
| 36 | +> For a development install, see the [contributing guide][contributing]. |
| 37 | +
|
| 38 | +The extension should then be installed automatically for your Jupyter client. |
| 39 | + |
| 40 | +> For JupyterLab `<3`, you may also need to ensure `nodejs` is installed, and |
| 41 | +> rebuild the application: |
| 42 | +> |
| 43 | +> ```bash |
| 44 | +> # conda install -c cond-forge 'nodejs>=12' |
| 45 | +> jupyter lab build |
| 46 | +> ``` |
| 47 | +
|
| 48 | +[contributing]: https://github.com/jupyter-widgets/pythreejs/blob/master/CONTRIBUTING.md |
| 49 | +
|
| 50 | +## Troubleshooting |
| 51 | +
|
| 52 | +If the extension is not automatically installed, you can manually enable it |
| 53 | +
|
| 54 | +### Jupyter Notebook Classic |
| 55 | +
|
| 56 | +```bash |
| 57 | +jupyter nbextension list |
23 | 58 | jupyter nbextension install --py --symlink --sys-prefix pythreejs |
24 | 59 | jupyter nbextension enable --py --sys-prefix pythreejs |
| 60 | +jupyter nbextension list |
25 | 61 | ``` |
26 | 62 |
|
27 | | -Or for jupyter lab: |
28 | | -``` |
29 | | -jupyter labextension install @jupyter-widgets/jupyterlab-manager |
30 | | -jupyter labextension install jupyter-threejs |
| 63 | +You should see: |
| 64 | + |
| 65 | +```bash |
| 66 | +Known nbextensions: |
| 67 | + ... |
| 68 | + jupyter-js-widgets/extension enabled |
| 69 | + - Validating: OK |
31 | 70 | ``` |
32 | 71 |
|
33 | | -Note for developers: the `--symlink` argument on Linux or OS X allows one to |
34 | | -modify the JavaScript code in-place. This feature is not available |
35 | | -with Windows. |
| 72 | +> Note for developers: the `--symlink` argument on Linux or MacOS allows one to |
| 73 | +> modify the JavaScript code in-place. This feature is not available on Windows. |
| 74 | +
|
| 75 | +### JupyterLab |
36 | 76 |
|
37 | | -Using conda |
| 77 | +To perform a _source installation_: |
38 | 78 |
|
39 | 79 | ```bash |
40 | | -conda install -c conda-forge pythreejs |
| 80 | +## ensure you have nodejs install, e.g. with conda |
| 81 | +# conda install -c conda-forge 'nodejs>=12' |
| 82 | +jupyter labextension list |
| 83 | +jupyter labextension install --no-build @jupyter-widgets/jupyterlab-manager |
| 84 | +jupyter labextension install --no-build jupyter-datawidgets/extension |
| 85 | +jupyter labextension install jupyter-threejs |
| 86 | +jupyter labextension list |
41 | 87 | ``` |
42 | 88 |
|
| 89 | +You should see: |
43 | 90 |
|
44 | | -## Developers |
45 | | - |
46 | | -### Autogen update |
| 91 | +```bash |
| 92 | +JupyterLab v... |
| 93 | + ... |
| 94 | + jupyterlab-datawidgets v... enabled OK |
| 95 | + @jupyter-widgets/jupyterlab-manager v... enabled OK |
| 96 | + jupyter-threejs v... enabled OK |
47 | 97 |
|
48 | | -This is a _significant_ re-work of the pythreejs extension that introduces an "autogen" script that generates the majority of the ipython-widget code to wrap each of three.js's types. It also takes a different view towards the pythreejs API. Whereas pythreejs adds custom functionality to the classes, sometimes renaming, etc., this approach attempts to mimic the low-level three.js API as closely as possible, opening up the possibility for others to build utility libraries on top of this. |
| 98 | +``` |
49 | 99 |
|
50 | | -The autogen script, `generate-wrappers.js`, takes advantage of a config file `three-class-config.js` to auto-generate both javascript and python files to define the ipywidget wrappers for each three.js class. The generated javascript files will have `.autogen.js` as the extension. The generated python files have `_autogen.py` as their extension. The script uses the handlebars template system to generate the various code files. |
| 100 | +> This approach is _not recommended_ for JupyterLab 3, which enables |
| 101 | +> _federated modules_, installed via `pip`, `conda` or other package managers, |
| 102 | +> and does not require rebuilding the entire application. |
51 | 103 |
|
52 | | -The autogen solution allows for overriding the default behavior of the generated classes. E.g., if `Object3D.js` is present, then it will be loaded into the namespace as opposed to loading `Object3D.autogen.js`. It is up to the author of the override classe to decide whether to inherit behavior from the autogen class or not. Same goes for the python modules. This allows for writing custom methods on both the python and javascript side when needed. |
| 104 | +## Uninstallation |
53 | 105 |
|
54 | | -The autogen script relies on a json-like config file (`three-class-config.js`) to describe the classes. Reasonable defaults should take care of most, but it allows specifying the base class, constructor args, etc. for each of the wrappers. A base version of this file can be generated by `generate-class-config.js`, but beware, it overwrites any customization to the config file that has already been done. |
| 106 | +Using `pip`: |
55 | 107 |
|
56 | | -#### Setup |
| 108 | +```bash |
| 109 | +pip uninstall pythreejs |
| 110 | +``` |
57 | 111 |
|
58 | | -The relevant commands while working on the repository are included below. These are not meant to be run sequentially, but rather as a list of useful commands: |
| 112 | +or `conda`: |
59 | 113 |
|
60 | 114 | ```bash |
61 | | -# To perform initial dev setup, run: |
62 | | -pip install -e . |
| 115 | +conda uninstall pythreejs |
| 116 | +``` |
63 | 117 |
|
64 | | -# All commands below assume to be in the ./js/ directory |
65 | | -cd ./js/ |
| 118 | +> If you applied any manual steps above, it may be necessary to remove the |
66 | 119 |
|
67 | | -# To re-generate autogen files, run: |
68 | | -npm run autogen |
| 120 | +### Jupyter Notebook Classic |
69 | 121 |
|
70 | | -# To build and install distribution files, run: |
71 | | -npm run build:all |
72 | | -jupyter nbextension install --py --symlink --sys-prefix pythreejs |
| 122 | +```bash |
| 123 | +jupyter nbextension disable --py --sys-prefix pythreejs |
| 124 | +``` |
73 | 125 |
|
74 | | -# To clean out generated files, run: |
75 | | -npm run clean |
| 126 | +### Jupyter Lab |
76 | 127 |
|
77 | | -# To symlink the jupyter lab extension |
78 | | -jupyter labextension develop .. --overwrite |
| 128 | +```bash |
| 129 | +jupyter labextension uninstall jupyter-threejs |
| 130 | +``` |
79 | 131 |
|
| 132 | +## Open Source |
80 | 133 |
|
81 | | -``` |
| 134 | +This software is licensed under the [BSD-3-Clause][] License. |
| 135 | + |
| 136 | +[bsd-3-clause]: https://github.com/jupyter-widgets/pythreejs/blob/master/LICENSE |
0 commit comments