Skip to content

Commit ad9bb43

Browse files
committed
test and fix setting timeline/time from python
1 parent 287e056 commit ad9bb43

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+97
-116
lines changed

crates/viewer/re_viewer/src/app_blueprint.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ use re_chunk::{Chunk, RowId};
44
use re_chunk_store::LatestAtQuery;
55
use re_entity_db::EntityDb;
66
use re_log_types::EntityPath;
7-
use re_types::blueprint::{
8-
archetypes::{PanelBlueprint, TimePanelBlueprint},
9-
components::PanelState,
7+
use re_types::{
8+
AsComponents,
9+
blueprint::{
10+
archetypes::{PanelBlueprint, TimePanelBlueprint},
11+
components::PanelState,
12+
},
1013
};
1114
use re_viewer_context::{
1215
CommandSender, SystemCommand, SystemCommandSender as _, TIME_PANEL_PATH,
@@ -234,12 +237,14 @@ impl AppBlueprint<'_> {
234237

235238
let timepoint = blueprint_timepoint_for_writes(blueprint_db);
236239

240+
let component_update: &dyn AsComponents = if panel_name == TIME_PANEL_PATH {
241+
&TimePanelBlueprint::update_fields().with_state(value)
242+
} else {
243+
&PanelBlueprint::update_fields().with_state(value)
244+
};
245+
237246
let chunk = Chunk::builder(entity_path)
238-
.with_archetype(
239-
RowId::new(),
240-
timepoint,
241-
&PanelBlueprint::update_fields().with_state(value),
242-
)
247+
.with_archetype(RowId::new(), timepoint, component_update)
243248
.build()
244249
// All builtin types, no reason for this to ever fail.
245250
.expect("Failed to build chunk.");

examples/python/blueprint/blueprint.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,26 @@ def main() -> None:
3939
),
4040
rrb.BlueprintPanel(state="collapsed"),
4141
rrb.SelectionPanel(state="collapsed"),
42-
rrb.TimePanel(state="collapsed"),
42+
rrb.TimePanel(state="collapsed", timeline="custom", sequence_cursor=15),
4343
auto_views=args.auto_views,
4444
)
4545

4646
rr.init("rerun_example_blueprint", spawn=True, default_blueprint=blueprint)
4747

48+
rr.set_time("custom", sequence=0)
49+
4850
img = np.zeros([128, 128, 3], dtype="uint8")
4951
for i in range(8):
5052
img[(i * 16) + 4 : (i * 16) + 12, :] = (0, 0, 200)
5153
rr.log("image", rr.Image(img))
54+
55+
rr.set_time("custom", sequence=10)
5256
rr.log(
5357
"rect/0",
5458
rr.Boxes2D(mins=[16, 16], sizes=[64, 64], labels="Rect0", colors=(255, 0, 0)),
5559
)
60+
61+
rr.set_time("custom", sequence=20)
5662
rr.log(
5763
"rect/1",
5864
rr.Boxes2D(mins=[48, 48], sizes=[64, 64], labels="Rect1", colors=(0, 255, 0)),

rerun_py/rerun_sdk/rerun/_baseclasses.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import numpy.typing as npt
99
import pyarrow as pa
1010
from attrs import define, fields
11-
1211
from rerun_bindings import ComponentDescriptor
1312

1413
from .error_utils import catch_and_log_exceptions

rerun_py/rerun_sdk/rerun/_properties.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from typing import TYPE_CHECKING
44

55
import rerun_bindings as bindings
6+
67
from rerun._log import log
78
from rerun.error_utils import catch_and_log_exceptions
89

rerun_py/rerun_sdk/rerun/_send_columns.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44

55
import numpy as np
66
import pyarrow as pa
7-
from typing_extensions import deprecated # type: ignore[misc, unused-ignore]
8-
97
import rerun_bindings as bindings
8+
from typing_extensions import deprecated # type: ignore[misc, unused-ignore]
109

1110
from ._baseclasses import Archetype, ComponentColumn, ComponentDescriptor
1211
from .error_utils import catch_and_log_exceptions

rerun_py/rerun_sdk/rerun/archetypes/asset_video_ext.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55

66
import numpy as np
77
import numpy.typing as npt
8-
from typing_extensions import deprecated
9-
108
import rerun_bindings as bindings
9+
from typing_extensions import deprecated
1110

1211
from ..error_utils import catch_and_log_exceptions
1312

rerun_py/rerun_sdk/rerun/blueprint/api.py

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from .._spawn import _spawn_viewer
1111
from ..datatypes import BoolLike, EntityPathLike, Float32ArrayLike, Utf8ArrayLike, Utf8Like
1212
from ..recording_stream import RecordingStream
13+
from ..time import to_nanos, to_nanos_since_epoch
1314
from .archetypes import (
1415
ContainerBlueprint,
1516
PanelBlueprint,
@@ -19,9 +20,12 @@
1920
ViewportBlueprint,
2021
)
2122
from .components import PanelState, PanelStateLike
22-
from .time import to_nanos, to_nanos_since_epoch
2323

2424
if TYPE_CHECKING:
25+
from datetime import datetime, timedelta
26+
27+
import numpy as np
28+
2529
from ..memory import MemoryRecording
2630
from .components.container_kind import ContainerKindLike
2731

@@ -430,15 +434,15 @@ class TimePanel(Panel):
430434
"""The state of the time panel."""
431435

432436
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:
442446
"""
443447
Construct a new time panel.
444448
@@ -454,32 +458,47 @@ def __init__(
454458
timeline:
455459
What timeline the timepanel should display.
456460
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+
457470
"""
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:
459472
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",
461474
)
462475

