-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* wip * wip * more wip * progress * more docs * more changes * add link * more examples and improvements * fix check-manifest * sort members * remove autogen images * remove _images * add font docs * add link to utils
- Loading branch information
1 parent
d1c0568
commit 97bb814
Showing
45 changed files
with
1,393 additions
and
540 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,3 +82,4 @@ src/superqt/_version.py | |
screenshots | ||
|
||
.mypy_cache | ||
docs/_auto_images/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
import sys | ||
from enum import EnumMeta | ||
from importlib import import_module | ||
from pathlib import Path | ||
from textwrap import dedent | ||
from typing import TYPE_CHECKING | ||
|
||
from jinja2 import pass_context | ||
from qtpy.QtCore import QObject, Signal | ||
|
||
if TYPE_CHECKING: | ||
from mkdocs_macros.plugin import MacrosPlugin | ||
|
||
EXAMPLES = Path(__file__).parent.parent / "examples" | ||
IMAGES = Path(__file__).parent / "_auto_images" | ||
IMAGES.mkdir(exist_ok=True, parents=True) | ||
|
||
|
||
def define_env(env: "MacrosPlugin"): | ||
@env.macro | ||
@pass_context | ||
def show_widget(context, width: int = 500) -> list[Path]: | ||
# extract all fenced code blocks starting with "python" | ||
page = context["page"] | ||
dest = IMAGES / f"{page.title}.png" | ||
if "build" in sys.argv: | ||
dest.unlink(missing_ok=True) | ||
|
||
codeblocks = [ | ||
b[6:].strip() | ||
for b in page.markdown.split("```") | ||
if b.startswith("python") | ||
] | ||
src = codeblocks[0].strip() | ||
src = src.replace( | ||
"QApplication([])", "QApplication.instance() or QApplication([])" | ||
) | ||
src = src.replace("app.exec_()", "") | ||
|
||
exec(src) | ||
_grab(dest, width) | ||
return f"![{page.title}](../{dest.parent.name}/{dest.name}){{ loading=lazy; width={width} }}\n\n" | ||
|
||
@env.macro | ||
def show_members(cls: str): | ||
# import class | ||
module, name = cls.rsplit(".", 1) | ||
_cls = getattr(import_module(module), name) | ||
|
||
first_q = next( | ||
( | ||
b.__name__ | ||
for b in _cls.__mro__ | ||
if issubclass(b, QObject) and ".Qt" in b.__module__ | ||
), | ||
None, | ||
) | ||
|
||
inherited_members = set() | ||
for base in _cls.__mro__: | ||
if issubclass(base, QObject) and ".Qt" in base.__module__: | ||
inherited_members.update( | ||
{k for k in dir(base) if not k.startswith("_")} | ||
) | ||
|
||
new_signals = { | ||
k | ||
for k, v in vars(_cls).items() | ||
if not k.startswith("_") and isinstance(v, Signal) | ||
} | ||
|
||
self_members = { | ||
k | ||
for k in dir(_cls) | ||
if not k.startswith("_") and k not in inherited_members | new_signals | ||
} | ||
|
||
enums = [] | ||
for m in list(self_members): | ||
if isinstance(getattr(_cls, m), EnumMeta): | ||
self_members.remove(m) | ||
enums.append(m) | ||
|
||
out = "" | ||
if first_q: | ||
url = f"https://doc.qt.io/qt-6/{first_q.lower()}.html" | ||
out += f"## Qt Class\n\n<a href='{url}'>`{first_q}`</a>\n\n" | ||
|
||
out += "" | ||
|
||
if new_signals: | ||
out += "## Signals\n\n" | ||
for sig in new_signals: | ||
out += f"### `{sig}`\n\n" | ||
|
||
if enums: | ||
out += "## Enums\n\n" | ||
for e in enums: | ||
out += f"### `{_cls.__name__}.{e}`\n\n" | ||
for m in getattr(_cls, e): | ||
out += f"- `{m.name}`\n\n" | ||
|
||
if self_members: | ||
|
||
out += dedent( | ||
f""" | ||
## Methods | ||
::: {cls} | ||
options: | ||
heading_level: 3 | ||
show_source: False | ||
show_inherited_members: false | ||
show_signature_annotations: True | ||
members: {sorted(self_members)} | ||
docstring_style: numpy | ||
show_bases: False | ||
show_root_toc_entry: False | ||
show_root_heading: False | ||
""" | ||
) | ||
|
||
return out | ||
|
||
|
||
def _grab(dest: str | Path, width) -> list[Path]: | ||
"""Grab the top widgets of the application.""" | ||
from qtpy.QtCore import QTimer | ||
from qtpy.QtWidgets import QApplication | ||
|
||
w = QApplication.topLevelWidgets()[-1] | ||
w.setFixedWidth(width) | ||
w.activateWindow() | ||
w.setMinimumHeight(40) | ||
w.grab().save(str(dest)) | ||
|
||
# hack to make sure the object is truly closed and deleted | ||
while True: | ||
QTimer.singleShot(10, w.deleteLater) | ||
QApplication.processEvents() | ||
try: | ||
w.parent() | ||
except RuntimeError: | ||
return |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# FAQ | ||
|
||
## Sliders not dragging properly on MacOS 12+ | ||
|
||
??? details | ||
On MacOS Monterey, with Qt5, there is a bug that causes all sliders | ||
(including native Qt sliders) to not respond properly to drag events. See: | ||
|
||
- [https://bugreports.qt.io/browse/QTBUG-98093](https://bugreports.qt.io/browse/QTBUG-98093) | ||
- [https://github.com/napari/superqt/issues/74](https://github.com/napari/superqt/issues/74) | ||
|
||
Superqt includes a workaround for this issue, but it is not perfect, and it requires using a custom stylesheet (which may interfere with your own styles). Note that you | ||
may not see this issue if you're already using custom stylesheets. | ||
|
||
To opt in to the workaround, do any of the following: | ||
|
||
- set the environment variable `USE_MAC_SLIDER_PATCH=1` before importing superqt | ||
(note: this is safe to use even if you're targeting more than just MacOS 12, it will only be applied when needed) | ||
- call the `applyMacStylePatch()` method on any of the superqt slider subclasses (note, this will override your slider styles) | ||
- apply the stylesheet manually: | ||
|
||
```python | ||
from superqt.sliders import MONTEREY_SLIDER_STYLES_FIX | ||
|
||
slider.setStyleSheet(MONTEREY_SLIDER_STYLES_FIX) | ||
``` |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# superqt | ||
|
||
## ![tiny](https://user-images.githubusercontent.com/1609449/120636353-8c3f3800-c43b-11eb-8732-a14dec578897.png) "missing" widgets and components for PyQt/PySide | ||
|
||
This repository aims to provide high-quality community-contributed Qt widgets | ||
and components for [PyQt](https://riverbankcomputing.com/software/pyqt/) & | ||
[PySide](https://www.qt.io/qt-for-python) that are not provided in the native | ||
QtWidgets module. | ||
|
||
Components are tested on: | ||
|
||
- macOS, Windows, & Linux | ||
- Python 3.7 and above | ||
- PyQt5 (5.11 and above) & PyQt6 | ||
- PySide2 (5.11 and above) & PySide6 | ||
|
||
## Installation | ||
|
||
```bash | ||
pip install superqt | ||
``` | ||
|
||
```bash | ||
conda install -c conda-forge superqt | ||
``` | ||
|
||
## Usage | ||
|
||
See the [Widgets](./widgets/) and [Utilities](./utilities/) pages for features offered by superqt. |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.