Skip to content

Commit bb76762

Browse files
committed
Merge branch 'VEX-1_v1.3' into main
2 parents cec7dfb + 306f05f commit bb76762

File tree

6 files changed

+211
-24
lines changed

6 files changed

+211
-24
lines changed

src/VexTrack.py

Lines changed: 91 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from tkinter import ttk, messagebox
99
from addDiag import AddDiag
1010

11+
from updaterUpdate import *
1112
from datetime import *
1213

1314
import matplotlib
@@ -17,9 +18,10 @@
1718
from matplotlib.patches import Rectangle
1819

1920
windowSize = vars.WINDOW_GEOMETRY.split("x")
21+
checkNewUpdaterVersion()
2022

2123
with open(vars.VERSION_PATH, 'r') as f:
22-
versionString = f.read()
24+
versionString = f.readlines()[0]
2325

2426
root = tk.Tk()
2527
root.title(vars.WINDOW_TITLE + " " + versionString)
@@ -244,12 +246,15 @@
244246
# History
245247
# --------------------------------
246248

249+
historyListContainer = tk.Frame(historyTab)
250+
historyListContainer.pack(fill="both", expand=True)
251+
247252
historyStyle = ttk.Style()
248253
historyStyle.configure("history.Treeview", highlightthickness=0, bd=0, font=('TkDefaultFont', 10))
249254
historyStyle.configure("history.Treeview.Heading", font=('TkDefaultFont', 10,'bold'))
250255
historyStyle.layout("history.Treeview", [('history.Treeview.treearea', {'sticky': 'nswe'})])
251256

252-
history = ttk.Treeview(historyTab, columns=(1, 2, 3), show="headings", height="16", style="history.Treeview")
257+
history = ttk.Treeview(historyListContainer, columns=(1, 2, 3), show="headings", height="16", style="history.Treeview")
253258
history.pack(side=tk.LEFT, fill="both", expand=True)
254259

255260
history.heading(1, text="Description", anchor="w")
@@ -261,11 +266,14 @@
261266
history.column(3, anchor="e")
262267

263268
# Create history Scrollbar
264-
historyScrollbar = Scrollbar(historyTab, orient=VERTICAL, command=history.yview)
269+
historyScrollbar = Scrollbar(historyListContainer, orient=VERTICAL, command=history.yview)
265270
historyScrollbar.pack(side=tk.LEFT, fill="y")
266271

267272
history.configure(yscrollcommand=historyScrollbar.set)
268273

274+
historyBtnContainer = tk.Frame(historyTab)
275+
historyBtnContainer.pack(fill="x")
276+
269277
# ================================
270278
# Daily XP Container
271279
# ================================
@@ -353,6 +361,30 @@ def resetCallback():
353361
return
354362
return
355363

364+
def editElementCallback():
365+
currElementFocus = history.focus()
366+
currElement = history.item(currElementFocus)
367+
currElementID = history.index(currElementFocus)
368+
369+
if len(currElement["values"]) == 0:
370+
return
371+
372+
editDiag = AddDiag(root, "Edit Element", currElement["values"][0], currElement["values"][1].strip(" XP"))
373+
if editDiag.description != currElement["values"][0] or editDiag.xpAmount != currElement["values"][1].strip(" XP"):
374+
editElement(currElementID, editDiag.description, int(editDiag.xpAmount))
375+
376+
def deleteElementCallback():
377+
currElementFocus = history.focus()
378+
currElement = history.item(currElementFocus)
379+
currElementID = history.index(currElementFocus)
380+
381+
if len(currElement["values"]) == 0:
382+
return
383+
384+
res = messagebox.askquestion("Delete Element", "Are you sure, that you want to delete the selected element?\nDescription: " + currElement["values"][0] + "\nAmount: " + currElement["values"][1])
385+
if res == "yes":
386+
deleteElement(currElementID)
387+
356388
# --------------------------------
357389
# Init
358390
# --------------------------------
@@ -407,6 +439,51 @@ def addXP(description, amount):
407439

408440
writeConfig(vars.CONFIG_PATH, config)
409441

