class CashGame(): def __init__(self): self.sessionStartTime = None self.pokerController = PokerController() self.handsData = [] self.handsDirectory = None self.startingFiles = None def startSession(self): self.handsDirectory = filedialog.askdirectory(initialdir = "C:\\Users\\Bobsleigh\\AppData\\Local\\PokerStars\\HandHistory\\TEST") self.sessionStartTime = datetime.now() self.startingFiles = os.listdir(self.handsDirectory) def updateSession(self): newFiles = self.checkForUpdatedFiles(self.handsDirectory, self.startingFiles) for fileName in newFiles: self.pokerController.FILEPATH = self.handsDirectory + "/" + fileName self.handsData.append(self.pokerController.loadPokerTextFile()) return self.pokerController.getPartialSum() def checkForUpdatedFiles(self, dirPath, startingFiles): newFiles = os.listdir(dirPath) newFiles[:] = [f for f in newFiles if f not in startingFiles] return newFiles
class MainWindow(Tk): """The main window of the program, where the widgets are placed. Attributes: All widgets n stuff """ def __init__(self): super().__init__() self.pokerController = PokerController() # Name of the window. self.title("FirePoker") self.bouton_width = 115 # Truc pour le redimensionnement automatique des éléments de la fenêtre. self.grid_columnconfigure(0, weight=1) self.grid_rowconfigure(0, weight=1) # Placing labels etiq = Label(self, text="BobTracker") etiq.grid() fra_stats = LabelFrame(self, text="Stats") fra_stats.grid(row=1, column=1, sticky=N + S) playerName = StringVar() playerName.set("Bobsleigh37") self.averageGain = StringVar() self.maxGain = StringVar() self.maxLoss = StringVar() self.amountOfHands = StringVar() lab_playerName = Label(fra_stats, text="Player Name", anchor=W) lab_playerName.grid(row=0, column=0, sticky=N + W + E) lab_playerNameVar = Label(fra_stats, textvariable=playerName, anchor=W) lab_playerNameVar.grid(row=0, column=1, sticky=E) lab_avg = Label(fra_stats, text="Average gain", anchor=W) lab_avg.grid(row=1, column=0, sticky=N + W + E) self.lab_avgVar = Label(fra_stats, textvariable=self.averageGain, anchor=E) self.lab_avgVar.grid(row=1, column=1, sticky=E) lab_maxGain = Label(fra_stats, text="Maximum gain", anchor=W) lab_maxGain.grid(row=2, column=0, sticky=N + W + E) lab_maxGainVar = Label(fra_stats, textvariable=self.maxGain, anchor=E) lab_maxGainVar.grid(row=2, column=1, sticky=E) lab_maxLoss = Label(fra_stats, text="Maximum loss", anchor=W) lab_maxLoss.grid(row=3, column=0, sticky=N + W + E) lab_maxLossVar = Label(fra_stats, textvariable=self.maxLoss, anchor=E) lab_maxLossVar.grid(row=3, column=1, sticky=E) lab_amountOfHands = Label(fra_stats, text="Hands in file", anchor=W) lab_amountOfHands.grid(row=4, column=0, sticky=N + W + E) lab_amountOfHandsVar = Label(fra_stats, textvariable=self.amountOfHands, anchor=E) lab_amountOfHandsVar.grid(row=4, column=1, sticky=E) f = Figure(figsize=(10, 6), dpi=100) a = f.add_subplot(111) a.plot([1, 2, 3, 4, 5, 6, 7, 8], [5, 6, 1, 3, 8, 9, 3, 5]) a.set_title("Chips Tracking") a.set_xlabel("Hand number") a.set_ylabel("Chip count") # Create frame for the canvas frame = Frame(self) label = Label(frame, text="Graph Page!") frame.grid() # Create canvas to display the graph plot canvas = FigureCanvasTkAgg(f, master=self) canvas.get_tk_widget().grid(row=1, column=0, padx=20, pady=20) # Create buttons btn_open_file = Button( self, text="Open a PokerStars hand text file", command=lambda: self.open_poker_file(a, canvas) ) btn_open_file.grid() btn_open_file = Button(self, text="Open Cash Session", command=lambda: self.openCashSessionWindow()) btn_open_file.grid() def open_poker_file(self, subplot, canvas): """Open a file prompt window to open the PokerStars hand info text file and loads it into memory. Returns: (string) : The complete filepath of the PokerStars hand text file """ filepath = filedialog.askopenfilename(defaultextension=".txt") self.pokerController.setFilePath(filepath) self.pokerController.loadPokerTextFile() partialSum = self.pokerController.getPartialSum() subplot.clear() subplot.plot(arange(1, len(partialSum) + 1), partialSum) subplot.set_title("Chips Tracking") subplot.set_xlabel("Hand number") subplot.set_ylabel("Chip count") canvas.draw() self.setLabelStats() return filepath def openCashSessionWindow(self): # Create child windows self.cashGameWindow = CashGameWindow(self.pokerController) def setLabelStats(self): self.averageGain.set(self.pokerController.getAverageGain()) self.maxGain.set(self.pokerController.getMaxGain()) self.maxLoss.set(self.pokerController.getMaxLoss()) self.amountOfHands.set(self.pokerController.getNumberOfHands())