-
Notifications
You must be signed in to change notification settings - Fork 0
/
program.py
187 lines (162 loc) · 6.98 KB
/
program.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
import sqlite3
import sys
from add_akk_form import AddAkkForm
from akk_info_form import AkkInfoForm
from auth_akk_form import AuthAkkForm
from PyQt6.QtWidgets import QApplication
from reauth_akk_form import ReauthAkkForm
from status_colors import STATUS_COLORS
from akk_status_funcs import check_akk_and_update
from sql_functions import get_akks, setup_db
from ui.main_window import MainWindow
class Program:
def __init__(self):
self.ui = MainWindow()
self.connection = sqlite3.connect("db.sqlite")
setup_db(self.connection)
self.add_akk_form = AddAkkForm(self.connection)
self.add_akk_form.installEventFilter(self)
self.akk_info_form = AkkInfoForm(self.connection)
self.akk_info_form.installEventFilter(self)
self.auth_akk_form = AuthAkkForm(self.connection)
self.auth_akk_form.installEventFilter(self)
self.reauth_akk_form = ReauthAkkForm(self.connection)
self.reauth_akk_form.installEventFilter(self)
self.add_akk_btn.clicked.connect(self.add_akk_form.show)
self.list_of_akks_widget.installEventFilter(self)
self.list_of_akks_widget.itemDoubleClicked.connect(self.show_akk_info_form)
self.update_akks()
# Запуск проверщика сети
def eventFilter(self, source, event):
if (
event.type() == QEvent.ContextMenu
and source is self.list_of_akks_widget
and type(source.itemAt(event.pos())) is QListWidgetItem
and self.isEnabled()
):
self.reload_akks()
menu = QMenu()
del_akk_action = QAction("Удалить")
reauth_akk_action = QAction("Переавторизовать")
auth_akk_action = QAction("Авторизовать")
list_of_actions = []
akk = source.itemAt(event.pos())
if akk.background().color() == STATUS_COLORS["banned"]:
# TODO: сделать удаление любого нерабочего акка, и сохраниение их в списке удаленных
list_of_actions.append(del_akk_action)
elif akk.background().color() == STATUS_COLORS["notauth"]:
list_of_actions.append(reauth_akk_action)
elif akk.background().color() == STATUS_COLORS["nofile"]:
list_of_actions.append(auth_akk_action)
menu.addActions(list_of_actions)
if action := menu.exec_(event.globalPos()):
if action == del_akk_action:
self.del_akk(akk)
elif action == reauth_akk_action:
self.reauth_akk(akk)
elif action == auth_akk_action:
self.auth_akk(akk)
return True
elif (
event.type() == QEvent.ContextMenu
and source is self.list_of_akks_widget
and self.isEnabled()
):
menu = QMenu()
update_akks_action = QAction("Обновить все")
menu.addAction(update_akks_action)
if action := menu.exec_(event.globalPos()):
if action == update_akks_action:
self.update_akks()
return True
elif event.type() == QEvent.Show and (
source is self.add_akk_form
or source is self.akk_info_form
or source is self.auth_akk_form
or source is self.reauth_akk_form
):
self.setEnabled(False)
return True
elif event.type() == QEvent.Close and (
source is self.add_akk_form
or source is self.akk_info_form
or source is self.auth_akk_form
or source is self.reauth_akk_form
):
self.setEnabled(True)
if source is not self.akk_info_form:
source.clean_form()
self.reload_akks()
return True
return super().eventFilter(source, event)
def update_akks(self):
self.reload_akks()
self.statusBar.clearMessage()
akks = get_akks(self.connection)
for phone, db_status in akks:
try:
check_akk_and_update(phone, db_status, self.connection)
except ConnectionError:
# TODO: разобраться когда по дефолту нет инета
# TODO: разобраться когда заного конект
# например когда нет подключения включается механизм проверки
# соединения который работает постоянно
self.statusBar().showMessage("Нет подключения к интернету!")
self.reload_akks()
def reload_akks(self):
self.list_of_akks_widget.clear()
akks = get_akks(self.connection)
there_is_banned = False
for phone, status_name in akks:
akk = QListWidgetItem(str(phone))
akk.setBackground(STATUS_COLORS[status_name])
self.list_of_akks_widget.addItem(akk)
if status_name == "banned":
there_is_banned = True
self.del_nwork_akks_btn.setEnabled(there_is_banned)
def show_akk_info_form(self, akk: QListWidgetItem):
self.akk_info_form.set_akk(akk)
def change_akk_status(self):
pass
def del_akk(self, akk: QListWidgetItem):
if check_akk_and_update(akk.text(), "banned", self.connection) == "banned":
if (
QMessageBox.question(
self,
"Удалить аккаунт",
"Вы действительно хоттите удалить акккаунт?",
)
== QMessageBox.Yes
):
# TODO: удаление аккаунта как в других формах
pass
self.reload_akks()
def reauth_akk(self, akk: QListWidgetItem):
self.statusBar.clearMessage()
try:
self.reauth_akk_form.set_akk(akk)
except ConnectionError:
self.statusBar.showMessage("Нет подключения к интернету!")
self.reload_akks()
def auth_akk(self, akk: QListWidgetItem):
self.statusBar.clearMessage()
try:
self.auth_akk_form.set_akk(akk)
except ConnectionError:
self.statusBar.showMessage("Нет подключения к интернету!")
self.reload_akks()
def load_tasks(self):
pass
def closeEvent(self, event):
self.add_akk_form.close()
self.akk_info_form.close()
self.auth_akk_form.close()
self.reauth_akk_form.close()
self.connection.close()
def except_hook(cls, exception, traceback):
sys.__excepthook__(cls, exception, traceback)
if __name__ == "__main__":
app = QApplication(sys.argv)
program = MainWindow()
sys.excepthook = except_hook
sys.exit(app.exec())