Update gui.rs

This commit is contained in:
KeksNino
2025-03-21 21:54:53 +01:00
parent a401c290ea
commit b36e641ffd
+34 -28
View File
@@ -3,15 +3,18 @@ use gtk::{
Application, ApplicationWindow, Box as GtkBox, Button, FileChooserAction, FileChooserDialog, Application, ApplicationWindow, Box as GtkBox, Button, FileChooserAction, FileChooserDialog,
Image, Orientation, PolicyType, ResponseType, ScrolledWindow, Image, Orientation, PolicyType, ResponseType, ScrolledWindow,
}; };
use std::cell::RefCell;
use std::path::PathBuf;
use std::process::Command; use std::process::Command;
use std::rc::Rc;
use walkdir::WalkDir; use walkdir::WalkDir;
const APP_ID: &str = "org.gtk_rs.Example"; const APP_ID: &str = "sieg_heil";
fn build_ui(app: &Application) { fn build_ui(app: &Application) {
let window = ApplicationWindow::builder() let window = ApplicationWindow::builder()
.application(app) .application(app)
.title("Images in Rows of 5") .title("Linux Wallpaper Engine GUI")
.default_width(800) .default_width(800)
.default_height(600) .default_height(600)
.build(); .build();
@@ -20,9 +23,35 @@ fn build_ui(app: &Application) {
wrapper_box.set_hexpand(true); wrapper_box.set_hexpand(true);
wrapper_box.set_vexpand(true); wrapper_box.set_vexpand(true);
// FILE CHOOSER BUTTON AND DIALOG
let button = Button::with_label("Folder"); let button = Button::with_label("Folder");
wrapper_box.append(&button); wrapper_box.append(&button);
let window_weak = window.downgrade();
button.connect_clicked(move |_| {
if let Some(window) = window_weak.upgrade() {
let dialog = FileChooserDialog::new(
Some("Select Workshop Folder"),
Some(&window),
FileChooserAction::Open,
&[
("Cancel", ResponseType::Cancel),
("Open", ResponseType::Accept),
],
);
dialog.connect_response(move |dialog, response| {
if response == ResponseType::Accept {
if let Some(file_path) = dialog.file().and_then(|f| f.path()) {
println!("Selected file: {}", file_path.display());
}
}
dialog.close();
});
dialog.present();
}
});
let scrolled_window = ScrolledWindow::builder() let scrolled_window = ScrolledWindow::builder()
.hscrollbar_policy(PolicyType::Never) .hscrollbar_policy(PolicyType::Never)
.vscrollbar_policy(PolicyType::Automatic) .vscrollbar_policy(PolicyType::Automatic)
@@ -32,7 +61,8 @@ fn build_ui(app: &Application) {
let all_rows_box = GtkBox::new(Orientation::Vertical, 5); let all_rows_box = GtkBox::new(Orientation::Vertical, 5);
let image_dir = "/home/user/Desktop/LinuxWallpaperEngineGUI"; let image_dir = file_path;
// let image_dir = "/home/user/Desktop/LinuxWallpaper431960/";
let mut row_box = GtkBox::new(Orientation::Horizontal, 5); let mut row_box = GtkBox::new(Orientation::Horizontal, 5);
let mut images_in_row = 0; let mut images_in_row = 0;
@@ -51,7 +81,7 @@ fn build_ui(app: &Application) {
button.connect_clicked(move |_| { button.connect_clicked(move |_| {
let command_path = path_clone.to_string_lossy().replace("/preview.jpg", ""); let command_path = path_clone.to_string_lossy().replace("/preview.jpg", "");
let command = Command::new("linux-wallpaperengine") Command::new("linux-wallpaperengine")
.arg("--use-angle=GL") .arg("--use-angle=GL")
.arg("--screen-root=DP-2") .arg("--screen-root=DP-2")
.arg("--screen-root=DP-1") .arg("--screen-root=DP-1")
@@ -81,30 +111,6 @@ fn build_ui(app: &Application) {
wrapper_box.append(&scrolled_window); wrapper_box.append(&scrolled_window);
let window_weak = window.downgrade();
button.connect_clicked(move |_| {
if let Some(window) = window_weak.upgrade() {
let dialog = FileChooserDialog::new(
Some("Select Workshop Folder"),
Some(&window),
FileChooserAction::Open,
&[
("Cancel", ResponseType::Cancel),
("Open", ResponseType::Accept),
],
);
dialog.connect_response(move |dialog, response| {
if response == ResponseType::Accept {
if let Some(file_path) = dialog.file().and_then(|f| f.path()) {
println!("Selected file: {}", file_path.display());
}
}
dialog.close();
});
dialog.present();
}
});
window.set_child(Some(&wrapper_box)); window.set_child(Some(&wrapper_box));
window.set_child(Some(&button)); window.set_child(Some(&button));
window.present(); window.present();