[modules/bluetooth] update to new API
This commit is contained in:
parent
359effdd85
commit
5aba8a6a36
1 changed files with 20 additions and 25 deletions
|
@ -13,49 +13,46 @@ Parameters:
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import bumblebee.input
|
|
||||||
import bumblebee.output
|
|
||||||
import bumblebee.engine
|
|
||||||
import bumblebee.util
|
|
||||||
import bumblebee.popup
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
import core.module
|
||||||
|
import core.widget
|
||||||
|
import core.input
|
||||||
|
|
||||||
class Module(bumblebee.engine.Module):
|
import util.cli
|
||||||
"""Bluetooth module."""
|
import util.format
|
||||||
|
import util.popup
|
||||||
|
|
||||||
def __init__(self, engine, config):
|
class Module(core.module.Module):
|
||||||
"""Initialize."""
|
def __init__(self, config, theme):
|
||||||
super(Module, self).__init__(engine, config,
|
super().__init__(config, theme, core.widget.Widget(self.status))
|
||||||
bumblebee.output.Widget(
|
|
||||||
full_text=self.status))
|
|
||||||
|
|
||||||
device = self.parameter('device', 'hci0')
|
device = self.parameter('device', 'hci0')
|
||||||
self.manager = self.parameter('manager', 'blueman-manager')
|
self.manager = self.parameter('manager', 'blueman-manager')
|
||||||
self._path = '/sys/class/bluetooth/{}'.format(device)
|
self._path = '/sys/class/bluetooth/{}'.format(device)
|
||||||
self._status = 'Off'
|
self._status = 'Off'
|
||||||
|
|
||||||
engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE,
|
core.input.register(self, button=core.input.LEFT_MOUSE,
|
||||||
cmd=self.manager)
|
cmd=self.manager)
|
||||||
|
|
||||||
# determine whether to use pop-up menu or simply toggle the device on/off
|
# determine whether to use pop-up menu or simply toggle the device on/off
|
||||||
right_click_popup = bumblebee.util.asbool(
|
right_click_popup = util.format.asbool(
|
||||||
self.parameter('right_click_popup', True))
|
self.parameter('right_click_popup', True))
|
||||||
|
|
||||||
if right_click_popup:
|
if right_click_popup:
|
||||||
engine.input.register_callback(self,
|
core.input.register(self,
|
||||||
button=bumblebee.input.RIGHT_MOUSE,
|
button=core.input.RIGHT_MOUSE,
|
||||||
cmd=self.popup)
|
cmd=self.popup)
|
||||||
else:
|
else:
|
||||||
engine.input.register_callback(self,
|
core.input.register(self,
|
||||||
button=bumblebee.input.RIGHT_MOUSE,
|
button=core.input.RIGHT_MOUSE,
|
||||||
cmd=self._toggle)
|
cmd=self._toggle)
|
||||||
|
|
||||||
def status(self, widget):
|
def status(self, widget):
|
||||||
"""Get status."""
|
"""Get status."""
|
||||||
return self._status
|
return self._status
|
||||||
|
|
||||||
def update(self, widgets):
|
def update(self):
|
||||||
"""Update current state."""
|
"""Update current state."""
|
||||||
if not os.path.exists(self._path):
|
if not os.path.exists(self._path):
|
||||||
self._status = '?'
|
self._status = '?'
|
||||||
|
@ -80,13 +77,9 @@ class Module(bumblebee.engine.Module):
|
||||||
except IOError:
|
except IOError:
|
||||||
self._status = '?'
|
self._status = '?'
|
||||||
|
|
||||||
def manager(self, widget):
|
|
||||||
"""Launch manager."""
|
|
||||||
bumblebee.util.execute(self.manager)
|
|
||||||
|
|
||||||
def popup(self, widget):
|
def popup(self, widget):
|
||||||
"""Show a popup menu."""
|
"""Show a popup menu."""
|
||||||
menu = bumblebee.popup.PopupMenu()
|
menu = util.popup.PopupMenu()
|
||||||
if self._status == 'On':
|
if self._status == 'On':
|
||||||
menu.add_menuitem('Disable Bluetooth')
|
menu.add_menuitem('Disable Bluetooth')
|
||||||
elif self._status == 'Off':
|
elif self._status == 'Off':
|
||||||
|
@ -115,7 +108,7 @@ class Module(bumblebee.engine.Module):
|
||||||
' boolean:{}'.format(dst, dst_path, state)
|
' boolean:{}'.format(dst, dst_path, state)
|
||||||
|
|
||||||
logging.debug('bt: toggling bluetooth')
|
logging.debug('bt: toggling bluetooth')
|
||||||
bumblebee.util.execute(cmd)
|
util.cli.execute(cmd)
|
||||||
|
|
||||||
def state(self, widget):
|
def state(self, widget):
|
||||||
"""Get current state."""
|
"""Get current state."""
|
||||||
|
@ -129,3 +122,5 @@ class Module(bumblebee.engine.Module):
|
||||||
state = ['OFF']
|
state = ['OFF']
|
||||||
|
|
||||||
return state
|
return state
|
||||||
|
|
||||||
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||||
|
|
Loading…
Reference in a new issue