mirror of
https://github.com/pyapp-kit/superqt.git
synced 2025-12-15 18:50:05 +01:00
Lazy-import pyconify (#270)
* lazy-import pyconify * change import pattern --------- Co-authored-by: Talley Lambert <talley.lambert@gmail.com>
This commit is contained in:
@@ -11,7 +11,6 @@ except PackageNotFoundError:
|
||||
from .collapsible import QCollapsible
|
||||
from .combobox import QColorComboBox, QEnumComboBox, QSearchableComboBox
|
||||
from .elidable import QElidingLabel, QElidingLineEdit
|
||||
from .iconify import QIconifyIcon
|
||||
from .selection import QSearchableListWidget, QSearchableTreeWidget
|
||||
from .sliders import (
|
||||
QDoubleRangeSlider,
|
||||
@@ -58,16 +57,21 @@ __all__ = [
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .combobox import QColormapComboBox # noqa: TC004
|
||||
from .iconify import QIconifyIcon # noqa: TC004
|
||||
from .spinbox._quantity import QQuantity # noqa: TC004
|
||||
|
||||
|
||||
def __getattr__(name: str) -> Any:
|
||||
if name == "QQuantity":
|
||||
from .spinbox._quantity import QQuantity
|
||||
|
||||
return QQuantity
|
||||
if name == "QColormapComboBox":
|
||||
from .cmap import QColormapComboBox
|
||||
|
||||
return QColormapComboBox
|
||||
if name == "QIconifyIcon":
|
||||
from .iconify import QIconifyIcon
|
||||
|
||||
return QIconifyIcon
|
||||
if name == "QQuantity":
|
||||
from .spinbox._quantity import QQuantity
|
||||
|
||||
return QQuantity
|
||||
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
||||
|
||||
@@ -7,16 +7,22 @@ from qtpy.QtCore import QSize, Qt
|
||||
from qtpy.QtGui import QIcon, QPainter, QPixmap
|
||||
from qtpy.QtWidgets import QApplication
|
||||
|
||||
try:
|
||||
from pyconify import svg_path
|
||||
except ModuleNotFoundError: # pragma: no cover
|
||||
raise ModuleNotFoundError(
|
||||
"pyconify is required to use QIconifyIcon. "
|
||||
"Please install it with `pip install pyconify` or use the "
|
||||
"`pip install superqt[iconify]` extra."
|
||||
) from None
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from typing import Literal
|
||||
|
||||
Flip = Literal["horizontal", "vertical", "horizontal,vertical"]
|
||||
Rotation = Literal["90", "180", "270", 90, 180, 270, "-90", 1, 2, 3]
|
||||
|
||||
try:
|
||||
from pyconify import svg_path
|
||||
except ModuleNotFoundError: # pragma: no cover
|
||||
svg_path = None
|
||||
__all__ = ["QIconifyIcon"]
|
||||
|
||||
|
||||
class QIconifyIcon(QIcon):
|
||||
@@ -74,12 +80,6 @@ class QIconifyIcon(QIcon):
|
||||
rotate: Rotation | None = None,
|
||||
dir: str | None = None,
|
||||
):
|
||||
if svg_path is None: # pragma: no cover
|
||||
raise ModuleNotFoundError(
|
||||
"pyconify is required to use QIconifyIcon. "
|
||||
"Please install it with `pip install pyconify` or use the "
|
||||
"`pip install superqt[iconify]` extra."
|
||||
)
|
||||
super().__init__()
|
||||
if key:
|
||||
self.addKey(*key, color=color, flip=flip, rotate=rotate, dir=dir)
|
||||
|
||||
Reference in New Issue
Block a user