[gjs/ewlsh/register-type: 5/5] temp




commit d1aa6e56c6dae47c80bb67fd0e697691d22ebdf4
Author: Evan Welsh <contact evanwelsh com>
Date:   Sat Sep 4 13:00:37 2021 -0700

    temp

 examples/gtk4-register.js | 72 +++++++++++++++++++++++++++++++++++++++++++++++
 examples/inher.js         | 24 ++++++++++++++++
 life.js                   | 20 +++++++++++++
 3 files changed, 116 insertions(+)
---
diff --git a/examples/gtk4-register.js b/examples/gtk4-register.js
new file mode 100644
index 00000000..e57f5bbe
--- /dev/null
+++ b/examples/gtk4-register.js
@@ -0,0 +1,72 @@
+// SPDX-License-Identifier: MIT OR LGPL-2.0-or-later
+// SPDX-FileCopyrightText: 2021 Andy Holmes <andyholmes gnome org>
+
+imports.gi.versions.Gtk = '4.0';
+const {GLib, GObject, Gio, Gtk} = imports.gi;
+
+
+Gtk.init();
+
+
+/* In this example the template contents are loaded from the file as a string.
+ *
+ * The `Template` property of the class definition will accept:
+ *   - a `Uint8Array` or `GLib.Bytes` of XML
+ *   - an absolute file URI, such as `file:///home/user/window.ui`
+ *   - a GResource URI, such as `resource:///org/gnome/AppName/window.ui`
+ */
+const file = Gio.File.new_for_path('gtk4-template.ui');
+const [, template] = file.load_contents(null);
+
+
+
+class ExampleWindow extends Gtk.Window {
+    static [GObject.GTypeName] = 'ExampleWindow';
+
+    static [Gtk.template] = template;
+
+    static [Gtk.children] = ['box'];
+
+    static [Gtk.internalChildren] = ['button'];
+
+    constructor(params = {}) {
+        super(params);
+    }
+
+    _init(...args) {
+        super._init(...args);
+        log(this);
+        // The template has been initialized and you can access the children
+        this.box.visible = true;
+
+        // Internal children are set on the instance prefixed with a `_`
+        this._button.visible = true;
+    }
+
+    // The signal handler bound in the UI file
+    _onButtonClicked(button) {
+        if (this instanceof Gtk.Window)
+            log('Callback scope is bound to `ExampleWindow`');
+
+        button.label = 'Button was clicked!';
+    }
+}
+
+Gtk.registerWidgetType(ExampleWindow);
+log(Gtk.Widget.set_template);
+log(Object.getPrototypeOf(Gtk.Window));
+log(Object.getPrototypeOf(ExampleWindow));
+// ExampleWindow.set_template(template);
+// ExampleWindow.bind_template_child_full('box', false, 0);
+// ExampleWindow.bind_template_child_full('button', true, 0);
+
+// Create a window that stops the program when it is closed
+const loop = GLib.MainLoop.new(null, false);
+
+const win = new ExampleWindow();
+log(win._init);
+win.connect('close-request', () => loop.quit());
+win.present();
+
+loop.run();
+
diff --git a/examples/inher.js b/examples/inher.js
new file mode 100644
index 00000000..6748077f
--- /dev/null
+++ b/examples/inher.js
@@ -0,0 +1,24 @@
+class A {
+    static doSomthin() {
+        console.log('hi');
+    }
+}
+A.hmmm = function () {
+    console.warn('no');
+};
+
+class B extends A {
+
+}
+
+class C extends B {
+
+}
+
+const c = new C();
+
+console.log(Object.getPrototypeOf(C));
+console.log(Object.getPrototypeOf(Object.getPrototypeOf(C)));
+
+C.doSomthin();
+C.hmmm();
diff --git a/life.js b/life.js
new file mode 100644
index 00000000..377d9c50
--- /dev/null
+++ b/life.js
@@ -0,0 +1,20 @@
+const {GObject} = imports.gi;
+class MyObject extends GObject.Object {
+    constructor(...params) {
+        log('0');
+        super(...params);
+        log('4');
+    }
+
+    _init(...params) {
+        log('1');
+        super._init(...params);
+        log('3');
+    }
+
+    _instance_init(...params) {
+        log('2');
+    }
+}
+GObject.registerType(MyObject);
+const myobj = new MyObject();


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]