auto-scripts/auto-gtkrs
#!/usr/bin/env python
import os
import sys
def chdir(d):
try:
os.chdir(d)
except Exception as e:
print(e)
sys.exit(-1)
def exec_cmd(cmd):
try:
os.system(cmd)
except Exception as e:
print(e)
sys.exit(-1)
def writeFile(filename,content,mode='w'):
try:
f = open(filename, mode)
f.write(content)
f.close()
except Exception as e:
print(e)
sys.exit(-1)
proj_name = sys.argv[1]
exec_cmd(f"cargo init {proj_name}")
chdir(proj_name)
exec_cmd("cargo add gtk4")
c='''use gtk4::prelude::*;
use gtk4::{Application, ApplicationWindow, glib};
const APP_ID: &str = "org.gtk_rs.HelloWorld";
fn main() -> glib::ExitCode {
// Create a new application
let app = Application::builder().application_id(APP_ID).build();
// Connect to "activate" signal of `app`
app.connect_activate(build_ui);
// Run the application
app.run()
}
fn build_ui(app: &Application) {
// Create a window and set the title
let window = ApplicationWindow::builder()
.application(app)
.title("My GTK App")
.build();
// Present window
window.present();
}'''
writeFile("src/main.rs",c)