【问题标题】:Display AboutDialog from GNOME Shell Extension从 GNOME Shell 扩展显示 AboutDialog
【发布时间】:2018-09-28 08:53:56
【问题描述】:

我正在尝试从我的 GNOME Shell 扩展中显示 Gtk.AboutDialog。我写了以下函数:

_showAbout: function() {
    var authors = ["Ralf"];
    // Create the About dialog
    let aboutDialog = new Gtk.AboutDialog({ title: "About AboutDialogTest",
        program_name: "MyExtension Version " + MySelf.metadata.version,
        copyright: "AboutDialogTest \xa9 2018",
        authors: authors,
        website: "https://...",
        website_label: "MyExtension Homepage",
        comments: "GNOME Shell extension to test AboutDialog"
    });
    // Connect the Close button to the destroy signal for the dialog
    aboutDialog.connect("response", function() {
        aboutDialog.destroy();
    });
    aboutDialog.show();
}

嗯,关于对话框已显示,但不正确。我可以通过单击将对话框置于前面,但单击 [x] 不会关闭对话框。可以通过按 ESC 关闭对话框。

在系统日志中我看到以下消息:

org.gnome.Shell.desktop[4033]: Gtk-Message: GtkDialog mapped without a transient parent. This is discouraged.
org.gnome.Shell.desktop[4033]: Window manager warning: Buggy client sent a _NET_ACTIVE_WINDOW message with a timestamp of 0 for 0xe0022c (About Abou)

我在扩展中,所以我没有“临时父母”。至少我不知道怎么弄。

知道我必须做什么才能正确显示它吗?

【问题讨论】:

    标签: gnome-shell gnome-shell-extensions


    【解决方案1】:

    好的,我会回答我自己的问题。 据我了解,无法在 GNOME Shell 扩展中使用 GTK 对话框。如果需要“关于对话框”,请使用 modaldialog.js 自行开发。 这不像 GTK 的东西那么酷,但至少是一些东西。

    const St = imports.gi.St;
    const Lang = imports.lang;
    const Gio = imports.gi.Gio;
    const ModalDialog = imports.ui.modalDialog;
    const Clutter = imports.gi.Clutter;
    
    const ExtensionUtils = imports.misc.extensionUtils;
    const MySelf = ExtensionUtils.getCurrentExtension();
    
    const MyAboutDialog = new Lang.Class({
        Name: 'MyAboutDialog',
        Extends: ModalDialog.ModalDialog,
    
        _init: function() {
            this.parent({ styleClass: 'extension-dialog' });
    
            this.setButtons([{ label: "OK",
                               action: Lang.bind(this, this._onClose),
                               key:    Clutter.Escape
                             }]);
    
            let box = new St.BoxLayout({ vertical: true});
            this.contentLayout.add(box);
    
            let gicon = new Gio.FileIcon({ file: Gio.file_new_for_path(MySelf.path + "/icons/icon.png") });
            let icon = new St.Icon({ gicon: gicon });
            box.add(icon);
    
            box.add(new St.Label({ text: "AboutDialogTest Version " + MySelf.metadata.version, x_align: Clutter.ActorAlign.CENTER, style_class: "title-label" }));
            box.add(new St.Label({ text: "GNOME Shell extension to display an About Dialog.", x_align: Clutter.ActorAlign.CENTER }));
            box.add(new St.Label({ text: "This program comes with absolutely no warranty.", x_align: Clutter.ActorAlign.CENTER, style_class: "warn-label" }));
            box.add(new St.Label({ text: "Copyright © 2017-2018 BlahBlahBlah", x_align: Clutter.ActorAlign.CENTER, style_class: "copyright-label" }));
        },
    
        _onClose: function(button, event) {
            this.close(global.get_current_time());
        },
    
    });
    

    然后这样称呼它:

    _showAbout2: function() {
        let dialog = new MyAboutDialog();
        dialog.open(global.get_current_time());
    },
    

    【讨论】:

    • 虽然在某些情况下它可能看起来/有点矫枉过正,但您也可以生成一个新的 gjs 脚本,例如 about.js。我这样做是为了使用 FileChooserDialog,而 proc 通常只有 5MB 左右。您可以将Gtk.Dialog::response 绑定到Gtk.main_quit() 或使用Gio.Subprocess.communicate_utf8() 通过stdin/stdout 获取响应数据。
    猜你喜欢
    • 2012-09-01
    • 1970-01-01
    • 2021-12-24
    • 2017-06-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多