Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Premature Call to Tkinter #354

Merged
merged 2 commits into from
Aug 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions leads/sft.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@


def mark_device(device: Device, system: str, *related: str, append: bool = True) -> None:
setattr(device, "__sft_marker__", getattr(device, "__sft_marker__") + [system, *related] if append and hasattr(
device, "__sft_marker__") else [system, *related])
setattr(device, "__sft_marker__", list(set(getattr(device, "__sft_marker__") + [
system, *related] if append and hasattr(device, "__sft_marker__") else [system, *related])))


def read_device_marker(device: Device) -> list[str] | None:
Expand Down
7 changes: 4 additions & 3 deletions leads_gui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
from typing import Callable as _Callable, Any as _Any
from customtkinter import set_default_color_theme as _set_default_color_theme

from leads import LEADS as _LEADS, Controller as _Controller, set_on_register_config as _set_on_register_config
from leads import LEADS as _LEADS, set_on_register_config as _set_on_register_config, \
get_controller as _get_controller, MAIN_CONTROLLER as _MAIN_CONTROLLER
from leads.types import OnRegister as _OnRegister
from leads_gui.config import *
from leads_gui.prototype import *
Expand Down Expand Up @@ -40,8 +41,8 @@ def _(cfg: Config) -> None:

def initialize(window: Window,
render: _Callable[[ContextManager], None],
leads: _LEADS[_Any],
main_controller: _Controller) -> ContextManager:
leads: _LEADS[_Any]) -> ContextManager:
main_controller = _get_controller(_MAIN_CONTROLLER)
ctx = ContextManager(window)
render(ctx)

Expand Down
23 changes: 14 additions & 9 deletions leads_gui/prototype.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
from numpy import lcm as _lcm
from screeninfo import get_monitors as _get_monitors

from leads import require_config as _require_config, DataContainer as _DataContainer
from leads import require_config as _require_config, DataContainer as _DataContainer, \
initialize_main as _initialize_main
from leads.comm import Server as _Server
from leads_gui.performance_checker import PerformanceChecker
from leads_gui.system import _ASSETS_PATH
Expand Down Expand Up @@ -372,17 +373,21 @@ def show(self) -> None:
finally:
self._active = True

def wrapper() -> None:
self._on_refresh(self)
for tag, fg in self._frequency_generators.items():
if not fg.attempt():
self.remove_frequency_generator(tag)
self._performance_checker.record_frame(self._last_interval)
def wrapper(init: bool) -> None:
if not init:
self._on_refresh(self)
for tag, fg in self._frequency_generators.items():
if not fg.attempt():
self.remove_frequency_generator(tag)
self._performance_checker.record_frame(self._last_interval)
elif getattr(self._master, "_window_exists"):
_initialize_main()
init = False
if self._active:
self._master.after(int((ni := self._performance_checker.next_interval()) * 1000), wrapper)
self._master.after(int((ni := self._performance_checker.next_interval()) * 1000), wrapper, init)
self._last_interval = ni

self._master.after(1, wrapper)
self._master.after(1, wrapper, True)
self._master.mainloop()

def kill(self) -> None:
Expand Down
10 changes: 4 additions & 6 deletions leads_vec/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
from screeninfo import get_monitors as _get_monitors

from leads import LEADS, SystemLiteral, require_config, register_context, DTCS, ABS, EBI, ATBS, GPSSpeedCorrection, \
ESCMode, get_controller, MAIN_CONTROLLER, L, EventListener, DataPushedEvent, UpdateEvent, has_device, \
GPS_RECEIVER, get_device, InterventionEvent, SuspensionEvent, Event, LEFT_INDICATOR, RIGHT_INDICATOR, SFT, \
initialize_main, format_duration, BRAKE_INDICATOR, REAR_VIEW_CAMERA, FRONT_VIEW_CAMERA, LEFT_VIEW_CAMERA, \
RIGHT_VIEW_CAMERA
ESCMode, L, EventListener, DataPushedEvent, UpdateEvent, has_device, GPS_RECEIVER, get_device, InterventionEvent, \
SuspensionEvent, Event, LEFT_INDICATOR, RIGHT_INDICATOR, SFT, format_duration, BRAKE_INDICATOR, REAR_VIEW_CAMERA, \
FRONT_VIEW_CAMERA, LEFT_VIEW_CAMERA, RIGHT_VIEW_CAMERA
from leads.comm import Callback, Service, start_server, create_server, my_ip_addresses, ConnectionBase
from leads_audio import DIRECTION_INDICATOR_ON, DIRECTION_INDICATOR_OFF, WARNING, CONFIRM
from leads_gui import RuntimeData, Window, GForceVar, FrequencyGenerator, Left, Color, Right, ContextManager, \
Expand Down Expand Up @@ -244,7 +243,7 @@ def switch_esc_mode(mode: str) -> None:
manager["esc"] = _CTkSegmentedButton(root, values=["STANDARD", "AGGRESSIVE", "SPORT", "OFF"], variable=var_esc,
command=switch_esc_mode, font=("Arial", cfg.font_size_small))

uim = initialize(w, render, ctx, get_controller(MAIN_CONTROLLER))
uim = initialize(w, render, ctx)

w.runtime_data().comm = start_server(create_server(cfg.comm_port, CommCallback(ctx, uim)), True)
if cfg.comm_stream:
Expand Down Expand Up @@ -431,7 +430,6 @@ def on_recover(e: SuspensionEvent) -> None:
for i in range(min(cfg.num_external_screens, len(_get_monitors()) - 1)):
add_secondary_window(uim, i + 1, var_lap_times, var_speed, var_speed_trend)
root.grid_rowconfigure(2, weight=1)
initialize_main()

def on_press(key: _Key | _KeyCode) -> None:
match key if isinstance(key, _Key) else key.char:
Expand Down
1 change: 1 addition & 0 deletions leads_vec/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class VeCController(Controller):
@override
def initialize(self, *parent_tags: str) -> None:
super().initialize(*parent_tags)
mark_device(self, "")
if not has_controller("pc"):
mark_device(self, "POWER", "BATT", "MOTOR", "BRAKE")
if not has_controller("wsc"):
Expand Down