-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMTGSpotCardChecker.py
76 lines (65 loc) · 2.68 KB
/
MTGSpotCardChecker.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
import CardManager
import customtkinter as gui
from PIL import Image
import re
import os
import sys
def Load():
global text
with open(ResourcePath("data.txt"), mode="r") as file:
for element in file.readlines():
inputText.insert('end', element)
priceText.insert('end', "50")
def Search():
result = inputText.get(0.0, "end").splitlines()
for cardId in range(len(result)):
result[cardId] = re.sub("^[0-9]* ", "", result[cardId])
search = CardManager.Data(result, upperBound=float(priceText.get(0.0, "end")))
sum = count = 0
outputText.delete(0.0, "end")
for card in search.result:
if card["cost"] != -1:
count += 1
sum += float(card["cost"])
outputText.insert("end", "[" + str(card["cost"]) + "] " + ((card["name"][:25] + '..') if len(card["name"]) > 25 else card["name"]) + "\n")
else:
outputText.insert("end", "[----] " + ((card["name"][:25] + '..') if len(card["name"]) > 25 else card["name"]) + "\n")
summaryLabel.configure(text=f"{count} of {len(result)} | {round(sum, 2)} zł")
myTab.set("Output")
def Save():
with open(ResourcePath("data.txt"), mode="w") as file:
file.write(inputText.get(0.0, "end"))
def ResourcePath(relative_path):
try:
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)
gui.set_appearance_mode("dark")
gui.set_default_color_theme("dark-blue")
root = gui.CTk()
root.geometry("400x1000+0+0")
root.title("MTG Spot Card Checker")
searchImage = gui.CTkImage(Image.open(ResourcePath("search.ico")).resize((20, 20)))
buttonFrame = gui.CTkFrame(root)
searchButton = gui.CTkButton(buttonFrame, image=searchImage, text="", width=90, command=Search)
myTab = gui.CTkTabview(root)
inputTab = myTab.add("Input")
outputTab = myTab.add("Output")
inputText = gui.CTkTextbox(inputTab, font=("consolas", 14))
priceFrame = gui.CTkFrame(inputTab)
priceLabel = gui.CTkLabel(priceFrame, text="Max Per Card [zł]:", font=("consolas", 18))
priceText = gui.CTkTextbox(priceFrame, font=("consolas", 18), height=30, width=80)
outputText = gui.CTkTextbox(outputTab, font=("consolas", 14))
summaryLabel = gui.CTkLabel(outputTab, text="Summary", font=("consolas", 18))
Load()
buttonFrame.pack(pady=10, padx=40)
searchButton.grid(row=0, column=0, padx=10)
myTab.pack(fill="both", expand=True)
priceFrame.pack(pady=10, padx=40)
priceLabel.grid(row=0, column=0, padx=10)
priceText.grid(row=0, column=1, padx=10)
inputText.pack(pady=10, padx=40, fill="both", expand=True)
summaryLabel.pack(pady=10, padx=40, fill="x")
outputText.pack(pady=10, padx=40, fill="both", expand=True)
root.mainloop()