commit 9592d057446ca6c6aa691d2dbfe5ff888c3f82a6 Author: William Söderberg Date: Fri Mar 20 00:21:32 2026 +0100 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..73b8816 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,92 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "proc-macro2" +version = "1.0.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "python-runner" +version = "1.0.0" +dependencies = [ + "winres", +] + +[[package]] +name = "quote" +version = "1.0.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "serde" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", +] + +[[package]] +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "syn" +version = "2.0.117" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "toml" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" +dependencies = [ + "serde", +] + +[[package]] +name = "unicode-ident" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" + +[[package]] +name = "winres" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b68db261ef59e9e52806f688020631e987592bd83619edccda9c47d42cde4f6c" +dependencies = [ + "toml", +] diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..2cf0721 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "python-runner" +version = "1.0.0" +edition = "2024" + +[build-dependencies] +winres = "0.1" diff --git a/Python.File.reg b/Python.File.reg new file mode 100644 index 0000000..f1910cd Binary files /dev/null and b/Python.File.reg differ diff --git a/README.md b/README.md new file mode 100644 index 0000000..fbf5ed7 --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ +# Python Executor + +Enables drophandler on `.py` files as well as edit with VS Code on normal file open action. + +## Installation + +Build the executable using `cargo` and place the resulting `python-runner.exe` at `C:\`. Execute the `.reg` file to add the drop-handler and open commands to `.py` files. + +### Build command + +```cmd +cargo build --release diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..2e793b2 --- /dev/null +++ b/build.rs @@ -0,0 +1,22 @@ +#[cfg(windows)] +fn main() { + let mut res = winres::WindowsResource::new(); + + // Attach your icon (Make sure py.ico is in the same folder as Cargo.toml) + res.set_icon("py.ico"); + + // Map your versioninfo.txt data + res.set("CompanyName", "Soderberg Tech"); + res.set("FileDescription", "Python Executor"); + res.set("FileVersion", "1.0.0.0"); + res.set("InternalName", "python_executor.exe"); + res.set("LegalCopyright", "© Soderberg Tech. All rights reserved."); + res.set("OriginalFilename", "python_executor.exe"); + res.set("ProductName", "Python Executor"); + res.set("ProductVersion", "1.0.0.0"); + + res.compile().unwrap(); +} + +#[cfg(not(windows))] +fn main() {} diff --git a/py.ico b/py.ico new file mode 100644 index 0000000..1d8a79b Binary files /dev/null and b/py.ico differ diff --git a/python-runner.exe b/python-runner.exe new file mode 100644 index 0000000..5d76f3d Binary files /dev/null and b/python-runner.exe differ diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..84d9dda --- /dev/null +++ b/src/main.rs @@ -0,0 +1,61 @@ +#![windows_subsystem = "windows"] + +use std::env; +use std::os::windows::process::CommandExt; +use std::path::Path; +use std::process::Command; + +const CREATE_NO_WINDOW: u32 = 0x08000000; + +fn main() { + let args: Vec = env::args().skip(1).collect(); + + if args.is_empty() { + let _ = Command::new("cmd.exe") + .args([ + "/k", + "TITLE", + "Python REPL", + "&", + "python", + "&", + "pause", + "&", + "exit", + ]) + .status(); + } else if args.len() == 1 { + let _ = Command::new("cmd.exe") + .args(["/c", "code", &args[0]]) + .creation_flags(CREATE_NO_WINDOW) + .spawn(); + } else { + // Extract just the script name + let script_name = Path::new(&args[0]) + .file_name() + .map(|s| s.to_string_lossy().into_owned()) + .unwrap_or_else(|| String::from("Script")); + + // Format the exact title you want + let tab_title = format!("Python > {}", script_name); + + let mut cmd_args = vec![ + String::from("/k"), + String::from("TITLE"), + tab_title, // Apply your custom title here + String::from("&"), + String::from("python"), + ]; + + cmd_args.extend(args); + + cmd_args.extend(vec![ + String::from("&"), + String::from("pause"), + String::from("&"), + String::from("exit"), + ]); + + let _ = Command::new("cmd.exe").args(&cmd_args).status(); + } +}