mirror of
https://github.com/13hannes11/focus_annotator.git
synced 2024-09-03 23:21:01 +02:00
change image paths are handled relative from the data file
This commit is contained in:
22
src/main.rs
22
src/main.rs
@@ -13,6 +13,7 @@ pub use crate::ui::ImageUI;
|
||||
|
||||
use std::cell::{RefCell};
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
use std::sync::{Arc};
|
||||
|
||||
use adw::{prelude::*, Application};
|
||||
@@ -113,13 +114,20 @@ fn build_ui(app: &Application) {
|
||||
let mut state = state.borrow_mut();
|
||||
|
||||
state.replace_foucs_stacks(new_dataset);
|
||||
state.save_path = Some(
|
||||
filename.clone().as_path()
|
||||
.to_str()
|
||||
.expect("failed to convert filname to str")
|
||||
.to_string()
|
||||
);
|
||||
eprintln!("{}", state.save_path.clone().unwrap());
|
||||
state.file_name = filename.clone().as_path().file_name().map(|x| x.to_str().expect("failed to convert filname to str").to_string());
|
||||
state.root_path = filename.clone().as_path().parent().map(|x| x.to_str().expect("failed to convert filname to str").to_string());
|
||||
|
||||
match (state.root_path.clone(), state.file_name.clone()) {
|
||||
(Some(root_path), Some(file_name)) => {
|
||||
let path = Path::new(&root_path).join(Path::new(&file_name));
|
||||
eprintln!("{:?}", path);
|
||||
}
|
||||
(_,_) => {
|
||||
eprintln!("Path not properly set");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
image_ui.update(&state);
|
||||
}
|
||||
dialog.close();
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use std::io::Write;
|
||||
use std::path::Path;
|
||||
use std::{collections::HashMap, fs::File};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -10,7 +11,8 @@ pub struct State {
|
||||
stacks: Vec<AnnotationZStack>,
|
||||
stack_index: Option<usize>,
|
||||
pub image_index: Option<usize>,
|
||||
pub save_path: Option<String>,
|
||||
pub file_name: Option<String>,
|
||||
pub root_path: Option<String>,
|
||||
}
|
||||
|
||||
impl State {
|
||||
@@ -19,7 +21,8 @@ impl State {
|
||||
stacks: Vec::new(),
|
||||
stack_index: None,
|
||||
image_index: None,
|
||||
save_path: None,
|
||||
file_name: None,
|
||||
root_path: None,
|
||||
}
|
||||
}
|
||||
pub fn set_image_index(&mut self, image_index: Option<usize>) {
|
||||
@@ -93,7 +96,9 @@ impl State {
|
||||
}
|
||||
|
||||
pub fn save(&self) {
|
||||
if let Some(path) = self.save_path.clone() {
|
||||
match (self.root_path.clone(), self.file_name.clone()) {
|
||||
(Some(root_path), Some(file_name)) => {
|
||||
let path = Path::new(&root_path).join(Path::new(&file_name));
|
||||
match File::create(path) {
|
||||
Ok(mut file) => {
|
||||
let contents =
|
||||
@@ -109,11 +114,13 @@ impl State {
|
||||
eprintln!("{}", e.to_string());
|
||||
}
|
||||
};
|
||||
} else {
|
||||
}
|
||||
(_, _) => {
|
||||
// TODO: error dialogue
|
||||
eprintln!("No save path specified");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn previous(&mut self) {
|
||||
let len = self.stacks.len();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::sync::Arc;
|
||||
use std::{path::Path, sync::Arc};
|
||||
|
||||
use adw::{Application, ApplicationWindow, HeaderBar, SplitButton};
|
||||
use gtk::{
|
||||
@@ -196,19 +196,31 @@ impl ImageUI {
|
||||
}
|
||||
|
||||
pub fn update(&self, state: &State) {
|
||||
if let Some(annotation_image) = state.get_current_annotation_image() {
|
||||
self.update_image(&annotation_image);
|
||||
match (
|
||||
state.get_current_annotation_image(),
|
||||
state.root_path.clone(),
|
||||
) {
|
||||
(Some(annotation_image), Some(base_path)) => {
|
||||
self.update_image(&annotation_image, base_path)
|
||||
}
|
||||
(_, _) => {}
|
||||
}
|
||||
self.update_focus_scale(&state);
|
||||
}
|
||||
fn update_image(&self, annotation_image: &AnnotationImage) {
|
||||
self.individual
|
||||
.set_from_file(Some(annotation_image.image_path.clone()));
|
||||
self.center
|
||||
.set_from_file(Some(annotation_image.image_path.clone()));
|
||||
fn update_image(&self, annotation_image: &AnnotationImage, base_path: String) {
|
||||
self.individual.set_from_file(Some(
|
||||
Path::new(&base_path).join(Path::new(&annotation_image.image_path)),
|
||||
));
|
||||
self.center.set_from_file(Some(
|
||||
Path::new(&base_path).join(Path::new(&annotation_image.image_path)),
|
||||
));
|
||||
|
||||
for index in 0..annotation_image.neighbours.len() {
|
||||
self.neighbours[index].set_from_file(annotation_image.neighbours[index].clone());
|
||||
self.neighbours[index].set_from_file(
|
||||
annotation_image.neighbours[index]
|
||||
.clone()
|
||||
.map(|x| Path::new(&base_path).join(Path::new(&x))),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user