forked from M-Labs/artiq
moninj: add _DoubleClickLineEdit
This commit is contained in:
parent
c4e775aa49
commit
15e1aef38b
|
@ -27,6 +27,42 @@ class _CancellableLineEdit(QtWidgets.QLineEdit):
|
||||||
QtWidgets.QLineEdit.keyPressEvent(self, event)
|
QtWidgets.QLineEdit.keyPressEvent(self, event)
|
||||||
|
|
||||||
|
|
||||||
|
# Cancellable and editable with double click.
|
||||||
|
# This class should not be used for programmatically changing text.
|
||||||
|
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)
|
||||||
|
|
||||||
|
|
||||||
class _TTLWidget(QtWidgets.QFrame):
|
class _TTLWidget(QtWidgets.QFrame):
|
||||||
override_toggled = QtCore.pyqtSignal(bool)
|
override_toggled = QtCore.pyqtSignal(bool)
|
||||||
level_toggled = QtCore.pyqtSignal(bool)
|
level_toggled = QtCore.pyqtSignal(bool)
|
||||||
|
@ -853,6 +889,7 @@ class _MonInjDock(QDockWidgetCloseDetect):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.manager = manager
|
self.manager = manager
|
||||||
grid = LayoutWidget()
|
grid = LayoutWidget()
|
||||||
|
self.setWidget(grid)
|
||||||
self._channel_dialog = _AddChannelDialog(self, self.manager.channel_model)
|
self._channel_dialog = _AddChannelDialog(self, self.manager.channel_model)
|
||||||
|
|
||||||
self._channel_dialog.accepted.connect(self.add_channels)
|
self._channel_dialog.accepted.connect(self.add_channels)
|
||||||
|
@ -863,13 +900,17 @@ class _MonInjDock(QDockWidgetCloseDetect):
|
||||||
QtWidgets.QStyle.SP_FileDialogListView))
|
QtWidgets.QStyle.SP_FileDialogListView))
|
||||||
add_channel_btn.clicked.connect(self._channel_dialog.open)
|
add_channel_btn.clicked.connect(self._channel_dialog.open)
|
||||||
grid.addWidget(add_channel_btn, 0, 0)
|
grid.addWidget(add_channel_btn, 0, 0)
|
||||||
|
|
||||||
newdock = QtWidgets.QToolButton()
|
newdock = QtWidgets.QToolButton()
|
||||||
newdock.setToolTip("Create new moninj dock")
|
newdock.setToolTip("Create new moninj dock")
|
||||||
newdock.setIcon(QtWidgets.QApplication.style().standardIcon(
|
newdock.setIcon(QtWidgets.QApplication.style().standardIcon(
|
||||||
QtWidgets.QStyle.SP_FileDialogNewFolder))
|
QtWidgets.QStyle.SP_FileDialogNewFolder))
|
||||||
newdock.clicked.connect(lambda: manager.create_new_dock())
|
newdock.clicked.connect(lambda: manager.create_new_dock())
|
||||||
grid.addWidget(newdock, 0, 1)
|
grid.addWidget(newdock, 0, 1)
|
||||||
self.setWidget(grid)
|
|
||||||
|
display_name_edit = _DoubleClickLineEdit(name)
|
||||||
|
grid.addWidget(display_name_edit, 0, 1)
|
||||||
|
|
||||||
scroll_area = QtWidgets.QScrollArea()
|
scroll_area = QtWidgets.QScrollArea()
|
||||||
grid.addWidget(scroll_area, 1, 0, 1, 10)
|
grid.addWidget(scroll_area, 1, 0, 1, 10)
|
||||||
self.flow = FlowLayout()
|
self.flow = FlowLayout()
|
||||||
|
|
Loading…
Reference in New Issue