-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXBRBTimer.pyw
More file actions
79 lines (65 loc) · 2.4 KB
/
XBRBTimer.pyw
File metadata and controls
79 lines (65 loc) · 2.4 KB
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
import PySimpleGUI as sg
import json
import keyboard
import requests
import os
import time
# ----- Setting up the directory -----
home_dir = os.path.expanduser("~")
documents_path = os.path.join(home_dir, "Documents")
target_dir = os.path.join(documents_path, "Ryzz3nn", "BRBTimer")
if not os.path.exists(target_dir):
os.makedirs(target_dir)
# ---------------------------------------------------------------
CURRENT_VERSION = "v1.0"
GITHUB_REPO_API_URL = "https://api.github.com/repos/razzeking/BRBTimer/releases/latest"
sg.theme('DarkBrown4')
timer_running = False
start_time = None
duration = 0
def check_for_updates():
try:
response = requests.get(GITHUB_REPO_API_URL)
response.raise_for_status()
latest_release = response.json()
latest_version = latest_release['tag_name']
if latest_version > CURRENT_VERSION:
return True, latest_version
else:
return False, None
except requests.RequestException:
return False, None
def format_time(seconds):
mins, secs = divmod(seconds, 60)
return f"{mins:02d}:{secs:02d}"
layout = [
[sg.Text("BRB Timer", font=("bahnschrift Condensed", 24), justification='center')],
[sg.HorizontalSeparator()],
[sg.Text("Timer", font=("bahnschrift Condensed", 20), justification='left')],
[sg.Text("00:00", size=(5, 1), key='-TIMER-', font=("bahnschrift Condensed", 14))],
[sg.Button("Start", key="-START-"), sg.Button("Reset", key="-RESET-")]
]
window = sg.Window("BRBTimer • {}".format(CURRENT_VERSION), layout, finalize=True, resizable=True)
while True:
event, values = window.read(timeout=100)
if timer_running:
elapsed_time = time.time() - start_time
window['-TIMER-'].update(format_time(int(elapsed_time)))
if event == sg.WIN_CLOSED:
break
elif event == "-START-":
if not timer_running:
start_time = time.time()
timer_running = True
window["-START-"].update(text="Pause")
else:
timer_running = False
duration += time.time() - start_time
window["-START-"].update(text="Start")
elif event == "-RESET-":
timer_running = False
start_time = None
duration = 0
window["-START-"].update(text="Start")
window['-TIMER-'].update("00:00")
window.close()