seed r110 - trunk/examples



Author: racarr
Date: Tue Nov  4 12:22:53 2008
New Revision: 110
URL: http://svn.gnome.org/viewvc/seed?rev=110&view=rev

Log:
More example cleanup.


Modified:
   trunk/examples/calculator.js
   trunk/examples/clutter.js
   trunk/examples/gconf.js
   trunk/examples/introspect.js
   trunk/examples/ls.js
   trunk/examples/mini-browser.js
   trunk/examples/n-oscillator.js
   trunk/examples/poppler.js
   trunk/examples/quine.js

Modified: trunk/examples/calculator.js
==============================================================================
--- trunk/examples/calculator.js	(original)
+++ trunk/examples/calculator.js	Tue Nov  4 12:22:53 2008
@@ -9,11 +9,6 @@
 var window, label;
 var calc_val = "";
 
-function end_program()
-{
-	Gtk.main_quit();
-}
-
 function update_display()
 {
 	label.set_markup("<span size='30000'>" + calc_val + "</span>");
@@ -42,6 +37,11 @@
 	calc_val = calc_val.replace("cos", "Math.cos");
 	calc_val = calc_val.replace("tan", "Math.tan");
 	calc_val = eval(calc_val) + "";
+	// Avoid rediculous amounts of precision from toString.
+	if (calc_val == Math.floor(calc_val))
+	    calc_val = Seed.sprintf("%d", calc_val);
+	else
+	    calc_val = Seed.sprintf("%.4f", calc_val);
 	label.set_markup("<span size='30000'>" + calc_val + "</span>");
 }
 
@@ -134,7 +134,7 @@
 var window = new Gtk.Window({title: "Calculator", resizable: false});
 
 window.resize(250, 250);
-window.signal_hide.connect(end_program);
+window.signal_hide.connect(Gtk.main_quit);
 window.opacity = 0.95;
 
 var label = new Gtk.Label({label: ""});

Modified: trunk/examples/clutter.js
==============================================================================
--- trunk/examples/clutter.js	(original)
+++ trunk/examples/clutter.js	Tue Nov  4 12:22:53 2008
@@ -47,7 +47,8 @@
 	stage.add_actor(r);
 	rectangles[i] = r;
 }
-
+// Was initially intended as a test to see if performance was accetable to do
+// custom animations at 60fps. Turns out to be fine, serves as an example now.
 timeline.signal_new_frame.connect(
 	function(timeline, frame_num)
 	{
@@ -80,7 +81,8 @@
 		Clutter.effect_fade(effect,text,0);
 		for (i in rectangles)
 		{
-			Clutter.effect_move(effect, rectangles[i], Math.random()*stage.width,
+			Clutter.effect_move(effect, rectangles[i], 
+					    Math.random()*stage.width,
 					    Math.random()*stage.height);
 		}
 	});

Modified: trunk/examples/gconf.js
==============================================================================
--- trunk/examples/gconf.js	(original)
+++ trunk/examples/gconf.js	Tue Nov  4 12:22:53 2008
@@ -3,6 +3,7 @@
 
 GConf.init(null, null);
 
+// client = new GConf.Client() makes GConf segfault, don't think it's our fault.
 client = GConf.client_get_default();
 value = client.get_string("/apps/gedit-2/preferences/editor/colors/scheme");
 Seed.print(value);

Modified: trunk/examples/introspect.js
==============================================================================
--- trunk/examples/introspect.js	(original)
+++ trunk/examples/introspect.js	Tue Nov  4 12:22:53 2008
@@ -1,7 +1,8 @@
 #!/usr/local/bin/seed
 Seed.import_namespace("Gtk");
-Seed.include("json2.js");
 
 proto = Seed.prototype(Gtk.Window);
 method = Seed.introspect(proto.translate_coordinates);
+//JSON.stringify and JSON.fromString come from json2.js available on json.org
+//Also in extensions/seed.js.
 Seed.print(JSON.stringify(method));
\ No newline at end of file

Modified: trunk/examples/ls.js
==============================================================================
--- trunk/examples/ls.js	(original)
+++ trunk/examples/ls.js	Tue Nov  4 12:22:53 2008
@@ -1,14 +1,17 @@
 #!/usr/local/bin/seed
 Seed.import_namespace("Gio");
 
+// Gio.File is an interface, not an actual instantiable class, so we can not
+// construct one with a "path" property. Instead it is necessary to use
+// Gio.file_new_for_path, etc...
 if (Seed.argv.length < 3)
     file = Gio.file_new_for_path(".");
 else
     file = Gio.file_new_for_path(Seed.argv[2]);
 
-enumerator = file.enumerate_children("standard::name");
+enumerator = file.enumerate_children("standard::name,standard::size");
 
 while (child = enumerator.next_file())
 {
-	Seed.print(child.get_name());
+    Seed.printf("%s\t%d",child.get_name(), child.get_size());
 }

Modified: trunk/examples/mini-browser.js
==============================================================================
--- trunk/examples/mini-browser.js	(original)
+++ trunk/examples/mini-browser.js	Tue Nov  4 12:22:53 2008
@@ -40,6 +40,9 @@
 	this.open(url_entry.text);
 }
 
