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