├── .clang-format ├── .cmake-format.json ├── .github └── workflows │ └── main.yml ├── .gitignore ├── .pre-commit-config.yaml ├── CMakeLists.txt ├── LICENSE ├── README.md ├── binder-logo.svg ├── docs ├── Doxyfile ├── Makefile ├── environment.yml ├── make.bat └── source │ ├── _static │ └── main_stylesheet.css │ ├── cmake.svg │ ├── compilers.rst │ ├── conda.svg │ ├── conf.py │ ├── custom.rst │ ├── debian.svg │ ├── embed_widgets │ ├── xleaflet_example.html │ ├── xleaflet_example.ipynb │ ├── xplot_example.html │ └── xplot_example.ipynb │ ├── index.rst │ ├── installation.rst │ ├── quantstack-white.svg │ ├── related_projects.rst │ ├── releasing.rst │ ├── usage.rst │ ├── widget-mvc.svg │ ├── xleaflet.svg │ ├── xplot.svg │ ├── xproperty.svg │ └── xwidgets.svg ├── environment-dev.yml ├── environment.yml ├── include └── xwidgets │ ├── xaccordion.hpp │ ├── xall.hpp │ ├── xaudio.hpp │ ├── xbinary.hpp │ ├── xboolean.hpp │ ├── xbox.hpp │ ├── xbutton.hpp │ ├── xcheckbox.hpp │ ├── xcolor.hpp │ ├── xcolor_picker.hpp │ ├── xcommon.hpp │ ├── xcontroller.hpp │ ├── xdropdown.hpp │ ├── xeither.hpp │ ├── xfactory.hpp │ ├── xholder.hpp │ ├── xhtml.hpp │ ├── ximage.hpp │ ├── xjson.hpp │ ├── xlabel.hpp │ ├── xlayout.hpp │ ├── xlink.hpp │ ├── xmaker.hpp │ ├── xmaterialize.hpp │ ├── xmedia.hpp │ ├── xmixin_description.hpp │ ├── xmixin_numeric.hpp │ ├── xnumber.hpp │ ├── xnumber_bounded.hpp │ ├── xobject.hpp │ ├── xoutput.hpp │ ├── xpassword.hpp │ ├── xplay.hpp │ ├── xprogress.hpp │ ├── xradiobuttons.hpp │ ├── xregistry.hpp │ ├── xselect.hpp │ ├── xselection.hpp │ ├── xselection_container.hpp │ ├── xselectionslider.hpp │ ├── xslider.hpp │ ├── xstring.hpp │ ├── xstyle.hpp │ ├── xtab.hpp │ ├── xtext.hpp │ ├── xtextarea.hpp │ ├── xtogglebutton.hpp │ ├── xtogglebuttons.hpp │ ├── xtransport.hpp │ ├── xvalid.hpp │ ├── xvideo.hpp │ ├── xwidget.hpp │ ├── xwidgets_config.hpp │ └── xwidgets_config_cling.hpp.in ├── notebooks ├── Big.Buck.Bunny.mp3 ├── Big.Buck.Bunny.mp4 ├── marie.png └── xwidgets.ipynb ├── readthedocs.yml ├── src ├── xaccordion.cpp ├── xaudio.cpp ├── xbinary.cpp ├── xbox.cpp ├── xbutton.cpp ├── xcheckbox.cpp ├── xcolor_picker.cpp ├── xcommon.cpp ├── xcontroller.cpp ├── xdropdown.cpp ├── xfactory.cpp ├── xholder.cpp ├── xholder_id.cpp ├── xhtml.cpp ├── ximage.cpp ├── xlabel.cpp ├── xlayout.cpp ├── xlink.cpp ├── xmedia.cpp ├── xmixin_description.cpp ├── xnumber.cpp ├── xnumber_bounded.cpp ├── xoutput.cpp ├── xpassword.cpp ├── xplay.cpp ├── xprogress.cpp ├── xradiobuttons.cpp ├── xregistry.cpp ├── xselect.cpp ├── xselectionslider.cpp ├── xslider.cpp ├── xtab.cpp ├── xtarget.cpp ├── xtarget.hpp ├── xtext.cpp ├── xtextarea.cpp ├── xtogglebutton.cpp ├── xtogglebuttons.cpp ├── xvalid.cpp └── xvideo.cpp ├── test ├── CMakeLists.txt ├── jupyterwidgetmodels.latest.json ├── main.cpp ├── test_widget_model.cpp ├── test_xholder.cpp └── test_xwidgets.cpp ├── widgets.gif └── xwidgetsConfig.cmake.in /.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: Mozilla 2 | AccessModifierOffset: '-4' 3 | AlignAfterOpenBracket: BlockIndent 4 | AlignEscapedNewlines: Left 5 | AllowAllArgumentsOnNextLine: false 6 | AllowAllParametersOfDeclarationOnNextLine: false 7 | AllowShortBlocksOnASingleLine: false 8 | AllowShortCaseLabelsOnASingleLine: false 9 | AllowShortFunctionsOnASingleLine: false 10 | AllowShortIfStatementsOnASingleLine: false 11 | # Forbid one line lambdas because clang-format makes a weird split when 12 | # single instructions lambdas are too long. 13 | AllowShortLambdasOnASingleLine: Empty 14 | AllowShortLoopsOnASingleLine: false 15 | AlwaysBreakAfterReturnType: None 16 | AlwaysBreakAfterDefinitionReturnType: None 17 | AlwaysBreakTemplateDeclarations: Yes 18 | SpaceAfterTemplateKeyword: true 19 | BinPackArguments: false 20 | BinPackParameters: false 21 | BreakBeforeBinaryOperators: NonAssignment 22 | BreakBeforeBraces: Allman 23 | BreakBeforeTernaryOperators: true 24 | BreakConstructorInitializers: BeforeComma 25 | BreakInheritanceList: AfterComma 26 | BreakStringLiterals: false 27 | ColumnLimit: '110' 28 | ConstructorInitializerIndentWidth: '4' 29 | ContinuationIndentWidth: '4' 30 | Cpp11BracedListStyle: true 31 | DerivePointerAlignment: false 32 | DisableFormat: false 33 | ExperimentalAutoDetectBinPacking: true 34 | EmptyLineAfterAccessModifier: Always 35 | EmptyLineBeforeAccessModifier: Always 36 | IncludeBlocks: Regroup 37 | IncludeCategories: 38 | - Regex: <[^.]+> 39 | Priority: 1 40 | - Regex: 41 | Priority: 3 42 | - Regex: <.+> 43 | Priority: 2 44 | - Regex: '"xwidgets/.+"' 45 | Priority: 4 46 | - Regex: '".+"' 47 | Priority: 5 48 | IndentCaseLabels: true 49 | IndentWidth: '4' 50 | IndentWrappedFunctionNames: false 51 | InsertTrailingCommas: Wrapped 52 | KeepEmptyLinesAtTheStartOfBlocks: false 53 | LambdaBodyIndentation: Signature 54 | Language: Cpp 55 | MaxEmptyLinesToKeep: '2' 56 | NamespaceIndentation: All 57 | ObjCBlockIndentWidth: '4' 58 | ObjCSpaceAfterProperty: false 59 | ObjCSpaceBeforeProtocolList: false 60 | PointerAlignment: Left 61 | PackConstructorInitializers: Never 62 | PenaltyBreakAssignment: 100000 63 | PenaltyBreakBeforeFirstCallParameter: 0 64 | PenaltyBreakComment: 10 65 | PenaltyBreakOpenParenthesis: 0 66 | PenaltyBreakTemplateDeclaration: 0 67 | PenaltyExcessCharacter: 10 68 | PenaltyIndentedWhitespace: 0 69 | PenaltyReturnTypeOnItsOwnLine: 10 70 | ReflowComments: true 71 | SeparateDefinitionBlocks: Always 72 | SortIncludes: CaseInsensitive 73 | SortUsingDeclarations: true 74 | SpaceAfterCStyleCast: true 75 | SpaceBeforeAssignmentOperators: true 76 | SpaceBeforeParens: ControlStatements 77 | SpaceInEmptyParentheses: false 78 | SpacesBeforeTrailingComments: '2' 79 | SpacesInAngles: false 80 | SpacesInCStyleCastParentheses: false 81 | SpacesInContainerLiterals: false 82 | SpacesInParentheses: false 83 | SpacesInSquareBrackets: false 84 | Standard: c++14 85 | TabWidth: '4' 86 | UseTab: Never 87 | InsertBraces: true 88 | -------------------------------------------------------------------------------- /.cmake-format.json: -------------------------------------------------------------------------------- 1 | { 2 | "encode": { 3 | "emit_byteorder_mark": false, 4 | "input_encoding": "utf-8", 5 | "output_encoding": "utf-8" 6 | }, 7 | "format": { 8 | "always_wrap": [], 9 | "autosort": false, 10 | "command_case": "lower", 11 | "dangle_align": "prefix", 12 | "dangle_parens": true, 13 | "enable_sort": true, 14 | "keyword_case": "upper", 15 | "layout_passes": {}, 16 | "line_ending": "unix", 17 | "line_width": 110, 18 | "max_lines_hwrap": 0, 19 | "max_pargs_hwrap": 6, 20 | "max_prefix_chars": 0, 21 | "max_rows_cmdline": 1, 22 | "max_subgroups_hwrap": 2, 23 | "min_prefix_chars": 0, 24 | "require_valid_layout": false, 25 | "separate_ctrl_name_with_space": false, 26 | "separate_fn_name_with_space": false, 27 | "tab_size": 4 28 | }, 29 | "misc": { 30 | "per_command": {} 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: 3 | workflow_dispatch: 4 | push: 5 | branches: 6 | - main 7 | pull_request: 8 | branches: 9 | - main 10 | 11 | defaults: 12 | run: 13 | shell: bash -l {0} 14 | 15 | jobs: 16 | 17 | pre-commit: 18 | runs-on: ubuntu-latest 19 | steps: 20 | - uses: actions/checkout@v4 21 | - uses: pre-commit/action@v3.0.0 22 | 23 | unix: 24 | runs-on: ${{ matrix.os }} 25 | 26 | strategy: 27 | fail-fast: false 28 | matrix: 29 | os: [ubuntu-20.04, ubuntu-22.04, macos-11, macos-12] 30 | 31 | steps: 32 | - uses: actions/checkout@v4 33 | 34 | - name: Get number of CPU cores 35 | uses: SimenB/github-actions-cpu-cores@v2 36 | 37 | - name: Install micromamba 38 | uses: mamba-org/setup-micromamba@v1 39 | with: 40 | environment-file: environment-dev.yml 41 | 42 | - name: Cmake configure 43 | run: | 44 | cmake -B build -Werror=dev \ 45 | ${CMAKE_ARGS} \ 46 | -D CMAKE_BUILD_TYPE=Release \ 47 | -D XWIDGETS_BUILD_TESTS=ON \ 48 | -D CMAKE_PREFIX_PATH="${CONDA_PREFIX}" \ 49 | -D CMAKE_INSTALL_PREFIX="${CONDA_PREFIX}" 50 | 51 | - name: Build 52 | run: cmake --build build/ --parallel 2 53 | 54 | - name: Test xwidgets 55 | uses: nick-invision/retry@v2 56 | with: 57 | timeout_minutes: 4 58 | max_attempts: 4 59 | shell: bash 60 | command: ctest --test-dir build/test --output-on-failure 61 | 62 | - name: Install xwidgets 63 | shell: bash -l -eo pipefail {0} 64 | run: cmake --install build/ 65 | 66 | # - name: Test notebook 67 | # if: ${{ startsWith(matrix.os, 'ubuntu') }} 68 | # shell: bash -l -eo pipefail {0} 69 | # run: > 70 | # jupyter nbconvert 71 | # --to notebook 72 | # --output-dir "$(mktemp -d)/out.ipynb" 73 | # --execute 74 | # notebooks/xwidgets.ipynb 75 | 76 | win: 77 | runs-on: ${{ matrix.os }} 78 | 79 | strategy: 80 | fail-fast: false 81 | matrix: 82 | os: [windows-2019, windows-2022] 83 | 84 | steps: 85 | - uses: actions/checkout@v4 86 | 87 | - name: Install micromamba 88 | uses: mamba-org/setup-micromamba@v1 89 | with: 90 | init-shell: cmd.exe 91 | environment-file: environment-dev.yml 92 | 93 | - name: Make build directory 94 | run: mkdir build 95 | 96 | - name: Cmake configure 97 | shell: cmd /C call {0} 98 | run: | 99 | cmake -B build -Werror=dev ^ 100 | -G Ninja ^ 101 | -D CMAKE_BUILD_TYPE=Release ^ 102 | -D XWIDGETS_BUILD_TESTS=ON ^ 103 | -D XWDIGETS_BUILD_TESTS=ON ^ 104 | -D CMAKE_PREFIX_PATH="%CONDA_PREFIX%\Library" ^ 105 | -D CMAKE_INSTALL_PREFIX="%CONDA_PREFIX%" 106 | 107 | - name: Build 108 | shell: cmd /C call {0} 109 | run: | 110 | set CL=/MP 111 | if %errorlevel% neq 0 exit /b %errorlevel% 112 | micromamba run -n xwidgets cmake --build build/ --parallel 113 | 114 | - name: Test xwidgets 115 | uses: nick-invision/retry@v2 116 | with: 117 | timeout_minutes: 4 118 | max_attempts: 4 119 | shell: cmd 120 | command: | 121 | set PATH=%CONDA_PREFIX%;%CONDA_PREFIX%\\Scripts;%CONDA_PREFIX%\\Library;%CONDA_PREFIX%\\Library\\bin;%PATH% 122 | ctest --test-dir build/test --output-on-failure 123 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Compiled Static libraries 20 | *.lai 21 | *.la 22 | *.a 23 | *.lib 24 | 25 | # Executables 26 | *.exe 27 | *.out 28 | *.app 29 | 30 | # Vim tmp files 31 | *.swp 32 | 33 | # Build directory 34 | build/ 35 | 36 | # Test build artefacts 37 | test/test_xwidgets 38 | test/CMakeCache.txt 39 | test/Makefile 40 | test/CMakeFiles/ 41 | test/cmake_install.cmake 42 | 43 | # Documentation build artefacts 44 | docs/CMakeCache.txt 45 | docs/xml/ 46 | docs/build/ 47 | 48 | # Jupyter artefacts 49 | .ipynb_checkpoints/ 50 | 51 | # Generated files 52 | *.pc 53 | 54 | # Generated header 55 | include/xwidgets/xwidgets_config_cling.hpp 56 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | repos: 2 | - repo: https://github.com/pre-commit/pre-commit-hooks 3 | rev: v4.4.0 4 | hooks: 5 | - id: check-added-large-files 6 | - id: check-case-conflict 7 | - id: end-of-file-fixer 8 | - id: trailing-whitespace 9 | - id: mixed-line-ending 10 | args: [--fix=lf] 11 | exclude: \.bat$ 12 | - id: check-json 13 | - id: pretty-format-json 14 | args: [--autofix, --top-keys=version] 15 | - id: check-yaml 16 | - id: detect-private-key 17 | - id: check-merge-conflict 18 | - repo: https://github.com/Lucas-C/pre-commit-hooks 19 | rev: v1.3.1 20 | hooks: 21 | - id: forbid-tabs 22 | - id: remove-tabs 23 | args: [--whitespaces-count, '4'] 24 | - repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks 25 | rev: v2.5.0 26 | hooks: 27 | - id: pretty-format-yaml 28 | args: [--autofix, --indent, '2'] 29 | - repo: https://github.com/tdegeus/cpp_comment_format 30 | rev: v0.2.0 31 | hooks: 32 | - id: cpp_comment_format 33 | - repo: https://github.com/tdegeus/conda_envfile 34 | rev: v0.4.2 35 | hooks: 36 | - id: conda_envfile_parse 37 | files: environment.yaml 38 | - repo: https://github.com/pre-commit/mirrors-clang-format 39 | rev: v15.0.7 40 | hooks: 41 | - id: clang-format 42 | files: .*\.[hc]pp$ 43 | - repo: https://github.com/cheshirekow/cmake-format-precommit 44 | rev: v0.6.13 45 | hooks: 46 | - id: cmake-format 47 | - repo: https://github.com/python-jsonschema/check-jsonschema 48 | rev: 0.20.0 49 | hooks: 50 | - id: check-github-workflows 51 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017, Sylvain Corlay, Johan Mabille and Loic Gouarin 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of the copyright holder nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ![xwidgets](docs/source/xwidgets.svg) 2 | 3 | [![GithubActions](https://github.com/jupyter-xeus/xwidgets/actions/workflows/main.yml/badge.svg)](https://github.com/jupyter-xeus/xwidgets/actions/workflows/main.yml) 4 | [![Documentation](http://readthedocs.org/projects/xwidgets/badge/?version=latest)](https://xwidgets.readthedocs.io/en/latest/?badge=latest) 5 | [![Binder](https://img.shields.io/badge/launch-binder-brightgreen.svg)](https://mybinder.org/v2/gh/jupyter-xeus/xwidgets/stable?filepath=notebooks/xwidgets.ipynb) 6 | [![Join the Gitter Chat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/QuantStack/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 7 | 8 | A C++ backend for Jupyter interactive widgets. 9 | 10 | ## Introduction 11 | 12 | `xwidgets` is a C++ implementation of the Jupyter interactive widgets protocol. 13 | The Python reference implementation is available in the 14 | [ipywidgets](https://github.com/jupyter-widgets/ipywidgets) project. 15 | 16 | `xwidgets` enables the use of the Jupyter interactive widgets in the C++ 17 | notebook, powered by the `xeus-cling` kernel and the `cling` C++ interpreter 18 | from CERN. `xwidgets` can also be used to create applications making use of the 19 | Jupyter interactive widgets without the C++ kernel *per se*. 20 | 21 | ## Usage 22 | 23 | Launch the jupyter notebook with `jupyter notebook` and launch a new C++ 24 | notebook by selecting the **xeus C++14** kernel in the *new* dropdown. 25 | 26 | ![Widgets](widgets.gif) 27 | 28 | ## Installation 29 | 30 | We provide a package for the mamba (or conda) package manager. 31 | 32 | - Installing `xwidgets` and the C++ kernel 33 | 34 | ```bash 35 | mamba install xeus-cling xwidgets -c conda-forge 36 | ``` 37 | 38 | Then, the front-end extension must be installed for either the classic notebook 39 | or JupyterLab. 40 | 41 | - Installing the extension for the classic notebook 42 | 43 | ``` 44 | mamba install widgetsnbextension -c conda-forge 45 | ``` 46 | 47 | ## Installation from sources 48 | 49 | Or you can directly install it from the sources if you have all the 50 | dependencies already installed: 51 | 52 | ```bash 53 | cmake -D CMAKE_INSTALL_PREFIX=your_install_prefix 54 | make install 55 | ``` 56 | 57 | ## Trying it online 58 | 59 | To try out xwidgets interactively in your web browser, just click on the binder 60 | link: 61 | 62 | [![Binder](binder-logo.svg)](https://mybinder.org/v2/gh/jupyter-xeus/xwidgets/stable?filepath=notebooks/xwidgets.ipynb) 63 | 64 | ## Documentation 65 | 66 | To get started with using `xwidgets`, check out the full documentation 67 | 68 | http://xwidgets.readthedocs.io/ 69 | 70 | ## Dependencies 71 | 72 | All the dependencies of xwidgets are available for the mamba (or conda) package manager. 73 | 74 | | `xwidgets` | `jupyterlab_widgets` | `widgetsnbextension` | `xproperty` | `xeus` | `nlohmann_json` | 75 | |------------|----------------------|----------------------|----------------|----------------|-----------------| 76 | | main | ^3.0.0 | ^4.0.0 | >=0.11.0,<0.12 | >=5.0,<6.0 | >=3.11.3,<3.12 | 77 | | 0.29.0 | ^3.0.0 | ^4.0.0 | >=0.11.0,<0.12 | >=5.0,<6.0 | >=3.11.3,<3.12 | 78 | 79 | Versions prior to 0.29 also depend on the xtl: 80 | 81 | | `xwidgets` | `jupyterlab_widgets` | `widgetsnbextension` | `xtl` | `xproperty` | `xeus` | `nlohmann_json` | 82 | |------------|----------------------|----------------------|----------------|----------------|----------------|-----------------| 83 | | master | ^3.0.0 | ^4.0.0 | >=0.7,<0.8 | >=0.11.0,<0.12 | >=3.2,<4.0 | >=3.9.1,<3.10 | 84 | | 0.28.1 | ^3.0.0 | ^4.0.0 | >=0.7,<0.8 | >=0.11.0,<0.12 | >=3.2,<4.0 | >=3.9.1,<3.10 | 85 | | 0.28.0 | ^3.0.0 | ^4.0.0 | >=0.7,<0.8 | >=0.11.0,<0.12 | >=3.0,<4.0 | >=3.9.1,<3.10 | 86 | | 0.27.3 | | ^3.0.0 | >=0.7,<0.8 | >=0.11.0,<0.12 | >=3.0,<4.0 | >=3.9.1,<3.10 | 87 | | 0.27.2 | | ^3.0.0 | >=0.7,<0.8 | >=0.11.0,<0.12 | >=3.0,<4.0 | >=3.9.1,<3.10 | 88 | | 0.27.1 | | ^3.0.0 | >=0.7,<0.8 | >=0.11.0,<0.12 | >=3.0,<4.0 | >=3.9.1,<3.10 | 89 | | 0.27.0 | | ^3.0.0 | >=0.7,<0.8 | >=0.11.0,<0.12 | >=3.0,<4.0 | >=3.9.1,<3.10 | 90 | | 0.26.1 | | ^3.0.0 | >=0.7,<0.8 | >=0.11.0,<0.12 | >=2.0,<3.0 | >=3.9.1,<3.10 | 91 | | 0.26.0 | | ^3.0.0 | >=0.7,<0.8 | >=0.11.0,<0.12 | >=2.0,<3.0 | >=3.9.1,<3.10 | 92 | | 0.25.0 | | ^3.0.0 | >=0.7,<0.8 | >=0.11.0,<0.12 | >=1.0,<2.0 | >=3.6.1,<4.0 | 93 | 94 | Packages `jupyterlab_widgets` and `widgetsnbextension` are not dependencies *per se*, but 95 | hold the frontend counterparts for JupyterLab and the classic notebook respectively that must be installed 96 | in the environment of the Jupyter server. 97 | 98 | ## License 99 | 100 | We use a shared copyright model that enables all contributors to maintain the 101 | copyright on their contributions. 102 | 103 | This software is licensed under the BSD-3-Clause license. 104 | See the [LICENSE](LICENSE) file for details. 105 | -------------------------------------------------------------------------------- /binder-logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 9 | 12 | 14 | 16 | 19 | 23 | 26 | 27 | 28 | 29 | 30 | 32 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /docs/Doxyfile: -------------------------------------------------------------------------------- 1 | PROJECT_NAME = "xwidgets" 2 | XML_OUTPUT = xml 3 | INPUT = ../include 4 | GENERATE_LATEX = NO 5 | GENERATE_MAN = NO 6 | GENERATE_RTF = NO 7 | CASE_SENSE_NAMES = NO 8 | GENERATE_HTML = NO 9 | GENERATE_XML = YES 10 | RECURSIVE = YES 11 | QUIET = YES 12 | JAVADOC_AUTOBRIEF = YES 13 | WARN_IF_UNDOCUMENTED = NO 14 | -------------------------------------------------------------------------------- /docs/environment.yml: -------------------------------------------------------------------------------- 1 | name: xwidgets-docs 2 | 3 | channels: 4 | - conda-forge 5 | 6 | dependencies: 7 | - breathe 8 | - sphinx_rtd_theme 9 | -------------------------------------------------------------------------------- /docs/source/_static/main_stylesheet.css: -------------------------------------------------------------------------------- 1 | .wy-nav-content{ 2 | max-width: 1000px; 3 | margin: auto; 4 | } 5 | -------------------------------------------------------------------------------- /docs/source/compilers.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2017, Johan Mabille and Sylvain Corlay 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | Compiler workarounds 8 | ==================== 9 | 10 | This page tracks the workarounds for the various compiler issues that we 11 | encountered in the development. This is mostly of interest for developers 12 | interested in contributing to xwidgets. 13 | 14 | Visual Studio 2017 and ``__declspec(dllexport)`` 15 | ------------------------------------------------ 16 | 17 | In ``xwidgets.cpp`` a number of widget types are precompiled, in order to 18 | improve the just-in-time compilation time in the context of the cling C++ 19 | interpreter. 20 | 21 | However, with Visual Studio 2017, the introduction of ``__declspec(dllexport)`` 22 | instructions for certain widget types causes compilation errors. This is the 23 | case for widget types that are used as properties for other widgets such as 24 | ``xlayout`` and style widgets. 25 | 26 | The upstream `MSVC issue`_ issue appears to have been solved with VS2017 15.7 27 | (Preview 3). The impacted build numbers for Visual Studio are 28 | ``_MSC_VER==1910``, ``_MSC_VER==1911``, ``_MSC_VER==1912``, 29 | ``_MSC_VER==1913``. 30 | 31 | Visual Studio and CRTP bases 32 | ---------------------------- 33 | 34 | If we have ``template class Foo : public Bar>``, then within 35 | the implementation of ``Foo``, ``Bar`` should be a template, and not refer to 36 | ``Bar>``. However, unlike GCC and Clang, Visual Studio incorrectly makes 37 | ``Bar`` refer to the fully specialized template type. 38 | 39 | Visual Studio and ambiguous calls to base constructors in mixins 40 | ---------------------------------------------------------------- 41 | 42 | In ``xobject.hpp``, we explicitely define constructors instead of making use of the 43 | ``using`` statement for the base constructor because MSVC wrongly reports that the 44 | call to the base class constructor is ambiguous in derived classes. 45 | 46 | .. _`MSVC issue`: https://developercommunity.visualstudio.com/content/problem/208938/compilation-error-c2057-expected-constant-expressi.html 47 | -------------------------------------------------------------------------------- /docs/source/conda.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /docs/source/conf.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | 4 | import os 5 | import subprocess 6 | 7 | on_rtd = os.environ.get('READTHEDOCS', None) == 'True' 8 | 9 | if on_rtd: 10 | subprocess.call('cd ..; doxygen', shell=True) 11 | 12 | import sphinx_rtd_theme 13 | 14 | 15 | def setup(app): 16 | app.add_css_file("main_stylesheet.css") 17 | 18 | html_theme = "sphinx_rtd_theme" 19 | 20 | html_theme_path = [sphinx_rtd_theme.get_html_theme_path()] 21 | 22 | extensions = ['breathe', 'sphinx_rtd_theme'] 23 | breathe_projects = { 'xwidgets': '../xml' } 24 | templates_path = ['_templates'] 25 | html_static_path = ['_static'] 26 | source_suffix = '.rst' 27 | master_doc = 'index' 28 | project = 'xwidgets' 29 | copyright = '2017, Johan Mabille and Sylvain Corlay' 30 | author = 'Johan Mabille and Sylvain Corlay' 31 | 32 | html_logo = 'quantstack-white.svg' 33 | 34 | exclude_patterns = [] 35 | highlight_language = 'c++' 36 | pygments_style = 'sphinx' 37 | todo_include_todos = False 38 | htmlhelp_basename = 'xwidgetsdoc' 39 | -------------------------------------------------------------------------------- /docs/source/embed_widgets/xleaflet_example.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "#include \"xwidgets/xhtml.hpp\"\n", 10 | "\n", 11 | "#include \"xleaflet/xmap.hpp\"\n", 12 | "#include \"xleaflet/xmarker.hpp\"\n", 13 | "\n", 14 | "auto html = xw::html::initialize()\n", 15 | " .value(\"Hello from an xwidget in an xmarker!\")\n", 16 | " .finalize();\n", 17 | "\n", 18 | "std::array center = {52.204793, 360.121558};\n", 19 | "\n", 20 | "auto map = xlf::map::initialize()\n", 21 | " .center(center)\n", 22 | " .zoom(15)\n", 23 | " .finalize();\n", 24 | "\n", 25 | "auto marker = xlf::marker::initialize()\n", 26 | " .location(center)\n", 27 | " .draggable(false)\n", 28 | " .popup(html)\n", 29 | " .finalize();\n", 30 | "map.add_layer(marker);\n", 31 | "\n", 32 | "map" 33 | ] 34 | } 35 | ], 36 | "metadata": { 37 | "kernelspec": { 38 | "display_name": "C++14", 39 | "language": "C++14", 40 | "name": "xeus-cling-cpp14" 41 | }, 42 | "language_info": { 43 | "version": "14", 44 | "codemirror_mode": "text/x-c++src", 45 | "file_extension": ".cpp", 46 | "mimetype": "text/x-c++src", 47 | "name": "c++" 48 | } 49 | }, 50 | "nbformat": 4, 51 | "nbformat_minor": 2 52 | } 53 | -------------------------------------------------------------------------------- /docs/source/embed_widgets/xplot_example.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "#include \n", 10 | "#include \n", 11 | "#include \n", 12 | "\n", 13 | "#include \"xplot/xfigure.hpp\"\n", 14 | "#include \"xplot/xmarks.hpp\"\n", 15 | "#include \"xplot/xaxes.hpp\"\n", 16 | "\n", 17 | "auto randn(std::size_t n)\n", 18 | "{\n", 19 | " std::vector output(n);\n", 20 | " std::random_device rd;\n", 21 | " std::mt19937 gen(rd());\n", 22 | " std::normal_distribution<> dis(5, 2);\n", 23 | "\n", 24 | " std::for_each(output.begin(), output.end(), [&dis, &gen](auto& v){v = dis(gen);});\n", 25 | "\n", 26 | " return output;\n", 27 | "}\n", 28 | "\n", 29 | "std::size_t data_size = 200;\n", 30 | "std::vector data_x(data_size);\n", 31 | "std::iota(data_x.begin(), data_x.end(), 0);\n", 32 | "std::vector data_y = randn(data_size);\n", 33 | "std::vector data_c = randn(data_size);\n", 34 | "\n", 35 | "xpl::linear_scale scale_x, scale_y;\n", 36 | "xpl::linear_scale scale_size;\n", 37 | "\n", 38 | "auto scatter = xpl::scatter::initialize(scale_x, scale_y, scale_size)\n", 39 | " .x(data_x)\n", 40 | " .y(data_y)\n", 41 | " .size(data_c)\n", 42 | " .stroke(\"black\")\n", 43 | " .default_size(128)\n", 44 | " .enable_move(true)\n", 45 | " .colors(std::vector>{\"orangered\"})\n", 46 | " .finalize();\n", 47 | "\n", 48 | "xpl::axis axis_x(scale_x), axis_y(scale_y);\n", 49 | "axis_x.label = \"x\";\n", 50 | "axis_y.label = \"y\";\n", 51 | "axis_y.orientation = \"vertical\";\n", 52 | "axis_y.side = \"left\";\n", 53 | "\n", 54 | "xpl::figure fig;\n", 55 | "fig.padding_x = 0.025;\n", 56 | "fig.add_mark(scatter);\n", 57 | "fig.add_axis(axis_x);\n", 58 | "fig.add_axis(axis_y);\n", 59 | "fig" 60 | ] 61 | } 62 | ], 63 | "metadata": { 64 | "kernelspec": { 65 | "display_name": "C++14", 66 | "language": "C++14", 67 | "name": "xeus-cling-cpp14" 68 | }, 69 | "language_info": { 70 | "version": "14", 71 | "codemirror_mode": "text/x-c++src", 72 | "file_extension": ".cpp", 73 | "mimetype": "text/x-c++src", 74 | "name": "c++" 75 | } 76 | }, 77 | "nbformat": 4, 78 | "nbformat_minor": 2 79 | } 80 | -------------------------------------------------------------------------------- /docs/source/index.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2017, Johan Mabille and Sylvain Corlay 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | .. image:: xwidgets.svg 8 | 9 | The C++ backend for Jupyter interactive widgets. 10 | 11 | Introduction 12 | ------------ 13 | 14 | ``xwidgets`` is a C++ implementation of the Jupyter interactive widgets protocol. The Python reference implementation is available in the ipywidgets_ project. 15 | 16 | xwidgets enables the use of the Jupyter interactive widgets in the C++ notebook, powered by the cling_ C++ interpreter and the xeus-cling_ kernel. xwidgets can also be used to create applications making use of the Jupyter interactive widgets without the C++ kernel per se. 17 | 18 | ``xwidgets`` and its dependencies require a modern C++ compiler supporting C++14. The following C++ compilers are supported: 19 | 20 | - On Windows platforms, Visual C++ 2015 Update 2, or more recent 21 | - On Unix platforms, gcc 4.9 or a recent version of Clang 22 | 23 | Licensing 24 | --------- 25 | 26 | We use a shared copyright model that enables all contributors to maintain the 27 | copyright on their contributions. 28 | 29 | This software is licensed under the BSD-3-Clause license. See the LICENSE file for details. 30 | 31 | .. toctree:: 32 | :caption: INSTALLATION 33 | :maxdepth: 2 34 | 35 | installation 36 | 37 | .. toctree:: 38 | :caption: USAGE 39 | :maxdepth: 2 40 | 41 | usage 42 | 43 | .. toctree:: 44 | :caption: AUTHORING CUSTOM WIDGETS 45 | :maxdepth: 2 46 | 47 | custom 48 | 49 | .. toctree:: 50 | :caption: DEVELOPER ZONE 51 | 52 | compilers 53 | releasing 54 | 55 | .. toctree:: 56 | :caption: MISCELLANEOUS 57 | 58 | related_projects 59 | 60 | .. _ipywidgets: https://github.com/jupyter-widgets/ipywidgets 61 | .. _xeus-cling: https://github.com/jupyter-xeus/xeus-cling 62 | .. _cling: https://root.cern.ch/cling 63 | -------------------------------------------------------------------------------- /docs/source/installation.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2017, Johan Mabille and Sylvain Corlay 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | 8 | .. raw:: html 9 | 10 | 20 | 21 | Installation 22 | ============ 23 | 24 | .. image:: conda.svg 25 | 26 | Using the conda-forge package 27 | ----------------------------- 28 | 29 | A package for xwidgets is available on the mamba (or conda) package manager. 30 | The package will also pull all the dependencies. 31 | 32 | .. code:: 33 | 34 | mamba install xwidgets -c conda-forge 35 | 36 | .. image:: cmake.svg 37 | 38 | From source with cmake 39 | ---------------------- 40 | 41 | You can also install ``xwidgets`` from source with cmake. On Unix platforms, from the source directory: 42 | However, you need to make sure to have the required libraries available on your machine. 43 | 44 | .. code:: 45 | 46 | mkdir build 47 | cd build 48 | cmake -DCMAKE_INSTALL_PREFIX=/path/to/prefix .. 49 | make install 50 | 51 | On Windows platforms, from the source directory: 52 | 53 | .. code:: 54 | 55 | mkdir build 56 | cd build 57 | cmake -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX=/path/to/prefix .. 58 | nmake 59 | nmake install 60 | -------------------------------------------------------------------------------- /docs/source/quantstack-white.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | image/svg+xml 53 | -------------------------------------------------------------------------------- /docs/source/related_projects.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | .. raw:: html 8 | :file: embed_widgets/xleaflet_example.html 9 | 10 | .. raw:: html 11 | :file: embed_widgets/xplot_example.html 12 | 13 | Related projects 14 | ================ 15 | 16 | .. image:: xplot.svg 17 | :alt: xplot 18 | 19 | xplot_ if the C++ backend for the bqplot_ 2-D plotting library 20 | 21 | **C++ code** 22 | 23 | .. code:: 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #include "xwidgets/xbox.hpp" 30 | 31 | #include "xplot/xtoolbar.hpp" 32 | #include "xplot/xfigure.hpp" 33 | #include "xplot/xmarks.hpp" 34 | #include "xplot/xaxes.hpp" 35 | 36 | auto randn(std::size_t n) 37 | { 38 | std::vector output(n); 39 | std::random_device rd; 40 | std::mt19937 gen(rd()); 41 | std::normal_distribution<> dis(5, 2); 42 | 43 | std::for_each(output.begin(), output.end(), [&dis, &gen](auto& v){v = dis(gen);}); 44 | 45 | return output; 46 | } 47 | 48 | std::size_t data_size = 200; 49 | std::vector data_x(data_size); 50 | std::iota(data_x.begin(), data_x.end(), 0); 51 | std::vector data_y = randn(data_size); 52 | std::vector data_c = randn(data_size); 53 | 54 | xpl::linear_scale scale_x, scale_y; 55 | xpl::linear_scale scale_size; 56 | 57 | auto scatter = xpl::scatter::initialize(scale_x, scale_y, scale_size) 58 | .x(data_x) 59 | .y(data_y) 60 | .size(data_c) 61 | .stroke("black") 62 | .default_size(128) 63 | .enable_move(true) 64 | .colors(std::vector>{"orangered"}) 65 | .finalize(); 66 | 67 | xpl::axis axis_x(scale_x), axis_y(scale_y); 68 | axis_x.label = "x"; 69 | axis_y.label = "y"; 70 | axis_y.orientation = "vertical"; 71 | axis_y.side = "left"; 72 | 73 | xpl::figure fig; 74 | fig.padding_x = 0.025; 75 | fig.add_mark(scatter); 76 | fig.add_axis(axis_x); 77 | fig.add_axis(axis_y); 78 | 79 | xpl::toolbar tb(fig); 80 | 81 | xw::vbox b = xw::vbox::initialize() 82 | .children({fig, tb}) 83 | .finalize(); 84 | b 85 | 86 | **Output** 87 | 88 | .. raw:: html 89 | 90 | 97 | 98 | 99 | .. image:: xleaflet.svg 100 | :alt: xleaflet 101 | 102 | xleaflet_ is the C++ backend for the leaflet maps visualization library. The Python reference implementation is available in the ipyleaflet_ project 103 | 104 | **C++ code** 105 | 106 | .. code:: 107 | 108 | #include "xwidgets/xhtml.hpp" 109 | 110 | #include "xleaflet/xmap.hpp" 111 | #include "xleaflet/xmarker.hpp" 112 | 113 | auto html = xw::html::initialize() 114 | .value("Hello from an xwidget in an xmarker!") 115 | .finalize(); 116 | 117 | std::array center = {52.204793, 360.121558}; 118 | 119 | auto map = xlf::map::initialize() 120 | .center(center) 121 | .zoom(15) 122 | .finalize(); 123 | 124 | auto marker = xlf::marker::initialize() 125 | .location(center) 126 | .draggable(false) 127 | .popup(html) 128 | .finalize(); 129 | map.add_layer(marker); 130 | 131 | map 132 | 133 | **Output** 134 | 135 | .. raw:: html 136 | 137 | 144 | 145 | .. image:: xproperty.svg 146 | :alt: xproperty 147 | 148 | xproperty_ is the C++ implementation of the observer pattern underlying 149 | ``xwidgets``. It is to ``xwidgets`` what the traitlets project is to 150 | ``ipywidgets``. 151 | 152 | .. _xplot: https://github.com/QuantStack/xplot.git 153 | .. _bqplot: https://github.com/bloomberg/bqplot.git 154 | .. _xleaflet: https://github.com/QuantStack/xleaflet.git 155 | .. _ipyleaflet: https://github.com/jupyter-widgets/ipyleaflet.git 156 | .. _xproperty: https://github.com/jupyter-xeus/xproperty.git 157 | -------------------------------------------------------------------------------- /docs/source/releasing.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2017, Johan Mabille and Sylvain Corlay 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | Releasing xwidgets 8 | ================== 9 | 10 | Releasing a new version 11 | ----------------------- 12 | 13 | From the master branch of xwidgets 14 | 15 | - Make sure that you are in sync with the master branch of the upstream remote. 16 | - In file ``xwidgets_config.hpp``, set the macros for ``XWIDGETS_VERSION_MAJOR``, ``XWIDGETS_VERSION_MINOR`` and ``XWIDGETS_VERSION_PATCH`` to the desired values. 17 | - Update the README file w.r.t. dependencies on xwidgets. 18 | - Update the environment.yml file used by binder with the new version of 19 | xwidgets and dependencies. 20 | - Stage the changes (``git add``), commit the changes (``git commit``) and add a tag of the form ``Major.minor.patch``. It is important to not add any other content to the tag name. 21 | - Push the new commit and tag to the main repository. (``git push``, and ``git push --tags``) 22 | - Release xwidgets on conda. 23 | - Update the stable branch to point to the latest tag. 24 | -------------------------------------------------------------------------------- /docs/source/xplot.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 9 | 10 | 11 | 19 | 24 | 25 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /docs/source/xproperty.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 9 | 10 | 18 | 23 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /docs/source/xwidgets.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 9 | 10 | 18 | 23 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /environment-dev.yml: -------------------------------------------------------------------------------- 1 | name: xwidgets 2 | channels: 3 | - conda-forge 4 | dependencies: 5 | # Build dependencies 6 | - cmake 7 | - cxx-compiler 8 | - ninja 9 | # Host dependencies 10 | - xeus>=5.0.0,<6 11 | - xproperty=0.12.0 12 | - nlohmann_json=3.11.3 13 | # Test dependencies 14 | - doctest >= 2.4.6 15 | - json_schema_validator 16 | - pre-commit 17 | - cmake-format 18 | -------------------------------------------------------------------------------- /environment.yml: -------------------------------------------------------------------------------- 1 | name: xwidgets 2 | channels: 3 | - conda-forge 4 | dependencies: 5 | - xeus-cling=0.13.0 6 | - xwidgets=0.26.1 7 | - widgetsnbextension >=3.0.0 8 | -------------------------------------------------------------------------------- /include/xwidgets/xaccordion.hpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2017, Sylvain Corlay and Johan Mabille * 3 | * * 4 | * Distributed under the terms of the BSD 3-Clause License. * 5 | * * 6 | * The full license is in the file LICENSE, distributed with this software. * 7 | ****************************************************************************/ 8 | 9 | #ifndef XWIDGETS_ACCORDION_HPP 10 | #define XWIDGETS_ACCORDION_HPP 11 | 12 | #include "xmaterialize.hpp" 13 | #include "xselection_container.hpp" 14 | 15 | namespace xw 16 | { 17 | /************************* 18 | * accordion declaration * 19 | *************************/ 20 | 21 | template 22 | class xaccordion : public xselection_container 23 | { 24 | public: 25 | 26 | using base_type = xselection_container; 27 | using derived_type = D; 28 | 29 | void serialize_state(nl::json&, xeus::buffer_sequence&) const; 30 | void apply_patch(const nl::json&, const xeus::buffer_sequence&); 31 | 32 | protected: 33 | 34 | xaccordion(); 35 | using base_type::base_type; 36 | 37 | private: 38 | 39 | void set_defaults(); 40 | }; 41 | 42 | using accordion = xmaterialize; 43 | 44 | /***************************** 45 | * xaccordion implementation * 46 | *****************************/ 47 | 48 | template 49 | inline void xaccordion::serialize_state(nl::json& state, xeus::buffer_sequence& buffers) const 50 | { 51 | base_type::serialize_state(state, buffers); 52 | } 53 | 54 | template 55 | inline void xaccordion::apply_patch(const nl::json& patch, const xeus::buffer_sequence& buffers) 56 | { 57 | base_type::apply_patch(patch, buffers); 58 | } 59 | 60 | template 61 | inline xaccordion::xaccordion() 62 | : base_type() 63 | { 64 | set_defaults(); 65 | } 66 | 67 | template 68 | inline void xaccordion::set_defaults() 69 | { 70 | this->_model_name() = "AccordionModel"; 71 | this->_view_name() = "AccordionView"; 72 | } 73 | 74 | /********************* 75 | * precompiled types * 76 | *********************/ 77 | 78 | extern template class xmaterialize; 79 | extern template class xtransport>; 80 | } 81 | 82 | #endif 83 | -------------------------------------------------------------------------------- /include/xwidgets/xall.hpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2022, QuantStack and XWidgets contributors * 3 | * * 4 | * Distributed under the terms of the BSD 3-Clause License. * 5 | * * 6 | * The full license is in the file LICENSE, distributed with this software. * 7 | ****************************************************************************/ 8 | 9 | #ifndef XWIDGETS_ALL_HPP 10 | #define XWIDGETS_ALL_HPP 11 | 12 | #include 13 | 14 | #include "xaccordion.hpp" 15 | #include "xaudio.hpp" 16 | #include "xbinary.hpp" 17 | #include "xboolean.hpp" 18 | #include "xbox.hpp" 19 | #include "xbutton.hpp" 20 | #include "xcheckbox.hpp" 21 | #include "xcolor.hpp" 22 | #include "xcolor_picker.hpp" 23 | #include "xcommon.hpp" 24 | #include "xcontroller.hpp" 25 | #include "xdropdown.hpp" 26 | #include "xhtml.hpp" 27 | #include "ximage.hpp" 28 | #include "xlabel.hpp" 29 | #include "xlayout.hpp" 30 | #include "xlink.hpp" 31 | #include "xmedia.hpp" 32 | #include "xnumber.hpp" 33 | #include "xnumber_bounded.hpp" 34 | #include "xoutput.hpp" 35 | #include "xpassword.hpp" 36 | #include "xplay.hpp" 37 | #include "xprogress.hpp" 38 | #include "xradiobuttons.hpp" 39 | #include "xselect.hpp" 40 | #include "xselection.hpp" 41 | #include "xselectionslider.hpp" 42 | #include "xslider.hpp" 43 | #include "xtab.hpp" 44 | #include "xtext.hpp" 45 | #include "xtextarea.hpp" 46 | #include "xtogglebutton.hpp" 47 | #include "xtogglebuttons.hpp" 48 | #include "xvalid.hpp" 49 | #include "xvideo.hpp" 50 | 51 | namespace xw 52 | { 53 | using AllWidgets = std::tuple< 54 | accordion, 55 | audio, 56 | box, 57 | button, 58 | checkbox, 59 | color_picker, 60 | controller, 61 | controller_axis, 62 | controller_button, 63 | directional_link, 64 | dropdown, 65 | hbox, 66 | html, 67 | image, 68 | label, 69 | layout, 70 | link, 71 | media, 72 | number_bounded, 73 | number_bounded, 74 | number_bounded, 75 | number, 76 | number, 77 | number, 78 | output, 79 | password, 80 | play, 81 | progress, 82 | progress, 83 | progress, 84 | radiobuttons, 85 | select, 86 | select_multiple, 87 | selection_rangeslider, 88 | selectionslider, 89 | slider, 90 | slider, 91 | slider, 92 | tab, 93 | text, 94 | textarea, 95 | togglebutton, 96 | togglebuttons, 97 | valid, 98 | vbox, 99 | video>; 100 | 101 | using AllStyles = std::tuple< 102 | button_style, 103 | checkbox_style, 104 | description_style, 105 | html_style, 106 | label_style, 107 | progress_style, 108 | slider_style, 109 | text_style, 110 | togglebutton_style, 111 | togglebuttons_style>; 112 | 113 | } 114 | 115 | #endif 116 | -------------------------------------------------------------------------------- /include/xwidgets/xaudio.hpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2017, Sylvain Corlay and Johan Mabille * 3 | * * 4 | * Distributed under the terms of the BSD 3-Clause License. * 5 | * * 6 | * The full license is in the file LICENSE, distributed with this software. * 7 | ****************************************************************************/ 8 | 9 | #ifndef XWIDGETS_AUDIO_HPP 10 | #define XWIDGETS_AUDIO_HPP 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | #include "xmaterialize.hpp" 17 | #include "xmedia.hpp" 18 | 19 | namespace xw 20 | { 21 | /********************* 22 | * audio declaration * 23 | *********************/ 24 | 25 | template 26 | class xaudio : public xmedia 27 | { 28 | public: 29 | 30 | using base_type = xmedia; 31 | using derived_type = D; 32 | 33 | void serialize_state(nl::json& state, xeus::buffer_sequence&) const; 34 | void apply_patch(const nl::json&, const xeus::buffer_sequence&); 35 | 36 | XPROPERTY(std::string, derived_type, format, "mp4"); 37 | XPROPERTY(bool, derived_type, autoplay, true); 38 | XPROPERTY(bool, derived_type, loop, true); 39 | XPROPERTY(bool, derived_type, controls, true); 40 | 41 | protected: 42 | 43 | xaudio(); 44 | using base_type::base_type; 45 | 46 | private: 47 | 48 | void set_defaults(); 49 | }; 50 | 51 | using audio = xmaterialize; 52 | 53 | /************************* 54 | * xaudio implementation * 55 | *************************/ 56 | 57 | template 58 | inline void xaudio::serialize_state(nl::json& state, xeus::buffer_sequence& buffers) const 59 | { 60 | base_type::serialize_state(state, buffers); 61 | 62 | xwidgets_serialize(format(), state["format"], buffers); 63 | xwidgets_serialize(autoplay(), state["autoplay"], buffers); 64 | xwidgets_serialize(loop(), state["loop"], buffers); 65 | xwidgets_serialize(controls(), state["controls"], buffers); 66 | } 67 | 68 | template 69 | inline void xaudio::apply_patch(const nl::json& patch, const xeus::buffer_sequence& buffers) 70 | { 71 | base_type::apply_patch(patch, buffers); 72 | 73 | set_property_from_patch(format, patch, buffers); 74 | set_property_from_patch(autoplay, patch, buffers); 75 | set_property_from_patch(loop, patch, buffers); 76 | set_property_from_patch(controls, patch, buffers); 77 | } 78 | 79 | template 80 | inline xaudio::xaudio() 81 | : base_type() 82 | { 83 | set_defaults(); 84 | } 85 | 86 | template 87 | inline void xaudio::set_defaults() 88 | { 89 | this->_model_name() = "AudioModel"; 90 | this->_view_name() = "AudioView"; 91 | } 92 | 93 | /********************** 94 | * custom serializers * 95 | **********************/ 96 | 97 | inline void set_property_from_patch( 98 | decltype(audio::value)& property, 99 | const nl::json& patch, 100 | const xeus::buffer_sequence& buffers 101 | ) 102 | { 103 | auto it = patch.find(property.name()); 104 | if (it != patch.end()) 105 | { 106 | using value_type = typename decltype(audio::value)::value_type; 107 | std::size_t index = buffer_index(patch[property.name()].template get()); 108 | const auto& value_buffer = buffers[index]; 109 | property = value_type(value_buffer.data(), value_buffer.data() + value_buffer.size()); 110 | } 111 | } 112 | 113 | inline auto audio_from_file(const std::string& filename) 114 | { 115 | return audio::initialize().value(read_file(filename)); 116 | } 117 | 118 | inline auto audio_from_url(const std::string& url) 119 | { 120 | std::vector value(url.cbegin(), url.cend()); 121 | return audio::initialize().value(value).format("url"); 122 | } 123 | 124 | /********************* 125 | * precompiled types * 126 | *********************/ 127 | 128 | extern template class xmaterialize; 129 | extern template class xtransport>; 130 | } 131 | #endif 132 | -------------------------------------------------------------------------------- /include/xwidgets/xbinary.hpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2017, Sylvain Corlay and Johan Mabille * 3 | * * 4 | * Distributed under the terms of the BSD 3-Clause License. * 5 | * * 6 | * The full license is in the file LICENSE, distributed with this software. * 7 | ****************************************************************************/ 8 | 9 | #ifndef XWIDGETS_BINARY_HPP 10 | #define XWIDGETS_BINARY_HPP 11 | 12 | #include 13 | #include 14 | 15 | #include 16 | #include 17 | 18 | #include "xwidgets_config.hpp" 19 | 20 | namespace nl = nlohmann; 21 | 22 | namespace xw 23 | { 24 | using xjson_path_type = std::vector; 25 | 26 | XWIDGETS_API void reorder_buffer_paths( 27 | const std::vector& buffer_paths, 28 | const nl::json& patch, 29 | std::vector& out 30 | ); 31 | 32 | XWIDGETS_API void insert_buffer_paths(nl::json& patch, const nl::json& buffer_paths); 33 | 34 | XWIDGETS_API const std::string& xbuffer_reference_prefix(); 35 | 36 | XWIDGETS_API bool is_buffer_reference(const std::string& arg); 37 | 38 | XWIDGETS_API std::size_t buffer_index(const std::string& v); 39 | } 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /include/xwidgets/xboolean.hpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2017, Sylvain Corlay and Johan Mabille * 3 | * * 4 | * Distributed under the terms of the BSD 3-Clause License. * 5 | * * 6 | * The full license is in the file LICENSE, distributed with this software. * 7 | ****************************************************************************/ 8 | 9 | #ifndef XWIDGETS_BOOLEAN_HPP 10 | #define XWIDGETS_BOOLEAN_HPP 11 | 12 | #include 13 | 14 | #include "xmixin_description.hpp" 15 | #include "xwidget.hpp" 16 | 17 | namespace xw 18 | { 19 | 20 | /***************************** 21 | * base xboolean declaration * 22 | *****************************/ 23 | 24 | template 25 | class xboolean : public xwidget, 26 | public mixin::xdescription 27 | { 28 | public: 29 | 30 | using derived_type = D; 31 | using base_type = xwidget; 32 | using mixin_description_type = mixin::xdescription; 33 | 34 | void serialize_state(nl::json&, xeus::buffer_sequence&) const; 35 | void apply_patch(const nl::json&, const xeus::buffer_sequence&); 36 | 37 | XPROPERTY(bool, derived_type, disabled); 38 | XPROPERTY(bool, derived_type, value); 39 | 40 | protected: 41 | 42 | xboolean(); 43 | 44 | private: 45 | 46 | void set_defaults(); 47 | }; 48 | 49 | /*************************** 50 | * xboolean implementation * 51 | ***************************/ 52 | 53 | template 54 | inline void xboolean::serialize_state(nl::json& state, xeus::buffer_sequence& buffers) const 55 | { 56 | base_type::serialize_state(state, buffers); 57 | mixin_description_type::serialize_state(state, buffers); 58 | 59 | xwidgets_serialize(disabled(), state["disabled"], buffers); 60 | xwidgets_serialize(value(), state["value"], buffers); 61 | } 62 | 63 | template 64 | inline void xboolean::apply_patch(const nl::json& patch, const xeus::buffer_sequence& buffers) 65 | { 66 | base_type::apply_patch(patch, buffers); 67 | mixin_description_type::apply_patch(patch, buffers); 68 | 69 | set_property_from_patch(disabled, patch, buffers); 70 | set_property_from_patch(value, patch, buffers); 71 | } 72 | 73 | template 74 | inline xboolean::xboolean() 75 | { 76 | set_defaults(); 77 | } 78 | 79 | template 80 | inline void xboolean::set_defaults() 81 | { 82 | this->_model_name() = "BoolModel"; 83 | this->_model_module() = "@jupyter-widgets/controls"; 84 | this->_view_module() = "@jupyter-widgets/controls"; 85 | this->_model_module_version() = XWIDGETS_CONTROLS_VERSION; 86 | this->_view_module_version() = XWIDGETS_CONTROLS_VERSION; 87 | } 88 | } 89 | 90 | #endif 91 | -------------------------------------------------------------------------------- /include/xwidgets/xcheckbox.hpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2017, Sylvain Corlay and Johan Mabille * 3 | * * 4 | * Distributed under the terms of the BSD 3-Clause License. * 5 | * * 6 | * The full license is in the file LICENSE, distributed with this software. * 7 | ****************************************************************************/ 8 | 9 | #ifndef XWIDGETS_CHECKBOX_HPP 10 | #define XWIDGETS_CHECKBOX_HPP 11 | 12 | #include 13 | #include 14 | 15 | #include "xboolean.hpp" 16 | #include "xmaterialize.hpp" 17 | #include "xstyle.hpp" 18 | 19 | namespace xw 20 | { 21 | /******************************** 22 | * checkbox_style declaration * 23 | ********************************/ 24 | 25 | template 26 | class xcheckbox_style : public xstyle 27 | { 28 | public: 29 | 30 | using base_type = xstyle; 31 | using derived_type = D; 32 | 33 | void serialize_state(nl::json&, xeus::buffer_sequence&) const; 34 | void apply_patch(const nl::json&, const xeus::buffer_sequence&); 35 | 36 | XPROPERTY(std::optional, derived_type, background); 37 | XPROPERTY(std::string, derived_type, description_width); 38 | 39 | protected: 40 | 41 | xcheckbox_style(); 42 | using base_type::base_type; 43 | 44 | private: 45 | 46 | void set_defaults(); 47 | }; 48 | 49 | using checkbox_style = xmaterialize; 50 | 51 | /************************ 52 | * checkbox declaration * 53 | ************************/ 54 | 55 | template 56 | class xcheckbox : public xboolean 57 | { 58 | public: 59 | 60 | using base_type = xboolean; 61 | using derived_type = D; 62 | 63 | void serialize_state(nl::json&, xeus::buffer_sequence&) const; 64 | void apply_patch(const nl::json&, const xeus::buffer_sequence&); 65 | 66 | XPROPERTY(bool, derived_type, indent, true); 67 | XPROPERTY(::xw::checkbox_style, derived_type, style); 68 | 69 | protected: 70 | 71 | xcheckbox(); 72 | 73 | using base_type::base_type; 74 | 75 | private: 76 | 77 | void set_defaults(); 78 | }; 79 | 80 | using checkbox = xmaterialize; 81 | 82 | /************************************ 83 | * xcheckbox_style implementation * 84 | ************************************/ 85 | 86 | template 87 | inline void xcheckbox_style::serialize_state(nl::json& state, xeus::buffer_sequence& buffers) const 88 | { 89 | base_type::serialize_state(state, buffers); 90 | 91 | xwidgets_serialize(background(), state["background"], buffers); 92 | xwidgets_serialize(description_width(), state["description_width"], buffers); 93 | } 94 | 95 | template 96 | inline void xcheckbox_style::apply_patch(const nl::json& patch, const xeus::buffer_sequence& buffers) 97 | { 98 | base_type::apply_patch(patch, buffers); 99 | 100 | set_property_from_patch(background, patch, buffers); 101 | set_property_from_patch(description_width, patch, buffers); 102 | } 103 | 104 | template 105 | inline xcheckbox_style::xcheckbox_style() 106 | : base_type() 107 | { 108 | set_defaults(); 109 | } 110 | 111 | template 112 | inline void xcheckbox_style::set_defaults() 113 | { 114 | this->_model_module() = "@jupyter-widgets/controls"; 115 | this->_model_name() = "CheckboxStyleModel"; 116 | } 117 | 118 | /**************************** 119 | * xcheckbox implementation * 120 | ****************************/ 121 | 122 | template 123 | inline void xcheckbox::serialize_state(nl::json& state, xeus::buffer_sequence& buffers) const 124 | { 125 | base_type::serialize_state(state, buffers); 126 | 127 | xwidgets_serialize(indent(), state["indent"], buffers); 128 | xwidgets_serialize(style(), state["style"], buffers); 129 | } 130 | 131 | template 132 | inline void xcheckbox::apply_patch(const nl::json& patch, const xeus::buffer_sequence& buffers) 133 | { 134 | base_type::apply_patch(patch, buffers); 135 | 136 | set_property_from_patch(indent, patch, buffers); 137 | set_property_from_patch(style, patch, buffers); 138 | } 139 | 140 | template 141 | inline xcheckbox::xcheckbox() 142 | : base_type() 143 | { 144 | set_defaults(); 145 | } 146 | 147 | template 148 | inline void xcheckbox::set_defaults() 149 | { 150 | this->_model_name() = "CheckboxModel"; 151 | this->_view_name() = "CheckboxView"; 152 | } 153 | 154 | /********************* 155 | * precompiled types * 156 | *********************/ 157 | 158 | extern template class xmaterialize; 159 | extern template class xtransport>; 160 | 161 | extern template class xmaterialize; 162 | extern template class xtransport>; 163 | } 164 | 165 | #endif 166 | -------------------------------------------------------------------------------- /include/xwidgets/xcolor.hpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2017, Sylvain Corlay and Johan Mabille * 3 | * * 4 | * Distributed under the terms of the BSD 3-Clause License. * 5 | * * 6 | * The full license is in the file LICENSE, distributed with this software. * 7 | ****************************************************************************/ 8 | 9 | #ifndef XWIDGETS_COLOR_HPP 10 | #define XWIDGETS_COLOR_HPP 11 | 12 | #include 13 | 14 | namespace xw 15 | { 16 | using html_color = std::string; 17 | } 18 | #endif 19 | -------------------------------------------------------------------------------- /include/xwidgets/xcolor_picker.hpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2017, Sylvain Corlay and Johan Mabille * 3 | * * 4 | * Distributed under the terms of the BSD 3-Clause License. * 5 | * * 6 | * The full license is in the file LICENSE, distributed with this software. * 7 | ****************************************************************************/ 8 | 9 | #ifndef XWIDGETS_COLOR_PICKER_HPP 10 | #define XWIDGETS_COLOR_PICKER_HPP 11 | 12 | #include "xcolor.hpp" 13 | #include "xmaterialize.hpp" 14 | #include "xmixin_description.hpp" 15 | #include "xwidget.hpp" 16 | 17 | namespace xw 18 | { 19 | /**************************** 20 | * color_picker declaration * 21 | ****************************/ 22 | 23 | template 24 | class xcolor_picker : public xwidget, 25 | public mixin::xdescription 26 | { 27 | public: 28 | 29 | using derived_type = D; 30 | using base_type = xwidget; 31 | using mixin_description_type = mixin::xdescription; 32 | using value_type = html_color; 33 | 34 | void serialize_state(nl::json&, xeus::buffer_sequence&) const; 35 | void apply_patch(const nl::json&, const xeus::buffer_sequence&); 36 | 37 | XPROPERTY(bool, derived_type, disabled); 38 | XPROPERTY(bool, derived_type, concise); 39 | XPROPERTY(value_type, derived_type, value, "black"); 40 | 41 | protected: 42 | 43 | xcolor_picker(); 44 | 45 | private: 46 | 47 | void set_defaults(); 48 | }; 49 | 50 | using color_picker = xmaterialize; 51 | 52 | /******************************** 53 | * xcolor_picker implementation * 54 | ********************************/ 55 | 56 | template 57 | inline void xcolor_picker::serialize_state(nl::json& state, xeus::buffer_sequence& buffers) const 58 | { 59 | base_type::serialize_state(state, buffers); 60 | mixin_description_type::serialize_state(state, buffers); 61 | 62 | xwidgets_serialize(concise(), state["concise"], buffers); 63 | xwidgets_serialize(disabled(), state["disabled"], buffers); 64 | xwidgets_serialize(value(), state["value"], buffers); 65 | } 66 | 67 | template 68 | inline void xcolor_picker::apply_patch(const nl::json& patch, const xeus::buffer_sequence& buffers) 69 | { 70 | base_type::apply_patch(patch, buffers); 71 | mixin_description_type::apply_patch(patch, buffers); 72 | 73 | set_property_from_patch(concise, patch, buffers); 74 | set_property_from_patch(disabled, patch, buffers); 75 | set_property_from_patch(value, patch, buffers); 76 | } 77 | 78 | template 79 | inline xcolor_picker::xcolor_picker() 80 | { 81 | set_defaults(); 82 | } 83 | 84 | template 85 | inline void xcolor_picker::set_defaults() 86 | { 87 | this->_model_name() = "ColorPickerModel"; 88 | this->_view_name() = "ColorPickerView"; 89 | this->_model_module() = "@jupyter-widgets/controls"; 90 | this->_view_module() = "@jupyter-widgets/controls"; 91 | this->_model_module_version() = XWIDGETS_CONTROLS_VERSION; 92 | this->_view_module_version() = XWIDGETS_CONTROLS_VERSION; 93 | } 94 | 95 | /********************* 96 | * precompiled types * 97 | *********************/ 98 | 99 | extern template class xmaterialize; 100 | extern template class xtransport>; 101 | } 102 | 103 | #endif 104 | -------------------------------------------------------------------------------- /include/xwidgets/xdropdown.hpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2017, Sylvain Corlay and Johan Mabille * 3 | * * 4 | * Distributed under the terms of the BSD 3-Clause License. * 5 | * * 6 | * The full license is in the file LICENSE, distributed with this software. * 7 | ****************************************************************************/ 8 | 9 | #ifndef XWIDGETS_DROPDOWN_HPP 10 | #define XWIDGETS_DROPDOWN_HPP 11 | 12 | #include 13 | 14 | #include "xmaterialize.hpp" 15 | #include "xselection.hpp" 16 | 17 | namespace xw 18 | { 19 | /************************ 20 | * dropdown declaration * 21 | ************************/ 22 | 23 | template 24 | class xdropdown : public xselection 25 | { 26 | public: 27 | 28 | using base_type = xselection; 29 | using derived_type = D; 30 | using options_type = typename base_type::options_type; 31 | 32 | void serialize_state(nl::json&, xeus::buffer_sequence&) const; 33 | void apply_patch(const nl::json&, const xeus::buffer_sequence&); 34 | 35 | protected: 36 | 37 | xdropdown(); 38 | 39 | template 40 | xdropdown(O&& options, T&& value); 41 | 42 | using base_type::base_type; 43 | 44 | private: 45 | 46 | void set_defaults(); 47 | }; 48 | 49 | using dropdown = xmaterialize; 50 | 51 | /**************************** 52 | * xdropdown implementation * 53 | ****************************/ 54 | 55 | template 56 | inline void xdropdown::serialize_state(nl::json& state, xeus::buffer_sequence& buffers) const 57 | { 58 | base_type::serialize_state(state, buffers); 59 | } 60 | 61 | template 62 | inline void xdropdown::apply_patch(const nl::json& patch, const xeus::buffer_sequence& buffers) 63 | { 64 | base_type::apply_patch(patch, buffers); 65 | } 66 | 67 | template 68 | inline xdropdown::xdropdown() 69 | : base_type() 70 | { 71 | set_defaults(); 72 | } 73 | 74 | template 75 | template 76 | inline xdropdown::xdropdown(O&& options, T&& value) 77 | : base_type(std::forward(options), std::forward(value)) 78 | { 79 | set_defaults(); 80 | } 81 | 82 | template 83 | inline void xdropdown::set_defaults() 84 | { 85 | this->_model_name() = "DropdownModel"; 86 | this->_view_name() = "DropdownView"; 87 | this->_model_module() = "@jupyter-widgets/controls"; 88 | this->_view_module() = "@jupyter-widgets/controls"; 89 | this->_model_module_version() = XWIDGETS_CONTROLS_VERSION; 90 | this->_view_module_version() = XWIDGETS_CONTROLS_VERSION; 91 | } 92 | 93 | /********************* 94 | * precompiled types * 95 | *********************/ 96 | 97 | extern template class xmaterialize; 98 | extern template class xtransport>; 99 | } 100 | #endif 101 | -------------------------------------------------------------------------------- /include/xwidgets/xeither.hpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2017, Sylvain Corlay and Johan Mabille * 3 | * * 4 | * Distributed under the terms of the BSD 3-Clause License. * 5 | * * 6 | * The full license is in the file LICENSE, distributed with this software. * 7 | ****************************************************************************/ 8 | 9 | #ifndef XWIDGETS_EITHER_HPP 10 | #define XWIDGETS_EITHER_HPP 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | template 18 | auto XEITHER(T... vals) 19 | { 20 | const std::unordered_set options({vals...}); 21 | return [options](const auto& proposal) 22 | { 23 | auto position = options.find(proposal); 24 | if (position == options.end()) 25 | { 26 | throw std::runtime_error("Invalid proposal for string enum"); 27 | } 28 | }; 29 | } 30 | 31 | template 32 | auto XEITHER_OPTIONAL(T... vals) 33 | { 34 | const std::unordered_set options({vals...}); 35 | return [options](const auto& proposal) 36 | { 37 | if (proposal.has_value()) 38 | { 39 | auto position = options.find(proposal.value()); 40 | if (position == options.end()) 41 | { 42 | throw std::runtime_error("Invalid proposal for optional string enum"); 43 | } 44 | } 45 | }; 46 | } 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /include/xwidgets/xfactory.hpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2017, Sylvain Corlay and Johan Mabille * 3 | * * 4 | * Distributed under the terms of the BSD 3-Clause License. * 5 | * * 6 | * The full license is in the file LICENSE, distributed with this software. * 7 | ****************************************************************************/ 8 | 9 | #ifndef XWIDGETS_FACTORY_HPP 10 | #define XWIDGETS_FACTORY_HPP 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | #include 17 | #include 18 | 19 | #include "xwidgets/xwidgets_config.hpp" 20 | 21 | namespace nl = nlohmann; 22 | 23 | namespace xw 24 | { 25 | class XWIDGETS_API xfactory 26 | { 27 | public: 28 | 29 | using maker_type = std::function; 30 | 31 | void register_maker( 32 | const std::string& model_module, 33 | const std::string& model_name, 34 | const std::string& view_module, 35 | const std::string& view_name, 36 | maker_type maker 37 | ); 38 | 39 | void make(xeus::xcomm&& comm, const nl::json& state, const xeus::buffer_sequence&) const; 40 | 41 | private: 42 | 43 | std::unordered_map m_makers; 44 | }; 45 | 46 | XWIDGETS_API xfactory& get_xfactory(); 47 | } 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /include/xwidgets/xhtml.hpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2017, Sylvain Corlay and Johan Mabille * 3 | * * 4 | * Distributed under the terms of the BSD 3-Clause License. * 5 | * * 6 | * The full license is in the file LICENSE, distributed with this software. * 7 | ****************************************************************************/ 8 | 9 | #ifndef XWIDGETS_HTML_HPP 10 | #define XWIDGETS_HTML_HPP 11 | 12 | #include 13 | #include 14 | 15 | #include "xmaterialize.hpp" 16 | #include "xstring.hpp" 17 | #include "xstyle.hpp" 18 | 19 | namespace xw 20 | { 21 | /**************************** 22 | * html_style declaration * 23 | ****************************/ 24 | 25 | template 26 | class xhtml_style : public xstyle 27 | { 28 | public: 29 | 30 | using base_type = xstyle; 31 | using derived_type = D; 32 | 33 | void serialize_state(nl::json&, xeus::buffer_sequence&) const; 34 | void apply_patch(const nl::json&, const xeus::buffer_sequence&); 35 | 36 | XPROPERTY(std::optional, derived_type, background); 37 | XPROPERTY(std::string, derived_type, description_width); 38 | XPROPERTY(std::optional, derived_type, font_size); 39 | XPROPERTY(std::optional, derived_type, text_color); 40 | 41 | protected: 42 | 43 | xhtml_style(); 44 | using base_type::base_type; 45 | 46 | private: 47 | 48 | void set_defaults(); 49 | }; 50 | 51 | using html_style = xmaterialize; 52 | 53 | /******************** 54 | * html declaration * 55 | ********************/ 56 | 57 | template 58 | class xhtml : public xstring 59 | { 60 | public: 61 | 62 | using base_type = xstring; 63 | using derived_type = D; 64 | 65 | void serialize_state(nl::json&, xeus::buffer_sequence&) const; 66 | void apply_patch(const nl::json&, const xeus::buffer_sequence&); 67 | 68 | XPROPERTY(::xw::html_style, derived_type, style); 69 | 70 | protected: 71 | 72 | xhtml(); 73 | using base_type::base_type; 74 | 75 | private: 76 | 77 | void set_defaults(); 78 | }; 79 | 80 | using html = xmaterialize; 81 | 82 | /******************************** 83 | * xhtml_style implementation * 84 | ********************************/ 85 | 86 | template 87 | inline void xhtml_style::serialize_state(nl::json& state, xeus::buffer_sequence& buffers) const 88 | { 89 | base_type::serialize_state(state, buffers); 90 | 91 | xwidgets_serialize(background(), state["background"], buffers); 92 | xwidgets_serialize(description_width(), state["description_width"], buffers); 93 | xwidgets_serialize(font_size(), state["font_size"], buffers); 94 | xwidgets_serialize(text_color(), state["text_color"], buffers); 95 | } 96 | 97 | template 98 | inline void xhtml_style::apply_patch(const nl::json& patch, const xeus::buffer_sequence& buffers) 99 | { 100 | base_type::apply_patch(patch, buffers); 101 | 102 | set_property_from_patch(background, patch, buffers); 103 | set_property_from_patch(description_width, patch, buffers); 104 | set_property_from_patch(font_size, patch, buffers); 105 | set_property_from_patch(text_color, patch, buffers); 106 | } 107 | 108 | template 109 | inline xhtml_style::xhtml_style() 110 | : base_type() 111 | { 112 | set_defaults(); 113 | } 114 | 115 | template 116 | inline void xhtml_style::set_defaults() 117 | { 118 | this->_model_name() = "HTMLStyleModel"; 119 | this->_model_module() = "@jupyter-widgets/controls"; 120 | this->_model_module_version() = XWIDGETS_CONTROLS_VERSION; 121 | } 122 | 123 | /************************ 124 | * xhtml implementation * 125 | ************************/ 126 | 127 | template 128 | inline void xhtml::serialize_state(nl::json& state, xeus::buffer_sequence& buffers) const 129 | { 130 | base_type::serialize_state(state, buffers); 131 | 132 | xwidgets_serialize(style(), state["style"], buffers); 133 | } 134 | 135 | template 136 | inline void xhtml::apply_patch(const nl::json& patch, const xeus::buffer_sequence& buffers) 137 | { 138 | base_type::apply_patch(patch, buffers); 139 | 140 | set_property_from_patch(style, patch, buffers); 141 | } 142 | 143 | template 144 | inline xhtml::xhtml() 145 | : base_type() 146 | { 147 | set_defaults(); 148 | } 149 | 150 | template 151 | inline void xhtml::set_defaults() 152 | { 153 | this->_model_name() = "HTMLModel"; 154 | this->_view_name() = "HTMLView"; 155 | } 156 | 157 | /********************* 158 | * precompiled types * 159 | *********************/ 160 | 161 | extern template class xmaterialize; 162 | extern template class xtransport>; 163 | 164 | extern template class xmaterialize; 165 | extern template class xtransport>; 166 | } 167 | 168 | #endif 169 | -------------------------------------------------------------------------------- /include/xwidgets/ximage.hpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2017, Sylvain Corlay and Johan Mabille * 3 | * * 4 | * Distributed under the terms of the BSD 3-Clause License. * 5 | * * 6 | * The full license is in the file LICENSE, distributed with this software. * 7 | ****************************************************************************/ 8 | 9 | #ifndef XWIDGETS_IMAGE_HPP 10 | #define XWIDGETS_IMAGE_HPP 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | #include "xmaterialize.hpp" 17 | #include "xmedia.hpp" 18 | 19 | namespace xw 20 | { 21 | /********************* 22 | * image declaration * 23 | *********************/ 24 | 25 | template 26 | class ximage : public xmedia 27 | { 28 | public: 29 | 30 | using base_type = xmedia; 31 | using derived_type = D; 32 | 33 | void serialize_state(nl::json& state, xeus::buffer_sequence&) const; 34 | void apply_patch(const nl::json&, const xeus::buffer_sequence&); 35 | 36 | XPROPERTY(std::string, derived_type, format, "png"); 37 | XPROPERTY(std::string, derived_type, width, ""); 38 | XPROPERTY(std::string, derived_type, height, ""); 39 | 40 | protected: 41 | 42 | ximage(); 43 | using base_type::base_type; 44 | 45 | private: 46 | 47 | void set_defaults(); 48 | }; 49 | 50 | using image = xmaterialize; 51 | 52 | /************************* 53 | * ximage implementation * 54 | *************************/ 55 | 56 | template 57 | inline void ximage::serialize_state(nl::json& state, xeus::buffer_sequence& buffers) const 58 | { 59 | base_type::serialize_state(state, buffers); 60 | 61 | xwidgets_serialize(format(), state["format"], buffers); 62 | xwidgets_serialize(width(), state["width"], buffers); 63 | xwidgets_serialize(height(), state["height"], buffers); 64 | } 65 | 66 | template 67 | inline void ximage::apply_patch(const nl::json& patch, const xeus::buffer_sequence& buffers) 68 | { 69 | base_type::apply_patch(patch, buffers); 70 | 71 | set_property_from_patch(format, patch, buffers); 72 | set_property_from_patch(width, patch, buffers); 73 | set_property_from_patch(height, patch, buffers); 74 | } 75 | 76 | template 77 | inline ximage::ximage() 78 | : base_type() 79 | { 80 | set_defaults(); 81 | } 82 | 83 | template 84 | inline void ximage::set_defaults() 85 | { 86 | this->_model_name() = "ImageModel"; 87 | this->_view_name() = "ImageView"; 88 | } 89 | 90 | inline auto image_from_file(const std::string& filename) 91 | { 92 | return image::initialize().value(read_file(filename)); 93 | } 94 | 95 | inline auto image_from_url(const std::string& url) 96 | { 97 | std::vector value(url.cbegin(), url.cend()); 98 | return image::initialize().value(value).format("url"); 99 | } 100 | 101 | /********************** 102 | * custom serializers * 103 | **********************/ 104 | 105 | inline void set_property_from_patch( 106 | decltype(image::value)& property, 107 | const nl::json& patch, 108 | const xeus::buffer_sequence& buffers 109 | ) 110 | { 111 | auto it = patch.find(property.name()); 112 | if (it != patch.end()) 113 | { 114 | using value_type = typename decltype(image::value)::value_type; 115 | std::size_t index = buffer_index(patch[property.name()].template get()); 116 | const auto& value_buffer = buffers[index]; 117 | property = value_type(value_buffer.data(), value_buffer.data() + value_buffer.size()); 118 | } 119 | } 120 | 121 | /********************* 122 | * precompiled types * 123 | *********************/ 124 | 125 | extern template class xmaterialize; 126 | extern template class xtransport>; 127 | } 128 | #endif 129 | -------------------------------------------------------------------------------- /include/xwidgets/xjson.hpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2024, QuantStack * 3 | * * 4 | * Distributed under the terms of the BSD 3-Clause License. * 5 | * * 6 | * The full license is in the file LICENSE, distributed with this software. * 7 | ****************************************************************************/ 8 | 9 | #ifndef XWIDGETS_JSON_HPP 10 | #define XWIDGETS_JSON_HPP 11 | 12 | #include 13 | 14 | #include 15 | 16 | namespace nlohmann 17 | { 18 | template 19 | struct adl_serializer> 20 | { 21 | static void to_json(nlohmann::json& j, const std::optional& o) 22 | { 23 | if (!o.has_value()) 24 | { 25 | j = nullptr; 26 | } 27 | else 28 | { 29 | j = o.value(); 30 | } 31 | } 32 | 33 | static void from_json(const nlohmann::json& j, std::optional& o) 34 | { 35 | if (j.is_null()) 36 | { 37 | o = std::nullopt; 38 | } 39 | else 40 | { 41 | o = j.get(); 42 | } 43 | } 44 | }; 45 | } 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /include/xwidgets/xmaker.hpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2017, Sylvain Corlay and Johan Mabille * 3 | * * 4 | * Distributed under the terms of the BSD 3-Clause License. * 5 | * * 6 | * The full license is in the file LICENSE, distributed with this software. * 7 | ****************************************************************************/ 8 | 9 | #ifndef XWIDGETS_MAKER_HPP 10 | #define XWIDGETS_MAKER_HPP 11 | 12 | #include "nlohmann/json.hpp" 13 | #include "xeus/xcomm.hpp" 14 | #include "xeus/xmessage.hpp" 15 | #include "xholder.hpp" 16 | #include "xmaterialize.hpp" 17 | #include "xregistry.hpp" 18 | 19 | namespace nl = nlohmann; 20 | 21 | namespace xw 22 | { 23 | /******************* 24 | * xmaker template * 25 | *******************/ 26 | 27 | template