463476
super().__init__(blueprint_path="time_panel", expanded=expanded, state=state)
464477
self.timeline = timeline
465478

466479
if sequence_cursor is not None:
467-
self.time = sequence
480+
self.time = sequence_cursor
468481
elif duration_cursor is not None:
469-
self.time = to_nanos(duration)
482+
self.time = to_nanos(duration_cursor)
470483
elif timestamp_cursor is not None:
471-
self.time = to_nanos_since_epoch(timestamp)
484+
self.time = to_nanos_since_epoch(timestamp_cursor)
472485

473486
def _log_to_stream(self, stream: RecordingStream) -> None:
474487
"""Internal method to convert to an archetype and log to the stream."""
475488
arch = TimePanelBlueprint(
476489
state=self.state,
477490
timeline=self.timeline,
478-
time = self.time,
479491
)
480492

481493
stream.log(self.blueprint_path(), arch) # type: ignore[attr-defined]
482494

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+
483502

484503
ContainerLike = Union[Container, View]
485504
"""

rerun_py/rerun_sdk/rerun/dataframe.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from typing import TYPE_CHECKING, Any
55

66
import pyarrow as pa
7-
87
from rerun_bindings import (
98
ComponentColumnDescriptor as ComponentColumnDescriptor,
109
ComponentColumnSelector as ComponentColumnSelector,

rerun_py/rerun_sdk/rerun/sinks.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
import logging
44
from typing import TYPE_CHECKING, Union
55

6-
from typing_extensions import deprecated
7-
86
import rerun_bindings as bindings
9-
from rerun.blueprint.api import BlueprintLike, create_in_memory_blueprint
10-
from rerun.recording_stream import RecordingStream, get_application_id
117
from rerun_bindings import (
128
FileSink,
139
GrpcSink,
1410
)
11+
from typing_extensions import deprecated
12+
13+
from rerun.blueprint.api import BlueprintLike, create_in_memory_blueprint
14+
from rerun.recording_stream import RecordingStream, get_application_id
1515

1616
from ._spawn import _spawn_viewer
1717

rerun_py/tests/unit/test_annotation_context.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from typing import TYPE_CHECKING
44

55
import pytest
6+
import rerun as rr
67
from rerun.components import AnnotationContext, AnnotationContextLike
78
from rerun.datatypes import (
89
AnnotationInfo,
@@ -16,8 +17,6 @@
1617
Utf8,
1718
)
1819

19-
import rerun as rr
20-
2120
if TYPE_CHECKING:
2221
from collections.abc import Sequence
2322

0 commit comments

Comments
 (0)