/
qt.py
154 lines (124 loc) · 5.07 KB
/
qt.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
#!/usr/bin/python
import sys
import pickle
import random
import math
import sys
from PyQt4 import QtGui, QtCore
import functions
class Person():
elo = 0 # Elo rating
group = 0 # Matchmaking group
k = 40 # Initial coefficient
battles = 0 # Batlles was played
class LoginWindow(QtGui.QDialog):
def __init__(self):
QtGui.QDialog().__init__(self)
class MainWindow(QtGui.QMainWindow):
def __init__(self, parent=None):#параметры по умолчанию класса MainWindow
QtGui.QMainWindow.__init__(self, parent)
#self — описание окна, определение переменных виджетов
self.setGeometry(300, 300, 1500, 800)
mainWidget = QtGui.QWidget()
self.setCentralWidget(mainWidget)
#Настройка меню
menu = self.menuBar()
list1 = menu.addMenu('File')
list1.addAction('exit')
list1.addAction('save')
list1.addAction('save as')
#Настройка панелей инструментов
toolbar = self.addToolBar('Exit')
toolbar.addAction('exit')
toolbar.addAction('save')
toolbar.addAction('save as')
#определение переменных кнопок, редакторов, сеток.
self.rButton = QtGui.QPushButton("Right")
self.lButton = QtGui.QPushButton("Left")
self.dButton = QtGui.QPushButton("Download")
self.label1 = QtGui.QLabel()
self.label2 = QtGui.QLabel()
self.textEdit = QtGui.QTextBrowser(readOnly=1)
self.textEdit.setOpenExternalLinks(True)
grid = QtGui.QGridLayout(mainWidget)
#положение на сетке
#grid.setSpacing(100)
grid.setColumnMinimumWidth(0, 400)
grid.setColumnMinimumWidth(1, 400)
grid.setColumnMinimumWidth(2, 200)
grid.addWidget(self.label1, 0, 0)
grid.addWidget(self.label2, 0, 1)
grid.addWidget(self.lButton, 1, 0)
grid.addWidget(self.rButton, 1, 1)
grid.addWidget(self.dButton, 1, 2)
grid.addWidget(self.textEdit, 0, 2)
self.person=functions.unpickle()
#self.person=self.person[:10]
self.rButton.clicked.connect(self.rbutton)
self.lButton.clicked.connect(self.lbutton)
self.dButton.clicked.connect(self.dbutton)
#self.person[13].elo=200
self.update(2)
self.setGeometry(300, 300, 250, 150)
#self.connect(self.rButton, QtCore.SIGNAL('clicked(int)'), self.update(1))
def rbutton(self):
self.update(0)
def lbutton(self):
self.update(1)
def dbutton(self):
functions.download()
self.person=functions.unpickle()
self.update(2)
def update(self, a):
#Новый рейтинг предыдущих
if a == 1:
functions.buttle(self.left, self.right)
self.person[self.nleft]=self.left
self.person[self.nright]=self.right
if a == 0:
functions.buttle(self.right, self.left)
self.person[self.nleft]=self.left
self.person[self.nright]=self.right
#сортируем`
self.person=sorted(self.person, key=lambda person: person.elo)
#матчмэйкинг
self.left=random.choice(self.person)
self.nleft=self.person.index(self.left)
d=1
if self.nleft<d:
self.right=[i for i in self.person[:d*2] if i != self.left]
elif self.nleft>(len(self.person)-d):
self.right=[i for i in self.person[self.nleft-d*2:] if i != self.left]
else:
self.right=[i for i in self.person[self.nleft-d:self.nleft+d] if i != self.left]
self.right=random.choice(self.right)
self.nright=self.person.index(self.right)
#Установка картинок
self.label1.setPixmap(QtGui.QPixmap(self.left.jpg).scaledToHeight(400))
self.label2.setPixmap(QtGui.QPixmap(self.right.jpg).scaledToHeight(400))
#self.label2.setGeometry(160, 40, 80, 30)
self.textEdit.clear()
#Текст
for i in range(len(self.person)):
text="<a href='http://www.vk.com/id"+str(self.person[i].id)+"'>"
text=text+self.person[i].sname.ljust(2)+' '+self.person[i].name+'</a>'
text=str(self.person[i].elo)[:4]+'\t'+text
self.textEdit.append(text)
self.textEdit.toHtml()
def closeEvent(self, event):
reply = QtGui.QMessageBox.question(self, 'Message',
"Are you sure to quit?", QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)
if reply == QtGui.QMessageBox.Yes:
functions.save(self.person)
event.accept()
else:
event.ignore()
def showEvent(self, event):
reply = QtGui.QDialog()
Login_Dialog.setObjectName("Login_Dialog")
Login_Dialog.resize(285, 134)
reply.show()
app = QtGui.QApplication(sys.argv)
main = MainWindow()
main.show()
sys.exit(app.exec_())