diff --git a/docs/_macros.py b/docs/_macros.py new file mode 100644 index 0000000..8005e96 --- /dev/null +++ b/docs/_macros.py @@ -0,0 +1,36 @@ +from pathlib import Path +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + from mkdocs_macros.plugin import MacrosPlugin + +EXAMPLES = Path(__file__).parent.parent / "examples" +IMAGES = Path(__file__).parent / "images" + + +def define_env(env: "MacrosPlugin"): + @env.macro + def insert_example(example: str, width: int = 300) -> list[Path]: + """Grab the top widgets of the application.""" + if not example.endswith(".py"): + example += ".py" + + src = (EXAMPLES / example).read_text() + output = f"```python\n{src}\n```\n\n" + + dest = IMAGES / f"{example}.png" + if not (dest).exists(): + src = src.replace("app.exec_()", "") + exec(src) + _grab(dest) + + output += f"![Image title](../images/{dest.name}){{ loading=lazy; width={width} }}\n\n" + return output + + +def _grab(dest: str | Path) -> list[Path]: + """Grab the top widgets of the application.""" + from qtpy.QtWidgets import QApplication + + w = next(iter(QApplication.topLevelWidgets())) + w.grab().save(str(dest)) diff --git a/docs/images/qcollapsible.py.png b/docs/images/qcollapsible.py.png new file mode 100644 index 0000000..362e50b Binary files /dev/null and b/docs/images/qcollapsible.py.png differ diff --git a/docs/index.md b/docs/index.md new file mode 100644 index 0000000..98d0d35 --- /dev/null +++ b/docs/index.md @@ -0,0 +1,2 @@ +# superqt documentation + diff --git a/docs/combobox.md b/docs/tmp/combobox.md similarity index 100% rename from docs/combobox.md rename to docs/tmp/combobox.md diff --git a/docs/decorators.md b/docs/tmp/decorators.md similarity index 100% rename from docs/decorators.md rename to docs/tmp/decorators.md diff --git a/docs/fonticon.md b/docs/tmp/fonticon.md similarity index 100% rename from docs/fonticon.md rename to docs/tmp/fonticon.md diff --git a/docs/listwidgets.md b/docs/tmp/listwidgets.md similarity index 100% rename from docs/listwidgets.md rename to docs/tmp/listwidgets.md diff --git a/docs/sliders.md b/docs/tmp/sliders.md similarity index 100% rename from docs/sliders.md rename to docs/tmp/sliders.md diff --git a/docs/utils.md b/docs/tmp/utils.md similarity index 100% rename from docs/utils.md rename to docs/tmp/utils.md diff --git a/docs/utilities/index.md b/docs/utilities/index.md new file mode 100644 index 0000000..880d3c8 --- /dev/null +++ b/docs/utilities/index.md @@ -0,0 +1,7 @@ +# Utilities + +| Object | Description | +| ----------- | --------------------- | +| [`QMessageHandler`]() | A context manager to intercept messages from Qt. | +| [`@ensure_main_thread`]() | Decorator that ensures a function is called in the main `QApplication` thread. | +| [`@ensure_object_thread`]() | Decorator that ensures a `QObject` method is called in the object's thread. | diff --git a/docs/widgets/index.md b/docs/widgets/index.md new file mode 100644 index 0000000..cdc2988 --- /dev/null +++ b/docs/widgets/index.md @@ -0,0 +1,31 @@ +# Widgets + +The following are QWidget subclasses: + +## Sliders and Numerical Inputs + +| Widget | Description | +| ----------- | --------------------- | +| [`QDoubleSlider`]() | Slider for float values | +| [`QLabeledSlider`]() | `QSlider` with editable `QSpinBox` that shows the current value | +| [`QLabeledDoubleSlider`]() | `QSlider` for float values with editable `QSpinBox` with the current value | +| [`QRangeSlider`]() | Multi-handle slider | +| [`QDoubleRangeSlider`]() | Multi-handle slider for float values | +| [`QLabeledRangeSlider`]() | `QRangeSlider` variant, with editable labels for each handle | +| [`QLabeledDoubleRangeSlider`]() | `QDoubleRangeSlider` variant with editable labels for each handle | +| [`QLargeIntSpinBox`]() | `QSpinbox` that accepts arbitrarily large integers | + +## Labels and categorical inputs + +| Widget | Description | +| ----------- | --------------------- | +| [`QSearchableListWidget`]() | `QListWidget` variant with search field that filters available options | +| [`QEnumComboBox`]() | `QComboBox` that populates the combobox from a python `Enum` | +| [`QSearchableComboBox`]() | `QComboBox` variant that filters available options based on text input | +| [`QElidingLabel`]() | A `QLabel` variant that will elide text (add `…`) to fit width. | + +## Frames and containers + +| Widget | Description | +| ----------- | --------------------- | +| [`QCollapsible`](./qcollapsible.md) | A collapsible widget to hide and unhide child widgets. | diff --git a/docs/widgets/qcollapsible.md b/docs/widgets/qcollapsible.md new file mode 100644 index 0000000..ab0f676 --- /dev/null +++ b/docs/widgets/qcollapsible.md @@ -0,0 +1,3 @@ +# QCollapsible + +{{ insert_example('qcollapsible') }} diff --git a/examples/collapsible.py b/examples/qcollapsible.py similarity index 100% rename from examples/collapsible.py rename to examples/qcollapsible.py diff --git a/mkdocs.yml b/mkdocs.yml new file mode 100644 index 0000000..9478697 --- /dev/null +++ b/mkdocs.yml @@ -0,0 +1,40 @@ +site_name: superqt +site_url: https://github.com/napari/superqt +site_description: >- + missing widgets and components for PyQt/PySide +# Repository +repo_name: napari/superqt +repo_url: https://github.com/napari/superqt + +# Copyright +copyright: Copyright © 2021 - 2022 Talley Lambert + +extra_css: + - stylesheets/extra.css + +watch: + - src + +theme: + name: material + features: + - navigation.instant + - search.highlight + - search.suggest + +markdown_extensions: + - admonition + - pymdownx.details + - pymdownx.superfences + - tables + - attr_list + - md_in_html + - pymdownx.emoji: + emoji_index: !!python/name:materialx.emoji.twemoji + emoji_generator: !!python/name:materialx.emoji.to_svg + +plugins: + - search + # - autorefs + - macros: + module_name: docs/_macros