PageRenderTime 11ms CodeModel.GetById 1ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/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
20import dbus
21import os, xf86misc
22
23class BrightAdjust:
24    def __init__(self):
25        self._initHAL()
26        self._initBrightness()
27
28    def _initHAL(self):
29        self.bus = dbus.SystemBus()
30        hal_manager_obj = self.bus.get_object("org.freedesktop.Hal", "/org/freedesktop/Hal/Manager")
31        self.hal_manager = dbus.Interface(hal_manager_obj, "org.freedesktop.Hal.Manager")
32
33    def _initBrightness(self):
34        """ Search HAL for a screen with brightness controls."""
35        brightnessDevice = self.hal_manager.FindDeviceByCapability("laptop_panel")
36        if len(brightnessDevice) >= 1:
37            self.brightnessObject = self.bus.get_object("org.freedesktop.Hal", brightnessDevice[0])
38            self.brightness_properties = self.brightnessObject.GetAllProperties(
39                                                dbus_interface="org.freedesktop.Hal.Device")
40
41    def getBrightness(self):
42        """ Read brightness from HAL. """
43        b = self.brightnessObject.GetBrightness(dbus_interface="org.freedesktop.Hal.Device.LaptopPanel")
44        return b
45
46    def adjustBrightness(self, level):
47        """ Adjust the brightness via HAL. """
48        self.brightnessObject.SetBrightness(level,
49                                            dbus_interface="org.freedesktop.Hal.Device.LaptopPanel")
50
51