小编Ale*_*rra的帖子

GJS:Gtk.TextView按键事件不起作用

我正在尝试使用gjs为gnome-shell创建简单的gtk应用程序.

它的窗口只包含Gtk.TextView,我想在用户输入时处理事件.

这是我的代码:

#!/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; …
Run Code Online (Sandbox Code Playgroud)

javascript gnome-shell gnome-3 gnome-shell-extensions gjs

7
推荐指数
1
解决办法
504
查看次数