Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
41 lines (32 loc) · 1.34 KB

File metadata and controls

41 lines (32 loc) · 1.34 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from __future__ import annotations
from typing import Optional
from typing import Tuple
from PySide6 import QtGui
from PySide6 import QtWidgets
from PySide6.QtCore import Qt
class FloatLineEdit(QtWidgets.QLineEdit): # type: ignore
def __init__(self, parent: Optional[QtWidgets.QWidget] = None) -> None:
super().__init__(parent)
self.setValidator(FloatValidator())
def keyPressEvent(self, event: QtGui.QKeyEvent) -> None:
if event.key() == Qt.Key_Space:
event.ignore()
else:
super().keyPressEvent(event)
def value(self) -> float:
try:
return float(self.text())
except ValueError:
return 0.0
class FloatValidator(QtGui.QDoubleValidator): # type: ignore
def __init__(self, parent: Optional[QtGui.QObject] = None) -> None:
super().__init__(parent)
def validate(self, input_str: str, pos: int) -> Tuple[QtGui.QValidator.State, str, int]:
state, num, pos = super().validate(input_str, pos)
if state == QtGui.QValidator.Acceptable:
return QtGui.QValidator.Acceptable, num, pos
if str(num).count(".") > 1:
return QtGui.QValidator.Invalid, num, pos
if input_str[pos - 1] == ".":
return QtGui.QValidator.Acceptable, num, pos
return QtGui.QValidator.Invalid, num, pos
Morty Proxy This is a proxified and sanitized view of the page, visit original site.