-
Notifications
You must be signed in to change notification settings - Fork 1
/
street_team.py
480 lines (400 loc) · 18 KB
/
street_team.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
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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
import logging
import os
import sys
from PySide6 import QtCore
from PySide6.QtCore import Qt, QPoint, QTimer, QEvent
from PySide6.QtGui import (QColor, QMouseEvent, QFont, QPalette, QPainter, QPen, QLinearGradient, QPixmap, QBrush)
from PySide6.QtWidgets import QWidget, QApplication, QLabel, QPushButton, QDialog, \
QVBoxLayout, QButtonGroup, QHBoxLayout, QGraphicsDropShadowEffect
from PySide6.QtSql import QSqlDatabase, QSqlQuery
from PySide6.QtWidgets import QSplashScreen
from PySide6.QtGui import QPixmap
#import widget
#
#from widget import wnd, cenv
from final import FinalWind
global apt
QtCore.QLocale.setDefault(QtCore.QLocale("ru_RU"))
class aStart():
def __init__(self, parent=None):
global tkolt,lmaxlw,blc,logo,name,lcnnxt,tots,shag,mascat,smx,gx,cnttxt,ccat,cenv,wnd,cenv,Category,simple_audio
sqlDB = QSqlDatabase.addDatabase('QSQLITE')
sqlDB.setDatabaseName("./jep.sqlite")
sqlDB.open()
#доимпорт
from widget import wnd, cenv
from categ import Category
import simpleaudio as simple_audio
name = ["", "", "", "", "", "", "", ""]
logo = ["", "", "", "", "", "", "", ""]
tots = [0, 0, 0, 0, 0, 0]
lcnnxt = 30
query = QSqlQuery()
if not query.exec(
"""
SELECT COUNT(*) FROM Teams;
"""
):
logging.error("Failed to query database16")
query.next()
tkolt = int(query.value(0)) # количество команд
query1 = QSqlQuery()
if not query1.exec("UPDATE settings SET tmpDat = 5 ,tmpDat1 = 5 ;"): # цена вопроса в бд становится равна 10
logging.error("Failed to query database16")
query = QSqlQuery()
if not query.exec(
"""
SELECT * FROM Teams;
"""
):
logging.error("Failed to query database17")
query.first()
s = ""
for i in range(tkolt):
logo[i] = str(query.value(1))
name[i] = str(query.value(2))
try:
tots[i]=int(query.value(3))
except ValueError:
tots[i] = 0
s += name[i] + " "
query.next()
# вычисляем кол-во букв в самом длинном слове в названиях команд
maxlenw = max(s.split(), key=len)
lmaxlw = len(maxlenw)
mascat = []
blc = 120
shag = 2
smx = 5
gx = 200
cnttxt = ""
global geometry
ccat = 1
cenv = 0
class Wint(QWidget):
global cnttxt, cntcode, ccat
# рисуем анимацию фона
global cenv
if os.path.exists("disanim"):
pass
else:
def paintEvent(self, event):
global smx
global gx
painter = QPainter(self)
# painter.begin(self)
x = 0
y = 0
wd = self.size().width()
hd = self.size().height()
gx += smx
if gx > wd * 1.5 or gx < 150:
smx *= -1
gradient = QLinearGradient(QPoint(x, y), QPoint(gx, y + 300 + wd * 300 / gx))
gradient.setColorAt(0.0, QColor(0, 0, 80, 180))
gradient.setColorAt(0.3, QColor(0, 120, 255, 225))
gradient.setColorAt(1.0, QColor(0, 80, 255, 80))
painter.setBrush(gradient)
pen = QPen()
pen.setWidth(1)
pen.setColor(QColor(0, 0, 50, 10))
painter.setPen(pen)
painter.drawRect(x, y, wd, hd)
# закончили с фоном
def __init__(self, tkol, parent=None):
self.plusSound = simple_audio.WaveObject.from_wave_file("./resourses/sound/plus.wav")
self.minusSound = simple_audio.WaveObject.from_wave_file("./resourses/sound/minus.wav")
global lmaxlw, ccat
super(Wint, self).__init__(parent)
# sqlDB = QSqlDatabase.addDatabase('QSQLITE')
# sqlDB.setDatabaseName("./jep.sqlite")
# sqlDB.open()
# Проверяем - новая игра, или продолжение прерванной (таблицs SCORE и STEPS)
# SQL запрос на создание таблицы
tql=QSqlQuery()
steps_query = """
CREATE TABLE IF NOT EXISTS steps (
cell_num INT
);
"""
if not tql.exec(steps_query):
logging.error("Таблица уже существует.")
# закончили проверку и создание таблиц SCORE и STEPS
font = QFont()
font.setFamilies([u"Arial"])
font.setBold(True)
alignmentc = Qt.AlignmentFlag.AlignCenter
tkol = tkolt
snd = ""
geometry = apt.primaryScreen().availableGeometry()
self.setGeometry(geometry)
wdt = self.size().width()
twdt = (wdt - 20) / tkol - 10
fw = int(twdt / lmaxlw)
hgt = self.size().height()
self.setAutoFillBackground(True)
mainlogoh = hgt / 5
self.mainlogo = QLabel(self)
self.mainlogo.setGeometry(10, 5, wdt - 30, mainlogoh)
pixmap = QPixmap("./resourses/logo/logo.png")
pixmap = pixmap.scaled(wdt / 3, hgt / 5 - 15, Qt.KeepAspectRatio)
self.mainlogo.setPixmap(pixmap)
alignmentr = Qt.AlignmentFlag.AlignRight
self.mainlogo.setAlignment(alignmentr)
self.sth = "background-color: rgba(0,0," + str(blc) + ",0);"
self.mainlogo.setStyleSheet(self.sth)
self.mainlogo.show()
hgt = hgt - mainlogoh
# Насыщенность фона
def scrupd():
if os.path.exists("disanim"):
self.sth = "background-color: rgba(0,40,230,255); color: #ddFFaa;"
else:
global blc, shag
blc += shag
if blc >= 254 or blc <= 90:
shag *= -1
self.sth = "background-color: rgba(0,0," + str(blc) + ",75); color: #ddFFaa;"
self.setStyleSheet(self.sth)
self.tmr = QTimer() # 4
self.tmr.timeout.connect(scrupd)
self.tmr.start(40)
# конец насыщенности фона
queryccat = QSqlQuery()
if not queryccat.exec("SELECT COUNT(*) FROM category;"):
logging.error("Failed to query database15")
queryccat.first()
ccat = queryccat.value(0)
# создаем экраны вопросов категорий
query = QSqlQuery()
if not query.exec("SELECT catname FROM category;"):
logging.error("Failed to query database1")
global mascat
while (query.next()):
cwnd = wnd(query.value(0), apt)
# print(query.value(0))
cwnd.setVisible(False)
# cwnd.setObjectName("widget_"+str(i))
mascat.append(cwnd)
# создаем виджет - один навсегда))
# конец init
# ПРОДОЛЖИТЬ
def cntn():
global cntname
# забираем название категории из settings
query = QSqlQuery()
if not query.exec("SELECT * FROM settings ;"):
logging.error("Failed to query database22")
query.first()
cntname = str(query.value(8))
querycatn = QSqlQuery()
if not querycatn.exec("SELECT ROW_NUMBER() OVER() as row_number,catname FROM Category ;"):
logging.error("Failed to query database21")
# querycatn.first()
while (querycatn.next()):
if (querycatn.value(1) == cntname):
mascat[int(querycatn.value(0)) - 1].showFullScreen()
def chcat(self):
vcat = Category(apt)
vcat.showFullScreen()
updcnttxt(self)
def updcnttxt(self):
global cnttxt, cntname, lcnnxt
query = QSqlQuery()
if not query.exec("SELECT * FROM settings ;"):
logging.error("Failed to query database6")
query.first()
cnttxt = query.value(8)
lcnnxt = len(cnttxt)
cntname = str(query.value(8))
for i in range(tkol):
if len(logo[i]) > 0:
self.logo = QLabel(self)
self.logo.setGeometry(i * (twdt + 10) + 10, mainlogoh + 10, twdt, hgt / 4 - 10)
self.logo.setAlignment(alignmentc)
pixmap = QPixmap("./img/logo/" + logo[i])
pixmap = pixmap.scaled(twdt, hgt / 4 - 20, Qt.KeepAspectRatio)
self.logo.setPixmap(pixmap)
self.logo.setStyleSheet(
"border:3px solid #99aaff;border-top-left-radius: 22px; border-top-right-radius: 22px; font-size: 48px")
self.logo.show()
self.tnm = QLabel(self)
# fnts = 66 - tkolt * 7
fnts = int(fw * (1.4-0.2*(1-kfont)))
if fnts>60:
fnts=60
stsh = "border:3px solid #99aaff;font-size: " + str(fnts) + "px"
self.tnm.setStyleSheet(stsh)
if len(logo[i]) > 0:
self.tnm.setGeometry(i * (twdt + 10) + 10, mainlogoh + 10 + hgt / 4, twdt, hgt / 3 - 20)
else:
self.tnm.setGeometry(i * (twdt + 10) + 10, mainlogoh + 10, twdt, hgt / 3 + hgt / 4 - 20)
self.tnm.setStyleSheet(
"border:3px solid #9999ff;border-top-left-radius: 22px; border-top-right-radius: 22px; font-size: " + str(
fnts) + "px")
self.tnm.setWordWrap(True)
self.tnm.setText(name[i])
self.tnm.setAlignment(alignmentc)
self.tnm.setFont(font)
self.tnm.show()
self.result = QLabel(self)
self.result.setObjectName("rst" + str(i))
self.result.setGeometry(i * (twdt + 10) + 10, mainlogoh + hgt / 4 + hgt / 3, twdt, hgt / 5)
self.result.setWordWrap(True)
self.result.setText(str(tots[i]))
self.result.setAlignment(alignmentc)
self.result.setFont(font)
fnts1 = 96 - tkolt * 4
stsh = "border:3px solid #99aaff;border-bottom-left-radius: 22px; border-bottom-right-radius: 22px;font-size: " + str(
fnts1) + "px"
botb = "QPushButton{font-size: " + str(
fnts1) + "px; border: 1px solid rgba(200,200,255,180)} QPushButton::hover{background-color: #0077ff ;} QPushButton::pressed {background-color: rgba(224, 255, 255, 195); color: rgba(0,0,255,255) }"
self.result.setStyleSheet(stsh)
self.result.show()
self.plusb = QPushButton(self)
self.plusb.setObjectName("pls" + str(i))
# QMessageBox.warning(self, "Нажматие!!!))", "Название объекта " + str(self.plusb.objectName()))
self.plusb.setGeometry(i * (twdt + 15-i) + 30, mainlogoh + hgt / 4 + hgt / 3 + hgt / 5 + 10, twdt / 2 - 30,
hgt / 10)
self.plusb.setText("+")
self.plusb.setStyleSheet(botb)
self.plusb.clicked.connect(self.sumf)
self.plusb.show()
self.minub = QPushButton(self)
self.minub.setObjectName("mns" + str(i))
self.minub.setGeometry(i * (twdt + 15-i) + 15 + twdt / 2, mainlogoh + hgt / 4 + hgt / 3 + hgt / 5 + 10,
twdt / 2 - 30,
hgt / 10)
self.minub.setText("-")
self.minub.setStyleSheet(botb)
self.minub.clicked.connect(self.sumf)
self.minub.show()
self.catch = QPushButton(self)
self.catch.setGeometry(10, mainlogoh + hgt - hgt / 15 - 10, (wdt - 25) / 2,
hgt / 15+5)
fs = int(1.5 * (((wdt - 25) / 2) / (lcnnxt + 2)))
self.catch.setText("Выбор категории")
# self.catch.setStyleSheet("font: bold 34px; border: 1px solid rgba(200,200,255,180); border-top-right-radius: 120px 60px; border-bottom-left-radius: 180px "+str(int(hgt / 15))+"px")
shst = "QPushButton { font: bold " + str(
fs) + "px; border: 1px solid rgba(200,200,255,180); border-top-right-radius: 120px 50px; border-bottom-left-radius: 160px " + str(
int(hgt / 15)) + "px} QPushButton::hover{background-color: #0077ff ;} QPushButton::pressed {background-color: rgba(224, 255, 255, 195); color: rgba(0,0,255,255) }"
self.catch.setStyleSheet(shst)
self.catch.clicked.connect(chcat)
updcnttxt(self)
if ccat > 1:
self.catch.show()
else:
self.catch.setVisible(False)
query=QSqlQuery()
query.exec("SELECT Catname FROM ThemeAndQ")
query.first()
cattxt=str(query.value(0))
query1 = QSqlQuery()
query1.exec("UPDATE settings SET curCatName= '"+cattxt+"' ;")
self.contin = QPushButton(self)
self.contin.setGeometry((wdt - 25) / 2+10, mainlogoh + hgt - hgt / 15 - 10, (wdt - 25) / 2, hgt / 15+5)
self.contin.setText(cnttxt)
self.contin.setStyleSheet("QPushButton {font: bold " + str(
fs) + "px; border: 1px solid rgba(200,200,255,180);border-top-right-radius: 160px " + str(
int(hgt / 15)) + "px; border-bottom-left-radius: 120px 50px} QPushButton::hover{background-color: #0077ff ;} QPushButton::pressed {background-color: rgba(224, 255, 255, 195); color: rgba(0,0,255,255) }")
self.contin.clicked.connect(cntn)
self.contin.show()
def sumf(self):
# считываем цену вопроса из tmpDat settings
quec = QSqlQuery()
if not quec.exec(
"""
SELECT * from settings;
"""
):
logging.error("Failed to query database7")
quec.next()
cenv = quec.value(5)
cenp = quec.value(6)
sndr = self.sender().objectName()
# QMessageBox.warning(self, "Нажматие!!!))", " " + str(self.sender().objectName()))
if sndr[:3] == "pls":
self.plbutclick = self.plusSound.play()
tots[int(sndr[3:])] += cenp
else:
self.minbutclick = self.minusSound.play()
tots[int(sndr[3:])] -= cenv
# меняем значения на лейблах
obj = self.findChild(QLabel, "rst" + sndr[3:])
obj.setText(str(tots[int(sndr[3:])]))
quec = QSqlQuery()
idt=int(sndr[3:])
if not quec.exec("UPDATE teams set sum="+str(tots[int(sndr[3:])]) + " WHERE Id="+str(idt)+";"):
logging.error("Failed to query database7")
else:
quec.exec("UPDATE score set result="+str(tots[int(sndr[3:])]) + " WHERE id="+str(idt)+";")
def keyPressEvent(self, event):
if event.key() == Qt.Key_Escape:
# диалоговое окно выхода из программы
def check_button(id_name):
if button_group.id(id_name) == 1:
clrq=QSqlQuery()
clrq.exec("delete from steps")
finw = FinalWind(apt)
finw.showFullScreen()
reply.close()
self.hide()
elif button_group.id(id_name) == 2:
reply.close()
event.ignore()
screen = apt.primaryScreen()
img = screen.grabWindow()
img.save('screenshot.png', 'png')
reply = QDialog()
reply.setWindowFlag(Qt.FramelessWindowHint)
sth = "background-color: rgba(0,0,255,90); color: #ddFFaa; font-size: 22px; border: 6px;"
reply.setStyleSheet(sth)
vbox = QVBoxLayout()
label_dialog = QLabel()
label_dialog.setStyleSheet(
"background-color: rgba(0,0,255,240);border-top-left-radius: 80px 20px; border-bottom-right-radius: 80px 20px;")
label_dialog.setText('Вы действительно хотите закончить игру?')
button_yes = QPushButton(reply)
button_yes.setText("Да")
shst = "QPushButton { background-color: rgba(0,0,200,100); color: rgba(220,220,255,255); text-align:center center; background-position: bottom center; border: 2px solid rgb(160, 180, 250); border-radius: 6px; font: Bold 22px} QPushButton::hover{background-color: #0077ff ;}"
button_yes.setStyleSheet(shst)
button_no = QPushButton(reply)
button_no.setText('Нет')
button_no.setStyleSheet(shst)
shadow = QGraphicsDropShadowEffect(
self, blurRadius=5, offset=3, color=QColor(80, 180, 180, 180)
)
button_no.setGraphicsEffect(shadow)
shadow = QGraphicsDropShadowEffect(
self, blurRadius=5, offset=3, color=QColor(80, 180, 180, 180)
)
button_yes.setGraphicsEffect(shadow)
button_group = QButtonGroup()
button_group.addButton(button_yes, 1)
button_group.addButton(button_no, 2)
button_group.buttonClicked.connect(check_button)
layout = QHBoxLayout()
layout.addWidget(button_yes)
layout.addWidget(button_no)
vbox.addWidget(label_dialog)
vbox.addSpacing(20)
vbox.addLayout(layout)
reply.setLayout(vbox)
reply.exec()
if __name__ == "__main__":
global gwidth,gheight,kfont
apt = QApplication([])
(gwidth, gheight) = apt.screens()[0].size().toTuple()
kfont=gwidth/1920
# pyside6 splash screen
splash = QSplashScreen()
splash.setPixmap(QPixmap("./resourses/logo/psplash.png"))
splash.show()
a = aStart()
wnt = Wint(tkolt)
splash.finish(wnt)
wnt.showFullScreen()
sys.exit(apt.exec())
sqlDB.close()
sqlDB.removeDatabase('QSQLITE')
sqlDB.removeDatabase('jep.sqlite')