Published 2015-05-08 00:00:00

And the next part in the series. Gir and Vala structures, Nothing like a slow day to write a few blog posts. 

The App Builder was originally designed to build applications using seed (the gobject introspection webkit javascript engines bindings), One of the key elements of how this was done involved introspecting the Gtk API, and extracting all the properties, signals and class structure.

In this post I will go through the history of how I extracted the API information on Gtk, initially from Gobject introspection and GIR files, upto the current version which uses libvala to get the correct API direct from the vapi files.

The Gtk API using Seed 

In the first versions this was done using the gobject introspection API Originally 

Using this API it is possible to work out all the properties of a Gtk.Window for example so that you can pick properties from a palete and add set them appropriately. The work done on the Seed documentation, was one of the drivers that helped create the initial builder code in Javascript. I initially mixed the API calls with an XML parser to read the comments from the Gir files, so that there was some 'helpful' documentation about all the properties.

The Vala version

When converting the code to Vala, it became clear quite early that the Gir and Vala API's while very similar have a few very slight differences, some of the signal names where missing, and some of the properties where not available. Unfortunately at that time, my understanding of the vala compiler, and the libvala library was quite limited, and as a stop gap solution, I decided to just use the Gir XML files as the basis for the properties in the builder. Using a simple xml node handler, and iterating through the xml file it was possible to extract all the data needed to get most of the properties for the builder.

This worked for most things, but I ended up with a few kludges, as things like GtkSourceView is Gtk.SourceView in vala, but GtkSource.View in gobject introspection. so there was a few hacks added to handle this issue.

The ability to access the API, is not only critical in the user interface to add properties and elements, but also in writing the vala source files generated from the builder. The code in NodeToVala.vala  converts the Tree structure used internally in the builder into vala code.

Souce code validation

One of the tricks we added early on in the Seed version of the builder was to validate the Javascript event handler code, It would highlight syntax and other errors in the gtksourceview editor, so you would not have to wait until you viewed or run the code to find out where your mistakes where.
The code for validation is in the Editor.js file

This was done by calling Seed.check_syntax, and parsing the exception thrown if there was a problem, In the vala version this was done by directly calling the JSCore engine of the Webkit API, then in the same way as the javascript version using the exception to determine the error location.
Checking Javascript code is now handled by the Palete/Javascript.vala code 

For Vala it was a slightly more complex issue, When I started writing the vala version of the builder, I used Ajunta usually to track down errors, as it has a nice compile output filter, where you can hide notes/depreciated and warnings, and only show the real 'errors'. This was quite a round trip, edit code in the builder, run the compiler, find the error - look at the generated file - work out how that relates to the element in the builder... 

