-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.py
264 lines (231 loc) · 9.53 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
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
import sys
import os
import configparser
import sys
from PyQt5 import QtGui
from PyQt5 import QtCore
from PyQt5 import QtWidgets
from PyQt5.QtCore import *
from neoEval import Card, Evaluator, Deck
from UI.gui import Ui_MainWindow
from UI.titleBar import TitleBar
from neoOdds import NeoOdds
# Setting custom variables
desktop_path = os.path.join(os.path.expanduser('~'), "Desktop")
try:
app_root = os.path.dirname(os.path.abspath(__file__))
except NameError:
import sys
app_root = os.path.dirname(os.path.abspath(sys.argv[0]))
class LoopThread(QThread):
notifyProgress = QtCore.pyqtSignal(int)
notifyOddsFlop = QtCore.pyqtSignal(int)
notifyOddsTurn = QtCore.pyqtSignal(int)
notifyOddsRiver = QtCore.pyqtSignal(int)
notifyEquityFlop = QtCore.pyqtSignal(int)
notifyEquityTurn = QtCore.pyqtSignal(int)
notifyEquityRiver = QtCore.pyqtSignal(int)
notifyOddsFlopP = QtCore.pyqtSignal(float)
notifyOddsTurnP = QtCore.pyqtSignal(float)
notifyOddsRiverP = QtCore.pyqtSignal(float)
def __init__(self, cal, gui):
QThread.__init__(self)
self.cal = cal
self.gui = gui
self.i = 0
def __del__(self):
self.wait()
def stop(self):
self.terminate()
def reset_ui(self):
self.gui.ui.labelCombi.setText("???")
self.gui.ui.labelInfo.setText("???")
def run(self):
n, a, b, c = 0, 0, 0, 0
while True:
n += 1
self.cal.get_poker_cards()
if self.cal.pokerstars.up:
a, b, c, n = 0, 0, 0, 0
self.gui.ui.lcdNumberPlayer.display(self.cal.pokerstars.nbrPlayers)
if self.cal.cards[0]:
self.gui.ui.labelHandCard.setText(Card.print_pretty_cards(self.cal.cards[0]))
if self.cal.cards[1]:
self.gui.ui.labelBoardCard.setText(Card.print_pretty_cards(self.cal.cards[1]))
self.notifyProgress.emit(10)
if len(self.cal.cards[0]) >= 2:
a1, b1, c1 = self.cal.odds(self.gui.ui.spinBox.value(), self.cal.pokerstars.nbrPlayers)
a += a1
b += b1
c += c1
if len(self.cal.cards[1]) <= 3:
self.notifyOddsFlop.emit(int(a / n))
self.notifyProgress.emit(20)
self.notifyOddsFlopP.emit(float(a / n))
else:
self.notifyOddsFlop.emit(0)
self.notifyOddsFlopP.emit(0)
if len(self.cal.cards[1]) <= 4:
self.notifyOddsTurn.emit(int(b / n))
self.notifyProgress.emit(50)
self.notifyOddsTurnP.emit(float(b / n))
else:
self.notifyOddsTurn.emit(0)
self.notifyOddsTurnP.emit(0)
self.notifyOddsRiver.emit(int(c / n))
self.notifyProgress.emit(90)
self.notifyOddsRiverP.emit(float(c / n))
if len(self.cal.cards[1]) >= 3:
self.cal.evaluate()
self.gui.ui.labelCombi.setText("Player 1 hand rank = %d (%s)\n" % (
self.cal.my_score, self.cal.my_class))
self.gui.ui.labelInfo.setText(str(n))
else:
self.reset_ui()
self.notifyProgress.emit(100)
self.sleep(1)
class MainWindow(QtWidgets.QMainWindow):
def __init__(self, parent=None):
QtWidgets.QMainWindow.__init__(self, parent, flags=QtCore.Qt.FramelessWindowHint)
self.m_titleBar = TitleBar(self, "PokerStats")
self.m_content = QtWidgets.QWidget(self)
self.m_content = QtWidgets.QWidget(self)
self.size = []
self.size.append(380)
self.size.append(HEIGHT - 38)
self.move((WIDTH - self.size[0]), 0)
self.ui = Ui_MainWindow()
self.ui.setupUi(self, self.size)
self.ui.verticalLayoutTitle.addWidget(self.m_titleBar)
path = os.path.join(app_root, 'UI', 'images', 'icon.png')
self.setWindowIcon(QtGui.QIcon(path))
self.set_connections()
self.url_list = []
self.complete_url_list = {}
self.convert_list = []
self.thread_pool = {}
self.rowcount = 0
self.show()
self.cal = NeoOdds()
self.loopthread = LoopThread(self.cal, self)
self.buttonStart = False
defaults = {'path': 'C:\\Users\\theis_p\\AppData\\Local\\PokerStars.FR\\PokerStars.log.0', 'result': '2000'}
self.config = configparser.SafeConfigParser(defaults=defaults)
self.loadIni()
for i in range(200):
self.ui.listWidgetHistory.addItem(str(i))
def set_connections(self):
self.ui.btnStart.clicked.connect(self.handleButton)
self.ui.btnApply.clicked.connect(self.saveIni)
self.ui.btnSrc.clicked.connect(self.set_destination)
# self.ui.BatchAdd.clicked.connect(self.batch_file)
# self.ui.BrowseConvertButton.clicked.connect(self.convert_file_browse)
# self.ui.ConvertMultipleButton.clicked.connect(self.convert_button)
# self.ui.BrowseConvertToButton.clicked.connect(self.browse_convert_destination)
def set_destination(self):
file_name = str(QtWidgets.QFileDialog.getExistingDirectory(self, "Select Directory"))
if file_name is not '':
self.ui.lineEditSrc.setText(file_name)
def handleButton(self):
if not self.buttonStart:
self.src = str(self.ui.lineEditSrc.text())
self.ui.labelInfo.setText(self.src)
self.cal.config(self.src)
self.onThread()
self.buttonStart = True
self.ui.btnStart.setText("Stop")
else:
self.ui.labelInfo.setText("Stop...")
self.loopthread.stop()
self.ui.btnStart.setText("Start ")
self.reset()
self.buttonStart = False
def onThread(self):
self.loopthread = LoopThread(self.cal, self)
self.loopthread.notifyProgress.connect(self.onProgress)
self.loopthread.notifyOddsFlop.connect(self.onOddsFlop)
self.loopthread.notifyOddsTurn.connect(self.onOddsTurn)
self.loopthread.notifyOddsRiver.connect(self.onOddsRiver)
self.loopthread.notifyEquityFlop.connect(self.onEquityFlop)
self.loopthread.notifyEquityTurn.connect(self.onEquityTurn)
self.loopthread.notifyEquityRiver.connect(self.onEquityRiver)
self.loopthread.notifyOddsFlopP.connect(self.onOddsFlopP)
self.loopthread.notifyOddsTurnP.connect(self.onOddsTurnP)
self.loopthread.notifyOddsRiverP.connect(self.onOddsRiverP)
self.loopthread.start()
def onProgress(self, i):
self.ui.progressBarLoop.setValue(i)
def onOddsFlop(self, a):
if a == 0:
self.ui.progressBar_3.setEnabled(False)
else:
self.ui.progressBar_3.setEnabled(True)
self.ui.progressBar_3.setValue(a)
def onOddsTurn(self, a):
if a == 0:
self.ui.progressBar_4.setEnabled(False)
else:
self.ui.progressBar_4.setEnabled(True)
self.ui.progressBar_4.setValue(a)
def onOddsRiver(self, a):
if a == 0:
self.ui.progressBar_5.setEnabled(False)
else:
self.ui.progressBar_5.setEnabled(True)
self.ui.progressBar_5.setValue(a)
def onEquityFlop(self, a):
if a == 0:
self.ui.progressBar.setEnabled(False)
else:
self.ui.progressBar.setEnabled(True)
self.ui.progressBar.setValue(a)
def onEquityTurn(self, a):
if a == 0:
self.ui.progressBar_2.setEnabled(False)
else:
self.ui.progressBar_2.setEnabled(True)
self.ui.progressBar_2.setValue(a)
def onEquityRiver(self, a):
if a == 0:
self.ui.progressBar_6.setEnabled(False)
else:
self.ui.progressBar_3.setEnabled(True)
self.ui.progressBar_6.setValue(a)
def onOddsFlopP(self, a):
self.ui.labelOddsFlopP.setText(str(round(a, 3)) + '%')
def onOddsTurnP(self, a):
self.ui.labelOddsTurnP.setText(str(round(a, 3)) + '%')
def onOddsRiverP(self, a):
self.ui.labelOddsRiverP.setText(str(round(a, 3)) + '%')
def reset(self):
self.ui.progressBar.setValue(0)
self.ui.progressBar_2.setValue(0)
self.ui.progressBar_6.setValue(0)
self.ui.progressBar_3.setValue(0)
self.ui.progressBar_4.setValue(0)
self.ui.progressBar_5.setValue(0)
self.ui.labelBoardCard.setText('')
self.ui.labelHandCard.setText('')
self.ui.lcdNumberPlayer.display(0)
self.ui.labelOddsFlopP.setText('0%')
self.ui.labelOddsTurnP.setText('0%')
self.ui.labelOddsRiverP.setText('0%')
self.cards = []
def loadIni(self):
self.config.read('pokerstats.ini')
if not self.config.has_section('config'):
self.config.add_section('config')
self.ui.lineEditSrc.setText(self.config.get('config', 'path'))
self.ui.spinBox.setValue(int(self.config.get('config', 'result')))
def saveIni(self):
self.config.set('config', 'path', str(self.ui.lineEditSrc.text()))
self.config.set('config', 'result', str(self.ui.spinBox.value()))
with open('pokerstats.ini', 'w') as configfile:
self.config.write(configfile)
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
screen_rect = app.desktop().screenGeometry()
WIDTH, HEIGHT = screen_rect.width(), screen_rect.height()
box = MainWindow()
box.show()
sys.exit(app.exec_())