forked from M-Labs/artiq
1
0
Fork 0

gui.tools: add DoubleClickLineEdit

This commit is contained in:
Simon Renblad 2024-05-02 15:22:38 +08:00 committed by Sébastien Bourdeauducq
parent 154f186f18
commit d3d50d790a
1 changed files with 34 additions and 0 deletions

View File

@ -4,6 +4,40 @@ import logging
from PyQt5 import QtCore, QtWidgets
class DoubleClickLineEdit(QtWidgets.QLineEdit):
finished = QtCore.pyqtSignal()
def __init__(self, init):
QtWidgets.QLineEdit.__init__(self, init)
self.setFrame(False)
self.setReadOnly(True)
self.returnPressed.connect(self._return_pressed)
self.editingFinished.connect(self._editing_finished)
self._text = init
def mouseDoubleClickEvent(self, event):
if self.isReadOnly():
self.setReadOnly(False)
self.setFrame(True)
QtWidgets.QLineEdit.mouseDoubleClickEvent(self, event)
def _return_pressed(self):
self._text = self.text()
def _editing_finished(self):
self.setReadOnly(True)
self.setFrame(False)
self.setText(self._text)
self.finished.emit()
def keyPressEvent(self, event):
key = event.key()
if key == QtCore.Qt.Key_Escape and not self.isReadOnly():
self.editingFinished.emit()
else:
QtWidgets.QLineEdit.keyPressEvent(self, event)
def log_level_to_name(level):
if level >= logging.CRITICAL:
return "CRITICAL"