-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruntimer.py
More file actions
79 lines (69 loc) · 2.17 KB
/
runtimer.py
File metadata and controls
79 lines (69 loc) · 2.17 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
#!/usr/bin/env python3
# Made by Severnarch on GitHub
import tkinter as tk, time as _time, math, tkinter.font as tkf, os, psutil, keyboard
app = tk.Tk()
app.geometry("140x46")
app.config(bg="#000000")
app.title("Run Timer | 1.0.5")
app.attributes("-topmost", True)
app.resizable(False, False)
font = tkf.Font(**tkf.nametofont("TkFixedFont").configure())
font.configure(size=15)
hfnt = tkf.Font(**tkf.nametofont("TkFixedFont").configure())
hfnt.configure(size=9)
lbl = tk.Label(app, text="00:00:00.00", font=font, width=20, fg="#ff0000", bg="#000000", anchor='w')
lbl.place(x=1,y=0)
stm = tk.Label(app, text="STOPPED%sMB"%(" "*10), font=hfnt, width=20, fg="#ff0000", bg="#000000", anchor='w')
stm.place(x=0,y=22)
def time(t:float=0.01):
try:
ms = str(t).split(".")[1][0:2]
except IndexError:
ms = "00"
ss = str(math.floor(t%60))
mn = str(math.floor((t/60)%60))
hr = str(math.floor(((t/60)/60)%60))
return '%s:%s:%s.%s'%("0"+hr if len(hr) == 1 else hr,"0"+mn if len(mn) == 1 else mn,"0"+ss if len(ss) == 1 else ss,"0"+ms if len(ms) == 1 else ms)
durat = 0
reseq = False
state = 0
def loop(lt=_time.time()):
global reseq, durat
stxt = ""
match state:
case 0:
lbl.config(fg="#ff0000")
stm.config(fg="#ff0000")
stxt = "STOPPED"
case 1:
lbl.config(fg="#00ff00")
stm.config(fg="#00ff00")
if reseq:
reseq = False
durat = 0
lbl.config(text=time(durat))
stxt = "ACTIVE "
case 2:
lbl.config(fg="#ff7700")
stm.config(fg="#ff7700")
stxt = "PAUSED "
mem = str((psutil.Process().memory_full_info().rss/1024**2)/2*1.084).split(".")
mem = (" ~"+mem[0] if int(mem[0])<10 else " ~"+mem[0] if int(mem[0])<100 else "~"+mem[0])+"."+mem[1][0:2]
stm.config(text=stxt+(" "*3)+str(mem)+"MB")
app.after(50, lambda: loop(_time.time()))
def setstate(ntate):
global state, reseq
lbl.config(text=time(durat))
if state == 0 and ntate == 1:
reseq = True
state = ntate
keyboard.add_hotkey("Pause", lambda:setstate(1 if state == 2 else 2))
keyboard.add_hotkey("End", lambda:setstate(0 if state == 1 or state == 2 else 1))
def timeloop():
global durat
if state == 1:
durat = durat + 0.01
app.after(10,timeloop)
app.after(10, timeloop)
app.after(50, loop)
app.mainloop()