menu change to tooltip
This commit is contained in:
@@ -8,9 +8,6 @@ import * as Main from 'resource:///org/gnome/shell/ui/main.js';
|
||||
import * as PanelMenu from 'resource:///org/gnome/shell/ui/panelMenu.js';
|
||||
import * as PopupMenu from 'resource:///org/gnome/shell/ui/popupMenu.js';
|
||||
|
||||
export var schema = 'org.gnome.desktop.background';
|
||||
export var imagePath = GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_PICTURES) + '/BingWallpaper';
|
||||
|
||||
export default class BingWallpaperExtension extends Extension {
|
||||
enable() {
|
||||
this._indicator = new PanelMenu.Button(0.0, this.metadata.name, false);
|
||||
@@ -25,13 +22,15 @@ export default class BingWallpaperExtension extends Extension {
|
||||
|
||||
Main.panel.addToStatusArea(this.uuid, this._indicator);
|
||||
|
||||
this.imagePath = GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_PICTURES) + '/BingWallpaper';
|
||||
const menu_browse = new PopupMenu.PopupImageMenuItem('Browse', 'folder-directory-symbolic', {});
|
||||
menu_browse.connect('activate', () => {
|
||||
let uri = 'file://' + imagePath;
|
||||
let uri = 'file://' + this.imagePath;
|
||||
Gio.app_info_launch_default_for_uri(uri, global.create_app_launch_context(0, -1));
|
||||
});
|
||||
this._indicator.menu.addMenuItem(menu_browse);
|
||||
|
||||
const schema = 'org.gnome.desktop.background';
|
||||
this.gsettings = new Gio.Settings({ schema: schema });
|
||||
let uri = this.gsettings.get_string('picture-uri');
|
||||
let filename = uri.substring(uri.lastIndexOf('/') + 1)
|
||||
@@ -43,6 +42,7 @@ export default class BingWallpaperExtension extends Extension {
|
||||
disable() {
|
||||
this._indicator?.destroy();
|
||||
this._indicator = null;
|
||||
this.gsettings = null;
|
||||
}
|
||||
|
||||
getWallpaper() {
|
||||
@@ -57,7 +57,7 @@ export default class BingWallpaperExtension extends Extension {
|
||||
let imgUrl = "http://www.bing.com" + json.images[0].url;
|
||||
var filename = json.images[0].enddate + '_' + json.images[0].urlbase.replace('/th?id=OHR.', '') + '.jpg';
|
||||
this.menu_update.label.text = json.images[0].copyright;
|
||||
var filepath = imagePath + '/' + filename;
|
||||
var filepath = this.imagePath + '/' + filename;
|
||||
let file = Gio.file_new_for_path(filepath);
|
||||
let request = Soup.Message.new('GET', imgUrl);
|
||||
httpSession.send_and_read_async(request, GLib.PRIORITY_DEFAULT, null, (httpSession, message) => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"uuid": "BingWallpaper@sonichy",
|
||||
"name": "Bing Wallpaper",
|
||||
"description": "Change wallpaper of GNOME with Bing wallpaper on one click.",
|
||||
"description": "Change wallpaper of GNOME with Bing wallpaper on one click. This extension is not affiliated, funded, or in any way associated with Microsoft and Bing.",
|
||||
"author": "sonichy",
|
||||
"version": "1.0",
|
||||
"shell-version": [ "45", "46", "47", "48" ],
|
||||
|
||||
@@ -37,8 +37,30 @@ export default class CMUDExtension extends Extension {
|
||||
// Add the indicator to the panel
|
||||
Main.panel.addToStatusArea(this.uuid, this._indicator);
|
||||
|
||||
const menuItem = new PopupMenu.PopupMenuItem('');
|
||||
this._indicator.menu.addMenuItem(menuItem);
|
||||
//const menuItem = new PopupMenu.PopupMenuItem('');
|
||||
//this._indicator.menu.addMenuItem(menuItem);
|
||||
|
||||
this.label_tooltip = new St.Label({ text: '' });
|
||||
this.label_tooltip.set_style('background:#222; padding:10px; border:1px solid #aaa; border-radius:10px;');
|
||||
global.stage.add_child(this.label_tooltip);
|
||||
this.label_tooltip.hide();
|
||||
this._indicator.connect('notify::hover', () => {
|
||||
const [x, y] = this._indicator.get_transformed_position();
|
||||
//console.log(x, y);
|
||||
if (x == 0 && y != 0) //LEFT
|
||||
this.label_tooltip.set_position(x + this._indicator.width + 1, y);
|
||||
else if (x != 0 && y == 0) //TOP
|
||||
this.label_tooltip.set_position(x, y + this.label_tooltip.height + 4);
|
||||
else
|
||||
if (this._indicator.height == Main.panel.height) //BOTTOM
|
||||
this.label_tooltip.set_position(x, y - this.label_tooltip.height - 1);
|
||||
else //RIGHT
|
||||
this.label_tooltip.set_position(x - this.label_tooltip.width - 1, y);
|
||||
if (this._indicator.hover)
|
||||
this.label_tooltip.show();
|
||||
else
|
||||
this.label_tooltip.hide();
|
||||
});
|
||||
|
||||
this._timeout = GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, 1, () => {
|
||||
var net = this.net();
|
||||
@@ -48,7 +70,8 @@ export default class CMUDExtension extends Extension {
|
||||
this.cpu();
|
||||
area_cpu.queue_repaint();
|
||||
var s = 'Uptime: ' + this.uptime() + '\nCPU: ' + cp + '%\nMem: ' + this.mem() + '\nUp: ' + this.B2G(net.ub) + '\nDown: ' + this.B2G(net.db);
|
||||
menuItem.label.text = s;
|
||||
//menuItem.label.text = s;
|
||||
this.label_tooltip.text = s;
|
||||
// Run as loop, not once.
|
||||
return GLib.SOURCE_CONTINUE;
|
||||
});
|
||||
|
||||
@@ -5,5 +5,5 @@
|
||||
"shell-version": [ "45", "46", "47", "48" ],
|
||||
"url": "https://github.com/sonichy/GNOME_extension",
|
||||
"uuid": "CMUD@sonichy",
|
||||
"version": 3
|
||||
"version": 1.1
|
||||
}
|
||||
|
||||
@@ -27,18 +27,26 @@ export default class DatetimeExtension extends Extension {
|
||||
calendar.setDate(now);
|
||||
this._indicator.menu.addMenuItem(menuItem);
|
||||
|
||||
const menuItem1 = new PopupMenu.PopupMenuItem('');
|
||||
//const menuItem1 = new PopupMenu.PopupMenuItem('');
|
||||
//menuItem1.label.set_style('text-align:center'); //无效
|
||||
this._indicator.menu.addMenuItem(menuItem1);
|
||||
//this._indicator.menu.addMenuItem(menuItem1);
|
||||
|
||||
this.label_tooltip = new St.Label({ text: '' });
|
||||
this.label_tooltip.set_style('background:#222;padding:10px;');
|
||||
this.label_tooltip.set_style('background:#222;padding:10px;border:1px solid #aaa;border-radius:10px;');
|
||||
global.stage.add_child(this.label_tooltip);
|
||||
this.label_tooltip.hide();
|
||||
this._indicator.connect('notify::hover', () => {
|
||||
const [x, y] = this._indicator.get_transformed_position();
|
||||
//console.log(x,y);
|
||||
this.label_tooltip.set_position(x, y - this.label_tooltip.height);
|
||||
//console.log(x, y);
|
||||
if (x == 0 && y != 0) //LEFT
|
||||
this.label_tooltip.set_position(x + this._indicator.width + 1, y);
|
||||
else if (x != 0 && y == 0) //TOP
|
||||
this.label_tooltip.set_position(x, y + this.label_tooltip.height + 4);
|
||||
else
|
||||
if (this._indicator.height == Main.panel.height) //BOTTOM
|
||||
this.label_tooltip.set_position(x, y - this.label_tooltip.height - 1);
|
||||
else //RIGHT
|
||||
this.label_tooltip.set_position(x - this.label_tooltip.width - 1, y);
|
||||
if (this._indicator.hover)
|
||||
this.label_tooltip.show();
|
||||
else
|
||||
@@ -58,7 +66,7 @@ export default class DatetimeExtension extends Extension {
|
||||
var weekday1 = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
|
||||
var text = h + ' : ' + m + '\n' + (date.getMonth() + 1) + '/' + date.getDate() + ' ' + weekday[day];
|
||||
label.set_text(text);
|
||||
menuItem1.label.text = date.toLocaleString() + ' ' + weekday1[day];
|
||||
//menuItem1.label.text = date.toLocaleString() + ' ' + weekday1[day];
|
||||
this.label_tooltip.text = date.toLocaleString() + ' ' + weekday1[day];
|
||||
// Run as loop, not once.
|
||||
return GLib.SOURCE_CONTINUE;
|
||||
|
||||
Reference in New Issue
Block a user