Adapt to the new hardware manager

This commit is contained in:
Marco Pesenti Gritti 2007-01-08 13:09:13 +01:00
parent 1ee6b7faf0
commit 17a1cb7ae4
5 changed files with 73 additions and 20 deletions

View File

@ -9,6 +9,7 @@ bin_SCRIPTS = \
sugardir = $(pkgdatadir)/shell sugardir = $(pkgdatadir)/shell
sugar_PYTHON = \ sugar_PYTHON = \
__init__.py __init__.py \
hardwaremanager.py
EXTRA_DIST = $(bin_SCRIPTS) EXTRA_DIST = $(bin_SCRIPTS)

View File

@ -16,21 +16,28 @@
import dbus import dbus
DCON_MANAGER_INTERFACE = 'org.laptop.DCONManager' HARDWARE_MANAGER_INTERFACE = 'org.laptop.HardwareManager'
DCON_MANAGER_SERVICE = 'org.laptop.DCONManager' HARDWARE_MANAGER_SERVICE = 'org.laptop.HardwareManager'
DCON_MANAGER_OBJECT_PATH = '/org/laptop/DCONManager' HARDWARE_MANAGER_OBJECT_PATH = '/org/laptop/HardwareManager'
class DCONManager(object): class HardwareManager(object):
COLOR_MODE = 0 COLOR_MODE = 0
BLACK_AND_WHITE_MODE = 1 B_AND_W_MODE = 1
def __init__(self): def __init__(self):
bus = dbus.SystemBus() bus = dbus.SystemBus()
proxy = bus.get_object(DCON_MANAGER_SERVICE, DCON_MANAGER_OBJECT_PATH) proxy = bus.get_object(HARDWARE_MANAGER_SERVICE,
self._service = dbus.Interface(proxy, DCON_MANAGER_INTERFACE) HARDWARE_MANAGER_OBJECT_PATH)
self._service = dbus.Interface(proxy, HARDWARE_MANAGER_INTERFACE)
def set_mode(self, mode): def set_display_mode(self, mode):
self._service.set_mode(mode) self._service.set_mode(mode)
def set_brightness(self, level): def set_display_brightness(self, level):
self._service.set_backlight_level(level) self._service.set_display_brightness(level)
def toggle_keyboard_brightness(self):
if self._service.get_keyboard_brightness():
self._service.set_keyboard_brightness(False)
else
self._service.set_keyboard_brightness(True)

View File

@ -11,5 +11,4 @@ sugar_PYTHON = \
clipboardmenu.py \ clipboardmenu.py \
OverlayWindow.py \ OverlayWindow.py \
Shell.py \ Shell.py \
dconmanager.py \
stylesheet.py stylesheet.py

View File

