Skip to content

Commit

Permalink
Add basic support for in-app "Getting Started" guides
Browse files Browse the repository at this point in the history
  • Loading branch information
abey79 committed Oct 11, 2023
1 parent 68e4d2e commit 7af2de0
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 5 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/re_viewer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ re_log_types.workspace = true
re_log.workspace = true
re_memory.workspace = true
re_renderer = { workspace = true, default-features = false }
re_sdk.workspace = true
re_smart_channel.workspace = true
re_space_view_bar_chart.workspace = true
re_space_view_spatial.workspace = true
Expand Down
7 changes: 7 additions & 0 deletions crates/re_viewer/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,13 @@ impl App {
}
}

SystemCommand::LoadLogMessage(mut log_messages) => {
for log_msg in log_messages.drain(..) {
let store_db = store_hub.store_db_mut(log_msg.store_id());
store_db.add(&log_msg).unwrap();
}
}

SystemCommand::ResetViewer => self.reset(store_hub, egui_ctx),
SystemCommand::UpdateBlueprint(blueprint_id, updates) => {
let blueprint_db = store_hub.store_db_mut(&blueprint_id);
Expand Down
1 change: 1 addition & 0 deletions crates/re_viewer/src/ui/welcome_screen/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod example_page;
mod python_quick_start;
mod welcome_page;

use egui::Widget;
Expand Down
88 changes: 88 additions & 0 deletions crates/re_viewer/src/ui/welcome_screen/python_quick_start.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
use re_viewer_context::{SystemCommand, SystemCommandSender};

pub(super) fn python_quick_start(
command_sender: &re_viewer_context::CommandSender,
) -> re_sdk::RecordingStreamResult<()> {
let (rec, storage) = re_sdk::RecordingStreamBuilder::new("Python Getting Started").memory()?;

rec.log(
"markdown",
&re_sdk::TextDocument::new(
r#"# Python Quick Start
## Installing the Rerun SDK
The Rerun SDK is available on [PyPI](https://pypi.org/) under the
[`rerun-sdk`](https://pypi.org/project/rerun-sdk/) name. It can be installed like any other
Python package:
```sh
pip3 install rerun-sdk
```
## Try out the viewer
The Rerun SDK comes with a demo that can be used to try the viewer. You can send a demo recording
to this viewer using the following command:
```sh
python3 -m rerun_sdk.demo --connect
```
This will open a new recording that looks like this:
![Demo recording](https://static.rerun.io/quickstart2_simple_cube/632a8f1c79f70a2355fad294fe085291fcf3a8ae/768w.png)
## Logging your own data
Instead of a pre-packaged demo, you can log your own data. Copy and paste the following snippet in a new
Python file and execute it to create a new recording in this viewer:
```python
import rerun as rr
import numpy as np
# Initialize the SDK and give our recording a unique name
rr.init("my_own_data")
# Connect to a local viewer using the default port
rr.connect()
# Create some data
SIZE = 10
pos_grid = np.meshgrid(*[np.linspace(-10, 10, SIZE)]*3)
positions = np.vstack([d.reshape(-1) for d in pos_grid]).T
col_grid = np.meshgrid(*[np.linspace(0, 255, SIZE)]*3)
colors = np.vstack([c.reshape(-1) for c in col_grid]).astype(np.uint8).T
# Log the data
rr.log(
# name under which this entity is logged (known as "entity path")
"my_points",
# log data as a 3D point cloud archetype
rr.Points3D(positions, colors=colors, radii=0.5)
)
```
## How does it work?
TBC
"#
.trim(),
)
.with_media_type(re_sdk::MediaType::markdown()),
)?;

let log_msgs = storage.take();
let store_id = rec.store_info().map(|info| info.store_id.clone());
command_sender.send_system(SystemCommand::LoadLogMessage(log_msgs));
if let Some(store_id) = store_id {
command_sender.send_system(SystemCommand::SetRecordingId(store_id));
}

Ok(())
}
13 changes: 9 additions & 4 deletions crates/re_viewer/src/ui/welcome_screen/welcome_page.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use super::{large_text_button, status_strings, url_large_text_button, WelcomeScreenResponse};
use super::{
large_text_button, python_quick_start::python_quick_start, status_strings,
url_large_text_button, WelcomeScreenResponse,
};
use egui::{NumExt, Ui};
use re_log_types::LogMsg;
use re_smart_channel::ReceiveSet;
use re_ui::UICommandSender;

//const CPP_QUICKSTART: &str = "https://www.rerun.io/docs/getting-started/cpp";
const PYTHON_QUICKSTART: &str = "https://www.rerun.io/docs/getting-started/python";
const RUST_QUICKSTART: &str = "https://www.rerun.io/docs/getting-started/rust";
const SPACE_VIEWS_HELP: &str = "https://www.rerun.io/docs/getting-started/viewer-walkthrough";

Expand Down Expand Up @@ -60,7 +61,11 @@ fn onboarding_content_ui(
add_buttons: Box::new(|ui: &mut egui::Ui| {
// TODO(ab): activate when C++ is ready!
// url_large_text_button(ui, "C++", CPP_QUICKSTART);
url_large_text_button(ui, "Python", PYTHON_QUICKSTART);
if large_text_button(ui, "Python").clicked() {
if let Err(err) = python_quick_start(command_sender) {
re_log::error!("Failed to load Python quick start: {}", err);
}
}
url_large_text_button(ui, "Rust", RUST_QUICKSTART);

false
Expand Down
5 changes: 4 additions & 1 deletion crates/re_viewer_context/src/command_sender.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use re_data_source::DataSource;
use re_log_types::{DataRow, StoreId};
use re_log_types::{DataRow, LogMsg, StoreId};
use re_ui::{UICommand, UICommandSender};

// ----------------------------------------------------------------------------
Expand All @@ -10,6 +10,9 @@ pub enum SystemCommand {
/// Load some data.
LoadDataSource(DataSource),

/// Load some log messages.
LoadLogMessage(Vec<LogMsg>),

/// Reset the `Viewer` to the default state
ResetViewer,

Expand Down

0 comments on commit 7af2de0

Please sign in to comment.