Prodded by me while I snoozed on his sofa and with his cat warming me up, a day before the Content Applications hackfest, Florian Müllner started working on fixing a long-standing gjs bug that made it impossible to use gom in GNOME/JavaScript applications. The result of that initial research came a few days later, and is now part of the latest gjs release.
This also fixes using GtkBuilder and json-glib when the libraries create new objects for the benefit of the JavaScript code.
We can finally use gom to store user data in applications like Bolso. Thanks Florian!
Showing posts with label gjs. Show all posts
Showing posts with label gjs. Show all posts
Saturday, 9 January 2016
Tuesday, 30 September 2014
GTK+ widget templates now in Javascript
Let's get the features in early!
If you're working on a Javascript application for GNOME, you'll be interested to know that you can now write GTK+ widget templates in gjs.
Many thanks to Giovanni for writing the original patches. And now to a small example:
And now you just need to create your widget:
You'll need gjs from git master to use this feature. And if you see anything that breaks, don't hesitate to file a bug against gjs in the GNOME Bugzilla.
If you're working on a Javascript application for GNOME, you'll be interested to know that you can now write GTK+ widget templates in gjs.
Many thanks to Giovanni for writing the original patches. And now to a small example:
const MyComplexGtkSubclass = new Lang.Class({ Name: 'MyComplexGtkSubclass', Extends: Gtk.Grid, Template: 'resource:///org/gnome/myapp/widget.xml', Children: ['label-child'], _init: function(params) { this.parent(params); this._internalLabel = this.get_template_child(MyComplexGtkSubclass, 'label-child'); } });
And now you just need to create your widget:
let content = new MyComplexGtkSubclass(); content._internalLabel.set_label("My updated label");
You'll need gjs from git master to use this feature. And if you see anything that breaks, don't hesitate to file a bug against gjs in the GNOME Bugzilla.
Thursday, 17 April 2014
What is GOM¹
Under that name is a simple idea: making it easier to save, load, update and query objects in an object store.
I'm not the main developer for this piece of code, but contributed a large number of fixes to it, while porting a piece of code to it as a test of the API. Much of the credit for the design of this very useful library goes to Christian Hergert.
The problem
It's possible that you've already implemented a data store inside your application, hiding your complicated SQL queries in a separate file because they contain injection security issues. Or you've used the filesystem as the store and threw away the ability to search particular fields without loading everything in memory first.
Given that SQLite pretty much matches our use case - it offers good search performance, it's a popular thus well-documented project and its files can be manipulated through a number of first-party and third-party tools - wrapping its API to make it easier to use is probably the right solution.
The GOM solution
GOM is a GObject based wrapper around SQLite. It will hide SQL from you, but still allow you to call to it if you have a specific query you want to run. It will also make sure that SQLite queries don't block your main thread, which is pretty useful indeed for UI applications.
For each table, you would have a GObject, a subclass of GomResource, representing a row in that table. Each column is a property on the object. To add a new item to the table, you would simply do:
We have a number of features which try to make it as easy as possible for application developers to use gom, such as:
The future
I'm currently working on some missing features to support a port of the grilo bookmarks plugin (support for column REFERENCES).
I will also be making (small) changes to the API to allow changing the backend from SQLite to a another one, such as XML, or a binary format. Obviously the SQL "escape hatches" wouldn't be available with those backends.
Don't hesitate to file bugs if there are any problems with the API, or its documentation, especially with respect to porting from applications already using SQLite directly. Or if there are bugs (surely, no).
Note that JavaScript support isn't ready yet, due to limitations in gjs.
¹: « SQLite don't hurt me, don't hurt me, no more »
I'm not the main developer for this piece of code, but contributed a large number of fixes to it, while porting a piece of code to it as a test of the API. Much of the credit for the design of this very useful library goes to Christian Hergert.
The problem
It's possible that you've already implemented a data store inside your application, hiding your complicated SQL queries in a separate file because they contain injection security issues. Or you've used the filesystem as the store and threw away the ability to search particular fields without loading everything in memory first.
Given that SQLite pretty much matches our use case - it offers good search performance, it's a popular thus well-documented project and its files can be manipulated through a number of first-party and third-party tools - wrapping its API to make it easier to use is probably the right solution.
The GOM solution
GOM is a GObject based wrapper around SQLite. It will hide SQL from you, but still allow you to call to it if you have a specific query you want to run. It will also make sure that SQLite queries don't block your main thread, which is pretty useful indeed for UI applications.
For each table, you would have a GObject, a subclass of GomResource, representing a row in that table. Each column is a property on the object. To add a new item to the table, you would simply do:
item = g_object_new (ITEM_TYPE_RESOURCE, "column1", value1, "column2", value2, NULL); gom_resource_save_sync (item, NULL);
We have a number of features which try to make it as easy as possible for application developers to use gom, such as:
- Automatic table creation for string, string arrays, and number types as well as GDateTime, and transformation support for complex types (say, colours or images).
- Automatic database version migration, using annotations on the properties ("new in version")
- Programmatic API for queries, including deferred fetches for results
The future
I'm currently working on some missing features to support a port of the grilo bookmarks plugin (support for column REFERENCES).
I will also be making (small) changes to the API to allow changing the backend from SQLite to a another one, such as XML, or a binary format. Obviously the SQL "escape hatches" wouldn't be available with those backends.
Don't hesitate to file bugs if there are any problems with the API, or its documentation, especially with respect to porting from applications already using SQLite directly. Or if there are bugs (surely, no).
Note that JavaScript support isn't ready yet, due to limitations in gjs.
¹: « SQLite don't hurt me, don't hurt me, no more »
Subscribe to:
Posts (Atom)