-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopup_temp.py
More file actions
88 lines (71 loc) · 2.91 KB
/
Copy pathpopup_temp.py
File metadata and controls
88 lines (71 loc) · 2.91 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QLabel, QPushButton, QApplication, QDesktopWidget
from PyQt5.QtCore import Qt
from functools import partial
import sys
import os
def get_style_path():
if getattr(sys, 'frozen', False):
base_path = os.path.dirname(sys.executable)
else:
base_path = os.path.dirname(os.path.abspath(__file__))
return os.path.join(base_path, "styles.qss")
def load_stylesheet():
with open(get_style_path(), "r") as file:
return file.read()
def show_temp_palette_popup(parent, eid, itype, name, entity_states, send_selected_temp, entity_info_types):
dim_widget = QWidget(parent)
dim_widget.setStyleSheet("background-color: rgba(0, 0, 0, 190);")
dim_widget.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint)
dim_widget.setAttribute(Qt.WA_TransparentForMouseEvents, True)
dim_widget.setGeometry(QApplication.desktop().geometry())
dim_widget.show()
popup = QWidget(parent)
vbox_layout = QVBoxLayout(popup)
stylesheet = load_stylesheet()
popup.setStyleSheet(stylesheet)
popup.setObjectName("popup")
popup.setWindowFlag(Qt.FramelessWindowHint)
popup.setWindowFlag(Qt.WindowStaysOnTopHint)
lala = entity_states.get(eid, {}).get("attributes", {})
hs_color = lala.get("hs_color")
current_value = hs_color[0] if isinstance(hs_color, (tuple, list)) else 200
entity_info_types[(eid, "temp")] = itype
label_ = QLabel(f"{name}: Temperature")
label_.setObjectName("names_popups")
label_.setAlignment(Qt.AlignCenter)
vbox_layout.addWidget(label_, Qt.AlignCenter)
color_list = ['#ffffff', '#ffebd9', '#ffdbb9', '#ffcc9c', '#ffac5e', '#ff9c3f', '#ff8c21', '#ff7b00']
hbox_palette = QHBoxLayout()
for color in color_list:
btn = QPushButton()
btn.setStyleSheet(f"""
QPushButton {{
background-color: {color};
border: none;
border-radius: 2px;
}}
QPushButton:pressed {{
background-color: rgb(17, 17, 17);
border: 1px solid #ffffff;
border-radius: 2px;
}}
""")
btn.setFixedSize(50, 50)
btn.clicked.connect(partial(send_selected_temp, eid, color))
hbox_palette.addWidget(btn)
vbox_layout.addLayout(hbox_palette)
spacer = QWidget()
spacer.setObjectName("spacer")
vbox_layout.addWidget(spacer)
btn_close = QPushButton("Close")
btn_close.setObjectName("close_button")
btn_close.clicked.connect(lambda: (popup.close(), dim_widget.close()))
vbox_layout.addWidget(btn_close)
popup.setLayout(vbox_layout)
popup.resize(600, 200)
screen_geometry = QDesktopWidget().availableGeometry()
x = (screen_geometry.width() - popup.width()) // 2
y = (screen_geometry.height() - popup.height()) // 2
popup.move(x, y)
popup.show()
return popup, dim_widget