-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove MainWindow and Parameters widgets, and split remaining code in…
… aperoll.widgets.parameters into a new module aperoll.widgets.line_edit and aperoll.utils
- Loading branch information
Showing
6 changed files
with
197 additions
and
904 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from PyQt5 import QtCore as QtC | ||
from PyQt5 import QtWidgets as QtW | ||
|
||
|
||
class LineEdit(QtW.QLineEdit): | ||
""" | ||
A QLineEdit with a signal emitted when pressing Enter, loosing focus or calling setText. | ||
The signal is emitted only if the text changed. | ||
""" | ||
|
||
value_changed = QtC.pyqtSignal(str) | ||
|
||
def __init__(self, parent): | ||
super().__init__(parent) | ||
self._prev_text = self.text() | ||
|
||
def setText(self, text, emit=False): | ||
super().setText(text) | ||
# in the following, emit=False so the signal is not emitted | ||
self._check_value(emit=emit) | ||
|
||
def keyPressEvent(self, event): | ||
super().keyPressEvent(event) | ||
if event.key() == QtC.Qt.Key_Return: | ||
self._check_value() | ||
|
||
def focusOutEvent(self, event): | ||
super().focusOutEvent(event) | ||
self._check_value() | ||
|
||
def _check_value(self, emit=True): | ||
if self.text() != self._prev_text: | ||
self._prev_text = self.text() | ||
if emit: | ||
self.value_changed.emit(self.text()) |
Oops, something went wrong.