Иконка в трее + статусбар
This commit is contained in:
parent
c82f32ed43
commit
f44cec8c15
@ -6,8 +6,8 @@ import json
|
||||
|
||||
# from PyQt6.QtCore import QLine
|
||||
from PyQt6.QtWidgets import QApplication, QMainWindow, QPushButton, QLabel, QFrame, \
|
||||
QVBoxLayout, QWidget, QButtonGroup, QStatusBar, QComboBox
|
||||
from PyQt6.QtGui import QPixmap, QIcon
|
||||
QVBoxLayout, QWidget, QButtonGroup, QStatusBar, QComboBox, QMenu, QSystemTrayIcon
|
||||
from PyQt6.QtGui import QPixmap, QIcon, QAction
|
||||
|
||||
WAL_HOST = '10.0.1.11'
|
||||
WAL_PORT = 9000
|
||||
@ -191,7 +191,26 @@ class WaaaghLampGUI(QMainWindow):
|
||||
}
|
||||
|
||||
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.status_bar = QStatusBar()
|
||||
@ -226,7 +245,7 @@ class WaaaghLampGUI(QMainWindow):
|
||||
self.main_layout.addWidget(splitter3)
|
||||
|
||||
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)
|
||||
|
||||
container = QWidget()
|
||||
@ -269,6 +288,10 @@ class WaaaghLampGUI(QMainWindow):
|
||||
self.send_message(self.mode_button_group.checkedId(), PALLETE[self.pallete_list.currentText()])
|
||||
|
||||
def send_message(self, mode, color=0x000000):
|
||||
def print_message(message):
|
||||
print(message)
|
||||
self.status_line.setText(message)
|
||||
|
||||
message = {
|
||||
"mode": mode,
|
||||
"color": color,
|
||||
@ -280,13 +303,13 @@ class WaaaghLampGUI(QMainWindow):
|
||||
s.settimeout(5)
|
||||
s.send(json.dumps(message).encode('utf-8'))
|
||||
except Exception as e:
|
||||
print(f"ERROR: {e}")
|
||||
print_message(f"ERROR: {e}")
|
||||
|
||||
data = ""
|
||||
try:
|
||||
data = s.recv(1024)
|
||||
except Exception as e:
|
||||
print(f"ERROR: {e}")
|
||||
print_message(f"ERROR: {e}")
|
||||
|
||||
if data != "":
|
||||
try:
|
||||
@ -294,21 +317,20 @@ class WaaaghLampGUI(QMainWindow):
|
||||
recieved_mode = self.state["mode"]
|
||||
recieved_color = self.state["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:
|
||||
print(f"ERROR: Wrong answer from lamp")
|
||||
print_message(f"ERROR: Wrong answer from lamp")
|
||||
except Exception as e:
|
||||
print(f"ERROR: {e}")
|
||||
print_message(f"ERROR: {e}")
|
||||
|
||||
s.close()
|
||||
|
||||
def exit(self):
|
||||
def close(self, event):
|
||||
print("Bye!")
|
||||
exit(0)
|
||||
|
||||
QApplication.quit()
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = QApplication(sys.argv)
|
||||
window = WaaaghLampGUI()
|
||||
window.show()
|
||||
app.exec()
|
||||
mainWindow = WaaaghLampGUI()
|
||||
mainWindow.show()
|
||||
sys.exit(app.exec())
|
||||
|
Loading…
Reference in New Issue
Block a user