update (not working)
This commit is contained in:
@@ -5,3 +5,4 @@ edition = "2021"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
gtk = { version = "0.9.6", package = "gtk4", features = ["v4_16"] }
|
gtk = { version = "0.9.6", package = "gtk4", features = ["v4_16"] }
|
||||||
|
walkdir = "2"
|
||||||
|
|||||||
+67
-25
@@ -1,21 +1,29 @@
|
|||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
use gtk::FileChooserDialog;
|
use gtk::FileChooserDialog;
|
||||||
use gtk::{glib, Application, ApplicationWindow, Button, FileChooserAction, ResponseType};
|
use gtk::{
|
||||||
|
glib, Application, ApplicationWindow, Box as GtkBox, Button, FileChooserAction, Image,
|
||||||
|
Orientation, ResponseType,
|
||||||
|
};
|
||||||
|
use std::fs;
|
||||||
|
use std::path::Path;
|
||||||
|
use walkdir::WalkDir;
|
||||||
|
|
||||||
const APP_ID: &str = "org.gtk_rs.HelloWorld";
|
const APP_ID: &str = "org.gtk_rs.HelloWorld";
|
||||||
|
|
||||||
pub fn main() -> glib::ExitCode {
|
pub fn main() -> glib::ExitCode {
|
||||||
// Create a new application
|
|
||||||
let app = Application::builder().application_id(APP_ID).build();
|
let app = Application::builder().application_id(APP_ID).build();
|
||||||
|
|
||||||
app.connect_activate(build_ui);
|
app.connect_activate(build_ui);
|
||||||
|
|
||||||
// Run the application
|
|
||||||
app.run()
|
app.run()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_ui(app: &Application) {
|
fn build_ui(app: &Application) {
|
||||||
// Create a button with label and margins
|
// Create a window first
|
||||||
|
let window = ApplicationWindow::builder()
|
||||||
|
.application(app)
|
||||||
|
.title("Linux WallpaperEngine GUI")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
// Create a button
|
||||||
let button = Button::builder()
|
let button = Button::builder()
|
||||||
.label("Folder")
|
.label("Folder")
|
||||||
.margin_top(2)
|
.margin_top(2)
|
||||||
@@ -24,14 +32,49 @@ fn build_ui(app: &Application) {
|
|||||||
.margin_end(2)
|
.margin_end(2)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// Connect button signal
|
app.connect_activate(|app| {
|
||||||
|
let window = ApplicationWindow::builder()
|
||||||
|
.application(app)
|
||||||
|
.title("Image Preview")
|
||||||
|
.default_width(800)
|
||||||
|
.default_height(600)
|
||||||
|
.build();
|
||||||
|
});
|
||||||
|
|
||||||
|
let container = GtkBox::new(Orientation::Horizontal, 5);
|
||||||
|
|
||||||
|
// let image_path = "/home/user/Pictures/Wallpapers/*.png";
|
||||||
|
// let image = Image::from_file(image_path);
|
||||||
|
// fs::create_dir("/home/user/.cache/LinuxWEGUI");
|
||||||
|
// fs::copy(image_path, "/home/user/.cache/LinuxWEGUI/a32xicnes4k91.png");
|
||||||
|
|
||||||
|
// let image_dir = "/media/gamedisk4/SteamLibrary/steamapps/workshop/content/431960/";
|
||||||
|
let image_dir = "/home/user/Desktop/LinuxWallpaperEngineGUI";
|
||||||
|
|
||||||
|
for entry in WalkDir::new(image_dir).into_iter().filter_map(Result::ok) {
|
||||||
|
let path = entry.path();
|
||||||
|
println!("processing file: {}", path.to_string_lossy());
|
||||||
|
|
||||||
|
if path.extension().map_or(false, |ext| ext == "png") {
|
||||||
|
let image = Image::from_file(path);
|
||||||
|
image.set_pixel_size(150);
|
||||||
|
container.append(&image);
|
||||||
|
|
||||||
|
let dest_path =
|
||||||
|
Path::new("/home/user.cache/LinuxWEGUI/").join(path.file_name().unwrap());
|
||||||
|
|
||||||
|
fs::copy(path, dest_path).expect("yeet");
|
||||||
|
|
||||||
|
// fs::copy(path, "/home/user.cache/LinuxWEGUI/").expect("yeet");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let window_weak = window.downgrade();
|
let window_weak = window.downgrade();
|
||||||
button.connect_clicked(move |_| {
|
button.connect_clicked(move |_| {
|
||||||
// Get a strong reference (to avoid borrowing issues)
|
// Get a strong reference back from the weak window
|
||||||
if let Some(window) = window_weak.upgrade() {
|
if let Some(window) = window_weak.upgrade() {
|
||||||
// Create file chooser dialog
|
|
||||||
let dialog = FileChooserDialog::new(
|
let dialog = FileChooserDialog::new(
|
||||||
Some("Select a file"),
|
Some("Select Workshop Folder"),
|
||||||
Some(&window),
|
Some(&window),
|
||||||
FileChooserAction::Open,
|
FileChooserAction::Open,
|
||||||
&[
|
&[
|
||||||
@@ -40,25 +83,24 @@ fn build_ui(app: &Application) {
|
|||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
// Run the dialog (blocks until a response is received)
|
// Use a response callback rather than dialog.run()
|
||||||
let response = dialog.run();
|
dialog.connect_response(move |dialog, response| {
|
||||||
if response == ResponseType::Accept {
|
if response == ResponseType::Accept {
|
||||||
if let Some(file_path) = dialog.file().and_then(|f| f.path()) {
|
if let Some(file_path) = dialog.file().and_then(|f| f.path()) {
|
||||||
println!("Selected file: {}", file_path.display());
|
println!("Selected file: {}", file_path.display());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
dialog.close();
|
||||||
|
});
|
||||||
|
|
||||||
dialog.close();
|
// Present the dialog (non-blocking)
|
||||||
|
dialog.present();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Create a window
|
// Attach the button to the window and show everything
|
||||||
let window = ApplicationWindow::builder()
|
window.set_child(Some(&button));
|
||||||
.application(app)
|
// window.set_child(Some(&image));
|
||||||
.title("Linux WallpaperEngine GUI")
|
window.set_child(Some(&container));
|
||||||
.child(&button)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
// Present window
|
|
||||||
window.present();
|
window.present();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user