Files
Beeps/beeptimes.py
2026-04-27 16:45:54 +01:00

328 lines
9.1 KiB
Python

import kivy
import time
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label
from kivy.clock import Clock
from kivy.lang import Builder
from kivy.properties import StringProperty
from kivy.core.window import Window
from kivy.config import Config
from tkinter import filedialog
from tkinter import simpledialog
from KivyOnTop import register_topmost, unregister_topmost
import configparser
from tkinter import *
#Configuration loading
config = configparser.ConfigParser()
config.read('Configuration.ini')
# Accessing variables from the 'GENERAL' section
Court_name = str(config['GENERAL']['CourtName'])
filePath = str(config['GENERAL']['BeepDetailsDirectory'])
print(filePath)
if filePath == "\\\\0.0.0.0\\RealTimeTennis\\DataBridge1\\Logs\\BounceDetails_1.log":
print(chr(27) + "[2J")
print("##################################################")
print("You have not changed the default Configuration.ini")
print("Please change the IP")
print("##################################################")
input()
exit()
# Accessing variables from the 'THRESHOLDS' section
Thresh1 = int(config['THRESHOLDS']['Thresh1'])
Thresh2 = int(config['THRESHOLDS']['Thresh2'])
Thresh3 = int(config['THRESHOLDS']['Thresh3'])
Thresh4 = int(config['THRESHOLDS']['Thresh4'])
Thresh5 = int(config['THRESHOLDS']['Thresh5'])
Thresh1str = str(config['THRESHOLDS']['Thresh1str'])
Thresh2str = str(config['THRESHOLDS']['Thresh2str'])
Thresh3str = str(config['THRESHOLDS']['Thresh3str'])
Thresh4str = str(config['THRESHOLDS']['Thresh4str'])
Thresh5str = str(config['THRESHOLDS']['Thresh5str'])
root = Tk()
root.withdraw()
print("Court Name: " + Court_name)
print("BeepDetails Directory: "+ filePath)
Builder.load_string("""
<MySec>:
rgba: (1,.2,.2,.2)
orientation: 'vertical'
Label:
id: Court_name
text: root.Court_name
font_size: 30
size_hint:(1,.2)
bold: True
canvas.before:
Color:
rgba: root.rgba
Rectangle:
size: self.size
pos: self.pos
Label:
id: kv_sec
text: root.seconds_string
font_size: 70
size_hint:(1,.5)
canvas.before:
Color:
rgba: root.rgba
Rectangle:
size: self.size
pos: self.pos
Label:
id: average
text: root.average
font_size: 25
size_hint:(1,.2)
canvas.before:
Color:
rgba: root.rgba
Rectangle:
size: self.size
pos: self.pos
Label:
id: info
text: root.info
font_size: 30
size_hint:(1,.2)
bold: True
canvas.before:
Color:
rgba: root.rgba
Rectangle:
size: self.size
pos: self.pos
""")
Window.size = (300, 300)
list = [0] * 10
class MySec(BoxLayout):
seconds_string = StringProperty('')
info = StringProperty('')
average = StringProperty('')
Court_name = StringProperty('')
Config.set('kivy','window_icon','./beeps.ico')
Config.set('graphics', 'always_on_top','1')
#Config.set('graphics','position', 'custom' )
Config.set('graphics','left',10)
Config.set('graphics','top',50)
Config.set('graphics','height',300)
Config.set('graphics','width',300)
Config.write()
#rgba = StringProperty('')
class MyApp(App):
def build(self):
self.title = 'Beeper V2.3'
Clock.schedule_interval(lambda dt: self.update_time(), 0.5)
return MySec()
def update_time(self):
if list[9] != 0:
del list[9]
else:
self.root.Court_name = Court_name
try:
with open(filePath,'r') as f:
lastLine = None
lines = f.readlines()
if lines[-1] != lastLine:
lastLine = lines[-1]
BC = lastLine.find("Bounce Count")
BC = lastLine[BC+14:BC+15]
BC = int(BC)
if BC == 0:
CN = lastLine.find("Crosses Net")
CN = lastLine[CN+13:CN+17]
if CN == 'true':
diff = lastLine.find("Time Diff")
diff = lastLine[diff+11:diff+19]
diff = float(diff)
diff = round((diff * 1000),1)
if diff <= Thresh1:
diff1 = (str(diff)+'ms')
self.root.seconds_string = diff1
self.root.info = Thresh1str
if list[0] != diff:
list.insert(0,diff)
avg = str(round((sum(list)/10),1))
self.root.average = ('10 beep average:' + avg)
self.root.rgba = [218/255,165/255,32/255,1]
else:
pass
elif ((diff > Thresh1) and (diff <= Thresh2)):
diff1 = (str(diff)+'ms')
self.root.seconds_string = diff1
self.root.info = Thresh2str
if list[0] != diff:
list.insert(0,diff)
avg = str(round((sum(list)/10),1))
self.root.average = ('10 beep average:' + avg)
self.root.rgba = [19/255,229/255,19/255,1]
else:
pass
elif ((diff > Thresh2) and (diff <= Thresh3)):
diff1 = (str(diff)+'ms')
self.root.seconds_string = diff1
self.root.info = Thresh3str
if list[0] != diff:
list.insert(0,diff)
avg = str(round((sum(list)/10),1))
self.root.average = ('10 beep average:' + avg)
self.root.rgba = [235/255,116/255,19/255,1]
else:
pass
elif ((diff > Thresh3) and (diff <= Thresh4)):
diff1 = (str(diff)+'ms')
self.root.seconds_string = diff1
self.root.info = Thresh4str
if list[0] != diff:
list.insert(0,diff)
avg = str(round((sum(list)/10),1))
self.root.average = ('10 beep average:' + avg)
self.root.rgba = [219/255,0/255,0/255,1]
else:
pass
elif diff > Thresh5:
diff1 = (str(diff)+'ms')
self.root.seconds_string = diff1
self.root.info = Thresh5str
if list[0] != diff:
list.insert(0,diff)
avg = str(round((sum(list)/10),1))
self.root.average = ('10 beep average:' + avg)
self.root.rgba = [90/255,4/255,4/255,1]
else:
pass
else:
pass
else:
pass
except:
print(chr(27) + "[2J")
print("#################################################################################")
print(filePath + "Is not reachable, please check its accessible through file explorer")
input()
exit()
if __name__ == '__main__':
MyApp().run()