forked from M-Labs/artiq
gui.tools: add DoubleClickLineEdit
This commit is contained in:
parent
154f186f18
commit
d3d50d790a
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user