Commit 56a2666c authored by Eisha Chen-yen-su's avatar Eisha Chen-yen-su

Add the initial architecture draft

This adds the initial architecture of Automata. In this, we have the
application composed with a frontend and a backend. These two parts
communicate through a Rust mpsc::channel.
parent e3c41e0b
use std::process::Command; use std::process::Command;
fn main() { fn main() {
Command::new("glib-compile-resources") Command::new("glib-compile-resources")
.args(&["--generate", "resources.xml"]) .args(&["--generate", "resources.xml"])
.current_dir("resources") .current_dir("resources")
.status() .status()
.unwrap(); .unwrap();
} }
use gio::prelude::*;
use gtk;
use gtk::prelude::*;
use std::sync::mpsc::channel;
use std::sync::{Arc, RwLock};
use crate::backend;
use crate::window;
pub fn launch() {
let app: gtk::Application =
gtk::Application::new("org.gnome.Automata", gio::ApplicationFlags::empty())
.expect("Could not create application");
let (sender, receiver) = channel::<String>();
let sender = Arc::new(RwLock::new(sender));
backend::launch(receiver);
app.connect_startup(move |app| {
let w: gtk::ApplicationWindow = window::new_window(sender.clone());
w.set_application(app);
w.show_all();
});
app.run(&std::env::args().collect::<Vec<_>>());
}
use std::sync::mpsc::Receiver;
use std::thread;
pub fn launch(cmd_chan: Receiver<String>) {
thread::spawn(move || loop {
match cmd_chan.recv() {
Ok(msg) => println!("Received: {}", msg),
Err(_) => {
println!("Error, exiting!");
break;
}
}
});
}
...@@ -2,28 +2,33 @@ extern crate gio; ...@@ -2,28 +2,33 @@ extern crate gio;
extern crate glib; extern crate glib;
extern crate gtk; extern crate gtk;
use gio::prelude::*; // http://gtk-rs.org/tuto/closures
use gio::ApplicationFlags; #[macro_export]
use gtk::prelude::*; macro_rules! clone {
use gtk::{Application, ApplicationWindow}; (@param _) => ( _ );
(@param $x:ident) => ( $x );
($($n:ident),+ => move || $body:expr) => (
{
$( let $n = $n.clone(); )+
move || $body
}
);
($($n:ident),+ => move |$($p:tt),+| $body:expr) => (
{
$( let $n = $n.clone(); )+
move |$(clone!(@param $p),)+| $body
}
);
}
mod app;
mod backend;
mod static_resource; mod static_resource;
mod window; mod window;
fn main() { fn main() {
gtk::init().expect("Error initialising gtk"); gtk::init().expect("Error initializing gtk.");
static_resource::init().expect("Error loading static resource"); static_resource::init().expect("Something went wrong with the resource file initialization.");
let app: Application = Application::new("org.gnome.Automata", ApplicationFlags::empty())
.expect("Could not create application");
app.connect_startup(setup_window);
app.run(&std::env::args().collect::<Vec<_>>());
}
fn setup_window(app: &Application) { app::launch();
let w: ApplicationWindow = window::new_window();
w.set_application(app);
w.show_all();
} }
...@@ -4,7 +4,10 @@ extern crate gtk; ...@@ -4,7 +4,10 @@ extern crate gtk;
use gtk::prelude::*; use gtk::prelude::*;
pub fn new_window() -> gtk::ApplicationWindow { use std::sync::mpsc::Sender;
use std::sync::{Arc, RwLock};
pub fn new_window(cmd_chan: Arc<RwLock<Sender<String>>>) -> gtk::ApplicationWindow {
let builder: gtk::Builder = let builder: gtk::Builder =
gtk::Builder::new_from_resource("/org/gnome/Automata/gtk/window.ui"); gtk::Builder::new_from_resource("/org/gnome/Automata/gtk/window.ui");
...@@ -21,7 +24,10 @@ pub fn new_window() -> gtk::ApplicationWindow { ...@@ -21,7 +24,10 @@ pub fn new_window() -> gtk::ApplicationWindow {
let btn_action: gtk::Button = builder let btn_action: gtk::Button = builder
.get_object("action_button") .get_object("action_button")
.expect("action_button not found"); .expect("action_button not found");
btn_action.connect_clicked(move |_| hello_label.set_text("Action button clicked")); btn_action.connect_clicked(clone!(cmd_chan => move |_| {
hello_label.set_text("Action button clicked");
cmd_chan.read().unwrap().send(String::from("Button clicked!")).unwrap();
}));
let mnu_about: gtk::MenuItem = builder let mnu_about: gtk::MenuItem = builder
.get_object("about_menu") .get_object("about_menu")
...@@ -38,8 +44,7 @@ pub fn new_window() -> gtk::ApplicationWindow { ...@@ -38,8 +44,7 @@ pub fn new_window() -> gtk::ApplicationWindow {
} }
fn show_about(window: &gtk::ApplicationWindow) { fn show_about(window: &gtk::ApplicationWindow) {
let builder: gtk::Builder = let builder: gtk::Builder = gtk::Builder::new_from_resource("/org/gnome/Automata/gtk/about.ui");
gtk::Builder::new_from_resource("/org/gnome/Automata/gtk/about.ui");
let about_dialog: gtk::AboutDialog = builder let about_dialog: gtk::AboutDialog = builder
.get_object("about_dialog") .get_object("about_dialog")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment