mirror of
https://github.com/pyapp-kit/superqt.git
synced 2025-08-31 06:40:07 +02:00
Compare commits
18 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
a556f16745 | ||
|
2864058974 | ||
|
463332f4fc | ||
|
f08e2d1720 | ||
|
39c10aa238 | ||
|
d5d40a35f3 | ||
|
5b92a19b82 | ||
|
a3b0f1b115 | ||
|
b1e6d55957 | ||
|
55535b7600 | ||
|
31c834053c | ||
|
69219c846d | ||
|
2edb3c287e | ||
|
218a7b4034 | ||
|
9ab24dbcf6 | ||
|
35acbbf5e6 | ||
|
0ae3350c57 | ||
|
c7f8780900 |
19
.github/workflows/test_and_deploy.yml
vendored
19
.github/workflows/test_and_deploy.yml
vendored
@@ -159,32 +159,33 @@ jobs:
|
||||
name: napari tests
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
path: superqt
|
||||
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
repository: napari/napari
|
||||
path: napari
|
||||
path: napari-repo
|
||||
fetch-depth: 2
|
||||
|
||||
- uses: tlambert03/setup-qt-libs@v1
|
||||
- uses: actions/setup-python@v2
|
||||
- uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: '3.9'
|
||||
python-version: '3.10'
|
||||
|
||||
- name: install
|
||||
run: |
|
||||
python -m pip install -U pip
|
||||
python -m pip install -e ./napari[testing,pyqt5]
|
||||
python -m pip install -e ./superqt
|
||||
python -m pip install ./superqt
|
||||
python -m pip install ./napari-repo[testing,pyqt5]
|
||||
|
||||
- name: Test napari magicgui
|
||||
- name: Test napari
|
||||
uses: GabrielBB/xvfb-action@v1
|
||||
with:
|
||||
run: python -m pytest --color=yes napari/napari/_qt
|
||||
working-directory: napari-repo
|
||||
run: python -m pytest --color=yes napari/_qt
|
||||
|
||||
check_manifest:
|
||||
runs-on: ubuntu-latest
|
||||
|
@@ -1,15 +1,16 @@
|
||||
repos:
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v4.2.0
|
||||
rev: v4.3.0
|
||||
hooks:
|
||||
- id: end-of-file-fixer
|
||||
- id: trailing-whitespace
|
||||
- repo: https://github.com/asottile/setup-cfg-fmt
|
||||
rev: v1.20.1
|
||||
rev: v2.0.0
|
||||
hooks:
|
||||
- id: setup-cfg-fmt
|
||||
args: ["--include-version-classifiers"]
|
||||
- repo: https://github.com/PyCQA/flake8
|
||||
rev: 4.0.1
|
||||
rev: 5.0.2
|
||||
hooks:
|
||||
- id: flake8
|
||||
additional_dependencies: [flake8-typing-imports==1.7.0]
|
||||
@@ -24,16 +25,16 @@ repos:
|
||||
hooks:
|
||||
- id: isort
|
||||
- repo: https://github.com/asottile/pyupgrade
|
||||
rev: v2.32.0
|
||||
rev: v2.37.3
|
||||
hooks:
|
||||
- id: pyupgrade
|
||||
args: [--py37-plus, --keep-runtime-typing]
|
||||
- repo: https://github.com/psf/black
|
||||
rev: 22.3.0
|
||||
rev: 22.6.0
|
||||
hooks:
|
||||
- id: black
|
||||
- repo: https://github.com/pre-commit/mirrors-mypy
|
||||
rev: v0.950
|
||||
rev: v0.971
|
||||
hooks:
|
||||
- id: mypy
|
||||
exclude: examples
|
||||
|
48
CHANGELOG.md
48
CHANGELOG.md
@@ -1,8 +1,38 @@
|
||||
# Changelog
|
||||
|
||||
## [0.3.2](https://github.com/napari/superqt/tree/0.3.2) (2022-05-02)
|
||||
## [0.3.5](https://github.com/napari/superqt/tree/0.3.5) (2022-08-17)
|
||||
|
||||
[Full Changelog](https://github.com/napari/superqt/compare/v0.3.1...0.3.2)
|
||||
[Full Changelog](https://github.com/napari/superqt/compare/v0.3.4...0.3.5)
|
||||
|
||||
**Fixed bugs:**
|
||||
|
||||
- fix range slider drag crash on PyQt6 [\#108](https://github.com/napari/superqt/pull/108) ([sfhbarnett](https://github.com/sfhbarnett))
|
||||
- Fix float value error in pyqt configuration [\#106](https://github.com/napari/superqt/pull/106) ([mstabrin](https://github.com/mstabrin))
|
||||
|
||||
## [v0.3.4](https://github.com/napari/superqt/tree/v0.3.4) (2022-07-24)
|
||||
|
||||
[Full Changelog](https://github.com/napari/superqt/compare/v0.3.3...v0.3.4)
|
||||
|
||||
**Fixed bugs:**
|
||||
|
||||
- fix: relax runtime typing extensions requirement [\#101](https://github.com/napari/superqt/pull/101) ([tlambert03](https://github.com/tlambert03))
|
||||
- fix: catch qpixmap deprecation [\#99](https://github.com/napari/superqt/pull/99) ([tlambert03](https://github.com/tlambert03))
|
||||
|
||||
## [v0.3.3](https://github.com/napari/superqt/tree/v0.3.3) (2022-07-10)
|
||||
|
||||
[Full Changelog](https://github.com/napari/superqt/compare/v0.3.2...v0.3.3)
|
||||
|
||||
**Implemented enhancements:**
|
||||
|
||||
- Add code syntax highlight utils [\#88](https://github.com/napari/superqt/pull/88) ([Czaki](https://github.com/Czaki))
|
||||
|
||||
**Fixed bugs:**
|
||||
|
||||
- fix: fix deprecation warning on fonticon plugin discovery on python 3.10 [\#95](https://github.com/napari/superqt/pull/95) ([tlambert03](https://github.com/tlambert03))
|
||||
|
||||
## [v0.3.2](https://github.com/napari/superqt/tree/v0.3.2) (2022-05-03)
|
||||
|
||||
[Full Changelog](https://github.com/napari/superqt/compare/v0.3.1...v0.3.2)
|
||||
|
||||
**Implemented enhancements:**
|
||||
|
||||
@@ -18,6 +48,10 @@
|
||||
|
||||
- Fix deprecation warnings in tests [\#82](https://github.com/napari/superqt/pull/82) ([tlambert03](https://github.com/tlambert03))
|
||||
|
||||
**Merged pull requests:**
|
||||
|
||||
- Add changelog for v0.3.2 [\#86](https://github.com/napari/superqt/pull/86) ([tlambert03](https://github.com/tlambert03))
|
||||
|
||||
## [v0.3.1](https://github.com/napari/superqt/tree/v0.3.1) (2022-03-02)
|
||||
|
||||
[Full Changelog](https://github.com/napari/superqt/compare/v0.3.0...v0.3.1)
|
||||
@@ -139,21 +173,13 @@
|
||||
|
||||
## [v0.2.1](https://github.com/napari/superqt/tree/v0.2.1) (2021-07-10)
|
||||
|
||||
[Full Changelog](https://github.com/napari/superqt/compare/v0.2.0rc0...v0.2.1)
|
||||
[Full Changelog](https://github.com/napari/superqt/compare/v0.2.0...v0.2.1)
|
||||
|
||||
**Fixed bugs:**
|
||||
|
||||
- Fix QLabeledRangeSlider API \(fix slider proxy\) [\#10](https://github.com/napari/superqt/pull/10) ([tlambert03](https://github.com/tlambert03))
|
||||
- Fix range slider with negative min range [\#9](https://github.com/napari/superqt/pull/9) ([tlambert03](https://github.com/tlambert03))
|
||||
|
||||
## [v0.2.0rc0](https://github.com/napari/superqt/tree/v0.2.0rc0) (2021-06-26)
|
||||
|
||||
[Full Changelog](https://github.com/napari/superqt/compare/v0.2.0rc1...v0.2.0rc0)
|
||||
|
||||
## [v0.2.0rc1](https://github.com/napari/superqt/tree/v0.2.0rc1) (2021-06-26)
|
||||
|
||||
[Full Changelog](https://github.com/napari/superqt/compare/v0.2.0...v0.2.0rc1)
|
||||
|
||||
|
||||
|
||||
\* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)*
|
||||
|
10
docs/utils.md
Normal file
10
docs/utils.md
Normal file
@@ -0,0 +1,10 @@
|
||||
# Utils
|
||||
|
||||
## Code highlighting
|
||||
|
||||
`superqt` provides a code highlighter subclass of `QSyntaxHighlighter`
|
||||
that can be used to highlight code in a QTextEdit.
|
||||
|
||||
Code lexer and available styles are from [`pygments`](https://pygments.org/) python library
|
||||
List of available languages are available [here](https://pygments.org/languages/).
|
||||
List of available styles are available [here](https://pygments.org/styles/).
|
32
examples/code_highlight.py
Normal file
32
examples/code_highlight.py
Normal file
@@ -0,0 +1,32 @@
|
||||
from PyQt5.QtGui import QColor, QPalette
|
||||
from qtpy.QtWidgets import QApplication, QTextEdit
|
||||
|
||||
from superqt.utils import CodeSyntaxHighlight
|
||||
|
||||
app = QApplication([])
|
||||
|
||||
text_area = QTextEdit()
|
||||
|
||||
highlight = CodeSyntaxHighlight(text_area.document(), "python", "monokai")
|
||||
|
||||
palette = text_area.palette()
|
||||
palette.setColor(QPalette.Base, QColor(highlight.background_color))
|
||||
text_area.setPalette(palette)
|
||||
text_area.setText(
|
||||
"""from argparse import ArgumentParser
|
||||
|
||||
def main():
|
||||
parser = ArgumentParser()
|
||||
parser.add_argument("name", help="Your name")
|
||||
args = parser.parse_args()
|
||||
print(f"Hello {args.name}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
"""
|
||||
)
|
||||
|
||||
text_area.show()
|
||||
|
||||
app.exec_()
|
@@ -36,8 +36,9 @@ project_urls =
|
||||
packages = find:
|
||||
install_requires =
|
||||
packaging
|
||||
pygments>=2.4.0
|
||||
qtpy>=1.1.0
|
||||
typing-extensions>=3.10.0.0
|
||||
typing-extensions
|
||||
python_requires = >=3.7
|
||||
include_package_data = True
|
||||
package_dir =
|
||||
|
@@ -17,7 +17,12 @@ class FontIconManager:
|
||||
|
||||
def _discover_fonts(self) -> None:
|
||||
self._PLUGINS.clear()
|
||||
for ep in entry_points().get(self.ENTRY_POINT, {}):
|
||||
entries = entry_points()
|
||||
if hasattr(entries, "select"): # python>3.10
|
||||
_entries = entries.select(group=self.ENTRY_POINT) # type: ignore
|
||||
else:
|
||||
_entries = entries.get(self.ENTRY_POINT, [])
|
||||
for ep in _entries:
|
||||
if ep not in self._BLOCKED:
|
||||
self._PLUGINS[ep.name] = ep
|
||||
|
||||
|
@@ -243,7 +243,9 @@ class _QFontIconEngine(QIconEngine):
|
||||
def pixmap(self, size: QSize, mode: QIcon.Mode, state: QIcon.State) -> QPixmap:
|
||||
# first look in cache
|
||||
pmckey = self._pmcKey(size, mode, state)
|
||||
pm = QPixmapCache.find(pmckey) if pmckey else None
|
||||
with warnings.catch_warnings():
|
||||
warnings.filterwarnings("ignore", "QPixmapCache.find")
|
||||
pm = QPixmapCache.find(pmckey) if pmckey else None
|
||||
if pm:
|
||||
return pm
|
||||
pixmap = QPixmap(size)
|
||||
|
@@ -146,11 +146,17 @@ class _GenericRangeSlider(_GenericSlider[Tuple], Generic[_T]):
|
||||
def mouseMoveEvent(self, ev: QtGui.QMouseEvent) -> None:
|
||||
if self._pressedControl == SC_BAR:
|
||||
ev.accept()
|
||||
delta = self._clickOffset - self._pixelPosToRangeValue(self._pick(ev.pos()))
|
||||
delta = self._clickOffset - self._pixelPosToRangeValue(
|
||||
self._pick(self._event_position(ev))
|
||||
)
|
||||
self._offsetAllPositions(-delta, self._sldPosAtPress)
|
||||
else:
|
||||
super().mouseMoveEvent(ev)
|
||||
|
||||
def _event_position(self, event):
|
||||
# API changes between PyQt5 (.pos()) and PyQt6 (.position())
|
||||
return event.pos() if hasattr(event, "pos") else event.position()
|
||||
|
||||
# ############### Implementation Details #######################
|
||||
|
||||
def _setPosition(self, val):
|
||||
|
@@ -128,7 +128,7 @@ class QLabeledSlider(_SliderProxy, QAbstractSlider):
|
||||
super().__init__(parent)
|
||||
|
||||
self._slider = self._slider_class()
|
||||
self._label = SliderLabel(self._slider, connect=self._slider.setValue)
|
||||
self._label = SliderLabel(self._slider, connect=self._setValue)
|
||||
self._edge_label_mode: EdgeLabelMode = EdgeLabelMode.LabelIsValue
|
||||
|
||||
self._rename_signals()
|
||||
@@ -142,6 +142,13 @@ class QLabeledSlider(_SliderProxy, QAbstractSlider):
|
||||
|
||||
self.setOrientation(orientation)
|
||||
|
||||
def _setValue(self, value: float):
|
||||
"""
|
||||
Convert the value from float to int before
|
||||
setting the slider value
|
||||
"""
|
||||
self._slider.setValue(int(value))
|
||||
|
||||
def _rename_signals(self):
|
||||
# for subclasses
|
||||
pass
|
||||
|
@@ -1,4 +1,5 @@
|
||||
__all__ = (
|
||||
"CodeSyntaxHighlight",
|
||||
"create_worker",
|
||||
"ensure_main_thread",
|
||||
"ensure_object_thread",
|
||||
@@ -15,7 +16,7 @@ __all__ = (
|
||||
"WorkerBase",
|
||||
)
|
||||
|
||||
|
||||
from ._code_syntax_highlight import CodeSyntaxHighlight
|
||||
from ._ensure_thread import ensure_main_thread, ensure_object_thread
|
||||
from ._message_handler import QMessageHandler
|
||||
from ._misc import signals_blocked
|
||||
|
93
src/superqt/utils/_code_syntax_highlight.py
Normal file
93
src/superqt/utils/_code_syntax_highlight.py
Normal file
@@ -0,0 +1,93 @@
|
||||
from itertools import takewhile
|
||||
|
||||
from pygments import highlight
|
||||
from pygments.formatter import Formatter
|
||||
from pygments.lexers import find_lexer_class, get_lexer_by_name
|
||||
from pygments.util import ClassNotFound
|
||||
from qtpy import QtGui
|
||||
|
||||
# inspired by https://github.com/Vector35/snippets/blob/master/QCodeEditor.py (MIT license) and
|
||||
# https://pygments.org/docs/formatterdevelopment/#html-3-2-formatter
|
||||
|
||||
|
||||
def get_text_char_format(style):
|
||||
"""
|
||||
Return a QTextCharFormat with the given attributes.
|
||||
|
||||
https://pygments.org/docs/formatterdevelopment/#html-3-2-formatter
|
||||
"""
|
||||
|
||||
text_char_format = QtGui.QTextCharFormat()
|
||||
text_char_format.setFontFamily("monospace")
|
||||
if style.get("color"):
|
||||
text_char_format.setForeground(QtGui.QColor(f"#{style['color']}"))
|
||||
|
||||
if style.get("bgcolor"):
|
||||
text_char_format.setBackground(QtGui.QColor(style["bgcolor"]))
|
||||
|
||||
if style.get("bold"):
|
||||
text_char_format.setFontWeight(QtGui.QFont.Bold)
|
||||
if style.get("italic"):
|
||||
text_char_format.setFontItalic(True)
|
||||
if style.get("underline"):
|
||||
text_char_format.setFontUnderline(True)
|
||||
|
||||
# TODO find if it is possible to support border style.
|
||||
|
||||
return text_char_format
|
||||
|
||||
|
||||
class QFormatter(Formatter):
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
self.data = []
|
||||
self._style = {name: get_text_char_format(style) for name, style in self.style}
|
||||
|
||||
def format(self, tokensource, outfile):
|
||||
"""
|
||||
`outfile` is argument from parent class, but
|
||||
in Qt we do not produce string output, but QTextCharFormat, so it needs to be
|
||||
collected using `self.data`.
|
||||
"""
|
||||
self.data = []
|
||||
|
||||
for token, value in tokensource:
|
||||
self.data.extend(
|
||||
[
|
||||
self._style[token],
|
||||
]
|
||||
* len(value)
|
||||
)
|
||||
|
||||
|
||||
class CodeSyntaxHighlight(QtGui.QSyntaxHighlighter):
|
||||
def __init__(self, parent, lang, theme):
|
||||
super().__init__(parent)
|
||||
self.formatter = QFormatter(style=theme)
|
||||
try:
|
||||
self.lexer = get_lexer_by_name(lang)
|
||||
except ClassNotFound:
|
||||
self.lexer = find_lexer_class(lang)()
|
||||
|
||||
@property
|
||||
def background_color(self):
|
||||
return self.formatter.style.background_color
|
||||
|
||||
def highlightBlock(self, text):
|
||||
cb = self.currentBlock()
|
||||
p = cb.position()
|
||||
text_ = self.document().toPlainText() + "\n"
|
||||
highlight(text_, self.lexer, self.formatter)
|
||||
|
||||
enters = sum(1 for _ in takewhile(lambda x: x == "\n", text_))
|
||||
# pygments lexer ignore leading empty lines, so we need to do correction
|
||||
# here calculating the number of empty lines.
|
||||
|
||||
# dirty, dirty hack
|
||||
# The core problem is that pygemnts by default use string streams,
|
||||
# that will not handle QTextCharFormat, so wee need use `data` property to work around this.
|
||||
for i in range(len(text)):
|
||||
try:
|
||||
self.setFormat(i, 1, self.formatter.data[p + i - enters])
|
||||
except IndexError: # pragma: no cover
|
||||
pass
|
@@ -21,10 +21,8 @@ from typing import (
|
||||
)
|
||||
|
||||
from qtpy.QtCore import QObject, QRunnable, QThread, QThreadPool, QTimer, Signal
|
||||
from typing_extensions import Literal, ParamSpec
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
||||
_T = TypeVar("_T")
|
||||
|
||||
class SigInst(Generic[_T]):
|
||||
@@ -40,11 +38,21 @@ if TYPE_CHECKING:
|
||||
def emit(*args: _T) -> None:
|
||||
...
|
||||
|
||||
from typing_extensions import Literal, ParamSpec
|
||||
|
||||
_P = ParamSpec("_P")
|
||||
# maintain runtime compatibility with older typing_extensions
|
||||
else:
|
||||
try:
|
||||
from typing_extensions import ParamSpec
|
||||
|
||||
_P = ParamSpec("_P")
|
||||
except ImportError:
|
||||
_P = TypeVar("_P")
|
||||
|
||||
_Y = TypeVar("_Y")
|
||||
_S = TypeVar("_S")
|
||||
_R = TypeVar("_R")
|
||||
_P = ParamSpec("_P")
|
||||
|
||||
|
||||
def as_generator_function(
|
||||
|
@@ -33,10 +33,22 @@ from functools import wraps
|
||||
from typing import TYPE_CHECKING, Callable, Generic, Optional, TypeVar, Union, overload
|
||||
|
||||
from qtpy.QtCore import QObject, Qt, QTimer, Signal
|
||||
from typing_extensions import Literal, ParamSpec
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from qtpy.QtCore import SignalInstance
|
||||
from typing_extensions import Literal, ParamSpec
|
||||
|
||||
P = ParamSpec("P")
|
||||
# maintain runtime compatibility with older typing_extensions
|
||||
else:
|
||||
try:
|
||||
from typing_extensions import ParamSpec
|
||||
|
||||
P = ParamSpec("P")
|
||||
except ImportError:
|
||||
P = TypeVar("P")
|
||||
|
||||
R = TypeVar("R")
|
||||
|
||||
|
||||
class Kind(IntFlag):
|
||||
@@ -179,8 +191,6 @@ class QSignalDebouncer(GenericSignalThrottler):
|
||||
|
||||
# below here part is unique to superqt (not from KD)
|
||||
|
||||
P = ParamSpec("P")
|
||||
R = TypeVar("R")
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from typing_extensions import Protocol
|
||||
@@ -199,12 +209,12 @@ if TYPE_CHECKING:
|
||||
|
||||
if sys.version_info < (3, 9):
|
||||
|
||||
def __call__(self, *args: P.args, **kwargs: P.kwargs) -> Future:
|
||||
def __call__(self, *args: "P.args", **kwargs: "P.kwargs") -> Future:
|
||||
...
|
||||
|
||||
else:
|
||||
|
||||
def __call__(self, *args: P.args, **kwargs: P.kwargs) -> Future[R]:
|
||||
def __call__(self, *args: "P.args", **kwargs: "P.kwargs") -> Future[R]:
|
||||
...
|
||||
|
||||
|
||||
@@ -220,7 +230,7 @@ def qthrottled(
|
||||
|
||||
@overload
|
||||
def qthrottled(
|
||||
func: Literal[None] = None,
|
||||
func: "Literal[None]" = None,
|
||||
timeout: int = 100,
|
||||
leading: bool = True,
|
||||
timer_type: Qt.TimerType = Qt.TimerType.PreciseTimer,
|
||||
@@ -279,7 +289,7 @@ def qdebounced(
|
||||
|
||||
@overload
|
||||
def qdebounced(
|
||||
func: Literal[None] = None,
|
||||
func: "Literal[None]" = None,
|
||||
timeout: int = 100,
|
||||
leading: bool = False,
|
||||
timer_type: Qt.TimerType = Qt.TimerType.PreciseTimer,
|
||||
@@ -347,7 +357,7 @@ def _make_decorator(
|
||||
future: Optional[Future] = None
|
||||
|
||||
@wraps(func)
|
||||
def inner(*args: P.args, **kwargs: P.kwargs) -> Future:
|
||||
def inner(*args: "P.args", **kwargs: "P.kwargs") -> Future:
|
||||
nonlocal last_f
|
||||
nonlocal future
|
||||
if last_f is not None:
|
||||
|
19
tests/test_code_highlight.py
Normal file
19
tests/test_code_highlight.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from qtpy.QtWidgets import QTextEdit
|
||||
|
||||
from superqt.utils import CodeSyntaxHighlight
|
||||
|
||||
|
||||
def test_code_highlight(qtbot):
|
||||
widget = QTextEdit()
|
||||
qtbot.addWidget(widget)
|
||||
code_highlight = CodeSyntaxHighlight(widget, "python", "default")
|
||||
assert code_highlight.background_color == "#f8f8f8"
|
||||
widget.setText("from argparse import ArgumentParser")
|
||||
|
||||
|
||||
def test_code_highlight_by_name(qtbot):
|
||||
widget = QTextEdit()
|
||||
qtbot.addWidget(widget)
|
||||
code_highlight = CodeSyntaxHighlight(widget, "Python Traceback", "monokai")
|
||||
assert code_highlight.background_color == "#272822"
|
||||
widget.setText("from argparse import ArgumentParser")
|
@@ -0,0 +1,3 @@
|
||||
Metadata-Version: 2.1
|
||||
Name: fake-plugin
|
||||
Version: 5.15.4
|
@@ -0,0 +1,2 @@
|
||||
[superqt.fonticon]
|
||||
ico = fake_plugin:ICO
|
@@ -0,0 +1 @@
|
||||
fake_plugin
|
6
tests/test_fonticon/fixtures/fake_plugin/__init__.py
Normal file
6
tests/test_fonticon/fixtures/fake_plugin/__init__.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
class ICO:
|
||||
__font_file__ = str(Path(__file__).parent / "icontest.ttf")
|
||||
smiley = "ico.\ue900"
|
@@ -11,7 +11,7 @@ TEST_PREFIX = "ico"
|
||||
TEST_CHARNAME = "smiley"
|
||||
TEST_CHAR = "\ue900"
|
||||
TEST_GLYPHKEY = f"{TEST_PREFIX}.{TEST_CHARNAME}"
|
||||
FONT_FILE = Path(__file__).parent / "icontest.ttf"
|
||||
FONT_FILE = Path(__file__).parent / "fixtures" / "fake_plugin" / "icontest.ttf"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
@@ -7,41 +7,15 @@ from qtpy.QtGui import QIcon, QPixmap
|
||||
from superqt.fonticon import _plugins, icon
|
||||
from superqt.fonticon._qfont_icon import QFontIconStore
|
||||
|
||||
try:
|
||||
from importlib.metadata import Distribution
|
||||
except ImportError:
|
||||
from importlib_metadata import Distribution # type: ignore
|
||||
|
||||
|
||||
class ICO:
|
||||
__font_file__ = str(Path(__file__).parent / "icontest.ttf")
|
||||
smiley = "ico.\ue900"
|
||||
FIXTURES = Path(__file__).parent / "fixtures"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def plugin_store(qapp, monkeypatch):
|
||||
class MockEntryPoint:
|
||||
name = "ico"
|
||||
group = _plugins.FontIconManager.ENTRY_POINT
|
||||
value = "fake_plugin.ICO"
|
||||
|
||||
def load(self):
|
||||
return ICO
|
||||
|
||||
class MockFinder:
|
||||
def find_distributions(self, *a):
|
||||
class D(Distribution):
|
||||
name = "mock"
|
||||
|
||||
@property
|
||||
def entry_points(self):
|
||||
return [MockEntryPoint()]
|
||||
|
||||
return [D()]
|
||||
|
||||
_path = [str(FIXTURES)] + sys.path.copy()
|
||||
store = QFontIconStore().instance()
|
||||
with monkeypatch.context() as m:
|
||||
m.setattr(sys, "meta_path", [MockFinder()])
|
||||
m.setattr(sys, "path", _path)
|
||||
yield store
|
||||
store.clear()
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
from superqt import QLabeledRangeSlider
|
||||
from superqt import QLabeledRangeSlider, QLabeledSlider
|
||||
|
||||
|
||||
def test_labeled_slider_api(qtbot):
|
||||
@@ -9,3 +9,10 @@ def test_labeled_slider_api(qtbot):
|
||||
slider.setBarVisible()
|
||||
slider.setBarMovesAllHandles()
|
||||
slider.setBarIsRigid()
|
||||
|
||||
|
||||
def test_slider_connect_works(qtbot):
|
||||
slider = QLabeledSlider()
|
||||
qtbot.addWidget(slider)
|
||||
|
||||
slider._label.editingFinished.emit()
|
||||
|
Reference in New Issue
Block a user