It slowed down progress on adding features to the builder considerably. My first step to solving this was to consider using the vala compiler code to see if we could do something similar to javascript (run a syntax check on some code). I had emailed Florian Brosch (author of, when I started looking at extracting the API from vapi's, he pointed me to the tree builder in the valadoc codebase. At the time I decided to go the easier route in using the GIR files. so I did not really make use of his suggestions.

However as I desperately wanted to get the syntax checking working, Eventually I decided to have another attempt at this. what resulted was  thi ValaSource.vala file, this started off by just creating a code context, and adding the generated file (with some comments to help work out where the error was in relation to the tested code). 

From this I created a SourceReport class to catch all the error messages, and then report back if there where any basic syntax errors. This was a huge improvement over the previous situation, but it did not completely solve the issue, as by just doing a syntax check, I could not really find out if the code would compile. it had no awareness of Object types, and how they related to the libraries that where needed to build the application.

Over time I slowly added features that allowed the builder to know about which vala packages (vapi files) where used to create the application, and all the other files that made up the application. This is all handled by the project properties section for Gtk Applications.

Select What packages to use for a project

Select what files to use to build a project

With this extra information, I was able to include all the correct elements needed to do a proper check on the edited code. so not only could it run context.parse(), but also context.check() the code in ValaSouce could actually build a binary from all the included files. 

The next step was to integrate this into the editor. running parse on a file is very fast, it can almost be done transparently on the edit keyup signal. However a full parse/check/emit could take 3-9 seconds on my SSD based machine (maybe even slower on a HHD). So the interface would hang while it tried to do this checking. To resolve this, I ended up working out how create a thread, call it using vala's excellent async infrastructure, and callback (using the correct thread) to the UI, so that while you are typing it is constantly trying to parse/check/emit the code you are writing. and notifying you if there are any errors - this has some simple queuing to prevent it doing the checking to match, basically it can only be running one check at a time.

Back to sorting out the API

Having got my hands dirty with the libvala API, I was pretty sure I would be able to figure out how to extract the Gtk API and others from the vapi files using libvala. During the conversations I had with Florien the only bit of the code that he showed me that I did not understand was how after running parse/check etc.. how do I get access to the tree, 

The code he showed me extended the Vala CodeVistor class, I had extended this when I created the code syntax checker (although it's not really needed). in his example he had some callbacks to visit_namespace(), a method overridden in the CodeVistor. however what I missed was how the context knew about the code visitor. - as you can see from the ValaSource file, the context does not know about the ValaSource file, so would not be able to call it.

After reading all the code in valadoc, I finally spotted this line..

This was one of those 'Light bulb moments', this was the call I was missing, basically by doing this, the context starts walking the AST tree - giving you access to all the details about the vapi files that I needed. In most of the examples of CodeVistor, it basically calls all the various visit_* methods on the Vistor as it walks through the tree (you need to call element.accept_children(this) to cause the walk to happen).  For my purpose, walking the tree this was not really that helpful, as I needed to build a Gir tree out of this data so the existing code would work with the new data. I discovered you do not have to walk the tree, basically all the walking code does is just iterate through properties that are available anyway, so you can just do that walking in the code, rather than using the callback walk.
The documentation for libvala is very helpful

The result of this is that I now have good reliable API data to build the Application, and the code writer should be more accurate. Next steps on this is to start using pulldowns for property enums, as I can extract that information from the API.


Nice blog
Great post full of useful tips! I adore what you have got right here. This is so applicable to most of the readers. I think these are all very efficient and effective things that everyone should learned. Thank you for the good tips that you have placed here. It was all useful and helpful stuffs. Thanks for sharing this magnificent info I was looking for this info for my mission.
#0 - buy college essay ( Link) on 2017-10-09 18:01:59 Delete Comment
Great Information
Not enough content here to understand the exact purpose of this blog. But it seems like it an effort of helping child in southafrica may be by creating some good opportunities for them. What these opportunities might be is not clear as author didn't mention here.

#1 - Suicide Squad Purple Coat ( Link) on 2017-11-07 14:53:36 Delete Comment
Great Information
I am very fond of traveling. Looking forward to some useful information on this new website. I hope Destin Travels brings some exciting deals on some great destinations.

#2 - write an assignment for me ( Link) on 2017-11-15 18:44:18 Delete Comment
Some Basic Lining To Counteract
It is always attempting to parse check transmit the code you are composing. what's more, telling you if there are any blunders this has some basic lining to counteract it doing the checking to coordinate, fundamentally it must run one check at any given moment.
#3 - Pay For Homework Help ( Link) on 2017-11-20 15:15:58 Delete Comment
Well the extracting of API is superb thing to have, I wanted some valuable source to get know more details about extracting of details, maybe this is the best thing I have read now.
#4 - Custom Paper Service ( Link) on 2017-11-23 16:02:47 Delete Comment
If you like drive you should have used experience! 【Software development of parking lot system】
Common in the city and near the station,
We are developing a system to manage coin parking and bicycle parking lot.
Now, we make software equipment of existing system as module (parts)
By combining them, we are making efforts to reduce the trouble of creating new products.

Specifically, in order to change the software so that it can be reused,
We are investigating what functions are available in existing systems.

Taking the parking lot system as an example,
Calculation of usage fees ⇒ to put money ⇒ to count money ⇒ liquidation ⇒ output of receipt
There is a series of flows such as.

In response to requests such as improvements in systems and addition of new services,
We will build a system that anyone can use easily and conveniently.
I am happy that many people can use the product I participated in development!
#5 - Can anyone do my assignment ( Link) on 2017-11-29 19:29:40 Delete Comment
There is a proper educational program, so leave it to newcomers quickly!
The parking vending machine has more than 5000 trial periods.
I repeatedly check to make sure there are no mistakes to finer details
Because it is required carefully and precisely, there are also many difficult aspects.

But based on the educational program
I can participate in the work of each and every newcomer actually!
Because I am only watching, I do not listen, so
I am strongly aware that I am engaged in development as a member of the team.

Now I am learning the contents of work such as product development and system improvement and how to proceed with work.
Read the program actually incorporated in the product,
Studying about the system,
In the help of senior employees' work,
I learned how to create a program and how to change product specifications.

In the future, when I am given my job I would like to do my best to be a fighting force even a little!
#6 - do my paper ( Link) on 2017-11-29 19:33:42 Delete Comment
Excellent Post
I am a new member of this site and hope that this will be an excellent post for most of the readers. I ahve no more idea about this topic. Thanks for sharing. Expecting more from here.
I really liked your post, it's a good analysis and a good API. it was interesting to read this. Thanks you
#8 - help with my homework ( Link) on 2017-12-07 17:30:08 Delete Comment
An API is a contract, that is it's a set of standards that mean a given set of commands with a given interface are guaranteed to perform in a certain way. Since you mention nothing whatsoever about the coding of this site other than the fact you have an API, we can't help you at all except to suggest this: if the site supports RSS syndication, that's probably the easiest way to access their content.
#9 - assignment expert ( Link) on 2017-12-12 18:25:07 Delete Comment
Extraction of API
The Data Extraction API exchanges and move stored data only, so the report data from it will not always match the data seen at the Analytics user interface..
#10 - assignment service uk ( Link) on 2017-12-13 20:19:53 Delete Comment
Great work
I am first time reading this long stuffs but thank you, god my time it’s now not waste the whole blog and it's simply exquisite I am hoping you share more thrilling stuff submit to this blog so I stored your blog hyperlink.
#11 - Topcelebs Jackets ( Link) on 2017-12-14 19:53:03 Delete Comment
java online help
This is great information for students. This article is very helpful i really like this blog thanks. I also have some information relevant for online dissertation help.
#12 - java online help ( Link) on 2017-12-16 18:59:00 Delete Comment
Your article has piqued a lot
Thank you for taking the time to publish this information very useful!I assure this would be beneficial for most of the people. Any way I'll be subscribing to your feed and I hope you post again soon.
Do My Medical Science Homework
I loved the way you discuss the topic great work thanks for the share.
Dissertation Writing Help United Kingdom
I personally like your post; you have shared good insights and experiences. Keep it up.
In the event that you set out to make me think today; mission achieved! I truly like your written work style and how you express your thoughts. Much obliged to you.
#16 - ex bankrupt mortgages ( Link) on 2018-01-08 19:33:31 Delete Comment
My Opinion

Github app builder providing the save platform for the developers. They can get the solution of their coding and solve their bugs.
help with economics homework
This is really a great stuff for sharing. Thanks for sharing.
#18 - help with economics homework ( Link) on 2018-01-11 14:53:53 Delete Comment
How to Fix your Norton Antivirus
Thank you For sharing this information.
Fixingblog is one of the best Tech Blog. Here you will get all kind of solution like Setup, Installation, Connection issue etc related to Routers, Range Extender, Windows, Printer etc.
#19 - ( Link) on 2018-01-11 19:17:01 Delete Comment
How to Fix your Norton Antivirus
Thank you For sharing this information.
Fixingblog is one of the best Tech Blog. Here you will get all kind of solution like Setup, Installation, Connection issue etc related to Routers, Range Extender, Windows, Printer etc.
#20 - ( Link) on 2018-01-11 19:19:15 Delete Comment
The Vala version
The Vala version is unnecessary to me.....planet php made an article about it
#21 - Music marketing companies ( Link) on 2018-01-13 03:10:40 Delete Comment
I appreciated your work very thanks
#22 - Enseigne commerciale ( Link) on 2018-01-13 19:11:42 Delete Comment
Case Study Analysis
My friend recommended this blog and he was totally right keep up the fantastic work!
#23 - Case Study Analysis ( Link) on 2018-01-17 14:39:09 Delete Comment
merrick bank login
Thank you for your work on the blog! You're doing a good job! I would like to read about it anymore. Prompt, what literature to study?

#24 - merrick bank login ( Link) on 2018-01-25 22:21:33 Delete Comment
Custom Essay Writing Service UK
Thank you for your inspiration. I agree with you. Tests should act as documentation. We must use tools and frameworks that can help us write tests that speak higher how the gadget behaves.
Do my Assignment for me
Much obliged to you for your motivation. I concur with you. Tests should go about as documentation. We should utilize apparatuses and structures that can enable us to compose tests that talk higher how the device carries on.
#26 - Do my Assignment for me ( Link) on 2018-02-13 17:34:32 Delete Comment

Add Your Comment