Merge pull request #489 from piyueh/bluetooth-dbus
Bluetooth module: dbus object path and popup menu
This commit is contained in:
commit
0ebd2bd854
1 changed files with 20 additions and 7 deletions
|
@ -5,6 +5,8 @@ Parameters:
|
|||
* bluetooth.device : the device to read state from (default is hci0)
|
||||
* bluetooth.manager : application to launch on click (blueman-manager)
|
||||
* bluetooth.dbus_destination : dbus destination (defaults to org.blueman.Mechanism)
|
||||
* bluetooth.dbus_destination_path : dbus destination path (defaults to /)
|
||||
* bluetooth.right_click_popup : use popup menu when right-clicked (defaults to True)
|
||||
|
||||
"""
|
||||
|
||||
|
@ -35,9 +37,19 @@ class Module(bumblebee.engine.Module):
|
|||
|
||||
engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE,
|
||||
cmd=self.manager)
|
||||
engine.input.register_callback(self,
|
||||
button=bumblebee.input.RIGHT_MOUSE,
|
||||
cmd=self.popup)
|
||||
|
||||
# determine whether to use pop-up menu or simply toggle the device on/off
|
||||
right_click_popup = bumblebee.util.asbool(
|
||||
self.parameter("right_click_popup", True))
|
||||
|
||||
if right_click_popup:
|
||||
engine.input.register_callback(self,
|
||||
button=bumblebee.input.RIGHT_MOUSE,
|
||||
cmd=self.popup)
|
||||
else:
|
||||
engine.input.register_callback(self,
|
||||
button=bumblebee.input.RIGHT_MOUSE,
|
||||
cmd=self._toggle)
|
||||
|
||||
def status(self, widget):
|
||||
"""Get status."""
|
||||
|
@ -85,11 +97,10 @@ class Module(bumblebee.engine.Module):
|
|||
# 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):
|
||||
def _toggle(self, widget=None):
|
||||
"""Toggle bluetooth state."""
|
||||
if self._status == "On":
|
||||
state = "false"
|
||||
|
@ -97,11 +108,13 @@ class Module(bumblebee.engine.Module):
|
|||
state = "true"
|
||||
|
||||
dst = self.parameter("dbus_destination", "org.blueman.Mechanism")
|
||||
dst_path = self.parameter("dbus_destination_path", "/")
|
||||
|
||||
cmd = "dbus-send --system --print-reply --dest={}"\
|
||||
" / org.blueman.Mechanism.SetRfkillState"\
|
||||
" boolean:{}".format(dst, state)
|
||||
" {} org.blueman.Mechanism.SetRfkillState"\
|
||||
" boolean:{}".format(dst, dst_path, state)
|
||||
|
||||
logging.debug('bt: toggling bluetooth')
|
||||
bumblebee.util.execute(cmd)
|
||||
|
||||
def state(self, widget):
|
||||
|
|
Loading…
Reference in a new issue