Skip to content

Commit 0fe84a8

Browse files
author
Patrick Barrett
committed
initial commit; holy shit that was easy
0 parents  commit 0fe84a8

File tree

4 files changed

+381
-0
lines changed

4 files changed

+381
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
target

Cargo.lock

+302
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[package]
2+
name = "hello_gtk"
3+
version = "0.1.0"
4+
authors = ["Patrick Barrett <[email protected]>"]
5+
6+
[dependencies]
7+
gtk = "^0"
8+
hyper = "^0"
9+
10+
[features]
11+
gtk_3_14 = ["gtk/gtk_3_14"]

src/main.rs

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
extern crate gtk;
2+
extern crate hyper;
3+
4+
use gtk::traits::*;
5+
use gtk::signal::Inhibit;
6+
7+
use std::io::Read;
8+
9+
use hyper::Client;
10+
use hyper::header::Connection;
11+
12+
fn main() {
13+
gtk::init();
14+
15+
// Create Top Level Window
16+
let window = gtk::Window::new(gtk::WindowType::TopLevel).unwrap();
17+
18+
// Setup Window Stuff
19+
window.set_title("Exosite Timestamp Reader Thing");
20+
window.set_border_width(10);
21+
//window.set_window_position(gtk::WindowPosition::Center);
22+
window.set_default_size(350, 70);
23+
24+
window.connect_delete_event(|_, _| {
25+
gtk::main_quit();
26+
Inhibit(true)
27+
});
28+
29+
// Create UI Elements
30+
let vbox = gtk::Box::new(gtk::Orientation::Vertical, 10).unwrap();
31+
let label = gtk::Label::new("Click Update, I Dare You!").unwrap();
32+
let button = gtk::Button::new_with_label("Update").unwrap();
33+
34+
// Connect Up Layout
35+
vbox.add(&label);
36+
vbox.add(&button);
37+
window.add(&vbox);
38+
39+
// Setup Button Click Handler
40+
button.connect_clicked(move |_| {
41+
label.set_text(&get_time())
42+
});
43+
44+
// Show and Run
45+
window.show_all();
46+
gtk::main();
47+
}
48+
49+
50+
51+
fn get_time() -> String {
52+
// Create a client.
53+
let mut client = Client::new();
54+
55+
// Creating an outgoing request.
56+
let mut res = client.get("http://m2.exosite.com/timestamp")
57+
// set a header
58+
.header(Connection::close())
59+
// let 'er go!
60+
.send().unwrap();
61+
62+
// Read the Response.
63+
let mut body = String::new();
64+
res.read_to_string(&mut body).unwrap();
65+
66+
body
67+
}

0 commit comments

Comments
 (0)