Eben specification and the new B3 keyboard (marco)
This commit is contained in:
parent
e78c0106ce
commit
5e655deb5a
3
NEWS
3
NEWS
@ -1,3 +1,6 @@
|
|||||||
|
* #958, #1433 Refactor brightness and volume key handling to follow
|
||||||
|
Eben specification and the new B3 keyboard (marco)
|
||||||
|
|
||||||
Snapshot fd7336c2f1
|
Snapshot fd7336c2f1
|
||||||
|
|
||||||
* Suppress traceback when creating a new buddy object on buddy-disappeared
|
* Suppress traceback when creating a new buddy object on buddy-disappeared
|
||||||
|
@ -48,6 +48,17 @@ class HardwareManager(object):
|
|||||||
if track.flags & gst.interfaces.MIXER_TRACK_MASTER:
|
if track.flags & gst.interfaces.MIXER_TRACK_MASTER:
|
||||||
self._master = track
|
self._master = track
|
||||||
|
|
||||||
|
def get_volume(self):
|
||||||
|
if not self._mixer or not self._master:
|
||||||
|
logging.error('Cannot get the volume')
|
||||||
|
return self._convert_volume(0)
|
||||||
|
|
||||||
|
max_volume = self._master.max_volume
|
||||||
|
min_volume = self._master.min_volume
|
||||||
|
volume = self._mixer.get_volume(self._master)[0]
|
||||||
|
|
||||||
|
return volume * 100.0 / (max_volume - min_volume) + min_volume
|
||||||
|
|
||||||
def set_volume(self, volume):
|
def set_volume(self, volume):
|
||||||
if not self._mixer or not self._master:
|
if not self._mixer or not self._master:
|
||||||
logging.error('Cannot set the volume')
|
logging.error('Cannot set the volume')
|
||||||
@ -59,7 +70,7 @@ class HardwareManager(object):
|
|||||||
max_volume = self._master.max_volume
|
max_volume = self._master.max_volume
|
||||||
min_volume = self._master.min_volume
|
min_volume = self._master.min_volume
|
||||||
|
|
||||||
volume = (volume / 100.0) * (max_volume - min_volume) + min_volume
|
volume = volume * (max_volume - min_volume) / 100.0 + min_volume
|
||||||
volume_list = [ volume ] * self._master.num_channels
|
volume_list = [ volume ] * self._master.num_channels
|
||||||
|
|
||||||
self._mixer.set_volume(self._master, tuple(volume_list))
|
self._mixer.set_volume(self._master, tuple(volume_list))
|
||||||
@ -83,10 +94,18 @@ class HardwareManager(object):
|
|||||||
|
|
||||||
def set_display_brightness(self, level):
|
def set_display_brightness(self, level):
|
||||||
if not self._service:
|
if not self._service:
|
||||||
|
logging.error('Cannot set display brightness')
|
||||||
return
|
return
|
||||||
|
|
||||||
self._service.set_display_brightness(level)
|
self._service.set_display_brightness(level)
|
||||||
|
|
||||||
|
def get_display_brightness(self):
|
||||||
|
if not self._service:
|
||||||
|
logging.error('Cannot get display brightness')
|
||||||
|
return
|
||||||
|
|
||||||
|
return self._service.get_display_brightness()
|
||||||
|
|
||||||
def toggle_keyboard_brightness(self):
|
def toggle_keyboard_brightness(self):
|
||||||
if not self._service:
|
if not self._service:
|
||||||
return
|
return
|
||||||
|
@ -26,22 +26,19 @@ from hardware import hardwaremanager
|
|||||||
from model.shellmodel import ShellModel
|
from model.shellmodel import ShellModel
|
||||||
from sugar._sugarext import KeyGrabber
|
from sugar._sugarext import KeyGrabber
|
||||||
|
|
||||||
|
_BRIGHTNESS_STEP = 2
|
||||||
|
_VOLUME_STEP = 10
|
||||||
|
|
||||||
_actions_table = {
|
_actions_table = {
|
||||||
'F1' : 'zoom_mesh',
|
'F1' : 'zoom_mesh',
|
||||||
'F2' : 'zoom_friends',
|
'F2' : 'zoom_friends',
|
||||||
'F3' : 'zoom_home',
|
'F3' : 'zoom_home',
|
||||||
'F4' : 'zoom_activity',
|
'F4' : 'zoom_activity',
|
||||||
'F5' : 'brightness_1',
|
'F9' : 'brightness_down',
|
||||||
'F6' : 'brightness_2',
|
'F10' : 'brightness_up',
|
||||||
'F7' : 'brightness_3',
|
'F11' : 'volume_down',
|
||||||
'F8' : 'brightness_4',
|
'F12' : 'volume_up',
|
||||||
'F9' : 'volume_1',
|
|
||||||
'F10' : 'volume_2',
|
|
||||||
'F11' : 'volume_3',
|
|
||||||
'F12' : 'volume_4',
|
|
||||||
'<alt>1' : 'screenshot',
|
'<alt>1' : 'screenshot',
|
||||||
'<alt>F8' : 'color_mode',
|
|
||||||
'<alt>F5' : 'b_and_w_mode',
|
|
||||||
'<alt>equal' : 'console',
|
'<alt>equal' : 'console',
|
||||||
'<alt>0' : 'console',
|
'<alt>0' : 'console',
|
||||||
'<alt>f' : 'frame',
|
'<alt>f' : 'frame',
|
||||||
@ -72,17 +69,26 @@ class KeyHandler(object):
|
|||||||
for key in _actions_table.keys():
|
for key in _actions_table.keys():
|
||||||
self._key_grabber.grab(key)
|
self._key_grabber.grab(key)
|
||||||
|
|
||||||
def _set_display_brightness(self, level):
|
def _change_volume(self, step):
|
||||||
hw_manager = hardwaremanager.get_manager()
|
hw_manager = hardwaremanager.get_manager()
|
||||||
|
|
||||||
|
volume = hw_manager.get_volume() + step
|
||||||
|
volume = min(max(0, volume), 100)
|
||||||
|
|
||||||
|
hw_manager.set_volume(volume)
|
||||||
|
hw_manager.set_mute(volume == 0)
|
||||||
|
|
||||||
|
def _change_brightness(self, step):
|
||||||
|
hw_manager = hardwaremanager.get_manager()
|
||||||
|
|
||||||
|
level = hw_manager.get_display_brightness() + step
|
||||||
|
level = min(max(0, level), 15)
|
||||||
|
|
||||||
hw_manager.set_display_brightness(level)
|
hw_manager.set_display_brightness(level)
|
||||||
if level == 0:
|
if level == 0:
|
||||||
self._set_display_mode(hardwaremanager.B_AND_W_MODE)
|
hw_manager.set_display_mode(hardwaremanager.B_AND_W_MODE)
|
||||||
else:
|
else:
|
||||||
self._set_display_mode(hardwaremanager.COLOR_MODE)
|
hw_manager.set_display_mode(hardwaremanager.COLOR_MODE)
|
||||||
|
|
||||||
def _set_display_mode(self, mode):
|
|
||||||
hw_manager = hardwaremanager.get_manager()
|
|
||||||
hw_manager.set_display_mode(mode)
|
|
||||||
|
|
||||||
def handle_zoom_mesh(self):
|
def handle_zoom_mesh(self):
|
||||||
self._shell.set_zoom_level(ShellModel.ZOOM_MESH)
|
self._shell.set_zoom_level(ShellModel.ZOOM_MESH)
|
||||||
@ -96,46 +102,21 @@ class KeyHandler(object):
|
|||||||
def handle_zoom_activity(self):
|
def handle_zoom_activity(self):
|
||||||
self._shell.set_zoom_level(ShellModel.ZOOM_ACTIVITY)
|
self._shell.set_zoom_level(ShellModel.ZOOM_ACTIVITY)
|
||||||
|
|
||||||
def handle_brightness_1(self):
|
def handle_brightness_up(self):
|
||||||
self._set_display_brightness(0)
|
self._change_brightness(_BRIGHTNESS_STEP)
|
||||||
|
|
||||||
def handle_brightness_2(self):
|
def handle_brightness_down(self):
|
||||||
self._set_display_brightness(5)
|
self._change_brightness(-_BRIGHTNESS_STEP)
|
||||||
|
|
||||||
def handle_brightness_3(self):
|
def handle_volume_up(self):
|
||||||
self._set_display_brightness(9)
|
self._change_volume(_VOLUME_STEP)
|
||||||
|
|
||||||
def handle_brightness_4(self):
|
def handle_volume_down(self):
|
||||||
self._set_display_brightness(15)
|
self._change_volume(-_VOLUME_STEP)
|
||||||
|
|
||||||
def handle_volume_1(self):
|
|
||||||
hw_manager = hardwaremanager.get_manager()
|
|
||||||
hw_manager.set_mute(True)
|
|
||||||
|
|
||||||
def handle_volume_2(self):
|
|
||||||
hw_manager = hardwaremanager.get_manager()
|
|
||||||
hw_manager.set_mute(False)
|
|
||||||
hw_manager.set_volume(50)
|
|
||||||
|
|
||||||
def handle_volume_3(self):
|
|
||||||
hw_manager = hardwaremanager.get_manager()
|
|
||||||
hw_manager.set_mute(False)
|
|
||||||
hw_manager.set_volume(80)
|
|
||||||
|
|
||||||
def handle_volume_4(self):
|
|
||||||
hw_manager = hardwaremanager.get_manager()
|
|
||||||
hw_manager.set_mute(False)
|
|
||||||
hw_manager.set_volume(100)
|
|
||||||
|
|
||||||
def handle_color_mode(self):
|
|
||||||
self._set_display_mode(hardwaremanager.COLOR_MODE)
|
|
||||||
|
|
||||||
def handle_screenshot(self):
|
def handle_screenshot(self):
|
||||||
self._shell.take_screenshot()
|
self._shell.take_screenshot()
|
||||||
|
|
||||||
def handle_b_and_w_mode(self):
|
|
||||||
self._set_display_mode(hardwaremanager.B_AND_W_MODE)
|
|
||||||
|
|
||||||
def handle_console(self):
|
def handle_console(self):
|
||||||
gobject.idle_add(self._toggle_console_visibility_cb)
|
gobject.idle_add(self._toggle_console_visibility_cb)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user