Widgets, my love: Bluezwitch

Another of my single-button widgets for the Nokia N900 got into Maemo Extras this week: Bluezwitch, a simple widget to turn Bluetooth on/off (saving you 3 clicks compared to the original way). Apparently, this widget is a great thing for many users, as it already got 12′000 downloads in just six days!

For me, the main work in this was to find out on how to programmatically enable/disable Bluetooth with Bluez 4.x using D-Bus - all the examples I found online only talked about the older Bluez 3.x versions. After digging through the Bluez Docs and some experimenting, here is how it works in Python:

  1. Find the default Bluetooth adapter.
  2. Modify the “Powered” property of the adapter.

The following snippet of code toggles the adapter on/off on each run:
import dbus
self.bus = dbus.SystemBus();
self.root = self.bus.get_object('org.bluez', '/')
self.manager = dbus.Interface(self.root, 'org.bluez.Manager')
self.defaultAdapter = self.manager.DefaultAdapter()
print "Default adapter is at", self.defaultAdapter
self.obj = self.bus.get_object('org.bluez', self.defaultAdapter)
self.adapter = dbus.Interface(self.obj, 'org.bluez.Adapter')
props = self.adapter.GetProperties()
powered = props['Powered']
if powered:
  self.adapter.SetProperty(’Powered’,False)
else:
  self.adapter.SetProperty(’Powered’,True)

Accidentally, “Bluezwitch” (Bluez-Switch :-) was rather a byproduct on my quest to another widget I’m currently working on: “Carmode” is a widget that toggles a number of things when entering the car. But more about that in another post of my “series”.

And BTW: From now on, I’m changing the button icon size on all my widgets from “Finger” (48px) to the “Thumb” (64px) size, as apparently the smaller icons were just too small for many people (dragging these icons became a mini-game in itself ;-). Bluezwitch has been updated today to version 1.0.0 to accommodate this change - it will show up in your favourite repository soon.

7 Responses to “Widgets, my love: Bluezwitch”

  1. Tolga Ciftci Says:

    I can literally say you are the man. Since the first day I got my phone which was the release date, I was begging for a simple bluetooth widget. Thank you sooo much…

  2. Michel Says:

    Hello, Yes this is a great widget, simply but very usefull, Thanks!

  3. Daniel Persson Says:

    Great work.
    I use Bluezwitch daily since i use a Stereo Headset to listen to music.
    PS. I sent you 2$ for you work, lets hope others do that too. Thank you.

  4. Daniel Marsh Says:

    Thanks for whipping this up! I really like the ability to 1 click toggle Bluetooth. Is there any way to do something similar for Wifi? Also, would it be possible to have the widget icon be greyed out or something to indicate the current on/off status?

    Thanks again!

  5. Pinguins Móveis » Blog Archive » Pinguins de fim-de-semana Says:

    [...] Theora no N900, fMMS 0.9.0 e um útil widget Bluetooth para Maemo. [...]

  6. Taomyn Says:

    Yes, I’d like to add my thanks to this and glad the icon has gotten a little bigger, though I find it odd that in settings I can only change the text for “off” and not for “on” as well. I assume it’s because the “on” message is a system one?

  7. Paul Freud Says:

    Just trying to cover my bases - bluezwitch widget not working with the new maemo upgrade. tried uninstalling and reinstalling - no change.

Leave a Reply