+// Being able to make new tabs is blocking on a GtkWebkit bug.
+// Yes this is why you've never been able to use open in new window in epiphany
+// webkit.
 function new_tab(browser_view, browser_frame, new_frame)
 {
 	//new_frame = new WebKit.WebView();
@@ -107,7 +110,8 @@
 	tab.pack_start(browser_view, true, true);
 	
 	var close_button = new Gtk.Button();
-	close_button.set_image(new Gtk.Image({stock: "gtk-close", icon_size: Gtk.IconSize.menu}));
+	close_button.set_image(new Gtk.Image({stock: "gtk-close", 
+			icon_size: Gtk.IconSize.menu}));
 	close_button.signal_clicked.connect(close_tab, tab);
 	close_button.set_relief(Gtk.ReliefStyle.none);
 	

Modified: trunk/examples/n-oscillator.js
==============================================================================
--- trunk/examples/n-oscillator.js	(original)
+++ trunk/examples/n-oscillator.js	Tue Nov  4 12:22:53 2008
@@ -5,6 +5,8 @@
 Gst.init(null, null);
 Gtk.init(null, null);
 
+// This is a really ugly program.
+
 function oscillator(freq)
 {
 	this.vbox = new Gtk.VBox();
@@ -14,6 +16,9 @@
 	this.button = new Gtk.Button({label: "Toggle"});
 	
 	this.pipeline = new Gst.Pipeline({name: "test"});
+	// No actual introspection data for audiotestsrc, so can not
+	// instantiate one with a constructor, have to use element_factory,
+	// likewise for the others.
 	this.audiosrc = Gst.element_factory_make("audiotestsrc", "audio");
 	this.audiosink = Gst.element_factory_make("alsasink", "sink");
 	this.volume = Gst.element_factory_make("volume", "vcontrol");

Modified: trunk/examples/poppler.js
==============================================================================
--- trunk/examples/poppler.js	(original)
+++ trunk/examples/poppler.js	Tue Nov  4 12:22:53 2008
@@ -26,10 +26,10 @@
 }
 function set_page(num)
 {
-    Seed.print(typeof num);
     current_page = current_document.get_page(num);
     draw_document();
     
+    //Get rid of precision.
     entry.text = Seed.sprintf("%d",num+1);
     page_num = num;
     if (page_num == num_pages-1)
@@ -54,7 +54,10 @@
     
     if(file_chooser.run() == Gtk.ResponseType.accept)
     {
-	current_document = Poppler.Document.new_from_file(file_chooser.get_uri());
+	// Poppler.Document will not take a uri as a construction property,
+	// use this:
+	current_document = 
+	    Poppler.Document.new_from_file(file_chooser.get_uri());
 	set_page(0);
 	num_pages = current_document.get_n_pages();
 	page_label.label = " of " + num_pages;
@@ -116,7 +119,6 @@
 main_vbox = new Gtk.VBox();
 
 drawing_area = new Gtk.DrawingArea();
-drawing_area.app_paintable = true;
 drawing_area.signal_expose_event.connect(draw_document);
 
 window.add(main_vbox);

Modified: trunk/examples/quine.js
==============================================================================
--- trunk/examples/quine.js	(original)
+++ trunk/examples/quine.js	Tue Nov  4 12:22:53 2008
@@ -3,5 +3,5 @@
 
 file = Gio.file_new_for_path(Seed.argv[1])
 input = file.read();
-
+//get_contents is an addition in extensions/Gio.js to make life easier.
 Seed.print(input.get_contents());
\ No newline at end of file



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]