Skip to content

Instantly share code, notes, and snippets.

@midoriiro
Last active September 11, 2021 15:04
Show Gist options
  • Save midoriiro/320c6990ab8e66343a7b to your computer and use it in GitHub Desktop.
Save midoriiro/320c6990ab8e66343a7b to your computer and use it in GitHub Desktop.
Bluetooth switcher in PyQt 5.5
'''
I've installed a new wifi card on my laptop with bluetooth support,
but there is no shortcut in my keyboard to swtich on/off bluetooth.
This script + custom shortcut with your linux DE (or other) work perfectly
'''
from PyQt5.QtCore import QCoreApplication
from PyQt5.QtBluetooth import QBluetoothLocalDevice
if __name__ == '__main__':
app = QCoreApplication(sys.argv)
local_device = QBluetoothLocalDevice()
if local_device.isValid():
is_off = local_device.hostMode() == QBluetoothLocalDevice.HostPoweredOff or False
if is_off:
local_device.powerOn()
else:
local_device.setHostMode(QBluetoothLocalDevice.HostPoweredOff)
app.exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment