Skip to content

Instantly share code, notes, and snippets.

@yurenju
Created May 28, 2011 19:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yurenju/997127 to your computer and use it in GitHub Desktop.
Save yurenju/997127 to your computer and use it in GitHub Desktop.
panel menu
const St = imports.gi.St;
const Mainloop = imports.mainloop;
const PanelMenu = imports.ui.panelMenu;
const PopupMenu = imports.ui.popupMenu;
const Main = imports.ui.main;
const Tweener = imports.tweener.tweener;
function _showHello() {
let text = new St.Label({ style_class: 'helloworld-label',
text: "Hello, world!" });
let monitor = global.get_primary_monitor();
global.stage.add_actor(text);
text.set_position(Math.floor (monitor.width / 2 - text.width / 2),
Math.floor(monitor.height / 2 - text.height / 2));
Mainloop.timeout_add(3000, function () { text.destroy(); });
}
function _rotateDate() {
let t = Main.panel._dateMenu.actor;
Tweener.addTween(t,
{ time: 2.0,
rotation_angle_z: t.rotation_angle_z+360
});
}
function HelloPanelButton() {
this._init();
}
HelloPanelButton.prototype = {
__proto__: PanelMenu.Button.prototype,
_init: function() {
PanelMenu.Button.prototype._init.call(this, 0.0);
let btn = new St.Label({text: 'hello'});
this.actor.set_child(btn);
let box = new St.BoxLayout({vertical: true});
this.menu.addActor(box);
let item = new PopupMenu.PopupMenuItem('hello');
item.connect('activate', _showHello);
box.add(item.actor);
item = new PopupMenu.PopupMenuItem('rotate');
item.connect('activate', _rotateDate);
box.add(item.actor);
},
};
function main() {
let hbtn = new HelloPanelButton();
Main.panel._leftBox.add(hbtn.actor);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment