Compare commits

...

7 Commits

Author SHA1 Message Date
Grzegorz Bokota
0f55cd3382 Merge 5d87bc5a2f into 1bb1a58a73 2024-04-23 11:31:04 +10:00
Talley Lambert
1bb1a58a73 inherit secret 2024-04-22 14:08:53 -04:00
Talley Lambert
1288250597 add secret 2024-04-22 13:51:54 -04:00
pre-commit-ci[bot]
34a776e8d0 ci: [pre-commit.ci] autoupdate (#238)
updates:
- [github.com/astral-sh/ruff-pre-commit: v0.3.0 → v0.3.5](https://github.com/astral-sh/ruff-pre-commit/compare/v0.3.0...v0.3.5)
- [github.com/pre-commit/mirrors-mypy: v1.8.0 → v1.9.0](https://github.com/pre-commit/mirrors-mypy/compare/v1.8.0...v1.9.0)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-04-22 13:15:40 -04:00
Grzegorz Bokota
5d87bc5a2f Merge branch 'main' into sci_notation_labels 2024-03-27 11:44:09 +01:00
Talley Lambert
4671b08c42 Merge branch 'main' into sci_notation_labels 2024-03-06 15:43:09 -05:00
Grzegorz Bokota
6691b4bd84 initial implementation 2023-12-15 17:15:11 +01:00
3 changed files with 73 additions and 21 deletions

View File

@@ -23,6 +23,8 @@ jobs:
qt: ${{ matrix.backend }}
pip-install-pre-release: ${{ github.event_name == 'schedule' }}
report-failures: ${{ github.event_name == 'schedule' }}
secrets:
codecov-token: ${{ secrets.CODECOV_TOKEN }}
strategy:
fail-fast: false
matrix:
@@ -69,6 +71,7 @@ jobs:
test-qt-minreqs:
uses: pyapp-kit/workflows/.github/workflows/test-pyrepo.yml@v1
secrets: inherit
with:
python-version: "3.8"
qt: pyqt5

View File

@@ -5,7 +5,7 @@ ci:
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.0
rev: v0.3.5
hooks:
- id: ruff
args: [--fix, --unsafe-fixes]
@@ -17,7 +17,7 @@ repos:
- id: validate-pyproject
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.8.0
rev: v1.9.0
hooks:
- id: mypy
exclude: tests|examples

View File

@@ -6,15 +6,14 @@ from functools import partial
from typing import Any, overload
from qtpy.QtCore import QPoint, QSize, Qt, Signal
from qtpy.QtGui import QFontMetrics, QValidator
from qtpy.QtGui import QDoubleValidator, QFontMetrics, QValidator
from qtpy.QtWidgets import (
QAbstractSlider,
QApplication,
QBoxLayout,
QDoubleSpinBox,
QHBoxLayout,
QLineEdit,
QSlider,
QSpinBox,
QStyle,
QStyleOptionSpinBox,
QVBoxLayout,
@@ -600,7 +599,7 @@ class QLabeledDoubleRangeSlider(QLabeledRangeSlider):
lbl.setDecimals(prec)
class SliderLabel(QDoubleSpinBox):
class SliderLabel(QLineEdit):
def __init__(
self,
slider: QSlider,
@@ -610,36 +609,74 @@ class SliderLabel(QDoubleSpinBox):
) -> None:
super().__init__(parent=parent)
self._slider = slider
self._prefix = ""
self._suffix = ""
self._min = slider.minimum()
self._max = slider.maximum()
self._value = self._min
self._callback = connect
self.setFocusPolicy(Qt.FocusPolicy.ClickFocus)
self.setMode(EdgeLabelMode.LabelIsValue)
self.setDecimals(0)
self.setText(str(self._value))
validator = QDoubleValidator(self)
validator.setNotation(QDoubleValidator.Notation.ScientificNotation)
self.setValidator(validator)
self.setRange(slider.minimum(), slider.maximum())
slider.rangeChanged.connect(self._update_size)
self.setAlignment(alignment)
self.setButtonSymbols(QSpinBox.ButtonSymbols.NoButtons)
self.setStyleSheet("background:transparent; border: 0;")
if connect is not None:
self.editingFinished.connect(lambda: connect(self.value()))
self.editingFinished.connect(self._editig_finished)
self.editingFinished.connect(self._silent_clear_focus)
self._update_size()
def _editig_finished(self):
self._silent_clear_focus()
self.setValue(float(self.text()))
if self._callback:
self._callback(self.value())
def setRange(self, min_: float, max_: float) -> None:
if max_ < min_:
max_ = min_
self._min = min_
self._max = max_
def setDecimals(self, prec: int) -> None:
super().setDecimals(prec)
# super().setDecimals(prec)
self._update_size()
def value(self) -> float:
return self._value
def setValue(self, val: Any) -> None:
super().setValue(val)
if val < self._min:
val = self._min
elif val > self._max:
val = self._max
self._value = val
self.setText(str(val))
if self._mode == EdgeLabelMode.LabelIsRange:
self._update_size()
def setMaximum(self, max: float) -> None:
super().setMaximum(max)
def minimum(self):
return self._min
def setMaximum(self, max_: float) -> None:
if max_ < self._min:
max_ = self._min
self._max = max_
if self._mode == EdgeLabelMode.LabelIsValue:
self._update_size()
def setMinimum(self, min: float) -> None:
super().setMinimum(min)
def maximum(self):
return self._max
def setMinimum(self, min_: float) -> None:
if min_ > self._max:
min_ = self._max
self._min = min_
if self._mode == EdgeLabelMode.LabelIsValue:
self._update_size()
@@ -658,6 +695,20 @@ class SliderLabel(QDoubleSpinBox):
self._slider.rangeChanged.connect(self.setRange)
self._update_size()
def prefix(self) -> str:
return self._prefix
def setPrefix(self, prefix: str) -> None:
self._prefix = prefix
self._update_size()
def suffix(self) -> str:
return self._suffix
def setSuffix(self, suffix: str) -> None:
self._suffix = suffix
self._update_size()
# --------------- private ----------------
def _silent_clear_focus(self) -> None:
@@ -672,21 +723,19 @@ class SliderLabel(QDoubleSpinBox):
if self._mode & EdgeLabelMode.LabelIsValue:
# determine width based on min/max/specialValue
mintext = self.textFromValue(self.minimum())[:18]
maxtext = self.textFromValue(self.maximum())[:18]
mintext = str(self.minimum())[:18]
maxtext = str(self.maximum())[:18]
w = max(0, _fm_width(fm, mintext + fixed_content))
w = max(w, _fm_width(fm, maxtext + fixed_content))
if self.specialValueText():
w = max(w, _fm_width(fm, self.specialValueText()))
if self._mode & EdgeLabelMode.LabelIsRange:
w += 8 # it seems as thought suffix() is not enough
else:
w = max(0, _fm_width(fm, self.textFromValue(self.value()))) + 3
w = max(0, _fm_width(fm, str(self.value()))) + 3
w += 3 # cursor blinking space
# get the final size hint
opt = QStyleOptionSpinBox()
self.initStyleOption(opt)
# self.initStyleOption(opt)
size = self.style().sizeFromContents(
QStyle.ContentsType.CT_SpinBox, opt, QSize(w, h), self
)