Skip to content

Instantly share code, notes, and snippets.

@yurenju
Created May 28, 2011 18:28
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/997104 to your computer and use it in GitHub Desktop.
Save yurenju/997104 to your computer and use it in GitHub Desktop.
add button
// Sample extension code, makes clicking on the panel show a message
const St = imports.gi.St;
const Mainloop = imports.mainloop;
const Main = imports.ui.main;
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(); });
}
// Put your extension initialization code here
function main() {
let label = new St.Label({text: 'hello'});
let btn = new St.Button({style_class: 'panel-button', reactive: true});
btn.set_child(label);
btn.connect('button-release-event', _showHello);
Main.panel._leftBox.add(btn)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment