|
Packit |
1470ea |
#!/usr/bin/gjs
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
imports.gi.versions.Gtk = '3.0';
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
const Gio = imports.gi.Gio;
|
|
Packit |
1470ea |
const Gtk = imports.gi.Gtk;
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
class CheckButtonExample {
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Create the application itself
|
|
Packit |
1470ea |
constructor() {
|
|
Packit |
1470ea |
this.application = new Gtk.Application({
|
|
Packit |
1470ea |
application_id: 'org.example.jscheckbutton',
|
|
Packit |
1470ea |
flags: Gio.ApplicationFlags.FLAGS_NONE
|
|
Packit |
1470ea |
});
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Connect 'activate' and 'startup' signals to the callback functions
|
|
Packit |
1470ea |
this.application.connect('activate', this._onActivate.bind(this));
|
|
Packit |
1470ea |
this.application.connect('startup', this._onStartup.bind(this));
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Callback function for 'activate' signal presents window when active
|
|
Packit |
1470ea |
_onActivate() {
|
|
Packit |
1470ea |
this._window.present();
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Callback function for 'startup' signal builds the UI
|
|
Packit |
1470ea |
_onStartup() {
|
|
Packit |
1470ea |
this._buildUI();
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Build the application's UI
|
|
Packit |
1470ea |
_buildUI() {
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Create the application window
|
|
Packit |
1470ea |
this._window = new Gtk.ApplicationWindow({
|
|
Packit |
1470ea |
application: this.application,
|
|
Packit |
1470ea |
window_position: Gtk.WindowPosition.CENTER,
|
|
Packit |
1470ea |
default_height: 100,
|
|
Packit |
1470ea |
default_width: 300,
|
|
Packit |
1470ea |
border_width: 10,
|
|
Packit |
1470ea |
title: "CheckButton Example"});
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Create the check button
|
|
Packit |
1470ea |
this._button = new Gtk.CheckButton ({label: "Show Title"});
|
|
Packit |
1470ea |
this._window.add (this._button);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Have the check button be checked by default
|
|
Packit |
1470ea |
this._button.set_active (true);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Connect the button to a function that does something when it's toggled
|
|
Packit |
1470ea |
this._button.connect ("toggled", this._toggledCB.bind(this));
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Show the window and all child widgets
|
|
Packit |
1470ea |
this._window.show_all();
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
_toggledCB() {
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Make the window title appear or disappear when the checkbox is toggled
|
|
Packit |
1470ea |
if (this._button.get_active() == true)
|
|
Packit |
1470ea |
this._window.set_title ("CheckButton Example");
|
|
Packit |
1470ea |
else
|
|
Packit |
1470ea |
this._window.set_title ("");
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
};
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Run the application
|
|
Packit |
1470ea |
let app = new CheckButtonExample ();
|
|
Packit |
1470ea |
app.application.run (ARGV);
|