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

相关内容

热门资讯

中国铁建全资子公司新增一项62... (转自:快查一企业中标了)快查APP显示,中国铁建相关公司中国铁建大桥工程局集团有限公司于2025年...
巴西总统抨击特朗普关税威胁 转自:财联社【巴西总统抨击特朗普关税威胁】财联社7月8日电,据CCTV国际时讯报道,巴西总统卢拉当地...
北京大北农科技集团股份有限公司...   证券代码:002385证券简称:大北农               公告编号:2025-060 ...
孕36周遭遇心血管“旋风炸弹”... 转自:天津日报  怀孕36周的准妈妈王女士遭遇有心血管“旋风炸弹”之称的主动脉夹层,天津医科大学第二...
12月4日小胖闯非洲在尼泊尔出... 12月4日小胖闯非洲在尼泊尔出什么事了小胖在尼泊尔直播的时候被杀身亡了12月4日,小胖闯非洲在尼泊尔...
牛为什么要吃草?要求科学解释? 牛为什么要吃草?要求科学解释?提示:为什么牛不搞光合作用,为什么牛不吃肉(自然为什么这么选择)?为什...
现在有什么好看的玄幻小说,要好... 现在有什么好看的玄幻小说,要好看的?类似斗破苍穹。神墓的!盘龙 我看过 挺好的
重庆燃气相关公司新增一项331... (转自:快查一企业中标了)快查APP显示,重庆燃气相关公司重庆渝西天然气管道有限公司于2025年7月...
小亭子连接职场“大舞台” 转自:光明日报  临近暑假,东北师范大学学生就业指导服务中心大厅里,两座AI面试亭依然“座无虚席”,...
从“被动养老”到“主动健康” 转自:光明日报  日前,在位于福建省厦门市嘉莲街道友邻中心的智慧健身房里,70岁的居民张凯明正对着镜...