キーボード修飾子の状態を取得しようとしています。この GDK の例を Gnome GJS に移植して、Gnome 拡張機能で使用します。
以下のコードは、https://developer.gnome.org/gnome-devel-demos/stable/hellognome.js.html.enの公式デモを変更したものです。
この問題は、正常に実行Gdk.Keymap.get_modifier_state()
される関数ではないと報告されていGdk.Keymap.get_default()
ます。
おそらく、JS で構造パラメーターを持つ関数を使用する際に何かが欠けています。(私はJSに精通していません)。では、私のコードの何が問題なのですか?
コード:
#!/usr/bin/gjs
//https://developer.gnome.org/gnome-devel-demos/stable/hellognome.js.html.en
const Gtk = imports.gi.Gtk;
const Gdk = imports.gi.Gdk;
const Lang = imports.lang;
const Webkit = imports.gi.WebKit;
const HelloGNOME = new Lang.Class ({
Name: 'Hello GNOME',
_init: function () {
this.application = new Gtk.Application ();
this.application.connect('activate', Lang.bind(this, this._onActivate));
this.application.connect('startup', Lang.bind(this, this._onStartup));
},
_onActivate: function () {
this._window.present ();
this._keymap = Gdk.Keymap.get_default ();
//this._state = Gdk.Keymap.get_modifier_state (this._keymap);
this._caps = Gdk.Keymap.get_modifier_state ();
},
_onStartup: function () {
this._buildUI ();
},
// Build the application's UI
_buildUI: function () {
// Create the application window
this._window = new Gtk.ApplicationWindow ({
application: this.application,
title: "Welcome to GNOME",
default_height: 200,
default_width: 400,
window_position: Gtk.WindowPosition.CENTER });
// Create a webview to show the web app
this._webView = new Webkit.WebView ();
// Put the web app into the webview
this._webView.load_uri (GLib.filename_to_uri (GLib.get_current_dir() +
"/hellognome.html", null));
// Put the webview into the window
this._window.add (this._webView);
// Show the window and all child widgets
this._window.show_all();
},
});
// Run the application
let app = new HelloGNOME ();
app.application.run (ARGV);
エラーメッセージ:
(gjs:2483): Gjs-WARNING **: JS ERROR: TypeError: Gdk.Keymap.get_modifier_state is not a function
HelloGNOME<._onActivate@./gdk_mod.js:23
wrapper@resource:///org/gnome/gjs/modules/lang.js:169
@./gdk_mod.js:58
ただし、次のようなドキュメントで確認できます: http://www.roojs.org/seed/gir-1.2-gtk-3.0/seed/Gdk.Keymap.htmlおよび GIR マッピング/usr/share/gir-1.0/Gdk-3.0.gir
:
<method name="get_modifier_state"
c:identifier="gdk_keymap_get_modifier_state"
version="3.4">
<doc xml:space="preserve">Returns the current modifier state.</doc>
<return-value transfer-ownership="none">
<doc xml:space="preserve">the current modifier state.</doc>
<type name="guint" c:type="guint"/>
</return-value>
<parameters>
<instance-parameter name="keymap" transfer-ownership="none">
<doc xml:space="preserve">a #GdkKeymap</doc>
<type name="Keymap" c:type="GdkKeymap*"/>
</instance-parameter>
</parameters>
</method>
問題がイントロスペクションバインディングにあるかどうかを確認するために、Pythonで試しました。とにかく、それはうまくいきます。
#!/usr/bin/python
from gi.repository import Gdk, GLib
def update(keymap):
print Gdk.Keymap.get_modifier_state(keymap)
return True
if __name__=="__main__":
#Gdk.init()
loop = GLib.MainLoop()
keymap = Gdk.Keymap.get_default()
GLib.timeout_add_seconds(1, update, keymap)
loop.run()