10
10
from .._spawn import _spawn_viewer
11
11
from ..datatypes import BoolLike , EntityPathLike , Float32ArrayLike , Utf8ArrayLike , Utf8Like
12
12
from ..recording_stream import RecordingStream
13
+ from ..time import to_nanos , to_nanos_since_epoch
13
14
from .archetypes import (
14
15
ContainerBlueprint ,
15
16
PanelBlueprint ,
19
20
ViewportBlueprint ,
20
21
)
21
22
from .components import PanelState , PanelStateLike
22
- from .time import to_nanos , to_nanos_since_epoch
23
23
24
24
if TYPE_CHECKING :
25
+ from datetime import datetime , timedelta
26
+
27
+ import numpy as np
28
+
25
29
from ..memory import MemoryRecording
26
30
from .components .container_kind import ContainerKindLike
27
31
@@ -430,15 +434,15 @@ class TimePanel(Panel):
430
434
"""The state of the time panel."""
431
435
432
436
def __init__ (
433
- self ,
434
- * ,
435
- expanded : bool | None = None ,
436
- state : PanelStateLike | None = None ,
437
- timeline : Utf8Like | None = None ,
438
- sequence_cursor : int | None = None ,
439
- duration_cursor : int | float | timedelta | np .timedelta64 | None = None ,
440
- timestamp_cursor : int | float | datetime | np .datetime64 | None = None ,
441
- ) -> None :
437
+ self ,
438
+ * ,
439
+ expanded : bool | None = None ,
440
+ state : PanelStateLike | None = None ,
441
+ timeline : Utf8Like | None = None ,
442
+ sequence_cursor : int | None = None ,
443
+ duration_cursor : int | float | timedelta | np .timedelta64 | None = None ,
444
+ timestamp_cursor : int | float | datetime | np .datetime64 | None = None ,
445
+ ) -> None :
442
446
"""
443
447
Construct a new time panel.
444
448
@@ -454,32 +458,47 @@ def __init__(
454
458
timeline:
455
459
What timeline the timepanel should display.
456
460
461
+ sequence_cursor:
462
+ The time cursor for a sequence timeline.
463
+
464
+ duration_cursor:
465
+ The time cursor for a duration timeline.
466
+
467
+ timestamp_cursor:
468
+ The time cursor for a timestamp timeline.
469
+
457
470
"""
458
- if sum (x is not None for x in (sequence , duration , timestamp )) > 1 :
471
+ if sum (x is not None for x in (sequence_cursor , duration_cursor , timestamp_cursor )) > 1 :
459
472
raise ValueError (
460
- f "At most one of `sequence`, `duration`, and `timestamp` must be set" ,
473
+ "At most one of `sequence`, `duration`, and `timestamp` must be set" ,
461
474
)
462
475
463
476
super ().__init__ (blueprint_path = "time_panel" , expanded = expanded , state = state )
464
477
self .timeline = timeline
465
478
466
479
if sequence_cursor is not None :
467
- self .time = sequence
480
+ self .time = sequence_cursor
468
481
elif duration_cursor is not None :
469
- self .time = to_nanos (duration )
482
+ self .time = to_nanos (duration_cursor )
470
483
elif timestamp_cursor is not None :
471
- self .time = to_nanos_since_epoch (timestamp )
484
+ self .time = to_nanos_since_epoch (timestamp_cursor )
472
485
473
486
def _log_to_stream (self , stream : RecordingStream ) -> None :
474
487
"""Internal method to convert to an archetype and log to the stream."""
475
488
arch = TimePanelBlueprint (
476
489
state = self .state ,
477
490
timeline = self .timeline ,
478
- time = self .time ,
479
491
)
480
492
481
493
stream .log (self .blueprint_path (), arch ) # type: ignore[attr-defined]
482
494
495
+ if self .time is not None :
496
+ static_arch = TimePanelBlueprint (
497
+ time = self .time
498
+ )
499
+
500
+ stream .log (self .blueprint_path (), static_arch , static = True )
501
+
483
502
484
503
ContainerLike = Union [Container , View ]
485
504
"""
0 commit comments