RooJSolutions http://roojs.com/index.php/View.html en http://roojs.com/Roojscom/templates/images/roojs_square_logo_150.png RSS: RooJSolutions - /index.php 150 150 Gtk3 introspection updates and Unusable Unity.. 2011-04-25 00:00:00 http://roojs.com/index.php/View/236/Gtk3_introspection_updates_and_Unusable_Unity.html <a href="http://roojs.com/index.php/View.html">Article originally from rooJSolutions blog</a><br/> <div><font size="2">Well, as Gnome 3 is out, it has to be tested.&nbsp;Luckily&nbsp;I've not got a huge deployment to sort out, but as I have a few applications that use Gtk, I thought it was about time I upgraded one of my machines to see what chaos I will have to deal with in the future.</font></div><div><font size="2"><br></font></div><div><font size="2">So it was one of my Ubuntu boxes that got the pleasure of a Natty and <a href="https://launchpad.net/~gnome3-team/+archive/gnome3">Gnome3 PPA</a> upgrade. (I use debian on my other development box, which actually got destroyed last week with a complete disk failure, although I suspect the motherboard may have problems... It's getting old like me...)</font></div><div><font size="2"><br></font></div><div><font size="2">Upgrading to Natty is not to bad, from what I remember it only took a small amount of brain surgery to get it to boot correctly after the upgrade. But once up, you get the pleasure of the Unity desktop. My first impressions where not to hot on unity, my wife uses it on her netbook, it's great there, after the initial shock of me upgrading without her knowing, she actually said it was alot better than compiz. Although she missed the special effects.</font></div><div><font size="2"><br></font></div><div><font size="2">But after using Unity on the big screens, it just became unbearable. Detached menus may seem like a cool idea, and are quite handy on a netbook, but they are an absolute nightmare when using things like gimp on dual head full HD monitors, my wrists hurt after a few minutes....&nbsp;</font></div><div><font size="2"><br></font></div><div><font size="2">Along with the removal of the Applications/Places/System menu's which while klunky are still handy for quickly finding applications. A classic example of this Alleyoop Memory Checker, a very nice wrapper around valgrind. In the Unity world if you do not know the name of the application, then finding it is a huge mouse journey around big icons.&nbsp;</font></div><div><font size="2"><br></font></div><div><font size="2">As for the left icon menu, all I can say is that I'm not the worlds best designer (although at least I did study it), but it's so graphically noisy that it unusable. It's basically a bad re-invention of Docky/Cairo Dock, which do far better jobs at providing a similar task role.&nbsp;</font></div><div><font size="2"><br></font></div><div><font size="2">So after all that I did try and get gnome-shell going, but unfortunatly the Gnome3 PPA build is not currrently working, and also has a rather nasty habit removing all usable desktop enviroments. I ended up adding xterm to one of the /etc/Xorg/X.sessiond files and starting up gnome-panel, mutter and docky to produce a usable desktop for the time being, while I wait to test out the latest gnome-shell.</font></div><h3><font size="2">So on with the harder stuff.. - Gtk3 and introspection.</font></h3><div><font size="2">One of the key applications I use to develop is<a href="http://www.roojs.org/blog.php/app.Builder.js.html"> app.Builder.js</a> , it's a drag/drop interface to build web applications, that also allows you to fill in all the code and associate it clearly with the element and event occuring. It's written in Javascript, and uses Gnome seed to run on the desktop. As I've mentioned before Seed is a bridge layer between the Webkit Javascript engine, and Gobject-introspection, the now standard way to interface Gnome/Gtk/Glib etc. projects to non-C languages, eg. Python, Javascript (and others...)</font></div><div><font size="2"><br></font></div><div><font size="2">With the introduction of Gtk3, GObject introspection has also been updated, and the updated mix between the two had quite a few knock on effects to the builder I had written using Gtk2 and pre-0.9 versions of Gobject introspections. Heres a general summary of the changes.</font></div><h3><font size="2">TreeIter and TextIter&nbsp;</font></h3><div><font size="2">The latest version of GObject introspection has a feature called caller allocates, this basically means that previously with Seed we had to create an instance of a TreeIter, the the TreeIter call would be of type 'inout' (eg. the Iter would be sent into the method, and returned out)</font></div><div><font size="2"><br></font></div><div><font size="2">eg. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</font></div><pre><font size="2">var iter = new Gtk.TreeIter();<br></font><font size="2">model.get_iter_from_string(iter, path);<br></font><font size="2">// iter would now contain the tree iter for that path..</font></pre><div><font size="2"><br></font></div><div><font size="2">In newer versions, the iter is an 'out' value, which means you have to create an object for the iter to be added to. eg.</font></div><pre><font size="2">var iret = {};<br></font><font size="2">model.get_iter_from_string(iret, path);<br></font><font size="2">// iret.iter now contains the tree iter.</font></pre><div><font size="2"><br></font></div><h3><font size="2">TreeSelection&nbsp;</font></h3><div><font size="2">since the get_selected method for a GtkTreeSelection now has 2 out values, the call has change from</font></div><div><font size="2"><br></font></div><div><font size="2">OLD:</font></div><pre><font size="2">var iter = new Gtk.TreeIter();<br></font><font size="2">selection.get_selected(model, iter);</font></pre><div><font size="2"><br></font></div><div><font size="2">NEW</font></div><pre><font size="2">var sret = {};<br></font><font size="2">selection.get_selected(sret);<br></font><font size="2">// sret now contains { model: **THE MODEL**, iter: **THE ITER** }</font></pre><div><font size="2"><br></font></div><h3><font size="2">TreeModel get_value</font></h3><div><font size="2"><br></font></div><div><font size="2">Since get_value does not have a return value, seed with return the 'out' values as the return object.</font></div><div><font size="2"><br></font></div><div><font size="2">OLD:</font></div><pre><font size="2">var value = new GObject.Value('');<br></font><font size="2">model.get_value(iter, 2, value);<br></font><font size="2">print(value.value);</font></pre><div><font size="2"><br></font></div><div><font size="2">NEW</font></div><pre><font size="2">var str = model.get_value(iter, 2).value.get_string();<br></font><font size="2">print(str);</font></pre><div><font size="2"><br></font></div><h3><font size="2">Drag pixmap becomes surfaces</font></h3><div><span style="font-size: small; ">This is a pure Gtk3 API change (BC break)</span></div><div><font size="2"><br></font></div><div><font size="2">OLD:</font></div><pre><font size="2">var pix = widget.create_row_drag_icon ( path);<br></font><font size="2">Gtk.drag_set_icon_pixmap (ctx, pix.get_colormap(), &nbsp; pix, &nbsp;null, ..... )</font></pre><div><font size="2"><br></font></div><div><font size="2">NEW:</font></div><pre><font size="2">var pix = widget.create_row_drag_icon ( path);<br></font><font size="2">Gtk.drag_set_icon_surface(ctx, pix);</font></pre><h3><font size="2">Drag drop data passing..</font></h3><div><font size="2"><br></font></div><div><font size="2">The drag drop signals appear to work ok, however I've not managed to get the data to go back and forth,&nbsp;</font></div><div><font size="2">a quick workaround is to just use some form of global variable to store the current dragged item (I doubt you will get more than one dragged item at once..)</font></div><div><font size="2"><br></font></div><h3><font size="2">Drag drop API</font></h3><div><span style="font-size: small; ">alot of these appear to have played musical chairs.</span></div><pre><font size="2">GtkWidget.prototype.drag_source_set -&gt; Gtk.drag_source_set</font><font size="2"><br></font><font size="2">Gtk.drag_source_set_target_list -&gt; GtkWidget.prototype.drag_source_set_target_list<br></font><font size="2">Gtk.drag_dest_set -&gt; GtkWidget.prototype.drag_dest_set</font></pre><div><font size="2"><br></font></div><h3><font size="2">Internal Seed changes</font></h3><div><font size="2"><br></font></div><div><font size="2">I've added a few more fixes to Seed in the last few weeks, mostly to handle compiling correctly and detecting the correct version of introspection. for the most part it's working fine, however I'm still a bit baffled by a Glib memory corruption bug, which occured after multiple model.set_value and model.get_value calls. After running valgrind, I managed to stop the corruption occuring by increasing the allocated size for a struct by 1 byte&nbsp;</font></div><div><font size="2">Around line 546 and 640 of seed-engine.c the change goes something like this.</font></div><pre><font size="2">- &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;out_args[n_out_args].v_pointer = g_malloc0 (size);<br></font><font size="2">+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;out_args[n_out_args].v_pointer = g_malloc0 (size+ 1);</font></pre><div><font size="2"><br></font></div><div><font size="2">Arround line 738 of seed-structs.c &nbsp;</font></div><pre><font size="2">- &nbsp;object = g_slice_alloc0 (size);<br></font><font size="2">+ &nbsp;object = g_slice_alloc0 (size +1);</font></pre><div><font size="2">&nbsp;</font></div><div><font size="2"><br></font></div><div><font size="2"><br></font></div><div style="font-size: 13px; "><br></div> GtkDjs, daily builds, added libraries and much more.. 2007-08-07 17:42:45 http://roojs.com/index.php/View/152/GtkDjs_daily_builds_added_libraries_and_much_more.html <a href="http://roojs.com/index.php/View.html">Article originally from rooJSolutions blog</a><br/> <h3>Daily builds / downloads available</h3>I've set up a cron job now, so all the bindings and binaries are built daily, you can download them from here.<br /><a href="http://devel.akbkhome.com/gtkjs/gtkjs_snapshot.tar.bz2">http://devel.akbkhome.com/gtkjs/gtkjs_snapshot.tar.bz2</a><br />This includes gtkjs, mjs and jsfastcgi, In theory it would not take too much to build this on Windows... - Send me the fixes if you  attempt it...<br /><br />Just download, unzip and try out <br /><pre>./gtkjs test/filetree.ds</pre>etc.<br /><br />the <a href="http://www.akbkhome.com/gtkDjs/">gtkdjs Documentation</a> is updated daily to match<br /><br />And I still need a better name for the project;)<br /><br /><br /><h3>Closure and scoping fixes. </h3>After seeing a post on the <a href="news://news.digitalmars.com/DMDScript">DMDScript newsgroup</a> concerning closures and scoping issues, I spent quite a while looking at the issue. <br /><br />The basic problem, was that the original DMDscript code was designed to create a cache of function definitions, and re-use them whenever they where refered to. Along with this, they had no concept of creationScope. so variables in the creating scope where not available. Fixing this involved quite a few changes to the compiler and runtime. Basically creating new Function instances when they are found, rather than only once at compile time. Along with storing the scope inside the Function instance. so when they are called they understand the correct scope. Anyway standard Javascript scoping, and closures all work as expected.<br /><br /><br /><h3>Undefined Warnings improved</h3>I mentioned in my last post that I added Warnings when undefined variables where accessed, I've modified this slightly as undefined is a valid type in Javascript, so unassigned arguments to a function call are flagged as undefined, but accessing them should not issue a warning. So only when the scope.Get(variablename) calls return null, rather than a Value.vtype[V_UNDEFINED] flag this warning now. <br /><h3>LibSoup extension </h3>LibSoup provides HTTP support, at present, basic sync requests work, the code is there for async calls, but I've not tested it yet. test code is in tests/Soup/.<br /><br />This little bit of code get's my web site, and shows headers, then extracts all the href from all the &lt;a&gt; tags.<br /><pre>var sess = new Soup.SessionSync();<br /><br />var msg = new Soup.Message(&quot;GET&quot;, &quot;http://www.akbkhome.com/&quot;);<br />status = sess.sendMessage(msg);<br /><br />println(&quot;Status is &quot; + status);<br />println(&quot;ResponseHeaders is &quot; + msg.responseHeaders.toSource());<br /><br /><br />var imp = new Dom.Implementation;<br />var doc = imp.createHtmlDocFromMemory(msg.response);<br />var a_s = doc.getElementsByTagName(&quot;a&quot;);<br />for(var i =0; i &lt; a_s.length; i++) {<br /> println(&quot;got href: &quot; + a_s.item(i).getAttribute(&quot;href&quot;));<br />}<br /></pre><h3>XML2 limited support</h3>To enable parsing of html documents for Gdome, I've added limited support for XML2, it's mostly used by the Gdome method:  <span style="font-weight: bold;">Dom.Implementation.prototype.createHtmlDocFromMemory( String htmltext )</span><br />The Generator code is currently tied into the libxml header files on my system.. this needs fixing so it uses the gtkwrap download script. (but the code is a  nice example of how to automatically create bindings based on .h files..)<br /><br /><br /><h3>Gtk.SourceView support</h3>In preperation for testing text editing (and eventually self-editing / morphing of applications), I've bound the GtkSourceView widget. Unlike the standard Leds editor which uses scintilla, I thought I'd try and see if using GtkSourceView would prove more robust. - The bindings had already been done for GtkD, so there was not much to change to the APILookupSourceView.txt code. I only used the full name &quot;sourceview&quot; rather than &quot;gsv&quot;<br /><br /><h3>Handling of missing functions and Libraries improved</h3>When I was testing GtkToolbar on one of my machines which had an old Gtk library, I discovered a segfault when it called a newer function that did not exist in the old library. To fix this, the Loader.d file now binds a simple function that throws and exception to any method it can not bind. So you can catch in javascript any call to unsupported methods in a library.<br /><br /><br /><h3>Phobos Path module added</h3>all the methods from <a href="http://www.digitalmars.com/d/phobos/std_path.html">std.path</a> are now exported to javascript, and in the manual. This enables a few usefull functions like<br /><br /><pre>var file = &quot;/etc/passwd&quot;<br />println(&quot;Directory = &quot; + Path.getDirName(file));<br />println(&quot;Filename = &quot; + Path.getBaseName(file));<br />println(&quot;combined filename = &quot; + Path.join(&quot;etc&quot;,&quot;passwd&quot;));<br /></pre><br /><h3>Regex Fixes</h3>In testing extjs parsing, I came across two bugs in D's regex implementation, that prevented it's loading.<br /><ul><li>forgetful parsing (?:abc|cde|xyz) - the fix for this was trivial and is in D's bugtracker, and there is a modified regex file in the dmdscript distribution.</li><li>the use of special chars in character range matching after the '-'. eg.  [\w-\*] and [\w-\.] which should be interpreted as [\w\*-] and [\w\.-].  These currently parse correctly however I've not got round to fixing the implementation properly so they are pretty broken at present. (basically matching everything from \w onwards...) - the bugs in D's bugtraker, but the fix is not... I may get back to this...</li></ul><h3>Simplified exporting of Structures</h3>One of the missing pieces for the Gtk Bindings, that I came accross with jLeds, was the event structures had not been bound. Since they are very simple structs, and you only need to get access to their properties, I developed a new action for the wrap file &quot;structDump&quot; which autogenerates the class file, forces the full Struct definition to be written and writes getter methods for all the exportable properties.<br /><br /><h3>Bindings builder flexibility</h3>Since we now have about 20 libraries bound, the Wrapping builder script can take a little while on slow systems to build all the bindings code. So I've added the ability to specify which APILookup files to action.<br />eg. to build LibSoup you can do.<br /><pre>sh buildit.sh APILookupGLib.txt APILookupGObject.txt APILookupSoup.txt </pre>It cant do the dependancy resolution yet, so you have to list all the pre-requisite packages so it has access to all the required types when building the library you need.<br /><br />The struct parser is also a  little more robust now, handling comments and lists of elements eg.<br />ushort x, y;<br /><br /><br /><br /><h3>Minor Gtk Fixes</h3><ul><li><span style="font-weight: bold;">G.Object.setProperty(String key, Any value)</span> now works, and converts value into G.Values automatically.</li><li><span style="font-weight: bold;">GtkTreePath[] Gtk.TreeSelection.prototype.getSelectedRows(Gtk.TreeModel model) </span> now works - although I need to look at generic ways to generate array of Objects from GList..</li><li><span style="font-weight: bold;">new Gtk.TreeStore(Array coltypes) </span>now works (where coltypes is either an array of strings, or G.Types.) - this works along with the other constructor methods - eg. varargs......</li><li><span style="font-weight: bold;">Gtk.TreeStore.prototype.set(Gtk.TreeIter row, Array values)</span> now works to quickly set the values of a tree row, rather than calling <span style="font-weight: bold;">set(GtkTreeIter row, Number col, Mixed value)</span></li><li><span style="font-weight: bold;">Gtk.Container.prototype.remove(Number item)</span> and <span style="font-weight: bold;">Gtk.Container.prototype.remove(Gtk.Widget widget)</span> are now working - I need to change this slightly, so you can remove all by sending '0' as the item, and waiting until it returns false...</li><li>Most of the  GtkEvent Structures are now exported, and all the properties are available as getters.</li><li><span style="font-weight: bold;">new GdkColor(Number color) </span> is based on 0xRRGGBB hexidecimal values, rather than longintegers.. (you can use the long version to do more precise colours: <span style="font-weight: bold;">new GdkColor(Number red, Number green , Number blue);</span></li><li><span style="font-weight: bold;">new Gdk.Pixbuf(Array xpmdata)</span> is now supported so converting xpm data for use as icons is very simple (just replace &quot;const char**&quot; with &quot;var&quot;)</li></ul><br /><br /><h3>ExtJs loading</h3>One of the goals is to make the engine compatible with existing code out there, a nice test of this was extjs, which it can now load correctly (with a few lines of javascript prefixing the loading). I've not actually tested any of the functionality yet, as XmlHttpRequest needs building from the libsoup bindings.<br /><br /><h3>jLeds port underway..</h3>What's a language without an editor (or an email client - if you know the old joke about every application eventually evolves until it can read email.).. So partly to test the bindings I've started looking at porting Leds to gtkjs - the code is in tests/jLeds, and gives a good example of some of the new Javascript2 features, along with the gtk bindings.<br /><br /><br />Try the newsgroup if you need support.<br /><a href="news://news.digitalmars.com/DMDScript">news://news.digitalmars.com/DMDScript</a><br /><br /> gtkds - more updates and better debugging.. 2007-07-31 23:08:00 http://roojs.com/index.php/View/151/gtkds__more_updates_and_better_debugging.html <a href="http://roojs.com/index.php/View.html">Article originally from rooJSolutions blog</a><br/> Add one feature, and create a few bugs.. seems like it's always the way..<br /><br />The two features added over the weekend where class syntax support and include support. My initial effort proved to be a little off the mark. <br /><br />Read on if you want to know the nitty gritty details about writing an interperted language runtime... Along with a list of the Gtk binding improvements..<span style="font-weight: bold;"><br /></span><p /><br /> Compairing Adobe AIR to dmdscript / fastcgijs / gtkjs 2007-07-28 22:36:00 http://roojs.com/index.php/View/150/Compairing_Adobe_AIR_to_dmdscript__fastcgijs__gtkjs.html <a href="http://roojs.com/index.php/View.html">Article originally from rooJSolutions blog</a><br/> A good friend of mine asked what's the difference between the dmdscript/fastcgijs/gtkjs stuff I'm doing and Adobe AIR.<br /><br />I've not really looked at Adobe AIR much, noticed that it was mentioned on the extjs site, so I thought I'd do a quick &quot;what's the difference&quot;..<br /><br />So what's the key differences<br /><br />For Adobe AIR<br /><ul><li>Backed by a huge company with unknown reasons for hooking you in.</li><li>Lot's of support for Adobe technology, but any other libraries, you can forget about.</li><li>Probably written in C++ or C, so there are probably a few nice security holes difficult to find in the memory allocation. Even if you did have access to the source - it would be a pretty complex task to write bindings for libraries.<br /></li><li>Great support for Windows, pretty good for Mac, and bugger all for other un*x's</li></ul>For GtkJs / Fastcgijs / dmdscript<br /><ul><li>Absolutly no support ;) - obviously only done, because it's interesting and fun!<br /></li><li>Lots of support for any open source library, as long as you are willing to waste a few days working out how mindblowingly simple it is to write bindings.</li><li>Written in D, which makes it pretty secure (well if you fix some of the bugs in my generator to do a small amount of sanity checks). And due to the fact that it's so similar in syntax to Javascript that makes the whole process of moving slow parts into compiled code considerable simpler than any other scripted language..</li><li>Great support for linux, and it might just work on any other platform, as long as you can find someone who knows those platforms.<br /></li></ul> Personally I think the Adobe AIR idea is pretty good, Javascript is a good basis for a language. But to be honest for the reasons above, I would not touch it with a barge pole..<br /> javascript2, ECMAScript4 and dmdscript. 2007-07-27 16:59:01 http://roojs.com/index.php/View/149/javascript2_ECMAScript4_and_dmdscript.html <a href="http://roojs.com/index.php/View.html">Article originally from rooJSolutions blog</a><br/> Last week I had a go using my little bindings for something useful, rather than just being a little toy. One of the projects I was working on was a hack to exim4, that logged all incomming and outgoing attachments into mysql and stored them on the filesystem.<br /><br />The basic idea was that the company needed the ability to review if any sensitive data was being sent out by email. The exim hacks are pretty simple for this (hook into the mime handler). The web viewer uses extjs and PHP at the backend, it's a small addition to their current email management interface.<br /><br />But one area that was needed was a little cron job that cleaned up the directories and deleted data and files older than 2 weeks (so they dont get too clogged up.)<br /><br />I thought this would be an interesting test of the mysql and file system bindings. So I threw together a horrifically simplistic version of DataObjects, and a short script that did an SQL query and based on the results deleted records and files.<br /><br />One issue was that I could not really do the DataObjects thing of overlaying the results, or query options into the dataobject as object variables in javascript are overlaid into the same namespaces as methods, so you could accidentally delete methods if your database had matching names. - So the data just gets put in (dataobject).data.*  <br /><br />The other issue was that the syntax for javascript while fun and flexible could really do with a class construct. If you look through the specifications for <a href="http://developer.mozilla.org/es4/spec/chapter_0_preface.html">ECMAScript4</a>, There is a huge amount of changes making Javascript as we know it far more Java / PHP5'y.. with interfaces, public private etc. So I had a go at adding some of the new features into the dmdscript core.<br /><br />I've managed to get class's and include working. although it probably needs quite a bit more testing. This basic syntax now works<br /><pre>include &quot;mytest.ds&quot;; // this is run at compile time (not runtime!)<br /><br />class A {<br /> function A() {<br /> println(&quot;This is the constructor A&quot;);<br /><br /> }<br /> var c = 12;<br /> function B() {<br /> println(&quot;This is B and c is &quot; + this.c);<br /> }<br /><br /><br />}<br />class C extends A <br />{<br /> function C() {<br /> println(&quot;This is the constructor C&quot;);<br /> A.prototype.constructor.call(this);<br /> }<br /> function D() {<br /> println(&quot;This is D and c is &quot; + this.c);<br /> }<br />}<br /> <br /> <br />var a = new A();<br />a.B();<br /><br />var c = new C();<br />c.B();<br />c.D();<br /><br /></pre>Will successfully output<br /><br /><pre>Hello from mytest<br />This is the constructor A<br />This is B and c is 12<br />This is the constructor C<br />This is the constructor A<br />This is B and c is 12<br />This is D and c is 12<br /><br /></pre>Now I can start writing tidy little javascript libraries...<br /><br /><br /><br /><br /> dmdscript with fastcgi 2007-07-13 18:25:37 http://roojs.com/index.php/View/147/dmdscript_with_fastcgi.html <a href="http://roojs.com/index.php/View.html">Article originally from rooJSolutions blog</a><br/> I've been slowly ticking away adding features to the gtk javascript bindings, in doing so, I'm adding extra libraries - Mysql works quite well, and Seeing the recent post on <a href="http://planet.dprogramming.com">planet.dprogramming.com</a> about <a href="http://dblog.aldacron.net/2007/07/09/fastcgi4d-09-alpha/">fastcgi4d</a>, I wondered if I could run dmdscript from fastcgi.<br /><br />To enable a web version of dmdscript with my bindings, I had to do quite a bit of re-organization, enabling it to be built with random libraries added in and exclude the Gtk stuff. Core to this was to move all the registration code into the directories that hold the binding code. Each binding directory now contains 3 files, binding***.d, binding***type.d and register***.d. Which manage the dynamic loading of .so (or .dll if windows actually works). and the registering of all the javascript objects and methods.<br /><br />For fastcgi, I had a look at the code described on the blog post, but was very reluctant to use it, as it <br /><ul><li>required tango, which is not a current requirement, and I'm a little concerned about using.</li><li>required knowlege of templates, which are still a bit of a black art. and I've only used very sparingly when absolutly every other alternative has been ruled out.</li></ul>So after considerable digging through the code and trying to make head or tail of the code on fastcgi.com, I finally found the python fastcgi code, which ported easily to D. <br /><br />The core files libraries that are helpers in dealing with fastcgi are here.<br />http://www.akbkhome.com/svn/gtkDS/src/fastcgi/<br /><br />They need the loader.d and paths.d file from here<br />http://www.akbkhome.com/svn/gtkDS/wrap/<br />to be usable.<br /><br />and the current, non-threaded simple responder is here<br />http://www.akbkhome.com/svn/gtkDS/src/fcgi.d<br /><br />So for hello world example, this simple piece of code dumps all the server variables and says hello world.<br /><pre>println(Request.toSource());<br /><br />println(&quot;hellow world from javascript&quot;);</pre>Next job is to look at how GET/POST data is passed around and how to escape data on output. among a list of 100 ideas for how it could all work.<br /> GtkD - Anatomy of the bindings generator. 2007-06-28 08:58:00 http://roojs.com/index.php/View/146/GtkD__Anatomy_of_the_bindings_generator.html <a href="http://roojs.com/index.php/View.html">Article originally from rooJSolutions blog</a><br/> <div> <p> </p><p><span style="font-family: 'arial';">To generate the Gtk bindings (and adding other features) for gtkDjs I use a code generator. This is pretty common to all the Gtk bindings. I worked on the PHP-GTK ones a long time ago, which in turn where based loosely off the Python bindings.</span></p> <p> </p><p><span style="font-family: 'arial';">For GtkDjs, the starting point was the GtkD binding code. While the current code is still similar to it's parent, It has grown considerably since it's original birth. So In the vain of &quot;if someone ever feels like helping out with the bindings&quot;, or wants to write and send me bindings for SQLite, Mysql, curl or libsoup etc. Here's the inside story of them.</span></p> <p> </p><p><span style="font-weight: bold; font-family: 'arial';">The basic concept.</span></p> <p><span style="font-family: 'arial';">In essence, the bindings work using &quot;generator scripts&quot; called APILookup*.txt, which contain a series of either information, or instructions to do tasks.</span></p> <p> </p><p><span style="font-family: 'arial';">Other than the overall configuration settings for the generator, or libraries, the core part of generating bindings is to create classes. In Gtk this is normally done by reading the HTML documentation for a specific Gtk Struct, and using that information to generate data about the Enums, Signals and Methods that are defined. This is all done by GtkClassParser.d</span></p> <p> </p><p><span style="font-family: 'arial';">Finally after the File has been parsed, the Output classes &quot;ClassOut, FuncOut, EnumOut, LibraryOut, PhobosOut, SignalOut&quot; generate the code files in the src directory.</span></p> <p> </p><p><span style="font-family: 'arial';">Unlike the original GtkD bindings GtkDjs does a double pass at generating each of the packages, as we use the first pass to calculate dependencies and inheritance, rather than relying on the list of imports in the APILookup files. This means that the APILookup*.txt files do not really have to list all the required imports. </span></p> <p> </p><p> </p><p><span style="font-weight: bold; font-family: 'arial';">More details on the APILookup files.</span></p> <p><span style="font-family: 'arial';">While I'm not going to explain all the possible commands available in the files, I will explain the concept and a few key ones. The file &quot;GtkWrap.d&quot; contains the parser, with a complete list of keywords and actions, it's a reasonably simple and obvious piece of code. I'm still adding new commands when I see them as necessary, and may even remove a few as some are pretty pointless or unused.. (like code: *** which is ignored but is usefull for reference on how GtkD did things).</span></p> <p> </p><p><span style="font-family: 'arial';">The basic concept of the file is a list of data in the formats:</span></p> <p> </p><p class="plain_text"> </p><pre style="font-family: courier new,courier,monospace;"><font size="2">#for simple data<span style="font-weight: bold;"><br />key</span><span lang="en-US" style="font-weight: bold;">word</span> : Value<br /># for building a list of key value pairs<span style="font-weight: bold;"><br />key</span><span lang="en-US" style="font-weight: bold;">word</span> : key valuepair<br />#for long data - like code etc.<span style="font-weight: bold;"><br />key</span><span lang="en-US" style="font-weight: bold;">word</span> : subject<br />......<span style="font-weight: bold;"><br />keyword</span> : <span style="font-weight: bold;">end</span></font></pre> <pre style="font-family: courier new,courier,monospace;"><font size="2">#for long data - (older style)<span lang="en-US" style="font-weight: bold;"><br />keyword</span> : <span lang="en-US" style="font-weight: bold;">start</span><br />......<span lang="en-US" style="font-weight: bold;"><br />key</span><span lang="en-US" style="font-weight: bold;">word</span> : <span lang="en-US" style="font-weight: bold;">end</span></font></pre> <p style="text-align: left; margin-bottom: 0in; margin-top: 0in; margin-right: 0in;" dir="ltr" class="plain_text"> </p><p> </p><p> </p><p><span style="font-family: 'arial';">Order is quite important, as the parser for the APIWrap is not forgiving and can easily go into infinite loops if you get the wrong or unknown keyword in the wrong place. Fortunately using the existing files as a basis for a new one should help out a bit.</span></p> <p> </p><p><span style="font-family: 'arial';">The core APILookup.txt files contains a few key pieces of information</span></p> <ul><li><span lang="en-US" style="font-family: 'arial';"> aliases of Gtk base types to D types (and a few kludges to work around other issues)</span></li><li><span lang="en-US" style="font-family: 'arial';"> mappings of the D-Types to Javascript Types (really related to the method calls on dmdscript.value)</span></li><li><span lang="en-US" style="font-family: 'arial';"> where the files are, like the gtk documentation and where the generated files should be written to.</span></li><li><span lang="en-US" style="font-family: 'arial';"> List of packages, and how they related to directories (Note that the GtkDjs bindings also use a jsPackage command in the individual wrapping files to determine how they are exposed to Javascript)</span></li><li><span lang="en-US" style="font-family: 'arial';"> A small bit of code to copy the dl() loader into the generated directory.</span></li><li><span lang="en-US" style="font-family: 'arial';"> And finally a &quot;include&quot; like statement &quot;lookup:&quot; which tells the parser to start using the new file as it's input.</span> </li></ul> <p style="margin-left: 0pt; text-indent: 0in;"> </p><p style="margin-left: 0pt; text-indent: 0in;"><span lang="en-US" style="font-family: 'arial';">The individual Binding for the specific libraries (or packages as the tend to be called) are structured a little differently.</span></p> <ul><li><span lang="en-US" style="font-family: 'arial';"> At present there are alot of add*: commands, which are generally ignored by GtkDjs, and will probably be removed. - As we auto generate most things </span></li><li><span lang="en-US" style="font-family: 'arial';"> In the Gobject bindings, you will see an example of structCode: which is how structs are described if they can not be done by just pretending they are pointers to void.</span></li><li><span lang="en-US" style="font-family: 'arial';"> Again in the Gobject you can see a manual enum description. necessary as the real Enum is not actually described in the documentation.</span></li><li><span lang="en-US" style="font-family: 'arial';"> next are the two key information, wrap and jsPackage - wrap indicates which package it is wrapping (from those listed in APILookup) - so it knows where to write the files. and jsPackage tells it how to expose it to Javascript</span></li><li><span lang="en-US" style="font-family: 'arial';"> structWrap: is used simply ensure that the struct is available usually as an empty struct.</span></li><li><span lang="en-US" style="font-family: 'arial';"> nostruct: is used to prevent a struct from being bound.. usually an indicator that something needs fixing..</span></li><li><span lang="en-US" style="font-family: 'arial';"> finally we have a small batch of code for each class to be written. The class: command indicates the filename of the code to be written, the real classname is based on the struct that is being wrapped usually. </span></li><li><span lang="en-US" style="font-family: 'arial';"> some of the files have jscode, and jssig elements describing how the automatic code and documentation generation should be overridden.</span> </li></ul> <p style="margin-left: 0pt; text-indent: 0in;"> </p><p style="margin-left: 0pt; text-indent: 0in;"><span lang="en-US" style="font-weight: bold; font-family: 'arial';">The generator code.</span></p> <p style="margin-left: 0pt; text-indent: 0in;"> </p><p style="margin-left: 0pt; text-indent: 0in;"> </p><p style="margin-left: 0pt; text-indent: 0in;"><span lang="en-US" style="font-family: 'arial';">In order of how they are used.</span></p> <p style="margin-left: 0pt; text-indent: 0in;"> </p><ul><li><span lang="en-US" style="font-weight: bold; font-family: 'arial';"> GtkWrap.d </span><span lang="en-US" style="font-family: 'arial';">(includes main()) and is the command interpreter, data from the commands is stored in a ConvParms class (</span><span lang="en-US" style="font-weight: bold; font-family: 'arial';">convparms.d</span><span lang="en-US" style="font-family: 'arial';">), and passed to the Outputters. Any packages that are defined are stored in a class defined in </span><span lang="en-US" style="font-weight: bold; font-family: 'arial';">Packages.d</span><span lang="en-US" style="font-family: 'arial';">.</span></li><li><span lang="en-US" style="font-family: 'arial';"> </span><span lang="en-US" style="font-weight: bold; font-family: 'arial';">DefReader.d</span><span lang="en-US" style="font-family: 'arial';"> is the helper class that does the low level conversion of the APILookup.txt files into commands.</span></li><li><span lang="en-US" style="font-family: 'arial';"> </span><span lang="en-US" style="font-weight: bold; font-family: 'arial';">GtkClassParser.d</span><span lang="en-US" style="font-family: 'arial';"> does the legwork of collection all the described definitions in the HTML file into Classes from </span><span lang="en-US" style="font-weight: bold; font-family: 'arial';">GtkStruct.d GtkFunc.d, GtkEnum.d </span><span lang="en-US" style="font-family: 'arial';">(note signals re-use the GtkFunc class). The </span><span lang="en-US" style="font-weight: bold; font-family: 'arial';">HtmlStrip.d </span><span lang="en-US" style="font-family: 'arial';">library just removes the HTML tags making the documentation files a bit easier to parse.</span></li><li><span lang="en-US" style="font-family: 'arial';"> Finally after a file is parsed, usually the outFile: command is found and the class code is generated by </span><span lang="en-US" style="font-weight: bold; font-family: 'arial';">ClassOut.d.</span><span lang="en-US" style="font-family: 'arial';"> Which in turn loops through the functions, signals and generates the code using </span><span lang="en-US" style="font-weight: bold; font-family: 'arial';">FuncOut.d</span><span lang="en-US" style="font-family: 'arial';"> and </span><span lang="en-US" style="font-weight: bold; font-family: 'arial';">SignalOut.d</span></li><li><span lang="en-US" style="font-family: 'arial';"> At the end of each package file, the loader, struct listing and enum lists are generated from </span><span lang="en-US" style="font-weight: bold; font-family: 'arial';">LibraryOut.d </span><span lang="en-US" style="font-family: 'arial';">which uses </span><span lang="en-US" style="font-weight: bold; font-family: 'arial';">EnumsOut.d </span><span lang="en-US" style="font-family: 'arial';">and </span><span lang="en-US" style="font-weight: bold; font-family: 'arial';">GtkStruct.d</span><span lang="en-US" style="font-family: 'arial';"> (although that wasn't the best of design hacks)</span></li><li><span lang="en-US" style="font-family: 'arial';"> </span><span lang="en-US" style="font-weight: bold; font-family: 'arial';">PhobosOut.d</span><span lang="en-US" style="font-family: 'arial';"> is used by the non-gtk code to generate code that does not need library links.</span> </li></ul> <p style="margin-left: 0pt; text-indent: 0in;"> </p><p style="margin-left: 0pt; text-indent: 0in;"><span lang="en-US" style="font-family: 'arial';">The design differs a little from the original GtkD generator in that I separated the parsing of the documentation and the code generation into separate classes. I felt the original code was pretty huge and unwieldy done that way. </span></p> <p style="margin-left: 0pt; text-indent: 0in;"> </p><p style="margin-left: 0pt; text-indent: 0in;"><span lang="en-US" style="font-family: 'arial';">Anyway comment away if you have any further thoughts...</span></p> </div> GtkDjs updates - manual in IE, user comments and treemodel object storage 2007-06-27 00:05:19 http://roojs.com/index.php/View/145/GtkDjs_updates__manual_in_IE_user_comments_and_treemodel_object_storage.html <a href="http://roojs.com/index.php/View.html">Article originally from rooJSolutions blog</a><br/> Two minor updates this week, First the <a href="http://www.akbkhome.com/gtkDjs/">GtkDjs manual</a> now works in IE, along with featuring user comments, - you can just add normal comments, code examples, rewrite the introduction, or note a bug. Eventually I plan to add an approval flag so it moves the comment into the documentation, along with the ability to create a comment based on another comments or the existing documentation. And maybe HTML comments... <br /><br />As for the bindings I've been looking at the GtkTreeView and Gtk.TreeStore. To push it a bit, I built a little file navigator (in the tests folder). Key to this was the ability to store Javascript objects in the Treestore. My initial idea of just using a gpointer to the class turned into a bit of a disaster, as the garbage collector assumed that the object was not being used, (even though a pointer to it remained in the store), and free'ed it. This leed to segfaults later when trying to read it.<br /><br />To solve this I ended up using boxed types, so hopefully I've implemented so the objects now get free'd correctly..<br /><br />I've also simplified the setting method for the store (next on the list is to look at  the fetching methods). So storing data in a node/row is a mater of:<br /><pre>store.append(iter,parentIter); <br />store.set(iter, 0, &quot;node title&quot;);<br />store.set(iter, 1, {directory: pdir + name + &quot;/&quot; });</pre>Getting a directory listing uses the new Phobos (or generic D binding backend) binding code.<br /><pre>var filelist = File.listdir(&quot;/home/alan&quot;);</pre>I did notice one little gotcha for the dmdscript backend, that it does not support the &quot;in&quot; comparison operator So<br /><pre>if (&quot;fred&quot; in myobject) {...}<br />becomes<br />if (myobject.hasOwnProperty(&quot;fred&quot;)) {....}<br /></pre><p>Talking of gotcha's I spent quite a long time getting the manual to work in IE. My little extjs tricks noted that comma's are a bit of a nightmare in IE, in that It doesnt like trailing comma's in lists of object properties. As typical with any Microsoft product, this is totally inconsistant with the behaviour for arrays, in which case it quite happily accepts trailing commans. Not only does it accept them,  it adds an undefined element on the end of the array... - which broke my method list horribly in IE.</p><p>Otherwise getting it to work in IE basically consisted of using Ext.DomQuery rather than trying to use standard DOM calls which never seem to work as expected. Anyway comment away...<br /></p><br /><br />