From 8c724233f95dec5a871bb1eb39da621902d3fcd1 Mon Sep 17 00:00:00 2001 From: Marek Siarkowicz Date: Mon, 15 Jun 2015 12:53:26 +0200 Subject: Refactor. Move. --- parrot_zik/interface/__init__.py | 0 parrot_zik/interface/base.py | 89 ++++++++++++++++ parrot_zik/interface/version1.py | 61 +++++++++++ parrot_zik/interface/version2.py | 224 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 374 insertions(+) create mode 100644 parrot_zik/interface/__init__.py create mode 100644 parrot_zik/interface/base.py create mode 100644 parrot_zik/interface/version1.py create mode 100644 parrot_zik/interface/version2.py (limited to 'parrot_zik/interface') diff --git a/parrot_zik/interface/__init__.py b/parrot_zik/interface/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/parrot_zik/interface/base.py b/parrot_zik/interface/base.py new file mode 100644 index 0000000..9ddf47a --- /dev/null +++ b/parrot_zik/interface/base.py @@ -0,0 +1,89 @@ +from .. import resource_manager +from ..indicator import MenuItem +from ..parrot_zik_model import BatteryStates + +RECONNECT_FREQUENCY = 5000 + + +class ParrotZikBaseInterface(object): + def __init__(self, indicator): + self.indicator = indicator + self.parrot = None + self.battery_level = MenuItem("Battery Level:", None, sensitive=False, + visible=False) + self.battery_state = MenuItem("Battery State:", None, sensitive=False, + visible=False) + self.firmware_version = MenuItem("Firmware Version:", None, + sensitive=False, visible=False) + self.auto_connection = MenuItem("Auto Connection", self.toggle_auto_connection, + checkitem=True, visible=False) + self.indicator.menu.append(self.battery_level) + self.indicator.menu.append(self.battery_state) + self.indicator.menu.append(self.firmware_version) + self.indicator.menu.append(self.auto_connection) + + def activate(self, manager): + self.parrot = self.parrot_class(manager) + self.read_battery() + self.indicator.info("Connected to: " + self.parrot.friendly_name) + self.firmware_version.set_label( + "Firmware version: " + self.parrot.version) + self.auto_connection.set_active(self.parrot.auto_connect) + self.battery_level.show() + self.battery_state.show() + self.firmware_version.show() + self.auto_connection.show() + self.indicator.active_interface = self + self.indicator.menu.reposition() + + @property + def parrot_class(self): + raise NotImplementedError + + def deactivate(self): + self.parrot = None + self.battery_level.hide() + self.battery_state.hide() + self.firmware_version.hide() + self.auto_connection.hide() + self.indicator.menu.reposition() + self.indicator.active_interface = None + self.indicator.setIcon("zik-audio-headset") + self.indicator.info('Lost Connection') + self.indicator.reconnect.start(self.indicator, RECONNECT_FREQUENCY) + + def toggle_auto_connection(self, widget): + try: + self.parrot.auto_connect = self.auto_connection.get_active() + self.auto_connection.set_active(self.parrot.auto_connect) + except resource_manager.DeviceDisconnected: + self.deactivate() + + def refresh(self): + self.read_battery() + + def read_battery(self): + try: + self.parrot.refresh_battery() + battery_level = self.parrot.battery_level + battery_state = self.parrot.battery_state + except resource_manager.DeviceDisconnected: + self.deactivate() + else: + if battery_state == BatteryStates.CHARGING: + self.indicator.setIcon("zik-battery-charging") + elif battery_level > 80: + self.indicator.setIcon("zik-battery-100") + elif battery_level > 60: + self.indicator.setIcon("zik-battery-080") + elif battery_level > 40: + self.indicator.setIcon("zik-battery-060") + elif battery_level > 20: + self.indicator.setIcon("zik-battery-040") + else: + self.indicator.setIcon("zik-battery-low") + + self.battery_state.set_label( + "State: " + BatteryStates.representation[battery_state]) + self.battery_level.set_label( + "Battery Level: " + str(battery_level)) diff --git a/parrot_zik/interface/version1.py b/parrot_zik/interface/version1.py new file mode 100644 index 0000000..5a00441 --- /dev/null +++ b/parrot_zik/interface/version1.py @@ -0,0 +1,61 @@ +from .. import resource_manager +from ..indicator import MenuItem +from ..interface.base import ParrotZikBaseInterface +from ..parrot_zik_model import ParrotZikVersion1 + + +class ParrotZikVersion1Interface(ParrotZikBaseInterface): + parrot_class = ParrotZikVersion1 + + def __init__(self, indicator): + super(ParrotZikVersion1Interface, self).__init__(indicator) + self.noise_cancelation = MenuItem( + "Noise Cancellation", self.toggle_noise_cancelation, + checkitem=True, visible=False) + self.lou_reed_mode = MenuItem("Lou Reed Mode", self.toggle_lou_reed_mode, + checkitem=True, visible=False) + self.concert_hall_mode = MenuItem( + "Concert Hall Mode", self.toggle_parrot_concert_hall, + checkitem=True, visible=False) + self.indicator.menu.append(self.noise_cancelation) + self.indicator.menu.append(self.lou_reed_mode) + self.indicator.menu.append(self.concert_hall_mode) + + def activate(self, manager): + self.noise_cancelation.show() + self.lou_reed_mode.show() + self.concert_hall_mode.show() + super(ParrotZikVersion1Interface, self).activate(manager) + self.noise_cancelation.set_active(self.parrot.cancel_noise) + self.lou_reed_mode.set_active(self.parrot.lou_reed_mode) + self.concert_hall_mode.set_active(self.parrot.concert_hall) + + def deactivate(self): + self.noise_cancelation.hide() + self.lou_reed_mode.hide() + self.concert_hall_mode.hide() + super(ParrotZikVersion1Interface, self).deactivate() + + def toggle_noise_cancelation(self, widget): + try: + self.parrot.cancel_noise = self.noise_cancelation.get_active() + self.noise_cancelation.set_active(self.parrot.cancel_noise) + except resource_manager.DeviceDisconnected: + self.deactivate() + + def toggle_lou_reed_mode(self, widget): + try: + self.parrot.lou_reed_mode = self.lou_reed_mode.get_active() + self.lou_reed_mode.set_active(self.parrot.lou_reed_mode) + self.concert_hall_mode.set_active(self.parrot.concert_hall) + self.concert_hall_mode.set_sensitive( + not self.lou_reed_mode.get_active()) + except resource_manager.DeviceDisconnected: + self.deactivate() + + def toggle_parrot_concert_hall(self, widget): + try: + self.parrot.concert_hall = self.concert_hall_mode.get_active() + self.concert_hall_mode.set_active(self.parrot.concert_hall) + except resource_manager.DeviceDisconnected: + self.deactivate() diff --git a/parrot_zik/interface/version2.py b/parrot_zik/interface/version2.py new file mode 100644 index 0000000..fc4af21 --- /dev/null +++ b/parrot_zik/interface/version2.py @@ -0,0 +1,224 @@ +import functools + +from .. import resource_manager +from ..indicator import MenuItem, Menu +from .base import ParrotZikBaseInterface +from ..parrot_zik_model import ParrotZikVersion2 +from ..parrot_zik_model import NoiseControlTypes +from ..parrot_zik_model import Rooms + + +class ParrotZikVersion2Interface(ParrotZikBaseInterface): + parrot_class = ParrotZikVersion2 + + def __init__(self, indicator): + self.room_dirty = False + self.angle_dirty = False + self.noise_cancelation_dirty = False + super(ParrotZikVersion2Interface, self).__init__(indicator) + self.noise_cancelation = MenuItem("Noise Control", None, visible=False) + self.noise_cancelation_submenu = Menu() + self.noise_cancelation.set_submenu(self.noise_cancelation_submenu) + + self.noise_control_cancelation_max = MenuItem( + "Max Calcelation", functools.partial( + self.toggle_noise_cancelation, + NoiseControlTypes.NOISE_CONTROL_MAX), checkitem=True, sensitive=False) + self.noise_control_cancelation_on = MenuItem( + "Normal Cancelation", functools.partial( + self.toggle_noise_cancelation, + NoiseControlTypes.NOISE_CONTROL_ON), checkitem=True, sensitive=False) + self.noise_control_off = MenuItem( + "Off", functools.partial( + self.toggle_noise_cancelation, + NoiseControlTypes.NOISE_CONTROL_OFF), checkitem=True, sensitive=False) + self.noise_control_street_mode = MenuItem( + "Street Mode", functools.partial( + self.toggle_noise_cancelation, + NoiseControlTypes.STREET_MODE), checkitem=True, sensitive=False) + self.noise_control_street_mode_max = MenuItem( + "Street Mode Max", functools.partial( + self.toggle_noise_cancelation, + NoiseControlTypes.STREET_MODE_MAX), checkitem=True, sensitive=False) + self.noise_cancelation_submenu.append(self.noise_control_cancelation_max) + self.noise_cancelation_submenu.append(self.noise_control_cancelation_on) + self.noise_cancelation_submenu.append(self.noise_control_off) + self.noise_cancelation_submenu.append(self.noise_control_street_mode) + self.noise_cancelation_submenu.append(self.noise_control_street_mode_max) + + self.room_sound_effect = MenuItem( + "Room Sound Effect", None, 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, checkitem=True) + self.rooms = MenuItem("Rooms", None, checkitem=False) + self.angle = MenuItem("Angle", None, checkitem=False) + self.room_sound_effect_submenu.append(self.room_sound_effect_enabled) + self.room_sound_effect_submenu.append(self.rooms) + self.room_sound_effect_submenu.append(self.angle) + + self.rooms_submenu = Menu() + self.rooms.set_submenu(self.rooms_submenu) + + self.concert_hall_mode = MenuItem( + "Concert Hall", functools.partial(self.toggle_room, Rooms.CONCERT_HALL), checkitem=True) + self.jazz_mode = MenuItem( + "Jazz Club", functools.partial(self.toggle_room, Rooms.JAZZ_CLUB), checkitem=True) + self.living_mode = MenuItem( + "Living Room", functools.partial(self.toggle_room, Rooms.LIVING_ROOM), checkitem=True) + self.silent_mode = MenuItem( + "Silent Room", functools.partial(self.toggle_room, Rooms.SILENT_ROOM), checkitem=True) + self.rooms_submenu.append(self.concert_hall_mode) + self.rooms_submenu.append(self.jazz_mode) + self.rooms_submenu.append(self.living_mode) + self.rooms_submenu.append(self.silent_mode) + + self.angle_submenu = Menu() + self.angle.set_submenu(self.angle_submenu) + self.angle_30 = MenuItem( + "30", functools.partial(self.toggle_angle, 30), checkitem=True) + self.angle_60 = MenuItem( + "60", functools.partial(self.toggle_angle, 60), checkitem=True) + self.angle_90 = MenuItem( + "90", functools.partial(self.toggle_angle, 90), checkitem=True) + self.angle_120 = MenuItem( + "120", functools.partial(self.toggle_angle, 120), checkitem=True) + self.angle_150 = MenuItem( + "150", functools.partial(self.toggle_angle, 150), checkitem=True) + self.angle_180 = MenuItem( + "180", functools.partial(self.toggle_angle, 180), checkitem=True) + self.angle_submenu.append(self.angle_30) + self.angle_submenu.append(self.angle_60) + self.angle_submenu.append(self.angle_90) + self.angle_submenu.append(self.angle_120) + self.angle_submenu.append(self.angle_150) + self.angle_submenu.append(self.angle_180) + + self.flight_mode = MenuItem("Flight Mode", self.toggle_flight_mode, + checkitem=True, visible=False) + self.indicator.menu.append(self.room_sound_effect) + self.indicator.menu.append(self.noise_cancelation) + self.indicator.menu.append(self.flight_mode) + + def activate(self, manager): + self.noise_cancelation.show() + self.flight_mode.show() + self.room_sound_effect.show() + super(ParrotZikVersion2Interface, self).activate(manager) + self._read_noise_cancelation() + self.flight_mode.set_active(self.parrot.flight_mode) + self._read_sound_effect_room() + self._read_sound_effect_angle() + 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) + + self.angle_30.set_sensitive(sound_effect) + self.angle_60.set_sensitive(sound_effect) + self.angle_90.set_sensitive(sound_effect) + self.angle_120.set_sensitive(sound_effect) + self.angle_150.set_sensitive(sound_effect) + self.angle_180.set_sensitive(sound_effect) + + def deactivate(self): + self.noise_cancelation.hide() + self.flight_mode.hide() + self.room_sound_effect.hide() + super(ParrotZikVersion2Interface, self).deactivate() + + def toggle_flight_mode(self, widget): + try: + self.parrot.flight_mode = self.flight_mode.get_active() + self.flight_mode.set_active(self.parrot.flight_mode) + except resource_manager.DeviceDisconnected: + self.deactivate() + + def toggle_room(self, room, widget): + try: + if not self.room_dirty: + self.parrot.room = room + self.room_dirty = True + self._read_sound_effect_room() + self.room_dirty = False + except resource_manager.DeviceDisconnected: + self.deactivate() + + 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): + try: + 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) + self.angle_30.set_sensitive(sound_effect) + self.angle_60.set_sensitive(sound_effect) + self.angle_90.set_sensitive(sound_effect) + self.angle_120.set_sensitive(sound_effect) + self.angle_150.set_sensitive(sound_effect) + self.angle_180.set_sensitive(sound_effect) + except resource_manager.DeviceDisconnected: + self.deactivate() + + def toggle_angle(self, angle, widget): + try: + if not self.angle_dirty: + self.parrot.angle = angle + self.angle_dirty = True + self._read_sound_effect_angle() + self.angle_dirty = False + except resource_manager.DeviceDisconnected: + self.deactivate() + + def _read_sound_effect_angle(self): + active_angle = self.parrot.angle + angle_to_menuitem_map = ( + (30, self.angle_30), + (60, self.angle_60), + (90, self.angle_90), + (120, self.angle_120), + (150, self.angle_150), + (180, self.angle_180), + ) + for angle, menu_item in angle_to_menuitem_map: + menu_item.set_active(angle == active_angle) + + def toggle_noise_cancelation(self, noise_calcelation, widget): + try: + if not self.noise_cancelation_dirty: + self.parrot.noise_control = noise_calcelation + self.noise_cancelation_dirty = True + self._read_noise_cancelation() + self.noise_cancelation_dirty = False + except resource_manager.DeviceDisconnected: + self.deactivate() + + def _read_noise_cancelation(self): + active_noise_control = self.parrot.noise_control + noise_control_to_menuitem_map = ( + (NoiseControlTypes.NOISE_CONTROL_MAX, self.noise_control_cancelation_max), + (NoiseControlTypes.NOISE_CONTROL_ON, self.noise_control_cancelation_on), + (NoiseControlTypes.NOISE_CONTROL_OFF, self.noise_control_off), + (NoiseControlTypes.STREET_MODE, self.noise_control_street_mode), + (NoiseControlTypes.STREET_MODE_MAX, self.noise_control_street_mode_max), + ) + for noise_control, menu_item in noise_control_to_menuitem_map: + menu_item.set_active(active_noise_control == noise_control) -- cgit v1.2.1 From afa654af0a2d2e6b34b47af52ed214977b7a3e12 Mon Sep 17 00:00:00 2001 From: Marek Siarkowicz Date: Mon, 15 Jun 2015 13:56:44 +0200 Subject: Refactor. Move. --- parrot_zik/interface/base.py | 2 +- parrot_zik/interface/version1.py | 2 +- parrot_zik/interface/version2.py | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'parrot_zik/interface') diff --git a/parrot_zik/interface/base.py b/parrot_zik/interface/base.py index 9ddf47a..1611874 100644 --- a/parrot_zik/interface/base.py +++ b/parrot_zik/interface/base.py @@ -1,6 +1,6 @@ from .. import resource_manager from ..indicator import MenuItem -from ..parrot_zik_model import BatteryStates +from ..model.base import BatteryStates RECONNECT_FREQUENCY = 5000 diff --git a/parrot_zik/interface/version1.py b/parrot_zik/interface/version1.py index 5a00441..1af71ec 100644 --- a/parrot_zik/interface/version1.py +++ b/parrot_zik/interface/version1.py @@ -1,7 +1,7 @@ from .. import resource_manager from ..indicator import MenuItem from ..interface.base import ParrotZikBaseInterface -from ..parrot_zik_model import ParrotZikVersion1 +from ..model.version1 import ParrotZikVersion1 class ParrotZikVersion1Interface(ParrotZikBaseInterface): diff --git a/parrot_zik/interface/version2.py b/parrot_zik/interface/version2.py index fc4af21..ff21004 100644 --- a/parrot_zik/interface/version2.py +++ b/parrot_zik/interface/version2.py @@ -3,9 +3,9 @@ import functools from .. import resource_manager from ..indicator import MenuItem, Menu from .base import ParrotZikBaseInterface -from ..parrot_zik_model import ParrotZikVersion2 -from ..parrot_zik_model import NoiseControlTypes -from ..parrot_zik_model import Rooms +from ..model.version2 import ParrotZikVersion2 +from ..model.version2 import NoiseControlTypes +from ..model.version2 import Rooms class ParrotZikVersion2Interface(ParrotZikBaseInterface): -- cgit v1.2.1 From 4573f9f3e95a0d79c576e3fe0f34023bbf6f0898 Mon Sep 17 00:00:00 2001 From: Marek Siarkowicz Date: Mon, 15 Jun 2015 14:56:52 +0200 Subject: Implement head detection setting. --- parrot_zik/interface/version2.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'parrot_zik/interface') diff --git a/parrot_zik/interface/version2.py b/parrot_zik/interface/version2.py index ff21004..c348bb4 100644 --- a/parrot_zik/interface/version2.py +++ b/parrot_zik/interface/version2.py @@ -98,14 +98,23 @@ class ParrotZikVersion2Interface(ParrotZikBaseInterface): self.flight_mode = MenuItem("Flight Mode", self.toggle_flight_mode, checkitem=True, visible=False) + self.settings = MenuItem("Settings", None, visible=False) + self.settings_submenu = Menu() + self.settings.set_submenu(self.settings_submenu) + + self.head_detection = MenuItem("Head Detection", self.toggle_head_detection, checkitem=True) + self.settings_submenu.append(self.head_detection) + self.indicator.menu.append(self.room_sound_effect) self.indicator.menu.append(self.noise_cancelation) self.indicator.menu.append(self.flight_mode) + self.indicator.menu.append(self.settings) def activate(self, manager): self.noise_cancelation.show() self.flight_mode.show() self.room_sound_effect.show() + self.settings.show() super(ParrotZikVersion2Interface, self).activate(manager) self._read_noise_cancelation() self.flight_mode.set_active(self.parrot.flight_mode) @@ -130,6 +139,7 @@ class ParrotZikVersion2Interface(ParrotZikBaseInterface): self.noise_cancelation.hide() self.flight_mode.hide() self.room_sound_effect.hide() + self.settings.hide() super(ParrotZikVersion2Interface, self).deactivate() def toggle_flight_mode(self, widget): @@ -222,3 +232,10 @@ class ParrotZikVersion2Interface(ParrotZikBaseInterface): ) for noise_control, menu_item in noise_control_to_menuitem_map: menu_item.set_active(active_noise_control == noise_control) + + def toggle_head_detection(self, widget): + try: + self.parrot.head_detection = self.head_detection.get_active() + self.head_detection.set_active(self.parrot.head_detection) + except resource_manager.DeviceDisconnected: + self.deactivate() \ No newline at end of file -- cgit v1.2.1 From e7089b04e59ae1cf7a24649ec2ef64af56eb7dce Mon Sep 17 00:00:00 2001 From: Marek Siarkowicz Date: Mon, 15 Jun 2015 17:46:22 +0200 Subject: Use absolute package imports. --- parrot_zik/interface/base.py | 6 +++--- parrot_zik/interface/version1.py | 8 ++++---- parrot_zik/interface/version2.py | 12 ++++++------ 3 files changed, 13 insertions(+), 13 deletions(-) (limited to 'parrot_zik/interface') diff --git a/parrot_zik/interface/base.py b/parrot_zik/interface/base.py index 1611874..225e53f 100644 --- a/parrot_zik/interface/base.py +++ b/parrot_zik/interface/base.py @@ -1,6 +1,6 @@ -from .. import resource_manager -from ..indicator import MenuItem -from ..model.base import BatteryStates +from parrot_zik import resource_manager +from parrot_zik.indicator import MenuItem +from parrot_zik.model.base import BatteryStates RECONNECT_FREQUENCY = 5000 diff --git a/parrot_zik/interface/version1.py b/parrot_zik/interface/version1.py index 1af71ec..6ddd1b5 100644 --- a/parrot_zik/interface/version1.py +++ b/parrot_zik/interface/version1.py @@ -1,7 +1,7 @@ -from .. import resource_manager -from ..indicator import MenuItem -from ..interface.base import ParrotZikBaseInterface -from ..model.version1 import ParrotZikVersion1 +from parrot_zik import resource_manager +from parrot_zik.indicator import MenuItem +from parrot_zik.interface.base import ParrotZikBaseInterface +from parrot_zik.model.version1 import ParrotZikVersion1 class ParrotZikVersion1Interface(ParrotZikBaseInterface): diff --git a/parrot_zik/interface/version2.py b/parrot_zik/interface/version2.py index c348bb4..74fdcc9 100644 --- a/parrot_zik/interface/version2.py +++ b/parrot_zik/interface/version2.py @@ -1,11 +1,11 @@ import functools -from .. import resource_manager -from ..indicator import MenuItem, Menu -from .base import ParrotZikBaseInterface -from ..model.version2 import ParrotZikVersion2 -from ..model.version2 import NoiseControlTypes -from ..model.version2 import Rooms +from parrot_zik import resource_manager +from parrot_zik.indicator import MenuItem, Menu +from parrot_zik.interface.base import ParrotZikBaseInterface +from parrot_zik.model.version2 import ParrotZikVersion2 +from parrot_zik.model.version2 import NoiseControlTypes +from parrot_zik.model.version2 import Rooms class ParrotZikVersion2Interface(ParrotZikBaseInterface): -- cgit v1.2.1 From 6049e5e3a9f77f4b784eeaf90ace6905feb1afd7 Mon Sep 17 00:00:00 2001 From: Marek Siarkowicz Date: Mon, 15 Jun 2015 18:55:12 +0200 Subject: Move auto connection to setttings. --- parrot_zik/interface/base.py | 15 +++++++++++---- parrot_zik/interface/version2.py | 6 ------ 2 files changed, 11 insertions(+), 10 deletions(-) (limited to 'parrot_zik/interface') diff --git a/parrot_zik/interface/base.py b/parrot_zik/interface/base.py index 225e53f..b93c6c0 100644 --- a/parrot_zik/interface/base.py +++ b/parrot_zik/interface/base.py @@ -1,4 +1,5 @@ from parrot_zik import resource_manager +from parrot_zik.indicator import Menu from parrot_zik.indicator import MenuItem from parrot_zik.model.base import BatteryStates @@ -15,12 +16,18 @@ class ParrotZikBaseInterface(object): visible=False) self.firmware_version = MenuItem("Firmware Version:", None, sensitive=False, visible=False) + self.settings = MenuItem("Settings", None, visible=False) + self.settings_submenu = Menu() + self.settings.set_submenu(self.settings_submenu) + self.auto_connection = MenuItem("Auto Connection", self.toggle_auto_connection, - checkitem=True, visible=False) + checkitem=True) + self.settings_submenu.append(self.auto_connection) + self.indicator.menu.append(self.battery_level) self.indicator.menu.append(self.battery_state) self.indicator.menu.append(self.firmware_version) - self.indicator.menu.append(self.auto_connection) + self.indicator.menu.append(self.settings) def activate(self, manager): self.parrot = self.parrot_class(manager) @@ -32,7 +39,7 @@ class ParrotZikBaseInterface(object): self.battery_level.show() self.battery_state.show() self.firmware_version.show() - self.auto_connection.show() + self.settings.show() self.indicator.active_interface = self self.indicator.menu.reposition() @@ -45,7 +52,7 @@ class ParrotZikBaseInterface(object): self.battery_level.hide() self.battery_state.hide() self.firmware_version.hide() - self.auto_connection.hide() + self.settings.hide() self.indicator.menu.reposition() self.indicator.active_interface = None self.indicator.setIcon("zik-audio-headset") diff --git a/parrot_zik/interface/version2.py b/parrot_zik/interface/version2.py index 74fdcc9..08af737 100644 --- a/parrot_zik/interface/version2.py +++ b/parrot_zik/interface/version2.py @@ -98,9 +98,6 @@ class ParrotZikVersion2Interface(ParrotZikBaseInterface): self.flight_mode = MenuItem("Flight Mode", self.toggle_flight_mode, checkitem=True, visible=False) - self.settings = MenuItem("Settings", None, visible=False) - self.settings_submenu = Menu() - self.settings.set_submenu(self.settings_submenu) self.head_detection = MenuItem("Head Detection", self.toggle_head_detection, checkitem=True) self.settings_submenu.append(self.head_detection) @@ -108,13 +105,11 @@ class ParrotZikVersion2Interface(ParrotZikBaseInterface): self.indicator.menu.append(self.room_sound_effect) self.indicator.menu.append(self.noise_cancelation) self.indicator.menu.append(self.flight_mode) - self.indicator.menu.append(self.settings) def activate(self, manager): self.noise_cancelation.show() self.flight_mode.show() self.room_sound_effect.show() - self.settings.show() super(ParrotZikVersion2Interface, self).activate(manager) self._read_noise_cancelation() self.flight_mode.set_active(self.parrot.flight_mode) @@ -139,7 +134,6 @@ class ParrotZikVersion2Interface(ParrotZikBaseInterface): self.noise_cancelation.hide() self.flight_mode.hide() self.room_sound_effect.hide() - self.settings.hide() super(ParrotZikVersion2Interface, self).deactivate() def toggle_flight_mode(self, widget): -- cgit v1.2.1 From 48a0498d56e54e01b9eed06af00b5ba127fe9134 Mon Sep 17 00:00:00 2001 From: Marek Siarkowicz Date: Mon, 15 Jun 2015 18:58:56 +0200 Subject: First get data from api then show. --- parrot_zik/interface/base.py | 1 - parrot_zik/interface/version1.py | 8 +++++--- parrot_zik/interface/version2.py | 8 +++++--- 3 files changed, 10 insertions(+), 7 deletions(-) (limited to 'parrot_zik/interface') diff --git a/parrot_zik/interface/base.py b/parrot_zik/interface/base.py index b93c6c0..90caa02 100644 --- a/parrot_zik/interface/base.py +++ b/parrot_zik/interface/base.py @@ -41,7 +41,6 @@ class ParrotZikBaseInterface(object): self.firmware_version.show() self.settings.show() self.indicator.active_interface = self - self.indicator.menu.reposition() @property def parrot_class(self): diff --git a/parrot_zik/interface/version1.py b/parrot_zik/interface/version1.py index 6ddd1b5..d0a1b2b 100644 --- a/parrot_zik/interface/version1.py +++ b/parrot_zik/interface/version1.py @@ -22,14 +22,16 @@ class ParrotZikVersion1Interface(ParrotZikBaseInterface): self.indicator.menu.append(self.concert_hall_mode) def activate(self, manager): - self.noise_cancelation.show() - self.lou_reed_mode.show() - self.concert_hall_mode.show() super(ParrotZikVersion1Interface, self).activate(manager) self.noise_cancelation.set_active(self.parrot.cancel_noise) self.lou_reed_mode.set_active(self.parrot.lou_reed_mode) self.concert_hall_mode.set_active(self.parrot.concert_hall) + self.noise_cancelation.show() + self.lou_reed_mode.show() + self.concert_hall_mode.show() + self.indicator.menu.reposition() + def deactivate(self): self.noise_cancelation.hide() self.lou_reed_mode.hide() diff --git a/parrot_zik/interface/version2.py b/parrot_zik/interface/version2.py index 08af737..b378a88 100644 --- a/parrot_zik/interface/version2.py +++ b/parrot_zik/interface/version2.py @@ -107,9 +107,6 @@ class ParrotZikVersion2Interface(ParrotZikBaseInterface): self.indicator.menu.append(self.flight_mode) def activate(self, manager): - self.noise_cancelation.show() - self.flight_mode.show() - self.room_sound_effect.show() super(ParrotZikVersion2Interface, self).activate(manager) self._read_noise_cancelation() self.flight_mode.set_active(self.parrot.flight_mode) @@ -130,6 +127,11 @@ class ParrotZikVersion2Interface(ParrotZikBaseInterface): self.angle_150.set_sensitive(sound_effect) self.angle_180.set_sensitive(sound_effect) + self.noise_cancelation.show() + self.flight_mode.show() + self.room_sound_effect.show() + self.indicator.menu.reposition() + def deactivate(self): self.noise_cancelation.hide() self.flight_mode.hide() -- cgit v1.2.1 From d6e3eb4ffb88959503cf41870dab72446ace6b46 Mon Sep 17 00:00:00 2001 From: Pavel Salomatov Date: Fri, 5 Feb 2016 15:41:47 +0300 Subject: Added functionality to change noise cancellation mode "Head detection" now initializes on startup --- parrot_zik/interface/version2.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'parrot_zik/interface') diff --git a/parrot_zik/interface/version2.py b/parrot_zik/interface/version2.py index b378a88..e6076ed 100644 --- a/parrot_zik/interface/version2.py +++ b/parrot_zik/interface/version2.py @@ -23,23 +23,23 @@ class ParrotZikVersion2Interface(ParrotZikBaseInterface): self.noise_control_cancelation_max = MenuItem( "Max Calcelation", functools.partial( self.toggle_noise_cancelation, - NoiseControlTypes.NOISE_CONTROL_MAX), checkitem=True, sensitive=False) + NoiseControlTypes.NOISE_CONTROL_MAX), checkitem=True) self.noise_control_cancelation_on = MenuItem( "Normal Cancelation", functools.partial( self.toggle_noise_cancelation, - NoiseControlTypes.NOISE_CONTROL_ON), checkitem=True, sensitive=False) + NoiseControlTypes.NOISE_CONTROL_ON), checkitem=True) self.noise_control_off = MenuItem( "Off", functools.partial( self.toggle_noise_cancelation, - NoiseControlTypes.NOISE_CONTROL_OFF), checkitem=True, sensitive=False) + NoiseControlTypes.NOISE_CONTROL_OFF), checkitem=True) self.noise_control_street_mode = MenuItem( "Street Mode", functools.partial( self.toggle_noise_cancelation, - NoiseControlTypes.STREET_MODE), checkitem=True, sensitive=False) + NoiseControlTypes.STREET_MODE), checkitem=True) self.noise_control_street_mode_max = MenuItem( "Street Mode Max", functools.partial( self.toggle_noise_cancelation, - NoiseControlTypes.STREET_MODE_MAX), checkitem=True, sensitive=False) + NoiseControlTypes.STREET_MODE_MAX), checkitem=True) self.noise_cancelation_submenu.append(self.noise_control_cancelation_max) self.noise_cancelation_submenu.append(self.noise_control_cancelation_on) self.noise_cancelation_submenu.append(self.noise_control_off) @@ -112,6 +112,8 @@ class ParrotZikVersion2Interface(ParrotZikBaseInterface): self.flight_mode.set_active(self.parrot.flight_mode) self._read_sound_effect_room() self._read_sound_effect_angle() + self.head_detection.set_active(self.parrot.head_detection) + sound_effect = self.parrot.sound_effect self.room_sound_effect_enabled.set_active(sound_effect) @@ -234,4 +236,4 @@ class ParrotZikVersion2Interface(ParrotZikBaseInterface): self.parrot.head_detection = self.head_detection.get_active() self.head_detection.set_active(self.parrot.head_detection) except resource_manager.DeviceDisconnected: - self.deactivate() \ No newline at end of file + self.deactivate() -- cgit v1.2.1