seed r132 - in trunk: doc examples/ide tests



Author: hortont
Date: Wed Nov  5 19:59:17 2008
New Revision: 132
URL: http://svn.gnome.org/viewvc/seed?rev=132&view=rev

Log:
Add test-maker; update runtime docs (not complete yet); keybindings for 
IDE.



Added:
   trunk/tests/make-test.py
Modified:
   trunk/doc/runtime.html
   trunk/examples/ide/ide.js
   trunk/examples/ide/tabview.js
   trunk/examples/ide/toolbar.js
   trunk/tests/run-tests.py

Modified: trunk/doc/runtime.html
==============================================================================
--- trunk/doc/runtime.html	(original)
+++ trunk/doc/runtime.html	Wed Nov  5 19:59:17 2008
@@ -96,20 +96,148 @@
 var win = new Gtk.Window();
 Seed.print(win);
 </pre>
+<div class="section"><b>Seed.printf</b>(format, ...)</div>
+<div class="section"><b>Seed.sprintf</b>(format, ...)</div>
+<p>
+<code>printf</code> prints, to standard output, a string formatted as specified by <i>format</i>. Following <i>format</i> should be values to substitute, as in C's <code>printf</code>. Most standard printf format strings should work.
+</p>
+<p>
+<code>sprintf</code> returns the string, instead of printing it.
+</p>
+<pre>
+Seed.printf("A number: %d\n", 5);
+Seed.printf("One third is approximately %.3f\n", 1/3);
+Seed.printf("%d %s %d\n", 2, " is not ", 5);
+
+var my_string = Seed.sprintf("%d + %d = %d", 2, 3, 2+3);
+var my_name = Seed.printf("[%s] is %d characters long!\n", my_string, my_string.length);
+</pre>
 <div class="section"><b>Seed.readline</b>(prompt)</div>
 <p><i>Returns: user input</i></p>
 <p>
 Uses the GNU Readline library to display a prompt (using the <i>prompt</i> argument) and then wait for input from the user. The readline prompt provides history (using the up and down arrow keys) within a single Seed process.
 </p>
-Seed.{import_namespace, include, print, readline, prototype, check_syntax, introspect, fork}
-Seed.argv
-
-.signal_<xyz>.connect
-
-Exceptions
+<pre>
+var input = Seed.readline("prompt> ");
+Seed.print(input);
+</pre>
+<div class="section"><b>Seed.check_syntax</b>(code)</div>
+<p>
+Examines a segment of Javascript, looking for syntax errors. If errors are found, an exception is thrown, which can be caught with a try/catch block.
+</p>
+<pre>
+try
+{ Seed.check_syntax("234[asdf"); }
+catch(e)
+{ Seed.print("Something horrible happened!"); }
+</pre>
+<div class="section"><b>Seed.fork</b>()</div>
+<p><i>Returns: pid of child (to parent); 0 (to child)</i></p>
+<p>
+Creates a new process which is an exact copy of the current one, starting from the next instruction in both processes. It works just as <a href="http://www.opengroup.org/onlinepubs/000095399/functions/fork.html";>POSIX fork</a> should.
+</p>
+<pre>
+var pid = Seed.fork();
 
