Hi there!
I am learning Gtk. I have the template generated by builder but I am not sure how to proceed. The template has subclass of Gtk.ApplicationWindow
in the window.js
file. Below is what it looks like.
const { GObject, Gtk } = imports.gi;
var CalculatorWindow = GObject.registerClass({
GTypeName: 'CalculatorWindow',
}, class CalculatorWindow extends Gtk.ApplicationWindow {
_init(application) {
super._init({ application });
}
});
Unfortunately, all the examples I have come across do not use subclass of the Gtk.ApplicationWindow
like the template used in builder. I am learning using the gjs guide.
The example on how to create an application in the gjs guide is clear just like the hello world app. It is a matter of creating an instance of Gtk.ApplicationWindow
class and adding widgets to it. But here I am, dealing with a subclass of Gtk.ApplicationWindow
class. How am I supposed to add widgets to the window? Should I do it Inside the callback handling the activate
signal like in the hello world example?
I am thinking of following the gjs guide example and do something like:
var CalculatorWindow = GObject.registerClass({
GTypeName: 'CalculatorWindow',
}, class CalculatorWindow extends Gtk.ApplicationWindow {
_init(application) {
super._init({ application });
this._window = null;
this.createMainWindow();
}
createMainWindow(){
this._window = new Gtk.ApplicationWindow({
defaultWidth: 400,
defaultHeight: 500,
title: 'Hello World'
});
}
present(){
this._window.show();
}
});
Surely what I am thinking about can’t be right, can it? CalculatorWindow
is a subclass of Gtk.ApplicationWindow
already. Would it therefore be correct to create a window using Gtk.ApplicationWindow
and add widgets to it in CalculatorWindow
?
The documentation just describes the methods and properties of the Gtk.ApplicationWindow
class but not how to use it. If someone can help me add a simple button with clicked
signal to the above example, it will go a long way in setting me off.
Thanks!