mirror of
https://github.com/13hannes11/focus_annotator.git
synced 2024-09-03 23:21:01 +02:00
split program setup logic into seperate functions
This commit is contained in:
54
src/main.rs
54
src/main.rs
@@ -1,5 +1,5 @@
|
|||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
use std::sync::Arc;
|
use std::sync::{Arc, Mutex};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
@@ -200,9 +200,25 @@ fn main() {
|
|||||||
adw::init();
|
adw::init();
|
||||||
});
|
});
|
||||||
|
|
||||||
application.connect_activate(|app| {
|
application.connect_startup(setup_shortcuts);
|
||||||
|
application.connect_activate(build_ui);
|
||||||
|
|
||||||
|
application.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn setup_shortcuts(app: &Application) {
|
||||||
|
app.set_accels_for_action("win.toggle_neighbour", &["G"]);
|
||||||
|
app.set_accels_for_action("win.increment_focus_scale", &["W"]);
|
||||||
|
app.set_accels_for_action("win.decrement_focus_scale", &["S"]);
|
||||||
|
app.set_accels_for_action("win.mark_focus", &["M"]);
|
||||||
|
app.set_accels_for_action("win.skip_focus", &["N"]);
|
||||||
|
app.set_accels_for_action("win.back_focus", &["B"]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fn build_ui(app: &Application) {
|
||||||
let current_z_stack_index = Arc::new(Cell::new(0));
|
let current_z_stack_index = Arc::new(Cell::new(0));
|
||||||
let mut annotaion_dataset = Vec::<AnnotationZStack>::new();
|
let annotaion_dataset = Arc::new(Mutex::new(Vec::<AnnotationZStack>::new()));
|
||||||
|
|
||||||
let mut z_stack = AnnotationZStack::new();
|
let mut z_stack = AnnotationZStack::new();
|
||||||
|
|
||||||
@@ -254,7 +270,7 @@ fn main() {
|
|||||||
],
|
],
|
||||||
));
|
));
|
||||||
|
|
||||||
annotaion_dataset.push(z_stack.clone());
|
annotaion_dataset.lock().unwrap().push(z_stack.clone());
|
||||||
|
|
||||||
{
|
{
|
||||||
let mut z_stack = AnnotationZStack::new();
|
let mut z_stack = AnnotationZStack::new();
|
||||||
@@ -277,7 +293,7 @@ fn main() {
|
|||||||
],
|
],
|
||||||
));
|
));
|
||||||
|
|
||||||
annotaion_dataset.push(z_stack.clone());
|
annotaion_dataset.lock().unwrap().push(z_stack.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////
|
//////////////////
|
||||||
@@ -447,7 +463,7 @@ fn main() {
|
|||||||
let filter = FileFilter::new();
|
let filter = FileFilter::new();
|
||||||
filter.add_pattern(r"*.json");
|
filter.add_pattern(r"*.json");
|
||||||
|
|
||||||
let file_chooser = FileChooserDialog::new(Some("Chose a data file!"), Some(&window), file_chooser_action, &buttons);
|
let file_chooser = Arc::new(FileChooserDialog::new(Some("Chose a data file!"), Some(&window), file_chooser_action, &buttons));
|
||||||
file_chooser.set_select_multiple(false);
|
file_chooser.set_select_multiple(false);
|
||||||
file_chooser.set_filter(&filter);
|
file_chooser.set_filter(&filter);
|
||||||
|
|
||||||
@@ -458,13 +474,16 @@ fn main() {
|
|||||||
let filename = file.path().expect("Couldn't get file path");
|
let filename = file.path().expect("Couldn't get file path");
|
||||||
let contents = fs::read_to_string(filename).expect("Something went wrong reading the file");
|
let contents = fs::read_to_string(filename).expect("Something went wrong reading the file");
|
||||||
|
|
||||||
let dataset : Vec<AnnotationZStack> = serde_json::from_str(&contents).unwrap();
|
let mut dataset : Vec<AnnotationZStack> = serde_json::from_str(&contents).unwrap();
|
||||||
|
eprintln!("{}", contents);
|
||||||
|
//annotaion_dataset.lock().unwrap().clear();
|
||||||
|
//annotaion_dataset.lock().unwrap().append(&mut dataset);
|
||||||
// TODO: update data after loading
|
// TODO: update data after loading
|
||||||
}
|
}
|
||||||
dialog.close();
|
dialog.close();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
open_button.connect_clicked(clone!(@weak window => move |_| {
|
open_button.connect_clicked(clone!(@weak window, @strong file_chooser => move |_| {
|
||||||
// TODO: actually open and load data
|
// TODO: actually open and load data
|
||||||
file_chooser.show();
|
file_chooser.show();
|
||||||
|
|
||||||
@@ -493,19 +512,20 @@ fn main() {
|
|||||||
mark_focus.connect_activate(clone!(@strong image_ui, @strong focus_scale, @strong current_z_stack_index, @strong annotaion_dataset => move |_, _| {
|
mark_focus.connect_activate(clone!(@strong image_ui, @strong focus_scale, @strong current_z_stack_index, @strong annotaion_dataset => move |_, _| {
|
||||||
eprintln! {"Focus Set!"};
|
eprintln! {"Focus Set!"};
|
||||||
let index = current_z_stack_index.as_ref().get();
|
let index = current_z_stack_index.as_ref().get();
|
||||||
|
annotaion_dataset.lock().unwrap()[index].best_index = Some(focus_scale.value() as usize);
|
||||||
|
|
||||||
save_annotation(&annotaion_dataset);
|
save_annotation(&annotaion_dataset.lock().unwrap());
|
||||||
next_image(current_z_stack_index.clone().as_ref(), annotaion_dataset.clone(), focus_scale.as_ref(), image_ui.as_ref());
|
next_image(current_z_stack_index.clone().as_ref(), annotaion_dataset.lock().unwrap().clone(), focus_scale.as_ref(), image_ui.as_ref());
|
||||||
}));
|
}));
|
||||||
|
|
||||||
let skip_focus = SimpleAction::new("skip_focus", None);
|
let skip_focus = SimpleAction::new("skip_focus", None);
|
||||||
skip_focus.connect_activate(clone!(@strong image_ui, @strong focus_scale, @strong current_z_stack_index, @strong annotaion_dataset => move |_, _| {
|
skip_focus.connect_activate(clone!(@strong image_ui, @strong focus_scale, @strong current_z_stack_index, @strong annotaion_dataset => move |_, _| {
|
||||||
next_image(current_z_stack_index.clone().as_ref(), annotaion_dataset.clone(), focus_scale.as_ref(), image_ui.as_ref());
|
next_image(current_z_stack_index.clone().as_ref(), annotaion_dataset.lock().unwrap().clone(), focus_scale.as_ref(), image_ui.as_ref());
|
||||||
}));
|
}));
|
||||||
|
|
||||||
let back_focus = SimpleAction::new("back_focus", None);
|
let back_focus = SimpleAction::new("back_focus", None);
|
||||||
back_focus.connect_activate(clone!(@strong image_ui, @strong focus_scale, @strong current_z_stack_index, @strong annotaion_dataset => move |_, _| {
|
back_focus.connect_activate(clone!(@strong image_ui, @strong focus_scale, @strong current_z_stack_index, @strong annotaion_dataset => move |_, _| {
|
||||||
previous_image(current_z_stack_index.clone().as_ref(), annotaion_dataset.clone(), focus_scale.as_ref(), image_ui.as_ref());
|
previous_image(current_z_stack_index.clone().as_ref(), annotaion_dataset.lock().unwrap().clone(), focus_scale.as_ref(), image_ui.as_ref());
|
||||||
}));
|
}));
|
||||||
|
|
||||||
window.add_action(&action_toggle_neighbour);
|
window.add_action(&action_toggle_neighbour);
|
||||||
@@ -516,14 +536,4 @@ fn main() {
|
|||||||
window.add_action(&back_focus);
|
window.add_action(&back_focus);
|
||||||
|
|
||||||
window.show();
|
window.show();
|
||||||
});
|
|
||||||
|
|
||||||
application.set_accels_for_action("win.toggle_neighbour", &["G"]);
|
|
||||||
application.set_accels_for_action("win.increment_focus_scale", &["W"]);
|
|
||||||
application.set_accels_for_action("win.decrement_focus_scale", &["S"]);
|
|
||||||
application.set_accels_for_action("win.mark_focus", &["M"]);
|
|
||||||
application.set_accels_for_action("win.skip_focus", &["N"]);
|
|
||||||
application.set_accels_for_action("win.back_focus", &["B"]);
|
|
||||||
|
|
||||||
application.run();
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user