Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New slider fix #1

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions .github/workflows/test_and_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 8 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ repos:
- 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.4
hooks:
- id: flake8
additional_dependencies: [flake8-typing-imports==1.7.0]
exclude: examples
- repo: https://github.com/myint/autoflake
rev: v1.4
- repo: https://github.com/PyCQA/autoflake
rev: v1.6.1
hooks:
- id: autoflake
args: ["--in-place", "--remove-all-unused-imports"]
Expand All @@ -24,16 +25,16 @@ repos:
hooks:
- id: isort
- repo: https://github.com/asottile/pyupgrade
rev: v2.34.0
rev: v2.38.2
hooks:
- id: pyupgrade
args: [--py37-plus, --keep-runtime-typing]
- repo: https://github.com/psf/black
rev: 22.3.0
rev: 22.8.0
hooks:
- id: black
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.961
rev: v0.971
hooks:
- id: mypy
exclude: examples
Expand Down
48 changes: 37 additions & 11 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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:**

Expand All @@ -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)
Expand Down Expand Up @@ -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)*
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ 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 =
Expand Down
5 changes: 4 additions & 1 deletion src/superqt/combobox/_enum_combobox.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@

def _get_name(enum_value: Enum):
"""Create human readable name if user does not provide own implementation of __str__"""
if enum_value.__str__.__module__ != "enum":
if (
enum_value.__str__.__module__ != "enum"
and not enum_value.__str__.__module__.startswith("shibokensupport")
):
# check if function was overloaded
name = str(enum_value)
else:
Expand Down
4 changes: 3 additions & 1 deletion src/superqt/fonticon/_qfont_icon.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,9 @@ def paint(
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)
Expand Down
8 changes: 7 additions & 1 deletion src/superqt/sliders/_generic_range_slider.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,17 @@ def event(self, ev: QEvent) -> bool:
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):
Expand Down
10 changes: 5 additions & 5 deletions src/superqt/sliders/_generic_slider.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@


class _GenericSlider(QSlider, Generic[_T]):
_fvalueChanged = Signal(float)
_fsliderMoved = Signal(float)
_frangeChanged = Signal(float, float)
_fvalueChanged = Signal(int)
_fsliderMoved = Signal(int)
_frangeChanged = Signal(int, int)

MAX_DISPLAY = 5000

Expand Down Expand Up @@ -134,8 +134,8 @@ def setMaximum(self, max: float) -> None:
self.setRange(min(self._minimum, max), max)

def setRange(self, min: float, max_: float) -> None:
oldMin, self._minimum = self._minimum, float(min)
oldMax, self._maximum = self._maximum, float(max(min, max_))
oldMin, self._minimum = self._minimum, self._type_cast(min)
oldMax, self._maximum = self._maximum, self._type_cast(max(min, max_))

if oldMin != self._minimum or oldMax != self._maximum:
self.sliderChange(self.SliderChange.SliderRangeChange)
Expand Down
9 changes: 8 additions & 1 deletion src/superqt/sliders/_labeled.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def __init__(self, *args, **kwargs) -> None:
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()
Expand All @@ -142,6 +142,13 @@ def __init__(self, *args, **kwargs) -> None:

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
Expand Down
4 changes: 4 additions & 0 deletions src/superqt/sliders/_sliders.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ def _type_cast(self, value) -> int:


class _FloatMixin:
_fvalueChanged = Signal(float)
_fsliderMoved = Signal(float)
_frangeChanged = Signal(float, float)

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._singleStep = 0.01
Expand Down
14 changes: 11 additions & 3 deletions src/superqt/utils/_qthreading.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@
)

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]):
Expand All @@ -40,11 +38,21 @@ def disconnect(slot: Callable[[_T], Any] = ...) -> None:
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(
Expand Down
26 changes: 18 additions & 8 deletions src/superqt/utils/_throttler.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,22 @@
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):
Expand Down Expand Up @@ -179,8 +191,6 @@ def __init__(

# below here part is unique to superqt (not from KD)

P = ParamSpec("P")
R = TypeVar("R")

if TYPE_CHECKING:
from typing_extensions import Protocol
Expand All @@ -199,12 +209,12 @@ def set_timeout(self, timeout: int) -> None:

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]:
...


Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -347,7 +357,7 @@ def deco(func: Callable[P, R]) -> "ThrottledCallable[P, R]":
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:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_sliders/_testutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def _hover_event(_type, position, old_position, widget=None):
return QHoverEvent(_type, position, old_position)


def _linspace(start, stop, n):
def _linspace(start: int, stop: int, n: int):
h = (stop - start) / (n - 1)
for i in range(n):
yield start + h * i
Loading