[modules/bluetooth] quotes

This commit is contained in:
tobi-wan-kenobi 2020-04-29 20:16:19 +02:00
parent c195b0398e
commit 359effdd85

View file

@ -30,17 +30,17 @@ class Module(bumblebee.engine.Module):
bumblebee.output.Widget( bumblebee.output.Widget(
full_text=self.status)) 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, engine.input.register_callback(self, button=bumblebee.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 = bumblebee.util.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, engine.input.register_callback(self,
@ -58,27 +58,27 @@ class Module(bumblebee.engine.Module):
def update(self, widgets): def update(self, widgets):
"""Update current state.""" """Update current state."""
if not os.path.exists(self._path): if not os.path.exists(self._path):
self._status = "?" self._status = '?'
return return
# search for whichever rfkill directory available # search for whichever rfkill directory available
try: try:
dirnames = next(os.walk(self._path))[1] dirnames = next(os.walk(self._path))[1]
for dirname in dirnames: for dirname in dirnames:
m = re.match(r"rfkill[0-9]+", dirname) m = re.match(r'rfkill[0-9]+', dirname)
if m is not None: if m is not None:
with open(os.path.join(self._path, with open(os.path.join(self._path,
dirname, dirname,
'state'), 'r') as f: 'state'), 'r') as f:
state = int(f.read()) state = int(f.read())
if state == 1: if state == 1:
self._status = "On" self._status = 'On'
else: else:
self._status = "Off" self._status = 'Off'
return return
except IOError: except IOError:
self._status = "?" self._status = '?'
def manager(self, widget): def manager(self, widget):
"""Launch manager.""" """Launch manager."""
@ -87,9 +87,9 @@ class Module(bumblebee.engine.Module):
def popup(self, widget): def popup(self, widget):
"""Show a popup menu.""" """Show a popup menu."""
menu = bumblebee.popup.PopupMenu() menu = bumblebee.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':
menu.add_menuitem('Enable Bluetooth') menu.add_menuitem('Enable Bluetooth')
else: else:
return return
@ -102,17 +102,17 @@ class Module(bumblebee.engine.Module):
def _toggle(self, widget=None): def _toggle(self, widget=None):
"""Toggle bluetooth state.""" """Toggle bluetooth state."""
if self._status == "On": if self._status == 'On':
state = "false" state = 'false'
else: else:
state = "true" state = 'true'
dst = self.parameter("dbus_destination", "org.blueman.Mechanism") dst = self.parameter('dbus_destination', 'org.blueman.Mechanism')
dst_path = self.parameter("dbus_destination_path", "/") dst_path = self.parameter('dbus_destination_path', '/')
cmd = "dbus-send --system --print-reply --dest={}"\ cmd = 'dbus-send --system --print-reply --dest={}'\
" {} org.blueman.Mechanism.SetRfkillState"\ ' {} org.blueman.Mechanism.SetRfkillState'\
" 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) bumblebee.util.execute(cmd)
@ -121,11 +121,11 @@ class Module(bumblebee.engine.Module):
"""Get current state.""" """Get current state."""
state = [] state = []
if self._status == "?": if self._status == '?':
state = ["unknown"] state = ['unknown']
elif self._status == "On": elif self._status == 'On':
state = ["ON"] state = ['ON']
else: else:
state = ["OFF"] state = ['OFF']
return state return state