-when you have things that aren't actually objects , like cluttercolor, you don't have an actual construction and it gets mappppppeed to Clutter.Color._new()
+if(pid)
+{
+    // Parent
+    
+    while(1)
+        Seed.print("From Parent");
+}
+else
+{
+    // Child
+    while(1)
+        Seed.print("From Child");
+}
+</pre>
+<div class="section"><b>Seed.setTimeout</b>(code, timeout)</div>
+<p>
+Evaluates a given segment of Javascript after <i>timeout</i> milliseconds. Keep in mind that this is evaluated in the global context, so local variables surrounding the call to setTimeout will not be available! Also, setTimeout will <b>only</b> work while a GLib main loop is running (after you've called Gtk.main(), etc.).
+</p>
+<div class="section"><b>Seed.prototype</b>(constructor)</div>
+<p>
+Returns the prototype for an object created with <i>constructor</i>. This can be used to add methods to all future objects of a particular class.
+</p>
+<pre>
+Seed.prototype(Gio.FileInputStream).get_contents = function()
+{
+	var stream = Gio.DataInputStream._new(this);
+	var line = stream.read_until("", 0);
+	return line;	
+}
+</pre>
+<div class="section"><b>Seed.introspect</b>(function)</div>
+<p>
+Returns an object containing information about the function, its arguments, etc. This will eventually support introspection of a wider variety of Javascript types.
+</p>
+<pre>
+proto = Seed.prototype(Gtk.Window);
+method = Seed.introspect(proto.translate_coordinates);
 
+for(i in method.args)
+{
+    Seed.print(method.args[i].type)
+}
+</pre>
+<div class="section"><b>Seed.stringify</b>(object)</div>
+<p>
+Returns a string representing the entire contents of <i>object</i> in a pretty-printed fashion, like that of JSON.
 </p>
+<pre>
+proto = Seed.prototype(Gtk.Window);
+method = Seed.introspect(proto.translate_coordinates);
+Seed.print(Seed.stringify(method);
+</pre>
+<div class="section"><b>Seed.argv</b></div>
+<p>
+An array representing the arguments passed to the <code>seed</code> interpreter.
+</p>
+<div class="section"><b><i>object</i>.signal_<i>signame</i>.connect</b>(function<i>, context</i>)</div>
+<p>
+Connects <i>function</i> to the signal, <i>signame</i>, on <i>object</i>. Any GObject signal will work. <i>context</i> is passed to the signal handler as the <code>this</code> object; if omitted, the global context is used.
+</p>
+<pre>
+function button_clicked()
+{
+    Seed.print("You pushed me!!");
+}
+
+var button = new Gtk.Button();
+button.signal_clicked.connect(button_clicked);
+</pre>
+<div class="section"><b>Exceptions</b></div>
+<p>
+Seed throws Javascript exceptions for errors in the GObject layer; our custom exception types are as follows:</p>
+<ul>
+<li><b>InvalidPropertyValue</b> - a property was set to a value out of range</li>
+<li><b>PropertyError</b> - an error occurred in GLib while trying to set a property</li>
+<li><b>NamespaceError</b> - Seed.import_namespace() was called with a nonexistant namespace or namespace version</li>
+<li><b>ArgumentError</b> - a function was called with the wrong number/type of arguments</li>
+<li><b>SyntaxError</b> - a syntax error was thrown from JavaScriptCore</li>
+<li><b>ParseError</b> - a parsing error was thrown from JavaScriptCore (make sure you close all of your brackets!)</li>
+</ul>
+<p>Exceptions are caught with the <code>try/catch</code> construct:</p>
+<pre>
+try
+{
+    var window = new Gtk.Window();
+    window.opacity = "hello!";
+}
+catch(e)
+{
+    Seed.print("An exception occurred!");
+}
+</pre>
+<p>
+<code>e</code> is the name we've given the Exception object in this examle. The Exception object has a handful of properties which provide more information about the exception:</p>
+<ul>
+<li><b>name</b> - the exception type</li>
+<li><b>message</b> - the detailed message describing the exception</li>
+<li><b>line</b> - the line on which the exception took place</li>
+<li><b>sourceURL</b> - the source file, if any, in which the exception took place</li>
+</ul>
 </body>
 </html>

Modified: trunk/examples/ide/ide.js
==============================================================================
--- trunk/examples/ide/ide.js	(original)
+++ trunk/examples/ide/ide.js	Wed Nov  5 19:59:17 2008
@@ -6,6 +6,7 @@
 Seed.import_namespace("Gio");
 Seed.import_namespace("Pango");
 Seed.import_namespace("GConf");
+Seed.import_namespace("Gdk");
 
 Gtk.init(null, null);
 GConf.init(null, null);

Modified: trunk/examples/ide/tabview.js
==============================================================================
--- trunk/examples/ide/tabview.js	(original)
+++ trunk/examples/ide/tabview.js	Wed Nov  5 19:59:17 2008
@@ -61,9 +61,7 @@
 
 function change_page(notebook, tab, n)
 {
-    //Seed.print("lol");
-    //tabs.get_tab_label(tabs.get_nth_page(n));
-    //update_window();
+    update_window(tabs.get_tab_label(tabs.get_nth_page(n)).get_children()[0].label);
 }
 
 function ide_ui()

Modified: trunk/examples/ide/toolbar.js
==============================================================================
--- trunk/examples/ide/toolbar.js	(original)
+++ trunk/examples/ide/toolbar.js	Wed Nov  5 19:59:17 2008
@@ -1,3 +1,47 @@
+function ide_actions(tab)
+{
+    this.actions = new Gtk.ActionGroup({name:"toolbar"});
+    
+    this.accels = new Gtk.AccelGroup();
+    window.add_accel_group(this.accels);
+    
+    this.new_action = new Gtk.Action({name:"new", label:"New",
+                                      tooltip:"New File", stock_id:"gtk-new"});
+    this.new_action.set_accel_group(this.accels);
+    this.actions.add_action_with_accel(this.new_action, "<Control>n");
+    this.new_action.connect_accelerator();
+    this.new_action.signal_activate.connect(new_file, tab);
+    
+    this.open_action = new Gtk.Action({name:"open", label:"Open",
+                                      tooltip:"Open File", stock_id:"gtk-open"});
+    this.open_action.set_accel_group(this.accels);
+    this.actions.add_action_with_accel(this.open_action, "<Control>o");
+    this.open_action.connect_accelerator();
+    this.open_action.signal_activate.connect(open_file, tab);
+    
+    this.save_action = new Gtk.Action({name:"save", label:"Save",
+                                      tooltip:"Save File", stock_id:"gtk-save"});
+    this.save_action.set_accel_group(this.accels);
+    this.actions.add_action_with_accel(this.save_action, "<Control>s");
+    this.save_action.connect_accelerator();
+    this.save_action.signal_activate.connect(save_file, tab);
+    
+    this.undo_action = new Gtk.Action({name:"undo", label:"Undo",
+                                      tooltip:"Undo", stock_id:"gtk-undo"});
+    this.undo_action.signal_activate.connect(undo, tab);
+    
+    this.redo_action = new Gtk.Action({name:"redo", label:"Redo",
+                                      tooltip:"Redo", stock_id:"gtk-redo"});
+    this.redo_action.signal_activate.connect(redo, tab);
+    
+    this.execute_action = new Gtk.Action({name:"execute", label:"Execute",
+                                      tooltip:"Execute File", stock_id:"gtk-execute"});
+    this.execute_action.set_accel_group(this.accels);
+    this.actions.add_action_with_accel(this.execute_action, "<Control>r");
+    this.execute_action.connect_accelerator();
+    this.execute_action.signal_activate.connect(execute, tab);
+}
+
 function new_file(sv)
 {
     var tab = new ide_tab("");
@@ -77,21 +121,15 @@
 
 function ide_toolbar(tab)
 {
+    actions = new ide_actions(tab);
     this.toolbar = new Gtk.Toolbar();
     
-    this.new_button = new Gtk.ToolButton({stock_id:"gtk-new"});
-    this.open_button = new Gtk.ToolButton({stock_id:"gtk-open"});
-    this.save_button = new Gtk.ToolButton({stock_id:"gtk-save"});
-    this.undo_button = new Gtk.ToolButton({stock_id:"gtk-undo"});
-    this.redo_button = new Gtk.ToolButton({stock_id:"gtk-redo"});
-    this.run_button = new Gtk.ToolButton({stock_id:"gtk-execute"});
-
-    this.new_button.signal_clicked.connect(new_file, tab);
-    this.open_button.signal_clicked.connect(open_file, tab);
-    this.save_button.signal_clicked.connect(save_file, tab);
-    this.undo_button.signal_clicked.connect(undo, tab);
-    this.redo_button.signal_clicked.connect(redo, tab);
-    this.run_button.signal_clicked.connect(execute, tab);
+    this.new_button = actions.new_action.create_tool_item();
+    this.open_button = actions.open_action.create_tool_item();
+    this.save_button = actions.save_action.create_tool_item();
+    this.undo_button = actions.undo_action.create_tool_item();
+    this.redo_button = actions.redo_action.create_tool_item();
+    this.execute_button = actions.execute_action.create_tool_item();
     
     this.toolbar.insert(this.new_button, -1);
     this.toolbar.insert(this.open_button, -1);
@@ -100,6 +138,6 @@
     this.toolbar.insert(this.undo_button, -1);
     this.toolbar.insert(this.redo_button, -1);
     this.toolbar.insert(new Gtk.SeparatorToolItem(), -1);
-    this.toolbar.insert(this.run_button, -1);
+    this.toolbar.insert(this.execute_button, -1);
 }
 

Added: trunk/tests/make-test.py
==============================================================================
--- (empty file)
+++ trunk/tests/make-test.py	Wed Nov  5 19:59:17 2008
@@ -0,0 +1,50 @@
+#!/usr/bin/python
+
+import os
+import re
+import sys
+import stat
+
+rfile = open(sys.argv[1], "r")
+test_code = rfile.readlines()
+
+if(test_code[1].find("// STDIN") >= 0):
+    test_in = test_code[1].replace("// STDIN:","").rstrip().replace("\\n","\n")
+else:
+    test_in = ""
+
+(n,out,err) = os.popen3("./" + sys.argv[1])
+		
+if(test_in != ""):
+	n.write(test_in + "\004")
+	n.close()
+
+outf = open(sys.argv[1].replace("_.js",".js"),"w")
+
+def sanitize(san):
+    san = san.replace("(","\\(");
+    san = san.replace(")","\\)");
+    san = san.replace("[","\\[");
+    san = san.replace("]","\\]");
+    san = san.replace("{","\\{");
+    san = san.replace("}","\\}");
+    san = san.replace(".","\\.");
+    san = san.replace("*","\\*");
+    san = san.replace("$","\\$");
+    san = san.replace("^","\\^");
+    san = san.replace("/","\\/");
+    san = san.replace("\\","\\\\");
+    san = san.replace("+","\\+");
+    return san
+
+outf.write(test_code[0])
+outf.write("// Returns: 0\n")
+outf.write("// STDIN:" + test_in + "\n")
+outf.write("// STDOUT:" + sanitize("".join(out.readlines()).rstrip()) + "\n")
+outf.write("// STDERR:" + sanitize("".join(out.readlines()).rstrip()) + "\n")
+
+outf.write("".join(test_code[2:]))
+
+outf.close()
+
+os.chmod(sys.argv[1].replace("_.js",".js"), stat.S_IREAD | stat.S_IEXEC | stat.S_IWRITE)

Modified: trunk/tests/run-tests.py
==============================================================================
--- trunk/tests/run-tests.py	(original)
+++ trunk/tests/run-tests.py	Wed Nov  5 19:59:17 2008
@@ -31,7 +31,7 @@
 failed = []
 
 for f in os.listdir("."):
-	if f.endswith(".js"):
+	if f.endswith(".js") and not f.endswith("_.js"):
 		rfile = open(f, "r")
 		test_code = rfile.readlines()
 		test_in = test_code[2].replace("// STDIN:","").rstrip().replace("\\n","\n");



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