/brightness-adjust/brightadjust.py

http://github.com/joelagnel/stumpwm-goodies · Python · 51 lines · 22 code · 8 blank · 21 comment · 1 complexity · 3cea1b55f14bbb5564a14dc7e22f91c5 MD5 · raw file

  1. #!/usr/bin/python
  2. # -*- coding: UTF-8 -*-
  3. ###########################################################################
  4. # Copyright (C) 2006 by Sebastian Kügler
  5. # <sebas@kde.org>
  6. #
  7. # Copyright: See COPYING file that comes with this distribution
  8. #
  9. ###########################################################################
  10. # An API for changing the powerstate of a notebook
  11. ###########################################################################
  12. #
  13. # Joel Agnel Fernandes (agnel.joel@gmail.com)
  14. # Isaac Praveen (icylisper@gmail.com)
  15. # Stolen from KDE's guidance power system, adapted (severely) for StumpWM
  16. # to change Brightness of Laptop Panel.
  17. #
  18. ###########################################################################
  19. import dbus
  20. import os, xf86misc
  21. class BrightAdjust:
  22. def __init__(self):
  23. self._initHAL()
  24. self._initBrightness()
  25. def _initHAL(self):
  26. self.bus = dbus.SystemBus()
  27. hal_manager_obj = self.bus.get_object("org.freedesktop.Hal", "/org/freedesktop/Hal/Manager")
  28. self.hal_manager = dbus.Interface(hal_manager_obj, "org.freedesktop.Hal.Manager")
  29. def _initBrightness(self):
  30. """ Search HAL for a screen with brightness controls."""
  31. brightnessDevice = self.hal_manager.FindDeviceByCapability("laptop_panel")
  32. if len(brightnessDevice) >= 1:
  33. self.brightnessObject = self.bus.get_object("org.freedesktop.Hal", brightnessDevice[0])
  34. self.brightness_properties = self.brightnessObject.GetAllProperties(
  35. dbus_interface="org.freedesktop.Hal.Device")
  36. def getBrightness(self):
  37. """ Read brightness from HAL. """
  38. b = self.brightnessObject.GetBrightness(dbus_interface="org.freedesktop.Hal.Device.LaptopPanel")
  39. return b
  40. def adjustBrightness(self, level):
  41. """ Adjust the brightness via HAL. """
  42. self.brightnessObject.SetBrightness(level,
  43. dbus_interface="org.freedesktop.Hal.Device.LaptopPanel")