2
0
mirror of https://github.com/m-labs/artiq.git synced 2024-12-20 17:06:30 +08:00
artiq/artiq/gui/tools.py

48 lines
1.2 KiB
Python

import logging
from PyQt5 import QtCore, QtWidgets, QtGui
def log_level_to_name(level):
if level >= logging.CRITICAL:
return "CRITICAL"
if level >= logging.ERROR:
return "ERROR"
if level >= logging.WARNING:
return "WARNING"
if level >= logging.INFO:
return "INFO"
return "DEBUG"
class _WheelFilter(QtCore.QObject):
def eventFilter(self, obj, event):
if event.type() == QtCore.QEvent.Wheel:
event.ignore()
return True
else:
return False
def disable_scroll_wheel(widget):
widget.setFocusPolicy(QtCore.Qt.StrongFocus)
widget.installEventFilter(_WheelFilter(widget))
class QDockWidgetCloseDetect(QtWidgets.QDockWidget):
sigClosed = QtCore.pyqtSignal()
def closeEvent(self, event):
self.sigClosed.emit()
QtWidgets.QDockWidget.closeEvent(self, event)
class LayoutWidget(QtWidgets.QWidget):
def __init__(self, parent=None):
QtWidgets.QWidget.__init__(self, parent)
self.layout = QtWidgets.QGridLayout()
self.setLayout(self.layout)
def addWidget(self, item, row=0, col=0, rowspan=1, colspan=1):
self.layout.addWidget(item, row, col, rowspan, colspan)