mypy things

pull/36045/head
Quantizr (Jimmy) 3 weeks ago
parent f4afe9c347
commit 2001898d8b
  1. 20
      tools/jotpluggler/layout.py
  2. 2
      tools/jotpluggler/pluggle.py
  3. 25
      tools/jotpluggler/views.py

@ -6,9 +6,9 @@ from openpilot.tools.jotpluggler.views import ViewPanel, TimeSeriesPanel
class LayoutNode(ABC):
def __init__(self, node_id: str = None):
def __init__(self, node_id: str | None = None):
self.node_id = node_id or str(uuid.uuid4())
self.tag = None
self.tag: str | None = None
@abstractmethod
def create_ui(self, parent_tag: str, width: int = -1, height: int = -1):
@ -88,14 +88,12 @@ class LeafNode(LayoutNode):
class SplitterNode(LayoutNode):
"""Splitter node that contains multiple child nodes"""
def __init__(self, children: list[LayoutNode], orientation: str = "horizontal", node_id: str = None):
def __init__(self, children: list[LayoutNode], orientation: str = "horizontal", node_id: str | None = None):
super().__init__(node_id)
self.children = children if children else []
self.orientation = orientation
self.child_proportions = [1.0 / len(self.children) for _ in self.children] if self.children else []
self.child_container_tags = [] # Track container tags for resizing (different from child tag)
self.child_container_tags: list[str] = [] # Track container tags for resizing
def preserve_data(self):
for child in self.children:
@ -194,7 +192,6 @@ class PlotLayoutManager:
self.data_manager = data_manager
self.playback_manager = playback_manager
self.scale = scale
self.root_node: LayoutNode = None
self.container_tag = "plot_layout_container"
self._initialize_default_layout()
@ -207,9 +204,8 @@ class PlotLayoutManager:
dpg.delete_item(self.container_tag)
with dpg.child_window(tag=self.container_tag, parent=parent_tag, border=False, width=-1, height=-1, no_scrollbar=True):
if self.root_node:
container_width, container_height = dpg.get_item_rect_size(self.container_tag)
self.root_node.create_ui(self.container_tag, container_width, container_height)
container_width, container_height = dpg.get_item_rect_size(self.container_tag)
self.root_node.create_ui(self.container_tag, container_width, container_height)
def on_viewport_resize(self):
if isinstance(self.root_node, SplitterNode):
@ -290,8 +286,8 @@ class PlotLayoutManager:
parent_width, parent_height = dpg.get_item_rect_size(parent_container)
node.create_ui(parent_container, parent_width, parent_height)
def _find_parent_and_index(self, target_node: LayoutNode) -> tuple: # TODO: probably can be stored in child
def search_recursive(node: LayoutNode, parent: LayoutNode = None, index: int = 0):
def _find_parent_and_index(self, target_node: LayoutNode): # TODO: probably can be stored in child
def search_recursive(node: LayoutNode | None, parent: LayoutNode | None = None, index: int = 0):
if node == target_node:
return parent, index
if isinstance(node, SplitterNode):

@ -34,7 +34,7 @@ class PlaybackManager:
self.current_time_s = max(0.0, min(time_s, self.duration_s))
self.last_indices.clear()
def update_time(self, delta_t: float) -> float:
def update_time(self, delta_t: float):
if self.is_playing:
self.current_time_s = min(self.current_time_s + delta_t, self.duration_s)
if self.current_time_s >= self.duration_s:

@ -32,21 +32,19 @@ class ViewPanel(ABC):
class TimeSeriesPanel(ViewPanel, Observer):
def __init__(self, data_manager: DataManager, playback_manager, panel_id: str = None):
def __init__(self, data_manager: DataManager, playback_manager, panel_id: str | None = None):
super().__init__(panel_id)
self.data_manager = data_manager
self.playback_manager = playback_manager
self.title = "Time Series Plot"
self.plotted_series: set[str] = set()
self.plot_tag = None
self.x_axis_tag = None
self.y_axis_tag = None
self.timeline_indicator_tag = None
self.plot_tag: str | None = None
self.x_axis_tag: str | None = None
self.y_axis_tag: str | None = None
self.timeline_indicator_tag: str | None = None
self._ui_created = False
# Store series data for restoration and legend management
self._preserved_series_data = [] # TODO: the way we do this right now doesn't make much sense
self._series_legend_tags = {} # Maps series_path to legend tag
self._preserved_series_data: list[tuple[str, tuple]] = [] # TODO: the way we do this right now doesn't make much sense
self._series_legend_tags: dict[str, str] = {} # Maps series_path to legend tag
self.data_manager.add_observer(self)
@ -110,7 +108,7 @@ class TimeSeriesPanel(ViewPanel, Observer):
if dpg.does_item_exist(series_tag):
dpg.configure_item(series_tag, label=legend_label)
def _add_series_with_data(self, series_path: str, rel_time_array, value_array):
def _add_series_with_data(self, series_path: str, rel_time_array, value_array) -> bool:
if series_path in self.plotted_series:
return False
@ -163,7 +161,7 @@ class TimeSeriesPanel(ViewPanel, Observer):
for series_path in self.plotted_series.copy():
self._update_series_data(series_path)
def _update_series_data(self, series_path: str):
def _update_series_data(self, series_path: str) -> bool:
time_value_data = self.data_manager.get_time_series_data(series_path)
if time_value_data is None:
return False
@ -189,17 +187,16 @@ class DataTreeNode:
def __init__(self, name: str, full_path: str = ""):
self.name = name
self.full_path = full_path
self.children = {}
self.children: dict[str, DataTreeNode] = {}
self.is_leaf = False
class DataTreeView(Observer):
def __init__(self, data_manager: DataManager, ui_lock: threading.Lock):
self.data_manager = data_manager
self.ui_lock = ui_lock
self.current_search = ""
self.data_tree = DataTreeNode(name="root")
self.active_leaf_nodes = []
self.active_leaf_nodes: list[DataTreeNode] = []
self.data_manager.add_observer(self)
def on_data_loaded(self, event: DataLoadedEvent):

Loading…
Cancel
Save