Cinnamon Applet 设置
创始人
2024-06-01 14:06:37
0

Cinnamon Applet 入门_海天鹰的博客-CSDN博客

进一步如何保存文本到提示文字呢?

1.设置界面 settings-schema.json (固定名称)

{    "memo" : {"type" : "textview","default" : "","description" : "Memo","tooltip" : "Set your memo here."}
}

2.在 applet.js 中绑定设置

this.settings = new Settings.AppletSettings(this, "datetime@sonichy", this.instance_id);
this.settings.bind("memo", "memo", null);

小程序 - 右键 - 配置,弹出窗口:

修改后关闭自动保存,小程序会自动读取。

效果图:

完整的 applet.js:

const Applet = imports.ui.applet;
const Settings = imports.ui.settings;
const PopupMenu = imports.ui.popupMenu;
const St = imports.gi.St;
const {GLib, Gio} = imports.gi;function MyApplet(orientation, panel_height, instance_id) {this._init(orientation, panel_height, instance_id);
}MyApplet.prototype = {__proto__: Applet.TextApplet.prototype,_init: function(orientation, panel_height, instance_id) {Applet.TextApplet.prototype._init.call(this, orientation, panel_height, instance_id);this.settings = new Settings.AppletSettings(this, "datetime@sonichy", this.instance_id);this.settings.bind("memo", "memo", null);this.set_applet_label("00:00\n1/1 一");this._applet_label.set_style("text-align:center");this.set_applet_tooltip(_("Tooltip"));this._applet_tooltip._tooltip.set_style("text-align:left");this.menuManager = new PopupMenu.PopupMenuManager(this);        this.menu = new Applet.AppletPopupMenu(this, orientation);this.menuManager.addMenu(this.menu);var label = new St.Label();this.menu.addActor(label);        //https://gjs.guide/guides/gjs/asynchronous-programming.html                  GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, 1, () => {            var date = new Date();var h = date.getHours();if (h < 10)h = "0" + h;var m = date.getMinutes();if (m < 10)m = "0" + m;var s = date.getSeconds();if (s < 10)s = "0" + s;var m1 = (date.getMonth()+1);var day = date.getDay();var weekday = ["日", "一", "二", "三", "四", "五", "六"];var s1 = h + ":" + m + "\n" + m1 + "/" + date.getDate() + " " + weekday[day];this.set_applet_label(s1);s1 = date.getFullYear() + "/" + m1 + "/" + date.getDate() + " " + h + ":" + m + ":" + s + "\n" + this.memo;this.set_applet_tooltip(s1);label.set_text(s1);return true; // loop});   	},on_applet_clicked: function() {this.menu.toggle();}};function main(metadata, orientation, panel_height, instance_id) {return new MyApplet(orientation, panel_height, instance_id);
}

相关内容

热门资讯

中证A500ETF摩根(560... 8月22日,截止午间收盘,中证A500ETF摩根(560530)涨1.19%,报1.106元,成交额...
A500ETF易方达(1593... 8月22日,截止午间收盘,A500ETF易方达(159361)涨1.28%,报1.104元,成交额1...
何小鹏斥资约2.5亿港元增持小... 每经记者|孙磊    每经编辑|裴健如 8月21日晚间,小鹏汽车发布公告称,公司联...
中证500ETF基金(1593... 8月22日,截止午间收盘,中证500ETF基金(159337)涨0.94%,报1.509元,成交额2...
中证A500ETF华安(159... 8月22日,截止午间收盘,中证A500ETF华安(159359)涨1.15%,报1.139元,成交额...
科创AIETF(588790)... 8月22日,截止午间收盘,科创AIETF(588790)涨4.83%,报0.760元,成交额6.98...
创业板50ETF嘉实(1593... 8月22日,截止午间收盘,创业板50ETF嘉实(159373)涨2.61%,报1.296元,成交额1...
港股异动丨航空股大幅走低 中国... 港股航空股大幅下跌,其中,中国国航跌近7%表现最弱,中国东方航空跌近5%,中国南方航空跌超3%,美兰...
电网设备ETF(159326)... 8月22日,截止午间收盘,电网设备ETF(159326)跌0.25%,报1.198元,成交额409....
红利ETF国企(530880)... 8月22日,截止午间收盘,红利ETF国企(530880)跌0.67%,报1.034元,成交额29.0...