-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMain.py
196 lines (151 loc) · 5.36 KB
/
Main.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
188
189
190
191
192
193
194
195
196
#! /usr/bin/env python
# -*- coding: utf-8 -*-
from log import Log, Console
from PyQt5.QtGui import QPixmap, QIcon
from PyQt5.QtWidgets import (QMainWindow, QLabel, QApplication, QFileDialog)
from PyQt5 import uic
import shutil
import sys
import os
from script import Verification
# Main menu
class MainMenu(QMainWindow):
def __init__(self):
super().__init__()
self.setFixedSize(700, 370)
self.setWindowTitle('WhoIs')
self.init_UI()
def init_UI(self):
# LOAD IMAGE
set_background(self)
# Загрузка GUI
uic.loadUi('GUI/MainMenu.ui', self)
self.pushExit.clicked.connect(self.close)
self.pushStart.clicked.connect(lambda: show_window(self, startWin))
self.pushAddPerson.clicked.connect(lambda: show_window(self, addPersonWin))
self.pushAbout.clicked.connect(lambda: show_window(self, aboutWin))
self.show()
class Analyze(QMainWindow):
def __init__(self):
super().__init__()
self.setFixedSize(700, 370)
self.setWindowTitle('WhoIs')
self.init_UI()
def init_UI(self):
try:
# LOAD IMAGE
self.setWindowIcon(QIcon(QPixmap('GUI/images_for_GUI/icon.jpg')))
# Загрузка GUI
uic.loadUi('GUI/Analyze.ui', self)
self.textError.hide()
self.textSuccess.hide()
self.pushBack.clicked.connect(lambda: show_window(self, mainWin))
self.pushOK.clicked.connect(self.search)
self.show()
except Exception as error:
print(str(error))
Log.error(None, str(error))
self.textError.show()
def search(self):
try:
self.textError.hide()
self.textSuccess.hide()
print('start finding')
Console.write(None, 'start finding')
v = Verification(self.textEdit.toPlainText(), self.textName.toPlainText().split(';'))
self.need = v.search()
self.pushLink.setText('http://127.0.0.1:8080/')
for i in range(len(self.need)):
self.need[i] = self.need[i].replace('\\', '/')
Log.successfulAnalyse(None)
self.textSuccess.show()
self.pushLink.clicked.connect(self.openBrowser)
except Exception as error:
print(str(error))
Log.error(None, str(error))
self.textError.show()
def openBrowser(self):
try:
self.directory = os.getcwd()
print(self.need)
Console.write(None, self.need)
os.startfile('console.py')
except Exception as error:
print(str(error))
Log.error(None, str(error))
self.textError.show()
# Класс для добавление лиц
class AddPerson(QMainWindow):
def __init__(self):
super().__init__()
self.setFixedSize(700, 370)
self.setWindowTitle('WhoIs')
self.init_UI()
def init_UI(self):
self.directory = os.getcwd()
self.filename = None
# Загрузка GUI
uic.loadUi('GUI/AddPerson.ui', self)
# LOAD IMAGE
self.setWindowIcon(QIcon(QPixmap('GUI/images_for_GUI/icon.jpg')))
self.textError.hide()
self.textSuccess.hide()
self.pushBack.clicked.connect(lambda: show_window(self, mainWin))
self.pushView.clicked.connect(self.choosePhotos)
self.pushAdd.clicked.connect(self.addPerson)
self.show()
def choosePhotos(self):
try:
self.filename = QFileDialog.getOpenFileName(self, 'Open file', '/home')
text = self.filename[0]
self.textFiles.setText(text)
self.textError.hide()
except Exception as error:
print(str(error))
Log.error(None, str(error))
self.textError.show()
def addPerson(self):
try:
shutil.copy2(self.filename[0],
self.directory + '/faces/' + self.textName.toPlainText() + '.' +
self.filename[0].split('.')[-1])
Log.addPerson(None, self.textName.toPlainText())
except Exception as error:
print(str(error))
Log.error(None, str(error))
self.textError.show()
else:
self.textSuccess.show()
class About(QMainWindow):
def __init__(self):
super().__init__()
self.setFixedSize(700, 370)
self.setWindowTitle('WhoIs')
self.setWindowIcon(QIcon(QPixmap('GUI/images_for_GUI/icon.jpg')))
self.init_UI()
def init_UI(self):
# Загрузка GUI
uic.loadUi('GUI/About.ui', self)
self.pushBack.clicked.connect(lambda: show_window(self, mainWin))
self.show()
# LOAD IMAGE
def set_background(self):
self.setWindowIcon(QIcon(QPixmap('GUI/images_for_GUI/icon.jpg')))
self.bg = QLabel(self)
self.bg.resize(700, 370)
self.bg.setPixmap(QPixmap("GUI/images_for_GUI/background.jpg").scaled(700, 370))
def show_window(old, new):
if not (new is None):
new.show()
if not (old is None):
old.hide()
if __name__ == '__main__':
app = QApplication(sys.argv)
mainWin = MainMenu()
startWin = Analyze()
startWin.hide()
addPersonWin = AddPerson()
addPersonWin.hide()
aboutWin = About()
aboutWin.hide()
sys.exit(app.exec_())