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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
| import datetime
import sqlite3
from PyQt5.QtWidgets import (QApplication, QWidget, QPushButton,
QToolTip, QLineEdit, QLabel, QLCDNumber, QVBoxLayout, QHBoxLayout, QGroupBox,
QTextBrowser, QDialog, QMessageBox)
from PyQt5.QtGui import QIcon, QFont
from registration import registration
from PyQt5.QtCore import QTime, QTimer, Qt
# Основное окно
class security (QWidget):
def __init__(self):
super(security, self).__init__()
self.setWindowTitle('Test• test')
self.setStyleSheet("background-color: rgba(238, 238, 238);")
button1 = self._pushbutton1() # отображение кнопки "Регистрация"
button2 = self._pushbutton2() # отображение кнопки "Закрыть"
button3 = self._pushbutton3() # отображение кнопки "Войти"
lineedit1 = self._lineedit1() # отображение поля для ввода логина
lineedit2 = self._lineedit2() # отображение поля для ввода пароля
label1 = self._labelline1() # отображение названия программы
groupbox1 = self._groupbox1() # отображение часов + даты
vbox_lbl = QVBoxLayout()
vbox_lbl.addWidget(label1)
hbox_lbl = QHBoxLayout()
hbox_lbl.addStretch(1)
hbox_lbl.addLayout(vbox_lbl)
hbox_lbl.addStretch(1)
vbox_lineedit = QVBoxLayout()
vbox_lineedit.addWidget(lineedit1)
vbox_lineedit.addWidget(lineedit2)
hbox_lineedit = QHBoxLayout()
hbox_lineedit.addWidget(groupbox1)
hbox_lineedit.addLayout(vbox_lineedit)
vbox_btn1 = QVBoxLayout()
vbox_btn1.addStretch(1)
vbox_btn1.addWidget(button1)
vbox_btn2 = QVBoxLayout()
vbox_btn2.addStretch(1)
vbox_btn2.addWidget(button2)
vbox_btn3 = QVBoxLayout()
vbox_btn3.addStretch(1)
vbox_btn3.addWidget(button3)
hbox_btn = QHBoxLayout()
hbox_btn.addStretch(1)
hbox_btn.addLayout(vbox_btn1)
hbox_btn.addLayout(vbox_btn3)
hbox_btn.addLayout(vbox_btn2)
hbox_btn.addStretch(1)
vbox_ready = QVBoxLayout()
vbox_ready.addStretch(1)
vbox_ready.addLayout(hbox_lbl)
vbox_ready.addStretch(1)
vbox_ready.addLayout(hbox_lineedit)
vbox_ready.addLayout(hbox_btn)
self.setLayout(vbox_ready)
self.loginDatabase = LoginDatabase('login.db')
if self.loginDatabase.is_table('USERS'):
pass
else:
self.loginDatabase.conn.execute("CREATE TABLE USERS(USERNAME TEXT NOT NULL, EMAIL TEXT, PASSWORD TEXT)")
self.loginDatabase.conn.execute("INSERT INTO USERS VALUES(?, ?, ?)",
('admin', 'admin@gmail.com', 'admin')
)
self.loginDatabase.conn.commit()
button3.clicked.connect(self.loginCheck)
def showMessageBox(self, title, message):
msgBox = QMessageBox()
msgBox.setIcon(QMessageBox.Warning)
msgBox.setWindowTitle(title)
msgBox.setText(message)
msgBox.setStandardButtons(QMessageBox.Ok)
msgBox.exec_()
def welcomeWindowShow(self):
print("Open, program. Very Good!")
def signUpShow(self):
print("Open, registration. Good!")
def loginCheck(self):
username = self._lineedit1().text()
password = self._lineedit2().text()
if (not username) or (not password):
msg = QMessageBox.information(self, 'Внимание!', 'Вы не заполнили все поля.')
return
result = self.loginDatabase.conn.execute("SELECT * FROM USERS WHERE USERNAME = ? AND PASSWORD = ?",
(username, password))
if len(result.fetchall()):
self.welcomeWindowShow(username)
self.hide()
self.loginDatabase.conn.close()
else:
self.showMessageBox('Внимание!', 'Неправильное имя пользователя или пароль.')
# GroupBox для часов и даты (страница авторизации)
def _groupbox1(self):
groupBox = QGroupBox("Сегодня:", self)
groupBox.setFixedSize(140, 100)
groupBox.setObjectName("MainGroupBox")
groupBox.setStyleSheet("QGroupBox#MainGroupBox {background-color: rgba(255, 255, 255);"
"border-style: groove;"
"border-width: 2px;"
"border-radius: 25px;"
"border-color: dark;"
"font: 14px;"
"font-family: Century;}")
time1 = DigitalClock()
time1.setFixedSize(110, 30)
time1.setObjectName("TimeinGroupBox")
time1.setStyleSheet("background-color: rgba(238, 238, 238);"
"border-style: groove;"
"border-width: 2px;"
"border-radius: 12px;"
"border-color: dark;"
"font: bold 14px;"
"font-family: Century;"
"padding: 6px;");
date1 = self._datetoday()
date1.setFixedSize(110, 30)
date1.setAlignment(Qt.AlignCenter)
date1.setStyleSheet("background-color: rgba(238, 238, 238);"
"border-style: groove;"
"border-width: 2px;"
"border-radius: 12px;"
"font-family: Century Gothic;"
"font: 13px;"
"border-color: dark;")
hbox_datetime = QVBoxLayout()
hbox_datetime.addWidget(date1)
hbox_datetime.addWidget(time1)
vbox_ready = QVBoxLayout()
vbox_ready.addLayout(hbox_datetime)
groupBox.setLayout(vbox_ready)
return groupBox
# Название программы (на странице авторизации)
def _labelline1(self):
label = QLabel(self)
label.setText("REMOTE DC v3.00PY")
label.setFont(QFont('Century', 30, QFont.Bold))
return label
# Кнопка "Регистрация" (страница авторизации)
def _pushbutton1(self):
QToolTip.setFont(QFont('Century Gothic', 8))
btn = QPushButton('Регистрация', self)
btn.setToolTip('Нажмите, чтобы перейти к регистрации')
btn.setFont(QFont('Century Gothic', 8))
btn.setFixedSize(85, 35)
btn.setStyleSheet("""
QPushButton:hover { background-color: rgba(255, 140, 0);
border-radius: 10px;
border-style: ridge;
border-color: dark;
border-width: 2px; }
QPushButton:!hover { background-color: white;
border-style: ridge;
border-width: 2px;
border-radius: 10px;
border-color: dark; }
QPushButton:pressed { background-color: rgb(255, 255, 0);
border-radius: 17px;}
""")
btn.clicked.connect(self.registrationopen)
btn.clicked.connect(self.securityclose)
return btn
# Кнопка "Закрыть" (страница авторизации)
def _pushbutton2(self):
btn2 = QPushButton('Закрыть', self)
btn2.setToolTip('Нажмите, чтобы выйти из программы')
btn2.setFont(QFont('Century Gothic', 8))
btn2.setFixedSize(85, 35)
btn2.setStyleSheet("""
QPushButton:hover { background-color: rgba(139, 0, 0);
border-radius: 10px;
border-style: ridge;
border-color: dark;
border-width: 2px; }
QPushButton:!hover { background-color: white;
border-style: ridge;
border-width: 2px;
border-radius: 10px;
border-color: dark; }
QPushButton:pressed { background-color: rgb(255, 0, 0);
border-radius: 17px;}
""")
btn2.clicked.connect(self.close)
return btn2
# Кнопка "Войти" (страница авторизации)
def _pushbutton3(self):
QToolTip.setFont(QFont('Century Gothic', 8))
btn3 = QPushButton('ВОЙТИ', self)
btn3.setToolTip('Нажмите, чтобы войти в приложение')
btn3.setFont(QFont('Century Gothic', 14))
btn3.setFixedSize(100, 50)
btn3.setStyleSheet("""
QPushButton:hover { background-color: green;
border-radius: 10px;
border-style: ridge;
border-color: dark;
border-width: 2px; }
QPushButton:!hover { background-color: white;
border-style: ridge;
border-width: 2px;
border-radius: 10px;
border-color: dark; }
QPushButton:pressed { background-color: rgb(0, 255, 0);
border-radius: 24px;}
""")
return btn3
#Строка для ввода логина (страница авторизации)
def _lineedit1(self):
le = QLineEdit(self)
le.setStyleSheet("background-color: rgba(255, 255, 255);"
"border-style: outset;"
"border-width: 2px;"
"border-radius: 17px;"
"border-color: dark;"
"font: bold 14px;"
"font-family: Century;"
"min-width: 10em;"
"padding: 6px;");
le.setPlaceholderText("Введите логин")
return le
# Строка для ввода пароля (страница авторизации)
def _lineedit2(self):
le2 = QLineEdit(self)
le2.setStyleSheet("background-color: rgba(255, 255, 255);"
"border-style: outset;"
"border-width: 2px;"
"border-radius: 17px;"
"border-color: dark;"
"font: bold 14px;"
"font-family: Century;"
"min-width: 10em;"
"padding: 6px;");
le2.setPlaceholderText("Введите пароль")
le2.setEchoMode(QLineEdit.Password)
return le2
# Отображение актуальной даты (виджет страница авторизации)
def _datetoday(self):
DATE = QTextBrowser(self)
datetoday = datetime.datetime.now()
DATE.setText('%s/%s/%s' % (datetoday.day, datetoday.month, datetoday.year))
DATE.setStyleSheet("margin-left:300px;"
"margin-right:0px;"
"text-indent:0px;")
return DATE
# !Функция, для открытия основного окна
def securityreturn(self):
self.securityreturn = security()
self.securityreturn.show()
# !Функция, для открытия окна регистрации
def registrationopen(self):
self.registrationopen = registration()
self.registrationopen.show()
# !Функция, для закрытия окна регистрации, при открытии окна авторизации
def registrationclose(self):
self.registrationclose = registration()
self.close()
# !Функция, для закрытия окна авторизации, при открытии окна регистрации
def securityclose(self):
self.securityclose = security()
self.close()
# Виджет часов
class DigitalClock(QLCDNumber):
def __init__(self, parent=None):
super(DigitalClock, self).__init__()
self.Clock()
def Clock(self):
self.setSegmentStyle(QLCDNumber.Filled)
self.setStyleSheet("background-color: rgba(0, 120, 215);"
"color: dark;"
"border-style: outset;")
timer = QTimer(self)
timer.timeout.connect(self.showTime)
timer.start(1000)
self.showTime()
def showTime(self):
time = QTime.currentTime()
text = time.toString('hh:mm')
if (time.second() % 2) == 0:
text = text[:2] + ' ' + text[3:]
self.display(text)
# База для пользовательских данных (авторизация)
class LoginDatabase():
def __init__(self, dbname):
self.dbname = dbname
self.conn = sqlite3.connect(dbname)
def is_table(self, table_name):
query = "SELECT name from sqlite_master WHERE type='table' AND name='{}';".format(table_name)
cursor = self.conn.execute(query)
result = cursor.fetchone()
if result == None:
return False
else:
return True
if __name__ == ('__main__'):
import sys
app = QApplication(sys.argv)
w = security()
w.show()
sys.exit(app.exec_()) |