I am trying to create simple gtk application for gnome-shell using gjs.
Its window contains Gtk.TextView only and I want to process events when user is typing.
Here is my code:
#!/usr/bin/gjs
var Gtk = imports.gi.Gtk;
function MainWindow () {
this._init ();
}
MainWindow.prototype = {
_init: function () {
this.window = new Gtk.Window ({
title: "Just Calculator",
window_position: Gtk.WindowPosition.CENTER,
default_height: 400,
default_width: 440,
});
//this.window.show ();
this.window.connect ("hide", Gtk.main_quit);
this.window.connect ("delete-event", function () {
Gtk.main_quit();
return true;
});
this.textbox = new Gtk.TextView();
this.textbox.connect('key-press-event', this._keyPress);
var sw = new Gtk.ScrolledWindow ({shadow_type:Gtk.ShadowType.IN});
sw.add (this.textbox);
this.window.add(sw);
this.window.show_all();
},
_keyPress: function(textview, event) {
print(event, event.type, event.keyval);
textview.buffer.text = 'ok';
return true;
}
}
Gtk.init (null, null);
var window = new MainWindow ();
Gtk.main ();
It works generally but I can not read event.keyval: console output is "undefined":
[union instance proxy GIName:Gdk.Event jsobj@0x7f99b1027040 native@0x1dfeab0] undefined undefined
Could someone tell me what I am doing wrong? Thanks!
_keyPress: function(self, textview, event)
– Bevel