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 valadoc.org), 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..
context.accept(this);

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.


Comments

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
Test
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.
com
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
API
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.
BachJohann
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 - Norton.com/setup ( 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 - Norton.com/setup ( 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
BachJohann
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
JavaScript
The work done on the Seed documentation was one of the drivers that made the underlying developer code in Javascript. I at first blended the API calls with an XML parser to peruse the remarks from the Gir records, so that there was some 'useful' documentation about every one of the properties.
#27 - Natasha Romanoff Jacket ( Link) on 2018-02-20 20:56:17 Delete Comment
Sons Of Anarchy Black Leather Jacket
Thankful to you for your inspiration. I agree with you. Tests ought to go about as documentation. We ought to use mechanical assemblies and structures that can empower us to make tests that discussion higher how the gadget continues.
economics help online
My friend recommended this blog and he was totally right keep up the good work
#29 - economics help online ( Link) on 2018-03-05 14:02:50 Delete Comment
Copywriting Service
Those who come to read your article will find lots of helpful and informative tips
#30 - Copywriting Service ( Link) on 2018-03-05 19:53:13 Delete Comment
Netflix Login
Though the only thing which might work for you is a legitimate & active Netflix account login and passwords. Moreover, this would even keep you away from harmful and malicious programs which you might encounter on your hunt, that usually ends up messing up things for you eventually.
#31 - Netflix Login ( Link) on 2018-03-09 17:49:44 Delete Comment
Benefits of Ginger
They're produced by the very best degree developers who will be distinguished for your polo dress creating. You'll find polo Ron Lauren inside exclusive array which include particular classes for men, women.
#32 - Benefits of Ginger ( Link) on 2018-03-19 04:11:02 Delete Comment
Guttering service London
I must admit that your post is really interesting. I have spent a lot of my spare time reading your content. Thank you a lot!
#33 - Guttering service London ( Link) on 2018-03-20 04:12:25 Delete Comment
appreciate you
I am a normal visitor of your site and appreciate you taking the time to maintain the nice site. I’ll be a regular visitor for a really long time.
#34 - clean energy co ( Link) on 2018-03-20 14:34:31 Delete Comment
Benefits of Beans
I’ve been searching for some decent stuff on the subject and haven't had any luck up until this point, You just got a new biggest fan!..
#35 - Benefits of Beans ( Link) on 2018-03-20 16:29:39 Delete Comment
Benefits of Beans
I’ve been searching for some decent stuff on the subject and haven't had any luck up until this point, You just got a new biggest fan!..
#36 - Benefits of Beans ( Link) on 2018-03-20 16:34:33 Delete Comment
Benefits of Apple
Hi! This is my first visit to your blog! We are a team of volunteers and new initiatives in the same niche. Blog gave us useful information to work. You have done an amazing job!
#37 - Benefits of Apple ( Link) on 2018-03-20 21:46:56 Delete Comment
Benefits of Apple
Hi! This is my first visit to your blog! We are a team of volunteers and new initiatives in the same niche. Blog gave us useful information to work. You have done an amazing job!
#38 - Benefits of Apple ( Link) on 2018-03-20 21:49:41 Delete Comment
Benefits of Apple
Hi! This is my first visit to your blog! We are a team of volunteers and new initiatives in the same niche. Blog gave us useful information to work. You have done an amazing job!
#39 - Benefits of Apple ( Link) on 2018-03-20 21:57:59 Delete Comment
Juice and Tea
I have to search sites with relevant information on given topic and provide them to teacher our opinion and the article.
#40 - Juice and Tea ( Link) on 2018-03-21 00:39:31 Delete Comment
Rapeseed Oil
It is perfect time to make some plans for the future and it is time to be happy. I’ve read this post and if I could I desire to suggest you few interesting things or tips. Perhaps you could write next articles referring to this article. I want to read more things about it!
#41 - Rapeseed Oil ( Link) on 2018-03-21 05:05:07 Delete Comment
Benefits of Pumpkin
All the contents you mentioned in post is too good and can be very useful. I will keep it in mind, thanks for sharing the information keep updating, looking forward for more posts.Thanks
#42 - Benefits of Pumpkin ( Link) on 2018-03-21 05:20:43 Delete Comment
Garlic
This is also a very good post which I really enjoyed reading. It is not every day that I have the possibility to see something like this..
#43 - Garlic ( Link) on 2018-03-21 16:19:17 Delete Comment
Mint Leaves
I definitely enjoying every little bit of it and I have you bookmarked to check out new stuff you post.
#44 - Mint Leaves ( Link) on 2018-03-21 22:57:28 Delete Comment
Benefits of Carbohydrates
I’ve been searching for some decent stuff on the subject and haven't had any luck up until this point, You just got a new biggest fan!..
#45 - Benefits of Carbohydrates ( Link) on 2018-03-22 02:23:00 Delete Comment
Two Proportion Test Homework Help
I Appreciate Your Efforts In Preparing This Post. I Really Like Your Blog Articles.
support
I would like to thank you for the efforts you have made in writing this article god bless You. You have a bright future ahead.
#47 - office.com/setup ( Link) on 2018-03-26 14:25:27 Delete Comment
wonderful
I would like to thank you for the efforts you have made in writing this article god bless You. You have a bright future ahead.
We are providing help and support for Microsoft office Setup and activation. Call us or email us the error or problem, our one of the expert contact you with the suitable perfect solution. Get the MS Office application suite and as per your need and see how it is easy to work with Microsoft Office. http://setupoffize.com
mcafee is one of the most reliable antivirus providers in the market. Norton is also delivering top rated protection from mobile devices and computers. Norton has 3 antivirus packages for further details hit the links below:
http://mcafeecomactivatenow.xyz
http://wwwnortoncomsetup.xyz/
We also provide apples apple support and apple support number at http://applenumber.com .

#48 - mcafee.com/activate ( Link) on 2018-03-30 19:31:12 Delete Comment
sl
certainly getting a charge out of each and every piece of it and I have you bookmarked to look at new stuff you post.
Assignment Help
This Academic article i very good, infact it’s good to find such a useful content on your website. For education purpose you can look forward to the Assignment help Online .Our assignment experts works hard to live up to the expectations and provide total peace of mind.
#50 - Assignment Help Online ( Link) on 2018-04-09 14:36:58 Delete Comment
Assignment Help
This Academic article i very good, infact it’s good to find such a useful content on your website. For education purpose you can look forward to the Assignment help Online .Our assignment experts works hard to live up to the expectations and provide total peace of mind.
#51 - Assignment Help Online ( Link) on 2018-04-09 16:50:34 Delete Comment
mcafee
Just feel free to contact anytime if you face any issue with McAfee Activation by visiting our website or just call on our Toll-free or just live chat with us as we are available 24*7 for Your Assistance.
#52 - mcafee ( Link) on 2018-04-12 06:32:20 Delete Comment
mcafee.com/activate
Just feel free to contact anytime if you face any issue with McAfee Activation by visiting our website or just call on our Toll-free or just live chat with us as we are available 24*7 for Your Assistance.
#53 - paul william ( Link) on 2018-04-12 06:42:15 Delete Comment
Cheap Essay Writing Service UK
I might want to thank you for the endeavors you have made in composing this article god favor You. You have a brilliant future ahead..Professional Essay Writers are well familiar with those difficulties and offer Cheap Essay Writing Service UK to the novice students
#54 - JasperTonny ( Link) on 2018-04-12 13:50:53 Delete Comment
Pathophysiology help
Students Assignment Help serves the highly-qualified assignment writers from top universities in the world who are fluent in academic writing and offers its best pathophysiology help. We deliver the assignments before the deadline.
#55 - Pathophysiology help ( Link) on 2018-04-13 13:59:16 Delete Comment
Assignment help Singapore
Avail exclusive assignment help Singapore services from Students Assignment Help and assure success in your academic career. Send us your requirements through Whats App +44-7555369184 for easy convenience.
#56 - Assignment help Singapore ( Link) on 2018-04-14 18:57:40 Delete Comment

Add Your Comment