9
by Erwin Rohde
Added script to control indicator-brightness through dbus |
1 |
#!/usr/bin/python
|
2 |
# Put this script in one of your keyboard shortcuts to control indicator-brightness
|
|
3 |
#
|
|
4 |
# Copyright (C) 2013 Erwin Rohde
|
|
5 |
# Many thanks to Jan Simon for setting up and maintaining this indicator in launchpad.
|
|
6 |
# Dbus code heavily borrowed from https://github.com/majorsilence/pygtknotebook/tree/master/examples/dbus
|
|
7 |
#
|
|
8 |
# This program is free software; you can redistribute it and/or
|
|
9 |
# modify it under the terms of the GNU General Public License
|
|
10 |
# as published by the Free Software Foundation; either version 2
|
|
11 |
# of the License, or (at your option) any later version.
|
|
12 |
#
|
|
13 |
# This program is distributed in the hope that it will be useful,
|
|
14 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15 |
# MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16 |
# GNU General Public License for more details.
|
|
17 |
#
|
|
18 |
# You should have received a copy of the GNU General Public License
|
|
19 |
# along with this program; if not, write to the Free Software
|
|
20 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
21 |
import os |
|
22 |
import gobject |
|
23 |
import dbus |
|
24 |
from dbus.mainloop.glib import DBusGMainLoop |
|
25 |
import gtk |
|
26 |
import argparse |
|
27 |
||
28 |
parser = argparse.ArgumentParser(description='Adjust screen brightness through dbus and indicator-brightness.') |
|
29 |
parser.add_argument('--up', action='store_true', help="Brightness up") |
|
30 |
parser.add_argument('--down', action='store_true', help="Brightness down") |
|
31 |
args = parser.parse_args() |
|
32 |
||
33 |
class DBusClient(object): |
|
34 |
def __init__(self): |
|
35 |
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) |
|
36 |
||
37 |
self.bus = dbus.SessionBus() |
|
38 |
||
39 |
self.proxy = self.bus.get_object('com.ubuntu.indicator.brightness', '/adjust') |
|
40 |
self.control_interface = dbus.Interface(self.proxy, 'com.ubuntu.indicator.brightness') |
|
41 |
#print self.control_interface.Introspect(dbus_interface='org.freedesktop.DBus.Introspectable')
|
|
42 |
if args.up: |
|
43 |
self.control_interface.brightness_up() |
|
44 |
if args.down: |
|
45 |
self.control_interface.brightness_down() |
|
46 |
||
47 |
if __name__ == "__main__": |
|
48 |
DBusClient() |