Skip to content

Commit a99aec1

Browse files
Implement basic quick actions screen
1 parent 6ea5b7f commit a99aec1

15 files changed

Lines changed: 148 additions & 83 deletions

File tree

example_configs/simulator.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,9 @@ heater_bed = [ 60, 70 ]
1313
[ui]
1414
dark_mode = true
1515
left_sidebar = ["files", "temperature", "move", "emergency_stop"]
16-
right_sidebar = ["fan", "macros", "console", "settings"]
16+
right_sidebar = ["fan", "macros", "console", "settings"]
17+
18+
[quick_actions]
19+
Restart = ["RESTART"]
20+
"Firmware Restart" = ["FIRMWARE_RESTART"]
21+
Home = ["G28"]

moonraker-rs/src/connector/websocket_write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl MoonrakerConnectionWriteLoop {
9292
&mut self,
9393
frame: &Mutex<Option<Frame<'static>>>,
9494
) -> Result<(), Error> {
95-
println!("Got raw frame to send");
95+
//println!("Got raw frame to send");
9696

9797
if let Some(frame) = frame.lock().await.take() {
9898
self.websocket_writer.write_frame(frame).await?;

src/config/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use std::collections::HashMap;
22

33
use crate::config::{MoonrakerConfig, OptionalGcodeCommands, OptionalUiConfig};
4-
use moonraker_rs::printer_objects::TemperatureConfiguration;
54
use serde::Deserialize;
65

76
use super::DisplayConfig;
@@ -13,4 +12,5 @@ pub struct Config {
1312
pub heater_presets: Option<HashMap<String, Vec<u32>>>,
1413
pub gcode_commands: Option<OptionalGcodeCommands>,
1514
pub ui: Option<OptionalUiConfig>,
15+
pub quick_actions: Option<HashMap<String, Vec<String>>>,
1616
}

src/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ async fn main() -> Result<(), Box<dyn Error>> {
104104
let ui_settings = &config.ui.unwrap_or(OptionalUiConfig::default());
105105
register_set_ui_settings(&ui, &ui_settings);
106106

107+
register_execute_quick_action(&ui, &config.quick_actions, &moonraker_connection);
108+
107109
tokio::task::block_in_place(|| {
108110
ui.run().unwrap();
109111
});

src/ui_functions/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub mod printer_firmware_restart;
1010
pub mod printer_execute_gcode_command;
1111
pub mod util_create_temperature_list;
1212
pub mod settings_set_ui_settings;
13+
pub mod quick_action_execute;
1314

1415
pub use util_format_bytes::*;
1516
pub use filesystem_download_thumbnail::*;
@@ -22,4 +23,5 @@ pub use printer_restart::*;
2223
pub use printer_firmware_restart::*;
2324
pub use printer_execute_gcode_command::*;
2425
pub use util_create_temperature_list::*;
25-
pub use settings_set_ui_settings::*;
26+
pub use settings_set_ui_settings::*;
27+
pub use quick_action_execute::*;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
use std::{collections::HashMap, sync::Arc};
2+
3+
use moonraker_rs::{moonraker_connection::MoonrakerConnection, requests::PrinterAdministrationRequestHandler};
4+
use slint::{ComponentHandle, ModelRc, SharedString, SharedVector, VecModel};
5+
6+
use crate::{AppWindow, QuickActions};
7+
8+
pub fn register_execute_quick_action(ui: &AppWindow, quick_actions: &Option<HashMap<String, Vec<String>>>, moonraker_connection: &Arc<MoonrakerConnection>)
9+
{
10+
let mut quick_actions_map: HashMap<String, String> = HashMap::new();
11+
let moonraker_connection = moonraker_connection.clone();
12+
13+
if let Some(quick_actions) = quick_actions
14+
{
15+
quick_actions.iter()
16+
.for_each(|f| {
17+
quick_actions_map.insert(
18+
f.0.clone(),
19+
f.1.join("\n"),
20+
);
21+
});
22+
}
23+
24+
let keys : Vec<SharedString> = quick_actions_map.keys().map(|f| SharedString::from(f)).collect();
25+
ui.global::<QuickActions>().set_quick_actions(ModelRc::new(VecModel::from(keys)));
26+
ui.global::<QuickActions>().on_execute_quick_action(move |f| {
27+
let moonraker_connection = moonraker_connection.clone();
28+
let gcode = match quick_actions_map.get(f.as_str())
29+
{
30+
Some(s) => s.clone(),
31+
None => return
32+
};
33+
34+
tokio::spawn(async move {
35+
if let Err(e) = moonraker_connection.run_gcode_script(&gcode).await
36+
{
37+
moonraker_connection.send_request_error(format!("Failed to send quick action '{}': {}", f.as_str(), e));
38+
}
39+
});
40+
});
41+
}

ui/assets/action.svg

Lines changed: 1 addition & 0 deletions
Loading

ui/components/ghost-button.slint

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,16 @@ export component GhostButton inherits VerticalLayout {
55
in property <color> text-color: Palette.foreground;
66
callback clicked;
77

8-
Rectangle {
8+
states [
9+
pressed when touch-area.pressed : {
10+
container.background: Palette.selection-background;
11+
}
12+
]
13+
14+
container := Rectangle {
915
height: t.height * 2;
1016
min-width: t.width * 1.5;
17+
border-radius: 10px;
1118
//background: red;
1219

1320
t := Text {
@@ -16,7 +23,7 @@ export component GhostButton inherits VerticalLayout {
1623
font-weight: 600;
1724
}
1825

19-
TouchArea {
26+
touch-area := TouchArea {
2027
clicked => { root.clicked(); }
2128
}
2229
}

ui/components/top-bar.slint

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export component TopBar inherits Rectangle {
88
background: Palette.alternate-background;
99

1010
HorizontalLayout {
11-
padding-top: 2px;
11+
padding-bottom: 2px;
1212
padding-left: 10px;
1313
padding-right: 10px;
1414
spacing: 10px;

ui/constants.slint

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ export global Icons {
2626
out property <image> quick_action: @image-url("assets/quickaction.svg");
2727
out property <image> settings: @image-url("assets/settings.svg");
2828
out property <image> temperature: @image-url("assets/temperature.svg");
29+
out property <image> action: @image-url("assets/action.svg");
2930
}

0 commit comments

Comments
 (0)