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

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);
}

相关内容

热门资讯

6月24日港股通红利低波ETF... 6月24日,港股通红利低波ETF华宝(159220)涨0.00%,成交额2308.42万元。当日份额...
田村:需将利率上调至2%左右的... 日本央行政策委员会成员田村表示,需将利率提升至2%左右的中性水平。译文内容由第三方软件翻译。声明:市...
6月24日科创医药ETF华夏(... 6月24日,科创医药ETF华夏(588130)涨1.17%,成交额2439.04万元。当日份额增加6...
6月24日科创50ETF富国(... 6月24日,科创50ETF富国(588940)涨3.99%,成交额8658.76万元。当日份额减少9...
清华新林院的“红色客厅”   周惠斌  清华新林院8号,是著名建筑学家梁思成、林徽因夫妇在1946年至1954年间居住的地方,...