@ -29,7 +29,7 @@ from view.ActivityHost import ActivityHost
from sugar.activity import ActivityFactory from sugar.activity import ActivityFactory
from sugar.activity import Activity from sugar.activity import Activity
from view.frame.Frame import Frame from view.frame.Frame import Frame
from view.dconmanager import DCONManager from hardwaremanager import HardwareManager
from _sugar import KeyGrabber from _sugar import KeyGrabber
from _sugar import AudioManager from _sugar import AudioManager
import sugar import sugar
@ -45,7 +45,7 @@ class Shell(gobject.GObject):
style.load_stylesheet(view.stylesheet) style.load_stylesheet(view.stylesheet)
self._dcon_manager = DCONManager() self._hw_manager = HardwareManager()
self._audio_manager = AudioManager() self._audio_manager = AudioManager()
self._key_grabber = KeyGrabber() self._key_grabber = KeyGrabber()
@ -99,6 +99,7 @@ class Shell(gobject.GObject):
self._key_grabber.grab('0xE0') # Overlay key self._key_grabber.grab('0xE0') # Overlay key
self._key_grabber.grab('0x93') # Frame key self._key_grabber.grab('0x93') # Frame key
self._key_grabber.grab('0x7C') # Power key self._key_grabber.grab('0x7C') # Power key
self._key_grabber.grab('0x86') # Keyboard brightness
self._key_grabber.grab('<alt>Tab') self._key_grabber.grab('<alt>Tab')
# For non-OLPC machines # For non-OLPC machines
@ -115,13 +116,13 @@ class Shell(gobject.GObject):
elif key == 'F4': elif key == 'F4':
self.set_zoom_level(sugar.ZOOM_ACTIVITY) self.set_zoom_level(sugar.ZOOM_ACTIVITY)
elif key == 'F5': elif key == 'F5':
self._dcon_manager.set_brightness(0) self._hw_manager.set_display_brightness(0)
elif key == 'F6': elif key == 'F6':
self._dcon_manager.set_brightness(5) self._hw_manager.set_display_brightness(5)
elif key == 'F7': elif key == 'F7':
self._dcon_manager.set_brightness(9) self._hw_manager.set_display_brightness(9)
elif key == 'F8': elif key == 'F8':
self._dcon_manager.set_brightness(15) self._hw_manager.set_display_brightness(15)
elif key == 'F9': elif key == 'F9':
self._audio_manager.set_volume(0) self._audio_manager.set_volume(0)
elif key == 'F10': elif key == 'F10':
@ -131,9 +132,9 @@ class Shell(gobject.GObject):
elif key == 'F12': elif key == 'F12':
self._audio_manager.set_volume(100) self._audio_manager.set_volume(100)
elif key == '<alt>F5': elif key == '<alt>F5':
self._dcon_manager.set_mode(DCONManager.COLOR_MODE) self._hw_manager.set_display_mode(HardwareManager.COLOR_MODE)
elif key == '<alt>F8': elif key == '<alt>F8':
self._dcon_manager.set_mode(DCONManager.BLACK_AND_WHITE_MODE) self._hw_manager.set_display_mode(HardwareManager.B_AND_W_MODE)
elif key == '<shft><alt>F9': elif key == '<shft><alt>F9':
self._frame.notify_key_press() self._frame.notify_key_press()
elif key == '<shft><alt>F10': elif key == '<shft><alt>F10':
@ -146,6 +147,8 @@ class Shell(gobject.GObject):
self._frame.notify_key_press() self._frame.notify_key_press()
elif key == '0x7C': # Power key elif key == '0x7C': # Power key
self._shutdown() self._shutdown()
elif key == '0x86': # Keyboard brightness
self._hw_manager.toggle_keyboard_brightness()
elif key == '<alt>Tab': elif key == '<alt>Tab':
self.set_zoom_level(sugar.ZOOM_HOME) self.set_zoom_level(sugar.ZOOM_HOME)
box = self._home_window.get_home_box() box = self._home_window.get_home_box()

View File

@ -0,0 +1,43 @@
# Copyright (C) 2006, Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import dbus
HARDWARE_MANAGER_INTERFACE = 'org.laptop.HardwareManager'
HARDWARE_MANAGER_SERVICE = 'org.laptop.HardwareManager'
HARDWARE_MANAGER_OBJECT_PATH = '/org/laptop/HardwareManager'
class HardwareManager(object):
COLOR_MODE = 0
B_AND_W_MODE = 1
def __init__(self):
bus = dbus.SystemBus()
proxy = bus.get_object(HARDWARE_MANAGER_SERVICE,
HARDWARE_MANAGER_OBJECT_PATH)
self._service = dbus.Interface(proxy, HARDWARE_MANAGER_INTERFACE)
def set_display_mode(self, mode):
self._service.set_mode(mode)
def set_display_brightness(self, level):
self._service.set_display_brightness(level)
def toggle_keyboard_brightness(self):
if self._service.get_keyboard_brightness():
self._service.set_keyboard_brightness(False)
else:
self._service.set_keyboard_brightness(True)