-
Notifications
You must be signed in to change notification settings - Fork 1
/
manager.py
137 lines (112 loc) · 4.01 KB
/
manager.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import sys
import threading
from PyQt5 import QtWidgets
from PyQt5 import uic
from PyQt5.QtCore import QFile, QTextStream
from PyQt5.QtWidgets import QWidget, QApplication, QMenu, QAction, qApp, QSystemTrayIcon, QStyle
import production_run
from data import db_session
from data.users import User
from qt.qt_func import resource_path
def server():
print("Starting up the server")
# try:
# import production_run
# except Exception as e:
# return 'cant find the production release file'
try:
production_run.run()
except Exception as e:
return 'server crashed. stack:' + str(e)
print("server shut down")
# def close_server():
# print('here')
# production_run.run.stop()
def select_dir():
var = None
class App(QWidget):
def __init__(self):
super().__init__()
if __name__ == '__main__':
uic.loadUi(resource_path('qt/main_qt.ui'), self)
else:
uic.loadUi(resource_path('qt/main_qt.ui'), self)
self.move(180, 100)
self.setFixedSize(480, 480)
self.setWindowTitle('control')
self.server = threading.Thread(target=server)
self.toclose = False
self.all_buttons = []
self.start_button.action = 'start'
self.close_server.action = 'close'
# self.close_server.setEnabled(0)
self.all_buttons.append(self.start_button)
self.all_buttons.append(self.close_server)
for i in self.all_buttons:
i.clicked.connect(self.onClick)
show_action = QAction("Show", self)
quit_action = QAction("Exit", self)
show_action.triggered.connect(self.show)
quit_action.triggered.connect(qApp.quit)
tray_menu = QMenu()
tray_menu.addAction(show_action)
tray_menu.addAction(quit_action)
self.tray_icon = QSystemTrayIcon(self)
self.tray_icon.setIcon(self.style().standardIcon(QStyle.SP_ComputerIcon))
self.tray_icon.setContextMenu(tray_menu)
self.tray_icon.show()
# ----------------- List_user -----------------
db_session.global_init("db/catclient.sqlite")
session = db_session.create_session()
# users = session.query(User).all()
#del users[0]
# list_name_user = [i.name for i in users]
list_name_user = ['', 'user 1', 'user 2']
self.list_user.addItems(list_name_user)
self.bselect_user.clicked.connect(self.select_user)
# ----------------- List_dirs -----------------
self.bselect_dir.clicked.connect(select_dir)
def select_user(self):
user = self.list_user.currentText()
session = db_session.create_session()
users = session.query(User).filter(User.name == user).first()
if users:
print(users.dirs)
if users.dirs is None:
self.list_dirs.clear()
self.list_dirs.addItems(['Not found'])
else:
self.list_dirs.clear()
dirs = users.dirs.split(',')
self.list_dirs.addItems(dirs)
def onClick(self):
btn = self.sender().action
print(btn, 'action released!')
if btn == 'start':
if not self.server.is_alive():
self.server.start()
self.start_button.setEnabled(0)
self.start_button.setText('Server running')
# self.close_server.setEnabled(1)
if btn == 'close':
# self.closeEvent()
# - func not work -
if self.server.is_alive():
self.closeEvent('None')
else:
exit(0)
def closeEvent(self, evnt):
if self.toclose:
super(App, self).closeEvent(evnt)
else:
evnt.ignore()
self.hide()
app_style = QtWidgets.QApplication(sys.argv)
file = QFile(":/dark.qss")
file.open(QFile.ReadOnly | QFile.Text)
stream = QTextStream(file)
app_style.setStyleSheet(stream.readAll())
app = QApplication(sys.argv)
form = App()
form.show()
sys.exit(app.exec())