Commit 7a49d507 authored by Eisha Chen-yen-su's avatar Eisha Chen-yen-su

Display `Grid` as `GtkImage`

parent dc36ec04
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.0 --> <!-- Generated with glade 3.22.1 -->
<interface> <interface>
<requires lib="gtk+" version="3.22"/> <requires lib="gtk+" version="3.22"/>
<object class="GtkMenu" id="app_menu"> <object class="GtkMenu" id="app_menu">
...@@ -19,17 +19,6 @@ ...@@ -19,17 +19,6 @@
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="default_width">600</property> <property name="default_width">600</property>
<property name="default_height">300</property> <property name="default_height">300</property>
<child>
<object class="GtkLabel" id="label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label">Hello, World!</property>
<attributes>
<attribute name="weight" value="bold"/>
<attribute name="scale" value="2"/>
</attributes>
</object>
</child>
<child type="titlebar"> <child type="titlebar">
<object class="GtkHeaderBar" id="header_bar"> <object class="GtkHeaderBar" id="header_bar">
<property name="visible">True</property> <property name="visible">True</property>
...@@ -64,5 +53,12 @@ ...@@ -64,5 +53,12 @@
</child> </child>
</object> </object>
</child> </child>
<child>
<object class="GtkImage" id="grid_da">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stock">gtk-missing-image</property>
</object>
</child>
</object> </object>
</interface> </interface>
extern crate gdk_pixbuf;
extern crate gio; extern crate gio;
extern crate glib; extern crate glib;
extern crate gtk; extern crate gtk;
......
extern crate gio; use gdk_pixbuf::Pixbuf;
extern crate glib;
extern crate gtk;
use gtk::prelude::*; use gtk::prelude::*;
use std::sync::{Arc, RwLock};
use std::sync::mpsc::{Receiver, Sender}; use std::sync::mpsc::{Receiver, Sender};
use std::sync::{Arc, RwLock};
use bkmessages::BackendUpdate;
pub fn new_window( pub fn new_window(
cmd_chan: Arc<RwLock<Sender<String>>>, cmd_chan: Arc<RwLock<Sender<String>>>,
update_chan: Arc<RwLock<Receiver<String>>>, update_chan: Arc<RwLock<Receiver<BackendUpdate>>>,
) -> gtk::ApplicationWindow { ) -> 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");
...@@ -23,16 +22,21 @@ pub fn new_window( ...@@ -23,16 +22,21 @@ pub fn new_window(
gtk::Inhibit(false) gtk::Inhibit(false)
}); });
let hello_label: gtk::Label = builder.get_object("label").expect("label not found"); let grid_da: gtk::Image = builder.get_object("grid_da").expect("grid_da not found");
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(clone!(cmd_chan, update_chan => move |_| { btn_action.connect_clicked(clone!(cmd_chan, update_chan => move |_| {
cmd_chan.read().unwrap().send(String::from("Button clicked!")).unwrap(); cmd_chan.read().unwrap().send(String::from("Button clicked!")).unwrap();
let msg = update_chan.read().unwrap().recv().unwrap(); let mut path = String::new();
match update_chan.read().unwrap().recv().unwrap() {
BackendUpdate::NewState(p) => path = p,
BackendUpdate::Err(msg) => println!("Error: {}", msg),
}
hello_label.set_text(&msg); grid_da.set_from_file(path);
})); }));
let mnu_about: gtk::MenuItem = builder let mnu_about: gtk::MenuItem = builder
......
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