Support running without network manager service.
Rework code to run without hardware manager service.
This commit is contained in:
parent
4c23a821ef
commit
8f57bf7c9d
@ -30,31 +30,18 @@ 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)
|
||||
except dbus.DBusException:
|
||||
self._service = None
|
||||
logging.error('Hardware manager service not found.')
|
||||
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):
|
||||
if not self._service:
|
||||
logging.error('Cannot set display mode. Service not found.')
|
||||
|
||||
self._service.set_mode(mode)
|
||||
|
||||
def set_display_brightness(self, level):
|
||||
if not self._service:
|
||||
logging.error('Cannot set display brightness. Service not found.')
|
||||
|
||||
self._service.set_display_brightness(level)
|
||||
|
||||
def toggle_keyboard_brightness(self):
|
||||
if not self._service:
|
||||
logging.error('Cannot set keyboard brightness. Service not found.')
|
||||
|
||||
if self._service.get_keyboard_brightness():
|
||||
self._service.set_keyboard_brightness(False)
|
||||
else:
|
||||
@ -69,6 +56,16 @@ def get_audio_manager():
|
||||
def get_network_manager():
|
||||
return _network_manager
|
||||
|
||||
_hardware_manager = HardwareManager()
|
||||
_audio_manager = AudioManager()
|
||||
_network_manager = NMClient()
|
||||
|
||||
try:
|
||||
_hardware_manager = HardwareManager()
|
||||
except dbus.DBusException, e:
|
||||
_hardware_manager = None
|
||||
logging.info('Hardware manager service not found.')
|
||||
|
||||
try:
|
||||
_network_manager = NMClient()
|
||||
except dbus.DBusException, e:
|
||||
_network_manager = None
|
||||
logging.info('Network manager service not found.')
|
||||
|
@ -87,10 +87,11 @@ class MeshModel(gobject.GObject):
|
||||
self._check_service(service)
|
||||
|
||||
network_manager = hardwaremanager.get_network_manager()
|
||||
for nm_device in network_manager.get_devices():
|
||||
self._add_network_device(nm_device)
|
||||
network_manager.connect('device-added',
|
||||
self._nm_device_added_cb)
|
||||
if network_manager:
|
||||
for nm_device in network_manager.get_devices():
|
||||
self._add_network_device(nm_device)
|
||||
network_manager.connect('device-added',
|
||||
self._nm_device_added_cb)
|
||||
|
||||
def _nm_device_added_cb(self, manager, nm_device):
|
||||
self._add_network_device(nm_device)
|
||||
|
@ -27,6 +27,8 @@ class DevicesModel(gobject.GObject):
|
||||
|
||||
def _observe_network_manager(self):
|
||||
network_manager = hardwaremanager.get_network_manager()
|
||||
if not network_manager:
|
||||
return
|
||||
|
||||
for device in network_manager.get_devices():
|
||||
self._check_network_device(device)
|
||||
|
@ -60,11 +60,10 @@ class AccessPointView(CanvasIcon):
|
||||
|
||||
def _activate_cb(self, icon):
|
||||
network_manager = hardwaremanager.get_network_manager()
|
||||
|
||||
device = self._model.get_nm_device()
|
||||
network = self._model.get_nm_network()
|
||||
|
||||
network_manager.set_active_device(device, network)
|
||||
if network_manager:
|
||||
device = self._model.get_nm_device()
|
||||
network = self._model.get_nm_network()
|
||||
network_manager.set_active_device(device, network)
|
||||
|
||||
def _update_name(self):
|
||||
self.props.tooltip = self._model.props.name
|
||||
|
@ -40,7 +40,6 @@ _actions_table = {
|
||||
class KeyHandler(object):
|
||||
def __init__(self, shell):
|
||||
self._shell = shell
|
||||
self._hw_manager = hardwaremanager.get_hardware_manager()
|
||||
self._audio_manager = hardwaremanager.get_audio_manager()
|
||||
self._screen_rotation = 0
|
||||
|
||||
@ -53,6 +52,16 @@ class KeyHandler(object):
|
||||
for key in _actions_table.keys():
|
||||
self._key_grabber.grab(key)
|
||||
|
||||
def _set_display_brightness(self, level):
|
||||
hw_manager = hardwaremanager.get_hardware_manager()
|
||||
if hw_manager:
|
||||
hw_manager.set_display_brightness(level)
|
||||
|
||||
def _set_display_mode(self, mode):
|
||||
hw_manager = hardwaremanager.get_hardware_manager()
|
||||
if hw_manager:
|
||||
hw_manager.set_display_mode(mode)
|
||||
|
||||
def handle_zoom_mesh(self):
|
||||
self._shell.set_zoom_level(sugar.ZOOM_MESH)
|
||||
|
||||
@ -66,16 +75,16 @@ class KeyHandler(object):
|
||||
self._shell.set_zoom_level(sugar.ZOOM_ACTIVITY)
|
||||
|
||||
def handle_brightness_1(self):
|
||||
self._hw_manager.set_display_brightness(0)
|
||||
self._set_display_brightness(0)
|
||||
|
||||
def handle_brightness_2(self):
|
||||
self._hw_manager.set_display_brightness(5)
|
||||
self._set_display_brightness(5)
|
||||
|
||||
def handle_brightness_3(self):
|
||||
self._hw_manager.set_display_brightness(9)
|
||||
self._set_display_brightness(9)
|
||||
|
||||
def handle_brightness_4(self):
|
||||
self._hw_manager.set_display_brightness(15)
|
||||
self._set_display_brightness(15)
|
||||
|
||||
def handle_volume_1(self):
|
||||
self._audio_manager.set_volume(0)
|
||||
@ -90,10 +99,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._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._set_display_mode(hardwaremanager.B_AND_W_MODE)
|
||||
|
||||
def handle_console(self):
|
||||
gobject.idle_add(self._toggle_console_visibility_cb)
|
||||
@ -126,7 +135,9 @@ class KeyHandler(object):
|
||||
mgr.Shutdown()
|
||||
|
||||
def handle_keyboard_brightness(self):
|
||||
self._hw_manager.toggle_keyboard_brightness()
|
||||
hw_manager = hardwaremanager.get_hardware_manager()
|
||||
if hw_manager:
|
||||
hw_manager.toggle_keyboard_brightness()
|
||||
|
||||
def handle_rotate(self):
|
||||
states = [ 'normal', 'left', 'inverted', 'right']
|
||||
|
Loading…
Reference in New Issue
Block a user