如何将滑块添加到 gnome shell 扩展?
How to add a slider to a gnome shell extension?
我正在尝试向我的扩展程序的指示器添加一个滑块,就像它们在声音选择器中所做的那样:
我试过这段代码:
class Indicator extends PanelMenu.Button {
_init() {
super._init(0.0, _('My Shiny Indicator'));
this.add_child(new St.Icon({
icon_name: 'face-smile-symbolic',
style_class: 'system-status-icon',
}));
let item = new PopupMenu.PopupMenuItem(_('Show Notification'));
item.connect('activate', () => {
Main.notify(_('Whatʼs up, folks?'));
});
this.menu.addMenuItem(item);
// create a slider
let slider = Gtk.Scale.new_with_range(Gtk.GTK_ORIENTATION_HORIZONTAL, 0, 1, 0.1)
// add it to the indicator
this.menu.addMenuItem(slider)
}
});
但我得到:
Expected an object of type ClutterActor for argument 'actor' but got type undefined
我是 运行 gnome-shell 40.
你可以试试这个。
this.itemx = new PopupMenu.PopupBaseMenuItem({ activate: false });
const Slider = imports.ui.slider;
this._slider = new Slider.Slider(0);
this.itemx.add_child(this._slider);
this.menu.addMenuItem(this.itemx);
如果你有问题,你可以看看别人的例子。例如:https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/main/js/ui/status/volume.js
我正在尝试向我的扩展程序的指示器添加一个滑块,就像它们在声音选择器中所做的那样:
我试过这段代码:
class Indicator extends PanelMenu.Button {
_init() {
super._init(0.0, _('My Shiny Indicator'));
this.add_child(new St.Icon({
icon_name: 'face-smile-symbolic',
style_class: 'system-status-icon',
}));
let item = new PopupMenu.PopupMenuItem(_('Show Notification'));
item.connect('activate', () => {
Main.notify(_('Whatʼs up, folks?'));
});
this.menu.addMenuItem(item);
// create a slider
let slider = Gtk.Scale.new_with_range(Gtk.GTK_ORIENTATION_HORIZONTAL, 0, 1, 0.1)
// add it to the indicator
this.menu.addMenuItem(slider)
}
});
但我得到:
Expected an object of type ClutterActor for argument 'actor' but got type undefined
我是 运行 gnome-shell 40.
你可以试试这个。
this.itemx = new PopupMenu.PopupBaseMenuItem({ activate: false });
const Slider = imports.ui.slider;
this._slider = new Slider.Slider(0);
this.itemx.add_child(this._slider);
this.menu.addMenuItem(this.itemx);
如果你有问题,你可以看看别人的例子。例如:https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/main/js/ui/status/volume.js