added indicator dot for alarm state
This commit is contained in:
@ -1,6 +1,9 @@
|
|||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from PyQt5.QtCore import Qt
|
from PyQt5.QtCore import Qt
|
||||||
from PyQt5.QtWidgets import QListWidget, QListWidgetItem
|
from PyQt5.QtWidgets import QListWidget, QListWidgetItem
|
||||||
|
from PyQt5.QtGui import QIcon, QPixmap, QPainter
|
||||||
|
|
||||||
|
from .theme import VIOLET, GREY4
|
||||||
|
|
||||||
|
|
||||||
class DictList(QListWidget):
|
class DictList(QListWidget):
|
||||||
@ -25,6 +28,7 @@ class DictList(QListWidget):
|
|||||||
def prepend_item_if_missing(self, key):
|
def prepend_item_if_missing(self, key):
|
||||||
if key not in self.data:
|
if key not in self.data:
|
||||||
itm = QListWidgetItem(key)
|
itm = QListWidgetItem(key)
|
||||||
|
set_alarm(itm, False)
|
||||||
self.prependItem(itm)
|
self.prependItem(itm)
|
||||||
|
|
||||||
def prependItem(self, itm):
|
def prependItem(self, itm):
|
||||||
@ -49,19 +53,42 @@ class DictList(QListWidget):
|
|||||||
|
|
||||||
def set_alarm_by_key(self, key, state):
|
def set_alarm_by_key(self, key, state):
|
||||||
itm = self.findItems(key, Qt.MatchExactly)[0]
|
itm = self.findItems(key, Qt.MatchExactly)[0]
|
||||||
set_bold(itm, state)
|
set_alarm(itm, state)
|
||||||
|
|
||||||
def set_alarm_by_index(self, index, state):
|
def set_alarm_by_index(self, index, state):
|
||||||
row = index.row()
|
row = index.row()
|
||||||
itm = self.item(row)
|
itm = self.item(row)
|
||||||
set_bold(itm, state)
|
set_alarm(itm, state)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def set_alarm(*args, **kwargs):
|
||||||
|
set_bold(*args, **kwargs)
|
||||||
|
set_dot(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
def set_bold(itm, state):
|
def set_bold(itm, state):
|
||||||
fnt = itm.font()
|
fnt = itm.font()
|
||||||
fnt.setBold(state)
|
fnt.setBold(state)
|
||||||
itm.setFont(fnt)
|
itm.setFont(fnt)
|
||||||
|
|
||||||
|
|
||||||
|
def set_dot(itm, state):
|
||||||
|
pixmap = QPixmap(8, 8)
|
||||||
|
pixmap.fill(Qt.transparent)
|
||||||
|
|
||||||
|
if state:
|
||||||
|
painter = QPainter()
|
||||||
|
painter.begin(pixmap)
|
||||||
|
painter.setRenderHint(QPainter.Antialiasing)
|
||||||
|
painter.setPen(GREY4)
|
||||||
|
painter.setBrush(VIOLET)
|
||||||
|
rect = pixmap.rect()
|
||||||
|
painter.drawEllipse(rect)
|
||||||
|
painter.end()
|
||||||
|
|
||||||
|
icon = QIcon(pixmap)
|
||||||
|
itm.setIcon(icon)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user