From f291feaa8a33645850818f811ba8d7f9eb9d4c31 Mon Sep 17 00:00:00 2001 From: Marek Siarkowicz Date: Mon, 15 Jun 2015 13:41:06 +0200 Subject: Refactor. --- parrot_zik/parrot_zik_tray | 85 ---------------------------------------------- 1 file changed, 85 deletions(-) delete mode 100755 parrot_zik/parrot_zik_tray (limited to 'parrot_zik/parrot_zik_tray') diff --git a/parrot_zik/parrot_zik_tray b/parrot_zik/parrot_zik_tray deleted file mode 100755 index 0e5b951..0000000 --- a/parrot_zik/parrot_zik_tray +++ /dev/null @@ -1,85 +0,0 @@ -#!/usr/bin/env python - -from parrot_zik.interface.version1 import ParrotZikVersion1Interface -from parrot_zik.interface.version2 import ParrotZikVersion2Interface -from parrot_zik import resource_manager -from parrot_zik import bluetooth_paired_devices -from parrot_zik.indicator import MenuItem -from parrot_zik.indicator import Menu -from parrot_zik.indicator import SysIndicator -from parrot_zik.utils import repeat - -REFRESH_FREQUENCY = 30000 -RECONNECT_FREQUENCY = 5000 - - - -class ParrotZikIndicator(SysIndicator): - def __init__(self): - - self.menu = Menu() - - self.info_item = MenuItem("Parrot Zik Not connected", - None, sensitive=False) - self.menu.append(self.info_item) - - self.version_1_interface = ParrotZikVersion1Interface(self) - self.version_2_interface = ParrotZikVersion2Interface(self) - self.quit_item = MenuItem("Quit", self.quit, checkitem=True) - self.menu.append(self.quit_item) - - SysIndicator.__init__(self, icon="zik-audio-headset", menu=self.menu) - - self.active_interface = None - - @repeat - def reconnect(self): - if self.active_interface: - self.reconnect.stop() - else: - self.info("Trying to connect") - try: - manager = bluetooth_paired_devices.connect() - except bluetooth_paired_devices.BluetoothIsNotOn: - self.info("Bluetooth is turned off") - except bluetooth_paired_devices.DeviceNotConnected: - self.info("Parrot Zik Not connected") - except bluetooth_paired_devices.ConnectionFailure: - self.info("Failed to connect") - else: - if manager.api_version.startswith('1'): - interface = self.version_1_interface - else: - interface = self.version_2_interface - try: - interface.activate(manager) - except resource_manager.DeviceDisconnected: - interface.deactivate() - else: - self.autorefresh(self) - self.autorefresh.start(self, REFRESH_FREQUENCY) - self.reconnect.stop() - - def info(self, message): - self.info_item.set_label(message) - print(message) - - @repeat - def autorefresh(self): - if self.active_interface: - self.active_interface.refresh() - else: - self.reconnect.start(self, RECONNECT_FREQUENCY) - self.autorefresh.stop() - - def main(self): - self.reconnect.start(self, RECONNECT_FREQUENCY) - SysIndicator.main(self) - - -if __name__ == "__main__": - try: - indicator = ParrotZikIndicator() - indicator.main() - except KeyboardInterrupt: - pass -- cgit v1.2.1