On Wed, Apr 26, 2017, 09:05 Sven Wick <sven.w...@gmx.de> wrote: > Hi, > > 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? > > ============ > extension.js > ============ > > const St = imports.gi.St; > const Main = imports.ui.main; > const Lang = imports.lang; > const Clutter = imports.gi.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 > }); > this.actor.connect('button-press-event', this._showData); > //this.actor.connect('enter-event', this._showData); > this.actor.connect('leave-event', this._hideData); > this.actor.add_actor(this.buttonText); > }, > > _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)); > Main.uiGroup.add_actor(this.label); > > }, > > _hideData: function () { > if (Main.uiGroup.contains(this.label)) { > Main.uiGroup.remove_actor(this.label); > } > }, > > stop: function() { > this.menu.removeAll(); > } > }); > > function init() { > } > > function enable() { > testIndicator = new TestIndicator; > Main.panel.addToStatusArea('test-indicator', testIndicator); > } > > function disable() { > testIndicator.stop(); > testIndicator.destroy(); > } > > ============= > metadata.json > ============== > > {"shell-version": ["3.10", "3.14", "3.18"], "uuid": "test", "name": > "test", "description": "shows test label"} > > ============== > stylesheet.css > ============== > > .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 > https://mail.gnome.org/mailman/listinfo/javascript-list
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. Regards, Philip C
_______________________________________________ javascript-list mailing list javascript-list@gnome.org https://mail.gnome.org/mailman/listinfo/javascript-list