[seed] Update twitter example
- From: Robert Carr <racarr src gnome org>
- To: svn-commits-list gnome org
- Subject: [seed] Update twitter example
- Date: Sun, 12 Apr 2009 17:22:39 -0400 (EDT)
commit 292052e0f19e03821f2f288d721b753cf3f02827
Author: Robert Carr <racarr mireia (none)>
Date: Sun Apr 12 17:22:30 2009 -0400
Update twitter example
---
examples/browser/BrowserStatusbar.js | 7 ++++-
examples/browser/BrowserView.js | 45 ++++++++++++++++++----------------
examples/browser/TabbedBrowser.js | 25 +++++++++++-------
examples/browser/main.js | 8 +++---
examples/twitter/twitter.js | 24 +++++++++---------
libseed/seed-engine.c | 3 +-
libseed/seed-engine.h | 2 +
libseed/seed-gtype.c | 8 ++++--
libseed/seed-gtype.h | 2 +
libseed/seed-importer.c | 2 +
10 files changed, 73 insertions(+), 53 deletions(-)
diff --git a/examples/browser/BrowserStatusbar.js b/examples/browser/BrowserStatusbar.js
index e4b7ac8..a3085bc 100644
--- a/examples/browser/BrowserStatusbar.js
+++ b/examples/browser/BrowserStatusbar.js
@@ -1,3 +1,6 @@
+Gtk = imports.gi.Gtk;
+WebKit = imports.gi.WebKit;
+
BrowserStatusbar = new GType({
parent: Gtk.Statusbar.type,
name: "BrowserStatusbar",
@@ -5,14 +8,14 @@ BrowserStatusbar = new GType({
{
// Private
var transient_status_group = this.get_context_id("transient");
-
+
// Public
this.set_status = function (status)
{
this.pop(transient_status_group);
this.push(transient_status_group, status);
};
-
+
// Implementation
}
});
diff --git a/examples/browser/BrowserView.js b/examples/browser/BrowserView.js
index 80527b5..c7b3d9b 100644
--- a/examples/browser/BrowserView.js
+++ b/examples/browser/BrowserView.js
@@ -1,3 +1,6 @@
+Gtk = imports.gi.Gtk;
+WebKit = imports.gi.WebKit;
+
BrowserView = new GType({
parent: WebKit.WebView.type,
name: "BrowserView",
@@ -5,58 +8,58 @@ BrowserView = new GType({
{
// Private
var tab;
-
+
var update_title = function (web_view, web_frame, title)
{
if(title.length > 25)
title = title.slice(0,25) + "...";
-
+
tab.get_tab_label().label = title;
};
-
+
var update_url = function (web_view, web_frame)
{
var toolbar = tab.get_toolbar();
-
+
toolbar.set_url(web_frame.get_uri());
toolbar.set_can_go_back(web_view.can_go_back());
toolbar.set_can_go_forward(web_view.can_go_forward());
};
-
+
var update_progress = function (bar, progress)
{
tab.get_toolbar().set_progress(progress / 100);
};
-
+
var create_new_tab = function (web_view, web_frame, new_web_view)
{
new_web_view = new BrowserView();
new_web_view.signal.web_view_ready.connect(show_new_tab);
return new_web_view;
};
-
+
var show_new_tab = function (new_web_view)
{
browser.new_tab("", new_web_view);
-
+
return false;
};
-
+
var hover_link = function (web_view, link, url)
{
tab.get_statusbar().set_status(url);
};
-
+
var load_finished = function ()
{
tab.get_toolbar().set_progress(0);
};
-
+
var load_committed = function (web_view, web_frame)
{
update_url(web_view, web_frame);
};
-
+
var clicked_link = function (web_view, web_frame, request,
action, decision, window)
{
@@ -66,10 +69,10 @@ BrowserView = new GType({
browser.new_tab(request.get_uri(), null);
return true;
}
-
+
return false;
};
-
+
// Public
this.browse = function (url)
{
@@ -78,31 +81,31 @@ BrowserView = new GType({
this.open(url);
};
-
+
this.set_tab = function (new_tab)
{
tab = new_tab;
};
-
+
this.get_tab = function ()
{
return tab;
};
-
+
// Implementation
this.set_scroll_adjustments(null, null);
-
+
this.signal.title_changed.connect(update_title);
this.signal.load_committed.connect(load_committed);
this.signal.load_finished.connect(load_finished);
this.signal.load_progress_changed.connect(update_progress);
-
+
// For some reason, this segfaults seed in the instance init closure handler
// Once that's fixed, uncommenting the next line will give middle-click-open-in-new tab
//this.signal.navigation_policy_decision_requested.connect(clicked_link);
-
+
this.signal.hovering_over_link.connect(hover_link);
-
+
this.signal.create_web_view.connect(create_new_tab);
}
});
diff --git a/examples/browser/TabbedBrowser.js b/examples/browser/TabbedBrowser.js
index 523055d..43f9680 100644
--- a/examples/browser/TabbedBrowser.js
+++ b/examples/browser/TabbedBrowser.js
@@ -1,3 +1,8 @@
+Gtk = imports.gi.Gtk;
+WebKit = imports.gi.WebKit;
+
+BrowserSettings = imports.BrowserSettings;
+
TabbedBrowser = new GType({
parent: Gtk.Notebook.type,
name: "TabbedBrowser",
@@ -8,38 +13,38 @@ TabbedBrowser = new GType({
{
browser.remove_page(browser.page_num(tab));
tab.destroy();
-
+
if(!browser.get_n_pages())
{
- browser.new_tab(home_page);
+ browser.new_tab(BrowserSettings.home_page);
}
};
-
+
this.new_tab = function (url, new_web_view)
{
var new_tab = new BrowserTab();
-
+
if(new_web_view)
new_tab.set_web_view(new_web_view);
else
new_tab.get_web_view().browse(url);
-
+
var tab_label = new Gtk.Label({label:"Untitled"});
var tab_button = new Gtk.Button({relief: Gtk.ReliefStyle.NONE});
- tab_button.set_image(new Gtk.Image({stock: "gtk-close",
+ tab_button.set_image(new Gtk.Image({stock: "gtk-close",
icon_size: Gtk.IconSize.MENU}));
tab_button.signal.clicked.connect(this.close_tab, this);
-
+
var tab_title = new Gtk.HBox();
tab_title.pack_start(tab_label);
tab_title.pack_start(tab_button);
tab_title.show_all();
-
+
new_tab.set_tab_label(tab_label);
-
+
this.append_page(new_tab, tab_title);
this.set_tab_reorderable(new_tab, true);
-
+
if(select_new_tabs)
this.page = this.page_num(new_tab);
};
diff --git a/examples/browser/main.js b/examples/browser/main.js
index f7938bd..85ec244 100755
--- a/examples/browser/main.js
+++ b/examples/browser/main.js
@@ -1,12 +1,12 @@
#!/usr/bin/env seed
-Seed.import_namespace("Gtk");
-Seed.import_namespace("WebKit");
+Gtk = imports.gi.Gtk;
+WebKit = imports.gi.WebKit;
Gtk.init(null, null);
-Seed.include("BrowserSettings.js");
-Seed.include("BrowserView.js");
+BrowserSettings = imports.BrowserSettings;
+BrowserView = imports.BrowserView;
Seed.include("BrowserStatusbar.js");
Seed.include("BrowserTab.js");
Seed.include("TabbedBrowser.js");
diff --git a/examples/twitter/twitter.js b/examples/twitter/twitter.js
index d0f8090..b5fc29f 100755
--- a/examples/twitter/twitter.js
+++ b/examples/twitter/twitter.js
@@ -1,16 +1,16 @@
#!/usr/bin/env seed
// Import libraries that are used by the program
-Seed.import_namespace("Gtk");
-Seed.import_namespace("Gdk");
-Seed.import_namespace("GdkPixbuf");
-Seed.import_namespace("Gio");
-Seed.import_namespace("GLib");
+Gtk = imports.gi.Gtk;
+Gdk = imports.gi.Gdk;
+GdkPixbuf = imports.gi.GdkPixbuf;
+Gio = imports.gi.Gio;
+GLib = imports.gi.GLib;
// Pretty.js is John Resig's date display library. It downloaded it and
// put it in the same directory as this script. You can easily use a lot
// of existing JS libs and import them into Seed applications at runtime.
-Seed.include("pretty.js");
+Pretty = imports.pretty;
// Initialize GTK+
Gtk.init(null, null);
@@ -59,7 +59,7 @@ function make_block(data) {
var heading = new Gtk.Label({
"use-markup": true,
"label": "<b><big>" + data.from_user + "</big></b>\n" +
- "<small>" + prettyDate(data.created_at) + "</small>"
+ "<small>" + Pretty.prettyDate(data.created_at) + "</small>"
});
// The message text is displayed in a TextView widget because the GTK+ label
@@ -67,7 +67,7 @@ function make_block(data) {
// label because of the RC change at the top of the script.
var message = new Gtk.TextView({"wrap-mode": 2, "editable": false});
message.buffer.text = data.text;
-
+
heading.set_alignment(0, 0);
vbox.pack_start(hbox);
hbox.pack_start(heading);
@@ -95,12 +95,12 @@ function async_callback(source, result)
var stream = source.read_finish(result);
var dstream = new Gio.DataInputStream.c_new(stream);
var data = JSON.parse(dstream.read_until("", 0));
-
+
messages.foreach(function(m) {messages.remove(m);});
data.results.forEach(function(m) { messages.pack_start(make_block(m));
while (GLib.main_context_pending())
GLib.main_context_iteration();});
-
+
messages.show_all();
}
@@ -109,10 +109,10 @@ function async_callback(source, result)
function do_search(w)
{
- var twitter =
+ var twitter =
Gio.file_new_for_uri("http://search.twitter.com/search.json?q="
+ textbox.get_text());
-
+
twitter.read_async(0, null, async_callback);
}
diff --git a/libseed/seed-engine.c b/libseed/seed-engine.c
index e749ada..589f7cd 100644
--- a/libseed/seed-engine.c
+++ b/libseed/seed-engine.c
@@ -22,6 +22,8 @@
#include <string.h>
#include <stdarg.h>
+JSObjectRef seed_obj_ref;
+
GQuark qname;
GQuark qprototype;
@@ -1533,7 +1535,6 @@ seed_init_with_context_group (gint * argc,
gchar *** argv,
JSContextGroupRef group)
{
- JSObjectRef seed_obj_ref;
JSStringRef defaults_script;
g_type_init ();
diff --git a/libseed/seed-engine.h b/libseed/seed-engine.h
index 5dae7c7..03d3285 100644
--- a/libseed/seed-engine.h
+++ b/libseed/seed-engine.h
@@ -33,6 +33,8 @@ extern JSClassRef seed_struct_constructor_class;
extern JSClassRef seed_callback_class;
extern SeedEngine *eng;
+extern JSObjectRef seed_obj_ref;
+
extern JSContextGroupRef context_group;
typedef struct _SeedScript
diff --git a/libseed/seed-gtype.c b/libseed/seed-gtype.c
index b6e5e1c..d79257e 100644
--- a/libseed/seed-gtype.c
+++ b/libseed/seed-gtype.c
@@ -22,6 +22,8 @@ JSClassRef seed_gtype_class;
GIBaseInfo *objectclass_info = NULL;
GIBaseInfo *paramspec_info = NULL;
+JSObjectRef seed_gtype_constructor;
+
GQuark qgetter;
GQuark qsetter;
@@ -564,16 +566,16 @@ void
seed_gtype_init (SeedEngine * local_eng)
{
JSClassDefinition gtype_def = kJSClassDefinitionEmpty;
- JSObjectRef gtype_constructor;
+
gtype_def.callAsConstructor = seed_gtype_constructor_invoked;
seed_gtype_class = JSClassCreate (>ype_def);
JSClassRetain (seed_gtype_class);
- gtype_constructor = JSObjectMake (local_eng->context, seed_gtype_class, 0);
+ seed_gtype_constructor = JSObjectMake (local_eng->context, seed_gtype_class, 0);
seed_object_set_property (local_eng->context,
- local_eng->global, "GType", gtype_constructor);
+ local_eng->global, "GType", seed_gtype_constructor);
qgetter = g_quark_from_static_string ("js-getter");
qsetter = g_quark_from_static_string ("js-setter");
diff --git a/libseed/seed-gtype.h b/libseed/seed-gtype.h
index c60cf37..5146bee 100644
--- a/libseed/seed-gtype.h
+++ b/libseed/seed-gtype.h
@@ -26,4 +26,6 @@
void seed_gtype_init (SeedEngine * eng);
+extern JSObjectRef seed_gtype_constructor;
+
#endif
diff --git a/libseed/seed-importer.c b/libseed/seed-importer.c
index 4d426b2..cd069d0 100644
--- a/libseed/seed-importer.c
+++ b/libseed/seed-importer.c
@@ -505,6 +505,8 @@ seed_importer_handle_file (JSContextRef ctx,
nctx = JSGlobalContextCreateInGroup (context_group, 0);
global = JSContextGetGlobalObject (nctx);
seed_object_set_property (ctx, global, "imports", importer);
+ seed_object_set_property (ctx, global, "GType", seed_gtype_constructor);
+ seed_object_set_property (ctx, global, "Seed", seed_obj_ref);
JSEvaluateScript (nctx, file_contents, NULL, file_name, 0, exception);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]