This repository has been archived by the owner on Jun 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
ui_info_panel_label.py
72 lines (61 loc) · 2.5 KB
/
ui_info_panel_label.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from PyQt5 import QtCore, QtGui, QtWidgets, Qt
from config import *
font = QtGui.QFont("Georgia", 8)
brush = Qt.QBrush(Qt.QColor(0xff, 0xff, 0xff))
class PanelLabel(QtWidgets.QWidget):
"""docstring for PanelLabel"""
def __init__(self, parent, name):
super(PanelLabel, self).__init__(parent)
self.parent = parent
# self.set_position(x, y)
# Creates the scne
self.scene = QtWidgets.QGraphicsScene()
# Adds view into the scene
self.view = QtWidgets.QGraphicsView(self.scene, self)
self.view.setStyleSheet("border: 0px;") # Borderless background
self.view.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) # Without scroll bars
self.view.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.view.setGeometry(0, 0, self.width(), self.height()) # Sets the geometry
# For not shadowing it two times
self.b_shadowed = False
self.blink = False
self.opacity = 255
self.max_opacity = 256
self.effect = QtWidgets.QGraphicsOpacityEffect(self);
self.effect.setOpacity(self.opacity / self.max_opacity)
self.setGraphicsEffect(self.effect)
# Shows it
self.show()
self.icon = name
self.text = ""
def set_position(self, x):
self.setGeometry(x, 0, self.width(), self.height())
def show_text(self, string):
if string is None or string == "":
return
# Creats Text item
text = QtWidgets.QGraphicsSimpleTextItem(string)
text.setFont(font)
text.setBrush(brush)
# Sets the position
boundingRectangle = text.sceneBoundingRect()
x, y = (self.width() - boundingRectangle.width() - 3), (
self.height() - boundingRectangle.height() - 2) // 2 # 21 21 the center
text.setPos(x, y);
self.scene.addItem(text)
def show_icon(self, icon_filename):
filename = PATH_PANEL_ICONS + icon_filename
# Creates the label with icon
pixmap = QtGui.QPixmap(ospath + filename)
# Refresh width and height
self.setGeometry(self.x(), self.y(), pixmap.width(), pixmap.height())
self.view.setGeometry(0, 0, self.width(), self.height())
# Adds the label with icon into scene
self.scene.addPixmap(pixmap).setPos(0, 0)
def redraw(self):
self.scene.clear()
self.show_icon(self.icon)
self.show_text(self.text)
# print(self.text)
if __name__ == '__main__':
pass