diff --git a/src/bin/.multithreading_context.rs b/src/bin/.multithreading_context.rs deleted file mode 100644 index 8bf7f01..0000000 --- a/src/bin/.multithreading_context.rs +++ /dev/null @@ -1,64 +0,0 @@ -extern crate gio; -extern crate glib; -extern crate gtk; - -use gio::prelude::*; -use gtk::prelude::*; - -use std::env::args; -use std::thread; -use std::time::Duration; - -fn build_ui(application: >k::Application) { - let window = gtk::ApplicationWindow::new(application); - - window.set_title("Multithreading GTK+ Program"); - window.set_border_width(10); - window.set_position(gtk::WindowPosition::Center); - window.set_default_size(600, 400); - - let text_view = gtk::TextView::new(); - let scroll = gtk::ScrolledWindow::new(gtk::NONE_ADJUSTMENT, gtk::NONE_ADJUSTMENT); - scroll.set_policy(gtk::PolicyType::Automatic, gtk::PolicyType::Automatic); - scroll.add(&text_view); - - let (tx, rx) = glib::MainContext::channel(glib::PRIORITY_DEFAULT); - - thread::spawn(move || { - for i in 1..100 { - // do long work - thread::sleep(Duration::from_millis(50)); - // send result to channel - tx.send(format!("#{} Text from another thread.", i)) - .expect("Couldn't send data to channel"); - // receiver will be run on the main thread - } - }); - - // Attach receiver to the main context and set the text buffer text from here - let text_buffer = text_view - .get_buffer() - .expect("Couldn't get buffer from text_view"); - rx.attach(None, move |text| { - text_buffer.set_text(&text); - - glib::Continue(true) - }); - - window.add(&scroll); - window.show_all(); -} - -fn main() { - let application = gtk::Application::new( - Some("com.github.gtk-rs.examples.multithreading_context"), - Default::default(), - ) - .expect("Initialization failed..."); - - application.connect_activate(|app| { - build_ui(app); - }); - - application.run(&args().collect::>()); -} \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 0800d70..abbed87 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -32,7 +32,7 @@ impl Config { } } -enum Message { +enum MessageSerialThread { Msg(String), Status(String) } @@ -243,7 +243,7 @@ pub fn build_ui(app: >k::Application, config: Arc::>) { } }); - //avrodith_btn + // avrodith_btn let avrodith_btn = builder.get_object::("avrodith_btn").expect("Resource file missing!"); let tmp_bar = bar.clone(); @@ -259,7 +259,7 @@ pub fn build_ui(app: >k::Application, config: Arc::>) { } }); - //clear_log + // clear_log let clear_log = builder.get_object::("clear_log").expect("Resource file missing!"); let tmp_log_area = log_area.clone(); @@ -276,7 +276,7 @@ pub fn build_ui(app: >k::Application, config: Arc::>) { send_text(&tmp_config, ent, &tmp_bar); }); - //send_btn + // send_btn let send_btn = builder.get_object::("send_btn").expect("Resource file missing!"); let tmp_bar = bar.clone(); @@ -285,7 +285,7 @@ pub fn build_ui(app: >k::Application, config: Arc::>) { send_text(&tmp_config, &send_entry, &tmp_bar); }); - // serial + // Serial Thread let (sender, receiver) = glib::MainContext::channel(glib::PRIORITY_DEFAULT); let tmp_config = Arc::clone(&config); @@ -297,14 +297,15 @@ pub fn build_ui(app: >k::Application, config: Arc::>) { } }); + // Serial Thread Reciver let full_log = builder.get_object::("full_log").expect("Resource file missing!"); let tmp_graph = Rc::clone(&graph); receiver.attach(None, move |msg| { match msg { - Message::Msg(text) => { + MessageSerialThread::Msg(text) => { receiver_for_msg(text, &tmp_graph, &full_log, &log_area); }, - Message::Status(text) => { + MessageSerialThread::Status(text) => { bar.push(1, &text); } } @@ -330,7 +331,7 @@ pub fn build_ui(app: >k::Application, config: Arc::>) { fn serial_thread_work( config: &Arc>, bufread: &mut Option>>, - sender: &glib::Sender, + sender: &glib::Sender, buf: &mut String) { match config.lock() { Ok(mut config) => { @@ -342,7 +343,7 @@ fn serial_thread_work( Status::JAGRIT => { if let Some(read) = bufread { if let Ok(_) = read.read_line(buf) { - sender.send(Message::Msg(buf.clone())).unwrap(); + sender.send(MessageSerialThread::Msg(buf.clone())).unwrap(); buf.clear(); } } @@ -363,7 +364,7 @@ fn serial_thread_work( } }, Err(_) => { - sender.send(Message::Status("Faild prepare for communication!".to_owned())).unwrap(); + sender.send(MessageSerialThread::Status("Faild prepare for communication!".to_owned())).unwrap(); return; } }; diff --git a/tests/plottest.rs b/tests/plottest.rs deleted file mode 100644 index d1ecdad..0000000 --- a/tests/plottest.rs +++ /dev/null @@ -1,5 +0,0 @@ - -#[test] -fn start() { - -} \ No newline at end of file