442+
def editElement(index, description, amount):
443+
config = readConfig(vars.CONFIG_PATH)
444+
historyLen = len(config["history"])
445+
446+
prevBPLevel = config["activeBPLevel"]
447+
448+
index = historyLen - 1 - index
449+
config["history"][index]["description"] = description
450+
config["history"][index]["amount"] = amount
451+
452+
config = recalcXP(config)
453+
deltaBP = prevBPLevel - config["activeBPLevel"]
454+
455+
if deltaBP > 0:
456+
for i in range(0, deltaBP, 1):
457+
messagebox.showinfo("Sorry", "You have lost Battlepass Level " + str(prevBPLevel - i - 1))
458+
elif deltaBP < 0:
459+
for i in range(0, deltaBP, -1):
460+
messagebox.showinfo("Congratulations", "Congratulations! You have unlocked Battlepass Level " + str(-1 * i + prevBPLevel))
461+
462+
writeConfig(vars.CONFIG_PATH, config)
463+
updateValues()
464+
465+
def deleteElement(index):
466+
config = readConfig(vars.CONFIG_PATH)
467+
historyLen = len(config["history"])
468+
469+
prevBPLevel = config["activeBPLevel"]
470+
471+
index = historyLen - 1 - index
472+
config["history"].pop(index)
473+
474+
config = recalcXP(config)
475+
deltaBP = prevBPLevel - config["activeBPLevel"]
476+
477+
if deltaBP > 0:
478+
for i in range(0, deltaBP, 1):
479+
messagebox.showinfo("Sorry", "You have lost Battlepass Level " + str(prevBPLevel - i - 1))
480+
elif deltaBP < 0:
481+
for i in range(0, deltaBP, -1):
482+
messagebox.showinfo("Congratulations", "Congratulations! You have unlocked Battlepass Level " + str(-1 * i + prevBPLevel))
483+
484+
writeConfig(vars.CONFIG_PATH, config)
485+
updateValues()
486+
410487
def updateGraph(config, epilogue, plot):
411488
plot.clear()
412489
timeAxis = []
@@ -463,10 +540,13 @@ def updateGraph(config, epilogue, plot):
463540
remainingDays = dateDelta.days
464541
dayDelta = duration - remainingDays
465542

466-
dailyProgress, dailyCollected, dailyRemaining, dailyTotal = calcDailyValues(config, epilogue)
543+
if date.fromtimestamp(config["history"][len(config["history"]) - 1]["time"]) == date.today(): offset = 1
544+
else: offset = 0
545+
467546
totalXPProgress, totalXPCollected, totalXPRemaining, totalXPTotal = calcTotalValues(config, epilogue)
547+
dailyTotal = round((totalXPTotal - yAxisYou[index - offset]) / (remainingDays - vars.BUFFER_DAYS))
468548

469-
yAxisDailyIdeal.append(totalXPCollected)
549+
yAxisDailyIdeal.append(yAxisYou[index - offset])
470550

471551
for i in range(1, remainingDays + 1):
472552
yAxisDailyIdeal.append(yAxisDailyIdeal[i - 1] + dailyTotal)
@@ -562,12 +642,17 @@ def updateValues():
562642
epilogueCheck = ttk.Checkbutton(buttonContainer, text="Epilogue", onvalue=1, offvalue=0, variable=epilogueVar, command=updateValues)
563643
epilogueCheck.pack(padx=8, pady=0, side=tk.RIGHT)
564644

645+
editBTN = ttk.Button(historyBtnContainer, text="Edit Element", command=editElementCallback)
646+
editBTN.pack(side=tk.RIGHT, fill="both", expand=True)
647+
648+
delBTN = ttk.Button(historyBtnContainer, text="Delete Element", command=deleteElementCallback)
649+
delBTN.pack(side=tk.LEFT, fill="both", expand=True)
650+
565651
# ================================
566652
# Main Loop
567653
# ================================
568654

569655
os.startfile(vars.UPDATER_PATH)
570-
571656
init()
572657

573658
while dailyBar == None:

src/addDiag.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
from tkinter import simpledialog, messagebox
33

44
class AddDiag(simpledialog.Dialog):
5-
def __init__(self, parent, title):
6-
self.xpAmount = None
7-
self.description = None
5+
def __init__(self, parent, title, description=None, amount=None):
6+
self.xpAmount = amount
7+
self.description = description
88
super().__init__(parent, title)
99

1010
def body(self, frame):
@@ -17,13 +17,17 @@ def body(self, frame):
1717
self.descriptionBox = Entry(self.descriptionContainer, width=32)
1818
self.descriptionBox.pack(padx=8, pady=0, side=LEFT)
1919

20+
if self.description != None: self.descriptionBox.insert(0, self.description)
21+
2022
self.xpAmountContainer = Frame(frame)
2123
self.xpAmountContainer.pack(padx=8, pady=8)
2224

2325
Label(self.xpAmountContainer, text="XP Amount").pack(padx=8, pady=0, side=LEFT)
2426
self.xpAmountBox = Entry(self.xpAmountContainer, width=32)
2527
self.xpAmountBox.pack(padx=8, pady=0, side=LEFT)
2628

29+
if self.xpAmount != None: self.xpAmountBox.insert(0, self.xpAmount)
30+
2731
return frame
2832

2933
def ok_pressed(self):

src/core.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,29 @@ def calcLevelValues(config, epilogue):
7878
levelRemaining = levelTotal - levelCollected
7979
levelProgress = round(levelCollected / levelTotal * 100)
8080

81-
return levelProgress, levelCollected, levelRemaining, levelTotal
81+
return levelProgress, levelCollected, levelRemaining, levelTotal
82+
83+
def recalcXP(config):
84+
collectedXP = 0
85+
86+
for i in range(0, len(config["history"])):
87+
collectedXP += int(config["history"][i]["amount"])
88+
89+
iteration = 2
90+
while collectedXP > 0:
91+
if iteration < vars.NUM_BPLEVELS:
92+
collectedXP -= vars.LEVEL2_OFFSET + iteration * vars.NUM_XP_PER_LEVEL
93+
elif iteration < vars.NUM_BPLEVELS + vars.NUM_EPLOGUE_LEVELS:
94+
collectedXP -= vars.NUM_EPLOGUE_XP_PER_LEVEL
95+
iteration += 1
96+
97+
iteration -= 1
98+
config["activeBPLevel"] = iteration
99+
100+
if iteration < vars.NUM_BPLEVELS:
101+
collectedXP += vars.LEVEL2_OFFSET + iteration * vars.NUM_XP_PER_LEVEL
102+
elif iteration < vars.NUM_BPLEVELS + vars.NUM_EPLOGUE_LEVELS:
103+
collectedXP += vars.NUM_EPLOGUE_XP_PER_LEVEL
104+
105+
config["cXP"] = collectedXP
106+
return config

src/updater.py

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,46 @@ def downloadNewVersion(versionString):
1616
with open(EXE_FILENAME, 'wb') as f:
1717
f.write(r.content)
1818

19+
content = []
20+
with open(VERSION_PATH, 'r') as f:
21+
content = f.readlines()
22+
23+
content[0] = versionString
24+
for i in range(0, len(content)):
25+
if i != len(content) - 1: content[i] += "\n"
26+
1927
with open(VERSION_PATH, 'w') as f:
20-
f.write(versionString)
28+
f.writelines(content)
2129

2230
def restartProgram():
2331
os.startfile(EXE_FILENAME)
2432

2533
def checkNewVersion():
26-
response = requests.get("https://api.github.com/repos/" + GITHUB_USER + "/" + GITHUB_REPO + "/releases/latest")
27-
latestVersionString = response.json()["tag_name"]
28-
2934
with open(VERSION_PATH, 'r') as f:
30-
versionString = f.read()
35+
versionString = f.readlines()[0]
3136

3237
versionNumber = versionString.split("v")[1]
33-
latestVersionNumber = latestVersionString.split("v")[1]
34-
35-
if(versionNumber < latestVersionNumber):
36-
res = messagebox.askquestion("Updater", "A new version is available: " + latestVersionString + "\nDo you want to update?")
37-
if res == "yes":
38-
downloadNewVersion(latestVersionString)
39-
messagebox.showinfo("Updater", "Update complete, program will restart now")
38+
39+
response = requests.get("https://api.github.com/repos/" + GITHUB_USER + "/" + GITHUB_REPO + "/releases")
40+
releases = response.json()
41+
42+
for r in releases:
43+
tokenized = r["name"].split()
44+
if tokenized[0] == GITHUB_REPO:
45+
latestVersionString = tokenized[1]
46+
latestVersionNumber = latestVersionString.split("v")[1]
47+
48+
if versionNumber > latestVersionNumber:
49+
break
50+
51+
if versionNumber < latestVersionNumber:
52+
res = messagebox.askquestion("Updater", "A new version is available: " + latestVersionString + "\nDo you want to update?")
53+
if res == "yes":
54+
downloadNewVersion(latestVersionString)
55+
messagebox.showinfo("Updater", "Update complete, program will restart now")
4056

41-
restartProgram()
57+
restartProgram()
58+
break
4259
root.destroy()
4360

4461
checkNewVersion()

src/updaterUpdate.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
from tkinter import *
2+
from tkinter import messagebox
3+
import os
4+
import requests
5+
from vars import *
6+
7+
root = Tk()
8+
root.withdraw()
9+
10+
def downloadNewUpdaterVersion(versionString):
11+
os.system("taskkill /f /im " + "Updater.exe")
12+
13+
url = "https://github.com/" + GITHUB_USER + "/" + GITHUB_REPO + "/releases/download/" + versionString + "/" + "Updater.exe"
14+
r = requests.get(url)
15+
16+
with open("Updater.exe", 'wb') as f:
17+
f.write(r.content)
18+
19+
content = []
20+
with open(VERSION_PATH, 'r') as f:
21+
content = f.readlines()
22+
23+
content[1] = versionString
24+
for i in range(0, len(content)):
25+
if i != len(content) - 1: content[i] += "\n"
26+
27+
with open(VERSION_PATH, 'w') as f:
28+
f.writelines(content)
29+
30+
def restartUpdater():
31+
os.startfile("Updater.exe")
32+
33+
def checkNewUpdaterVersion():
34+
with open(VERSION_PATH, 'r') as f:
35+
versionString = f.readlines()[1]
36+
37+
versionNumber = versionString.split("v")[1]
38+
response = requests.get("https://api.github.com/repos/" + GITHUB_USER + "/" + GITHUB_REPO + "/releases")
39+
releases = response.json()
40+
41+
for r in releases:
42+
tokenized = r["name"].split()
43+
if tokenized[0] == "Updater":
44+
latestVersionString = tokenized[1]
45+
latestVersionNumber = latestVersionString.split("v")[1]
46+
47+
if versionNumber > latestVersionNumber:
48+
break
49+
50+
if versionNumber < latestVersionNumber:
51+
downloadNewUpdaterVersion(latestVersionString)
52+
restartUpdater()
53+
break
54+
55+
root.destroy()

version

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
v1.2
1+
v1.3
2+
v1.1

0 commit comments

Comments
 (0)