3 ##### HELPERS ################################################################
5 # !SET YOUR CONFIGURATION HERE!
9 hbus
= dbus
.SystemBus()
10 hobj
= hbus
.get_object('org.freedesktop.Hal', '/org/freedesktop/Hal/devices/computer')
11 hifc
= dbus
.Interface(hobj
, 'org.freedesktop.Hal.Device.SystemPowerManagement')
16 hbus
= dbus
.SystemBus()
17 hobj
= hbus
.get_object('org.freedesktop.Hal', '/org/freedesktop/Hal/devices/computer')
18 hifc
= dbus
.Interface(hobj
, 'org.freedesktop.Hal.Device.SystemPowerManagement')
23 ec
= os
.popen('cat /proc/acpi/button/lid/LID/state','r').read().split(' ')[-1].split('\n')[0]
25 hbus
= dbus
.SystemBus()
26 hobj
= hbus
.get_object('org.freedesktop.Hal', '/org/freedesktop/Hal/devices/computer')
27 hifc
= dbus
.Interface(hobj
, 'org.freedesktop.Hal.Device.SystemPowerManagement')
32 # toggle bluetooth switch
33 hbus
= dbus
.SystemBus()
34 hobj
= hbus
.get_object('org.freedesktop.Hal', '/org/freedesktop/Hal/devices/computer_rfkill_eeepc_wlan_wlan')
35 hifc
= dbus
.Interface(hobj
, 'org.freedesktop.Hal.Device.KillSwitch')
38 ec
= os
.system(arg
+ ' start')
40 ec
= os
.system(arg
+ ' stop')
44 global state_videomode
45 if state_videomode
== 0:
46 # was in the internal mode, have to switch to external:
47 ec
= os
.system('xrandr --output LVDS --off --output VGA --auto &')
49 elif state_videomode
== 1:
50 # was in the external mode, have to switch to internal & external:
51 ec
= os
.system('xrandr --output VGA --auto --output LVDS --auto &')
53 elif state_videomode
== 2:
54 # was in the internal & external mode, have to switch to internal:
55 ec
= os
.system('xrandr --output LVDS --auto --output VGA --off &')
70 # fourth silver button
74 # second silver button
76 # toggle bluetooth switch
77 hbus
= dbus
.SystemBus()
78 hobj
= hbus
.get_object('org.freedesktop.Hal', '/org/freedesktop/Hal/devices/computer_rfkill_eeepc_bluetooth_bluetooth')
79 hifc
= dbus
.Interface(hobj
, 'org.freedesktop.Hal.Device.KillSwitch')
81 # now toggle bluetooth
82 hifc
.SetPower((cs
+ 1) % 2)
96 ##### END HELPERS ############################################################
98 ##### CALLBACKS ##############################################################
101 # # Parse a string into a dictionary.
102 # # Fetch a *copy* of the default dictionary.
103 # ret = DEFAULTDICT.copy()
105 # lines = s.split('\n')
106 # # Loop through lines.
108 # # Strip whitespace.
109 # line = line.strip()
110 # # Skip comment and blank lines.
111 # if line and line[0] != '#':
112 # # Split the line in the pair key, value
113 # values = line.split()
115 # ret[values[0]] = int(values[1])
116 # # Return dictionary.
119 def callback(kind
, key
):
120 """Handles Condition events from org.freedesktop.Hal.Device"""
121 if kind
== 'ButtonPressed':
124 KEYMAP
[key
][0](KEYMAP
[key
][1])
125 print 'Executed event for key: %s' % key
127 print 'No event defined for key: %s' % key
129 ##### END CALLBACKS ##########################################################
131 import os
, dbus
, gobject
132 from dbus
.mainloop
.glib
import DBusGMainLoop
133 dbus
.mainloop
.glib
.DBusGMainLoop(set_as_default
=True)
135 ## Open file: filename: ~/.buttons-eee901-rc
136 #if os.path.exists('~/.buttons-eee901-rc') == True:
137 # f = file('~/.buttons-eee901-rc')
139 # # Read whole file as one string.
144 # # Parse data string.
145 # config = parse(data)
149 'power' : (key_power
, ('')),
150 'sleep' : (key_sleep
, ('')),
151 'lid' : (key_lid
, ('')),
152 'wlan' : (key_wlan
, ('wifi')),
153 'switch-videomode' : (key_swvid
, ('')),
154 'coffee' : (key_coffee
, ('xset dpms force off &')),
155 'prog1' : (key_prog1
, ('xterm -e top &')),
156 'prog2' : (key_prog2
, ('firefox &')),
157 'prog3' : (key_prog3
, ('sylpheed &')),
158 'prog4' : (key_prog4
, ('')),
159 'mute' : (key_mute
, ('amixer -q -c 0 set LineOut toggle &')),
160 'volume-down' : (key_volup
, ('amixer -q -c 0 set LineOut 5%- &')),
161 'volume-up' : (key_voldn
, ('amixer -q -c 0 set LineOut 5%+ &')),
164 # connect to the message bus
165 hal_1
= 'org.freedesktop.Hal'
166 hal_2
= '/org/freedesktop/Hal'
171 # 2: internal & external
174 # Connect to DBUS System Bus
175 hbus
= dbus
.SystemBus()
177 # Add an event handler: Condition
178 hbus
.add_signal_receiver(callback
,
179 dbus_interface
=hal_1
+".Device",
180 signal_name
="Condition")
182 # Add an event handler: PropertyModified
183 #hbus.add_signal_receiver(button_pressed_cb,
184 # dbus_interface=hal_1+".Device",
185 # signal_name="PropertyModified")
187 # Add an event handler: DeviceAdded
188 #hbus.add_signal_receiver(button_pressed_cb,
189 # dbus_interface=hal_1+".Device",
190 # signal_name="DeviceAdded")
192 # Add an event handler: DeviceRemoved
193 #hbus.add_signal_receiver(button_pressed_cb,
194 # dbus_interface=hal_1+".Device",
195 # signal_name="DeviceRemoved")
197 # other interesting stuff
199 #hbus = dbus.SystemBus()
200 #hmgr = hbus.get_object(hal_1, hal_2+'/Manager')
201 #hifc1 = dbus.Interface(hmgr, hal_1+'.Manager')
202 #hudi = hifc1.FindDeviceByCapability('laptop_panel')
203 #hobj = hbus.get_object('org.freedesktop.Hal', hudi[0])
204 #hifc2 = dbus.Interface(hobj, 'org.freedesktop.Hal.Device.LaptopPanel')
205 #hifc3 = dbus.Interface(hobj, 'org.freedesktop.Hal.Device')
206 #print 100 * hifc2.GetBrightness() / (hifc3.GetProperty('laptop_panel.num_levels') - 1)
208 loop
= gobject
.MainLoop()