Wobuzz/wobuzz/utils.py

38 lines
1,016 B
Python

#!/usr/bin/python3
import os
from pathlib import Path
class Utils:
home_path = str(Path.home())
wobuzz_location = os.path.dirname(os.path.abspath(__file__))
settings_location = f"{wobuzz_location}/settings.json"
def __init__(self, app):
self.app = app
def format_time(self, ms):
seconds = int(ms / 1000) % 60
minutes = int(ms / (1000 * 60)) % 60
hours = int(ms / (1000 * 60 * 60))
seconds_str, minutes_str, hours_str = ("",) * 3 # create empty strings
if hours > 0:
hours_str = f"{hours}:"
minutes_str = f"{minutes}:".zfill(2)
seconds_str = f"{seconds}".zfill(2)
output = hours_str + minutes_str + seconds_str
return output
def on_close(self, event):
self.app.settings.window_size = (self.app.gui.window.width(), self.app.gui.window.height())
self.app.settings.window_maximized = self.app.gui.window.isMaximized()
self.app.settings.save(self.settings_location)