From 85ec7c43316d53e7560939351cf32308d10b3634 Mon Sep 17 00:00:00 2001 From: brunosmmm Date: Thu, 1 Jun 2017 20:25:40 -0400 Subject: [PATCH] example usage of popup menu in the bluetooth module. --- bumblebee/modules/bluetooth.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/bumblebee/modules/bluetooth.py b/bumblebee/modules/bluetooth.py index 323df9d..8e54b56 100644 --- a/bumblebee/modules/bluetooth.py +++ b/bumblebee/modules/bluetooth.py @@ -14,6 +14,8 @@ import bumblebee.input import bumblebee.output import bumblebee.engine import bumblebee.util +import bumblebee.popup +import logging class Module(bumblebee.engine.Module): @@ -34,7 +36,7 @@ class Module(bumblebee.engine.Module): cmd=self.manager) engine.input.register_callback(self, button=bumblebee.input.RIGHT_MOUSE, - cmd=self.toggle) + cmd=self.popup) def status(self, widget): """Get status.""" @@ -69,14 +71,31 @@ class Module(bumblebee.engine.Module): """Launch manager.""" bumblebee.util.execute(self.manager) - def toggle(self, widget): + def popup(self, widget): + """Show a popup menu.""" + menu = bumblebee.popup.PopupMenu() + if self._status == "On": + menu.add_menuitem('Disable Bluetooth') + elif self._status == "Off": + menu.add_menuitem('Enable Bluetooth') + else: + return + + # show menu and get return code + ret = menu.show(widget) + if ret == 0: + logging.debug('bt: toggling bluetooth') + # first (and only) item selected. + self._toggle() + + def _toggle(self): """Toggle bluetooth state.""" if self._status == "On": state = "false" else: state = "true" - cmd = "dbus-send --system --dest=org.blueman.Mechanism"\ + cmd = "dbus-send --system --print-reply --dest=org.blueman.Mechanism"\ " / org.blueman.Mechanism.SetRfkillState"\ " boolean:{}".format(state)