diff options
author | Marek Siarkowicz <mareksiarkowicz@gmail.com> | 2015-06-13 02:43:36 +0200 |
---|---|---|
committer | Marek Siarkowicz <mareksiarkowicz@gmail.com> | 2015-06-13 02:43:36 +0200 |
commit | 52fb4f7f5561c38631e279a403cd55d8a6632955 (patch) | |
tree | 53fb6b20d43de37f44bcdf5f5763f04f5d5ff875 | |
parent | 2dda7cdb0d159f5fd0c25766cc668ba8a4aa4c7d (diff) | |
download | pyParrotZikTCP-52fb4f7f5561c38631e279a403cd55d8a6632955.tar.xz pyParrotZikTCP-52fb4f7f5561c38631e279a403cd55d8a6632955.zip |
Add Room sound effect feature.
Diffstat (limited to '')
-rw-r--r-- | ParrotZik.py | 28 | ||||
-rwxr-xr-x | ParrotZikTray | 95 |
2 files changed, 102 insertions, 21 deletions
diff --git a/ParrotZik.py b/ParrotZik.py index 0cdab71..80dc591 100644 --- a/ParrotZik.py +++ b/ParrotZik.py @@ -101,6 +101,19 @@ class BatteryStates: CHARGING: 'Charging', } +class Rooms: + CONCERT_HALL = 'concert' + JAZZ_CLUB = 'jazz' + LIVING_ROOM = 'living' + SILENT_ROOM = 'silent' + representation = { + CONCERT_HALL: 'Concert Hall', + JAZZ_CLUB: 'Jazz Club', + LIVING_ROOM: 'Living Room', + SILENT_ROOM: 'Silent Room', + } + + class ParrotZikBase(object): def __init__(self, api): @@ -206,12 +219,21 @@ class ParrotZikVersion2(ParrotZikBase): self.api.set('/api/flight_mode', arg) @property - def room_size(self): + def sound_effect(self): + data = self.api.get('/api/audio/sound_effect/enabled') + return self._result_to_bool(data.answer.audio.sound_effect['enabled']) + + @sound_effect.setter + def sound_effect(self, arg): + self.api.set('/api/audio/sound_effect/enabled', arg) + + @property + def room(self): data = self.api.get('/api/audio/sound_effect/room_size') return data.answer.audio.sound_effect['room_size'] - @room_size.setter - def room_size(self, arg): + @room.setter + def room(self, arg): self.api.set('/api/audio/sound_effect/room_size', arg) @property diff --git a/ParrotZikTray b/ParrotZikTray index 9a96b9b..67ccf65 100755 --- a/ParrotZikTray +++ b/ParrotZikTray @@ -4,6 +4,7 @@ import gtk import BluetoothPairedDevices from ParrotZik import BatteryStates from ParrotZik import connect +from ParrotZik import Rooms from SysIndicator import MenuItem from SysIndicator import Menu from SysIndicator import SysIndicator @@ -223,6 +224,7 @@ class ParrotZikVersion1Interface(ParrotZikBaseInterface): class ParrotZikVersion2Interface(ParrotZikBaseInterface): def __init__(self, indicator): + self.dirty = False super(ParrotZikVersion2Interface, self).__init__(indicator) self.noise_cancelation = MenuItem("Noise Cancellation", None, sensitive=True, visible=False) @@ -246,27 +248,28 @@ class ParrotZikVersion2Interface(ParrotZikBaseInterface): self.noise_cancelation_submenu.append(self.noise_cancelation_mode3) self.indicator.menu.append(self.noise_cancelation) - self.concert_hall_mode = MenuItem( - "Sound Mode", None, sensitive=True, checkitem=False, visible=False) - self.concert_hall_mode_submenu = Menu() - self.concert_hall_mode.set_submenu(self.concert_hall_mode_submenu) - - self.concert_hall_mode_enabled = MenuItem("Enabled", None, - sensitive=True, checkitem=True) - self.concert_hall = MenuItem("Concert Hall", None, - sensitive=True, checkitem=True) - self.jazz_mode = MenuItem("Jazz Club", None, + self.room_sound_effect = MenuItem( + "Room Sound Effect", None, sensitive=True, checkitem=False, visible=False) + self.room_sound_effect_submenu = Menu() + self.room_sound_effect.set_submenu(self.room_sound_effect_submenu) + + self.room_sound_effect_enabled = MenuItem( + "Enabled", self.toggle_room_sound_effect, sensitive=True, checkitem=True) + self.concert_hall_mode = MenuItem("Concert Hall", + self.toggle_concert_hall_mode, + sensitive=True, checkitem=True) + self.jazz_mode = MenuItem("Jazz Club", self.toggle_jazz_club_mode, sensitive=True, checkitem=True) - self.living_mode = MenuItem("Libing Room", None, + self.living_mode = MenuItem("Libing Room", self.toggle_living_room_mode, sensitive=True, checkitem=True) - self.silent_mode = MenuItem("Silent Room", None, + self.silent_mode = MenuItem("Silent Room", self.toggle_silent_room_mode, sensitive=True, checkitem=True) - self.concert_hall_mode_submenu.append(self.concert_hall_mode_enabled) - self.concert_hall_mode_submenu.append(self.concert_hall) - self.concert_hall_mode_submenu.append(self.jazz_mode) - self.concert_hall_mode_submenu.append(self.living_mode) - self.concert_hall_mode_submenu.append(self.silent_mode) - self.indicator.menu.append(self.concert_hall_mode) + self.room_sound_effect_submenu.append(self.room_sound_effect_enabled) + self.room_sound_effect_submenu.append(self.concert_hall_mode) + self.room_sound_effect_submenu.append(self.jazz_mode) + self.room_sound_effect_submenu.append(self.living_mode) + self.room_sound_effect_submenu.append(self.silent_mode) + self.indicator.menu.append(self.room_sound_effect) self.flight_mode = MenuItem("Flight Mode", self.toggle_flight_mode, sensitive=True, checkitem=True, visible=False) @@ -276,9 +279,25 @@ class ParrotZikVersion2Interface(ParrotZikBaseInterface): self.noise_cancelation.show() self.concert_hall_mode.show() self.flight_mode.show() + self.room_sound_effect.show() super(ParrotZikVersion2Interface, self).activate(parrot) self.noise_cancelation_enabled.set_active(self.parrot.noise_cancel) self.flight_mode.set_active(self.parrot.flight_mode) + self.read_sound_effect_room() + + sound_effect = self.parrot.sound_effect + self.room_sound_effect_enabled.set_active(sound_effect) + self.concert_hall_mode.set_sensitive(sound_effect) + self.jazz_mode.set_sensitive(sound_effect) + self.living_mode.set_sensitive(sound_effect) + self.silent_mode.set_sensitive(sound_effect) + + def deactivate(self): + self.noise_cancelation.hide() + self.concert_hall_mode.hide() + self.flight_mode.hide() + self.room_sound_effect.hide() + super(ParrotZikVersion2Interface, self).deactivate() def toggleANC(self, widget): if self.connected: @@ -293,6 +312,46 @@ class ParrotZikVersion2Interface(ParrotZikBaseInterface): def toggledummy(self, widget): print(widget.get_name()) + def toggle_concert_hall_mode(self, widget): + self.toggle_room(Rooms.CONCERT_HALL) + + def toggle_jazz_club_mode(self, widget): + self.toggle_room(Rooms.JAZZ_CLUB) + + def toggle_living_room_mode(self, widget): + self.toggle_room(Rooms.LIVING_ROOM) + + def toggle_silent_room_mode(self, widget): + self.toggle_room(Rooms.SILENT_ROOM) + + def toggle_room(self, room): + if self.connected and not self.dirty: + self.parrot.room = room + self.dirty = True + self.read_sound_effect_room() + self.dirty = False + + def read_sound_effect_room(self): + active_room = self.parrot.room + room_to_menuitem_map = ( + (Rooms.CONCERT_HALL, self.concert_hall_mode), + (Rooms.JAZZ_CLUB, self.jazz_mode), + (Rooms.LIVING_ROOM, self.living_mode), + (Rooms.SILENT_ROOM, self.silent_mode), + ) + for room, menu_item in room_to_menuitem_map: + menu_item.set_active(room == active_room) + + def toggle_room_sound_effect(self, widget): + if self.connected: + self.parrot.sound_effect = self.room_sound_effect_enabled.get_active() + sound_effect = self.parrot.sound_effect + self.room_sound_effect_enabled.set_active(sound_effect) + self.concert_hall_mode.set_sensitive(sound_effect) + self.jazz_mode.set_sensitive(sound_effect) + self.living_mode.set_sensitive(sound_effect) + self.silent_mode.set_sensitive(sound_effect) + if __name__ == "__main__": indicator = ParrotZikIndicator() |