Move hardwaremanager out of the view to his own module

This commit is contained in:
Marco Pesenti Gritti 2007-02-25 01:07:05 +01:00
parent cb6a808832
commit 89aa65d0f6
7 changed files with 31 additions and 27 deletions

View File

@ -117,6 +117,7 @@ services/clipboard/Makefile
services/datastore/Makefile
shell/Makefile
shell/data/Makefile
shell/hardware/Makefile
shell/view/Makefile
shell/view/devices/Makefile
shell/view/frame/Makefile

View File

@ -0,0 +1,4 @@
sugardir = $(pkgdatadir)/shell/hardware
sugar_PYTHON = \
__init__.py \
hardwaremanager.py

View File

View File

@ -18,20 +18,22 @@ import logging
import dbus
HARDWARE_MANAGER_INTERFACE = 'org.laptop.HardwareManager'
HARDWARE_MANAGER_SERVICE = 'org.laptop.HardwareManager'
HARDWARE_MANAGER_OBJECT_PATH = '/org/laptop/HardwareManager'
from _sugar import AudioManager
_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
class HardwareManager(object):
def __init__(self):
try:
bus = dbus.SystemBus()
proxy = bus.get_object(HARDWARE_MANAGER_SERVICE,
HARDWARE_MANAGER_OBJECT_PATH)
self._service = dbus.Interface(proxy, HARDWARE_MANAGER_INTERFACE)
proxy = bus.get_object(_HARDWARE_MANAGER_SERVICE,
_HARDWARE_MANAGER_OBJECT_PATH)
self._service = dbus.Interface(proxy, _HARDWARE_MANAGER_INTERFACE)
except dbus.DBusException:
self._service = None
logging.error('Hardware manager service not found.')
@ -56,3 +58,12 @@ class HardwareManager(object):
self._service.set_keyboard_brightness(False)
else:
self._service.set_keyboard_brightness(True)
def get_hardware_manager():
return _hardware_manager
def get_audio_manager():
return _audio_manager
_hardware_manager = HardwareManager()
_audio_manager = AudioManager()

View File

@ -11,5 +11,4 @@ sugar_PYTHON = \
clipboardmenu.py \
keyhandler.py \
OverlayWindow.py \
Shell.py \
hardwaremanager.py
Shell.py

View File

@ -26,8 +26,6 @@ from view.ActivityHost import ActivityHost
from sugar.activity import activityfactory
from view.frame.frame import Frame
from view.keyhandler import KeyHandler
from view.hardwaremanager import HardwareManager
from _sugar import AudioManager
import sugar
class Shell(gobject.GObject):
@ -40,9 +38,6 @@ class Shell(gobject.GObject):
self._current_host = None
self._screen_rotation = 0
self._hw_manager = HardwareManager()
self._audio_manager = AudioManager()
self._home_window = HomeWindow(self)
self._home_window.show()
self.set_zoom_level(sugar.ZOOM_HOME)
@ -88,12 +83,6 @@ class Shell(gobject.GObject):
if self._current_host:
self._current_host.set_active(True)
def get_hardware_manager(self):
return self._hw_manager
def get_audio_manager(self):
return self._audio_manager
def get_model(self):
return self._model

View File

@ -2,7 +2,7 @@ import dbus
import gobject
from sugar import env
from view.hardwaremanager import HardwareManager
from hardware import hardwaremanager
from model.ShellModel import ShellModel
from _sugar import KeyGrabber
import sugar
@ -40,8 +40,8 @@ _actions_table = {
class KeyHandler(object):
def __init__(self, shell):
self._shell = shell
self._hw_manager = shell.get_hardware_manager()
self._audio_manager = shell.get_audio_manager()
self._hw_manager = hardwaremanager.get_hardware_manager()
self._audio_manager = hardwaremanager.get_audio_manager()
self._screen_rotation = 0
self._key_grabber = KeyGrabber()
@ -90,10 +90,10 @@ class KeyHandler(object):
self._audio_manager.set_volume(100)
def handle_color_mode(self):
self._hw_manager.set_display_mode(HardwareManager.COLOR_MODE)
self._hw_manager.set_display_mode(hardwaremanager.COLOR_MODE)
def handle_b_and_w_mode(self):
self._hw_manager.set_display_mode(HardwareManager.B_AND_W_MODE)
self._hw_manager.set_display_mode(hardwaremanager.B_AND_W_MODE)
def handle_console(self):
gobject.idle_add(self._toggle_console_visibility_cb)