mirror of
https://git.hiabuto.net/C3MA/CCMA.git
synced 2026-08-25 06:55:17 +02:00
feat: configure minimum splash duration
This commit is contained in:
+25
-1
@@ -1,6 +1,8 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import math
|
||||
import threading
|
||||
import time
|
||||
import tkinter as tk
|
||||
from collections.abc import Callable
|
||||
from dataclasses import dataclass
|
||||
@@ -33,6 +35,7 @@ class SplashScreen(tk.Toplevel):
|
||||
run_housekeeper: bool = True,
|
||||
monitor: MonitorBounds | None = None,
|
||||
housekeeper_settings: HousekeeperSettings | None = None,
|
||||
minimum_display_seconds: float = 5.0,
|
||||
):
|
||||
super().__init__(master)
|
||||
self.repository = repository
|
||||
@@ -41,6 +44,10 @@ class SplashScreen(tk.Toplevel):
|
||||
self.run_housekeeper = run_housekeeper
|
||||
self.monitor = monitor
|
||||
self.housekeeper_settings = housekeeper_settings
|
||||
self.minimum_display_seconds = (
|
||||
max(0.0, float(minimum_display_seconds)) if math.isfinite(float(minimum_display_seconds)) else 5.0
|
||||
)
|
||||
self.shown_at = time.monotonic()
|
||||
self._messages: Queue[tuple[str, object]] = Queue()
|
||||
self.overrideredirect(True)
|
||||
self.resizable(False, False)
|
||||
@@ -145,7 +152,15 @@ class SplashScreen(tk.Toplevel):
|
||||
def _finish(self, result: StartupResult) -> None:
|
||||
self.progress.stop()
|
||||
self._set_status(f"Bereit · {len(result.findings)} Vorgänge benötigen Aufmerksamkeit")
|
||||
self.after(350, lambda: self._complete(result))
|
||||
self._after_minimum(lambda: self._complete(result))
|
||||
|
||||
def _after_minimum(self, callback: Callable[[], None]) -> None:
|
||||
remaining_ms = _remaining_minimum_ms(
|
||||
self.shown_at,
|
||||
self.minimum_display_seconds,
|
||||
time.monotonic(),
|
||||
)
|
||||
self.after(remaining_ms, callback)
|
||||
|
||||
def _set_status(self, text: str) -> None:
|
||||
self.canvas.itemconfigure(self.status_item, text=text)
|
||||
@@ -156,6 +171,10 @@ class SplashScreen(tk.Toplevel):
|
||||
|
||||
def _fail(self, error: Exception) -> None:
|
||||
self.progress.stop()
|
||||
self._set_status("Start fehlgeschlagen")
|
||||
self._after_minimum(lambda: self._complete_error(error))
|
||||
|
||||
def _complete_error(self, error: Exception) -> None:
|
||||
self.destroy()
|
||||
self.on_error(error)
|
||||
|
||||
@@ -177,3 +196,8 @@ def centered_position(
|
||||
x = min(max(pointer_x - width // 2, screen_x), maximum_x)
|
||||
y = min(max(pointer_y - height // 2, screen_y), maximum_y)
|
||||
return x, y
|
||||
|
||||
|
||||
def _remaining_minimum_ms(started_at: float, minimum_seconds: float, now: float) -> int:
|
||||
remaining = max(0.0, minimum_seconds - max(0.0, now - started_at))
|
||||
return int(remaining * 1000 + 0.999)
|
||||
|
||||
Reference in New Issue
Block a user