Re: Problem with simple Gnome Shell Extension

On Wed, Apr 26, 2017, 09:05 Sven Wick <Sven Wick gmx de> wrote:
I have a problem with my first extension
which just creates a button that shows a label when clicked
and removes the label when the mouse moves away.

The issue I have is that when I click twice or more
before I move the mouse, the label sticks to the screen.

Actually, it looks like that every click creates a new label
and only the last one gets removed.
I tried to put the line which creates the label to different parts
but then I always get an "undefined" in the log.

Could someone give me a hint how to fix this?

const St        =;
const Main      = imports.ui.main;
const Lang      = imports.lang;
const Clutter   =;
const PanelMenu = imports.ui.panelMenu;
const TestIndicator = new Lang.Class({
    Name: 'TestIndicator',
    Extends: PanelMenu.Button,
    _init: function () {
        this.parent(0.0, "Test Indicator", false);
        this.buttonText = new St.Label({
            text: _("Test..."),
            y_align: Clutter.ActorAlign.CENTER
        });'button-press-event', this._showData);
    //'enter-event', this._showData);'leave-event', this._hideData);;
    _showData: function () {
        this.label = new St.Label({ style_class: 'test-label', text: "TEST" });
        let monitor = Main.layoutManager.primaryMonitor;
        this.label.set_position(Math.floor(monitor.width  / 2 - this.label.width  / 2),
                                Math.floor(monitor.height / 2 - this.label.height / 2));
    _hideData: function () {
        if (Main.uiGroup.contains(this.label)) {
    stop: function() {;
function init() {
function enable() {
    testIndicator = new TestIndicator;
    Main.panel.addToStatusArea('test-indicator', testIndicator);
function disable() {
{"shell-version": ["3.10", "3.14", "3.18"], "uuid": "test", "name": "test", "description": "shows test label"}
.test-label {
    font-size: 36px;
    font-weight: bold;
    color: #DC143C;
    background-color: rgba(10,10,10,0.7);
    border-radius: 5px;
    padding: .5em;
_javascript_-list mailing list
_javascript_-list gnome org

Hi Sven,

This is probably a better question for gnome-shell-list; I've forwarded it there.

You probably want to keep only one instance of a label, and change its text rather than creating a new label.

Philip C

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]