Skip to content

Instantly share code, notes, and snippets.

@segphault
Created January 11, 2009 04:07
Show Gist options
  • Save segphault/45633 to your computer and use it in GitHub Desktop.
Save segphault/45633 to your computer and use it in GitHub Desktop.
Twitter search demo for Seed
Seed.import_namespace("Gtk");
Seed.import_namespace("Gdk");
Seed.import_namespace("Gio");
Seed.include("pretty.js");
Gtk.init(null, null);
var window = new Gtk.Window({"title": "Twitter Search", "border-width": 5});
window.signal.hide.connect(Gtk.main_quit);
Gtk.rc_parse_string('style "tv" {base[NORMAL] = @bg_color} widget_class "*GtkTextView" style "tv"');
function twitter_search(query) {
return JSON.parse(Gio.file_new_for_uri(
"http://search.twitter.com/search.json?q=" + query).read().get_contents());
}
function make_block(data) {
var vbox = new Gtk.VBox({"spacing": 10, "border-width": 5});
var heading = new Gtk.Label({
"use-markup": true,
"label": "<b><big>" + data.from_user + "</big></b>" +
"(<small>" + prettyDate(data.created_at) + "</small>)"
});
var message = new Gtk.TextView({"wrap-mode": 2});
message.buffer.text = data.text;
heading.set_alignment(0, 0);
vbox.pack_start(heading);
vbox.pack_start(message);
var frame = new Gtk.Frame({"border-width": 5});
frame.add(vbox);
return frame;
}
var messages = new Gtk.VBox();
var scroll = new Gtk.ScrolledWindow();
scroll.add_with_viewport(messages);
scroll.set_policy(1, 1)
var textbox = new Gtk.Entry();
var button = new Gtk.Button({label: "Search"});
button.signal.clicked.connect(function(w) {
var results = twitter_search(textbox.get_text()).results
messages.foreach(function(c) {messages.remove(c)});
for (index in results) {
messages.pack_start(make_block(results[index]));
}
messages.show_all();
});
var searchbox = new Gtk.HBox();
searchbox.pack_start(textbox, true, true);
searchbox.pack_start(button);
var layout = new Gtk.VBox({"spacing": 5});
layout.pack_start(searchbox);
layout.pack_start(scroll, true, true);
window.add(layout);
window.show_all();
Gtk.main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment