Иконка в трее + статусбар
This commit is contained in:
parent
c82f32ed43
commit
f44cec8c15
@ -6,8 +6,8 @@ import json
|
|||||||
|
|
||||||
# from PyQt6.QtCore import QLine
|
# from PyQt6.QtCore import QLine
|
||||||
from PyQt6.QtWidgets import QApplication, QMainWindow, QPushButton, QLabel, QFrame, \
|
from PyQt6.QtWidgets import QApplication, QMainWindow, QPushButton, QLabel, QFrame, \
|
||||||
QVBoxLayout, QWidget, QButtonGroup, QStatusBar, QComboBox
|
QVBoxLayout, QWidget, QButtonGroup, QStatusBar, QComboBox, QMenu, QSystemTrayIcon
|
||||||
from PyQt6.QtGui import QPixmap, QIcon
|
from PyQt6.QtGui import QPixmap, QIcon, QAction
|
||||||
|
|
||||||
WAL_HOST = '10.0.1.11'
|
WAL_HOST = '10.0.1.11'
|
||||||
WAL_PORT = 9000
|
WAL_PORT = 9000
|
||||||
@ -191,7 +191,26 @@ class WaaaghLampGUI(QMainWindow):
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.setWindowTitle("WaaaghLamp GUI")
|
self.setWindowTitle("WaaaghLamp GUI")
|
||||||
# self.setFixedSize(200, 100)
|
self.setFixedSize(250, 450)
|
||||||
|
|
||||||
|
# Установка иконки в трей
|
||||||
|
self.tray_icon = QSystemTrayIcon(self)
|
||||||
|
self.tray_icon.setIcon(QIcon("res/waaagh_icon.png"))
|
||||||
|
self.tray_menu = QMenu()
|
||||||
|
self.tray_icon.activated.connect(self.showMaximized)
|
||||||
|
|
||||||
|
# Создание действий для меню трея
|
||||||
|
minimize_action = QAction("Свернуть", self)
|
||||||
|
minimize_action.triggered.connect(self.showMinimized)
|
||||||
|
self.tray_menu.addAction(minimize_action)
|
||||||
|
|
||||||
|
exit_action = QAction("Выход", self)
|
||||||
|
exit_action.triggered.connect(self.close)
|
||||||
|
self.tray_menu.addAction(exit_action)
|
||||||
|
|
||||||
|
# Привязка меню к иконке трея
|
||||||
|
self.tray_icon.setContextMenu(self.tray_menu)
|
||||||
|
self.tray_icon.show()
|
||||||
|
|
||||||
self.mode_button_group = QButtonGroup()
|
self.mode_button_group = QButtonGroup()
|
||||||
self.status_bar = QStatusBar()
|
self.status_bar = QStatusBar()
|
||||||
@ -226,7 +245,7 @@ class WaaaghLampGUI(QMainWindow):
|
|||||||
self.main_layout.addWidget(splitter3)
|
self.main_layout.addWidget(splitter3)
|
||||||
|
|
||||||
self.exit_button = QPushButton("Exit")
|
self.exit_button = QPushButton("Exit")
|
||||||
self.exit_button.clicked.connect(self.exit)
|
self.exit_button.clicked.connect(self.close)
|
||||||
self.main_layout.addWidget(self.exit_button)
|
self.main_layout.addWidget(self.exit_button)
|
||||||
|
|
||||||
container = QWidget()
|
container = QWidget()
|
||||||
@ -269,6 +288,10 @@ class WaaaghLampGUI(QMainWindow):
|
|||||||
self.send_message(self.mode_button_group.checkedId(), PALLETE[self.pallete_list.currentText()])
|
self.send_message(self.mode_button_group.checkedId(), PALLETE[self.pallete_list.currentText()])
|
||||||
|
|
||||||
def send_message(self, mode, color=0x000000):
|
def send_message(self, mode, color=0x000000):
|
||||||
|
def print_message(message):
|
||||||
|
print(message)
|
||||||
|
self.status_line.setText(message)
|
||||||
|
|
||||||
message = {
|
message = {
|
||||||
"mode": mode,
|
"mode": mode,
|
||||||
"color": color,
|
"color": color,
|
||||||
@ -280,13 +303,13 @@ class WaaaghLampGUI(QMainWindow):
|
|||||||
s.settimeout(5)
|
s.settimeout(5)
|
||||||
s.send(json.dumps(message).encode('utf-8'))
|
s.send(json.dumps(message).encode('utf-8'))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"ERROR: {e}")
|
print_message(f"ERROR: {e}")
|
||||||
|
|
||||||
data = ""
|
data = ""
|
||||||
try:
|
try:
|
||||||
data = s.recv(1024)
|
data = s.recv(1024)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"ERROR: {e}")
|
print_message(f"ERROR: {e}")
|
||||||
|
|
||||||
if data != "":
|
if data != "":
|
||||||
try:
|
try:
|
||||||
@ -294,21 +317,20 @@ class WaaaghLampGUI(QMainWindow):
|
|||||||
recieved_mode = self.state["mode"]
|
recieved_mode = self.state["mode"]
|
||||||
recieved_color = self.state["color"]
|
recieved_color = self.state["color"]
|
||||||
if recieved_mode == mode and recieved_color == color:
|
if recieved_mode == mode and recieved_color == color:
|
||||||
print(f"Mode {mode} with color {color} set successfully")
|
print_message(f"Mode {mode} with color {color}")
|
||||||
else:
|
else:
|
||||||
print(f"ERROR: Wrong answer from lamp")
|
print_message(f"ERROR: Wrong answer from lamp")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"ERROR: {e}")
|
print_message(f"ERROR: {e}")
|
||||||
|
|
||||||
s.close()
|
s.close()
|
||||||
|
|
||||||
def exit(self):
|
def close(self, event):
|
||||||
print("Bye!")
|
print("Bye!")
|
||||||
exit(0)
|
QApplication.quit()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app = QApplication(sys.argv)
|
app = QApplication(sys.argv)
|
||||||
window = WaaaghLampGUI()
|
mainWindow = WaaaghLampGUI()
|
||||||
window.show()
|
mainWindow.show()
|
||||||
app.exec()
|
sys.exit(app.exec())
|
||||||
|
Loading…
Reference in New Issue
Block a user