aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-x[-rw-r--r--]ParrotZikTray.py58
1 files changed, 45 insertions, 13 deletions
diff --git a/ParrotZikTray.py b/ParrotZikTray.py
index c342a53..6280fac 100644..100755
--- a/ParrotZikTray.py
+++ b/ParrotZikTray.py
@@ -8,7 +8,7 @@ import re
import os
import ParrotZik
-UPDATE_FREQUENCY = 10 # seconds
+UPDATE_FREQUENCY = 30 # seconds
class ParrotZikIndicator:
def __init__(self):
@@ -16,7 +16,7 @@ class ParrotZikIndicator:
"indicator-messages",
appindicator.CATEGORY_APPLICATION_STATUS)
self.ind.set_status(appindicator.STATUS_ACTIVE)
- self.ind.set_icon("gtk-info")
+ self.ind.set_icon("audio-headset")
self.menu_setup()
self.ind.set_menu(self.menu)
self.connected=False
@@ -35,6 +35,12 @@ class ParrotZikIndicator:
self.check.show()
self.menu.append(self.check)
+ self.check2 = gtk.CheckMenuItem("Auto Connection")
+ self.check2.connect("activate", self.toggleAuto)
+ self.check2.set_sensitive(False)
+ self.check2.show()
+ self.menu.append(self.check2)
+
self.quit_item = gtk.MenuItem("Quit")
self.quit_item.connect("activate", self.quit)
self.quit_item.show()
@@ -51,20 +57,33 @@ class ParrotZikIndicator:
def EstablishConnection(self):
if self.connected:
- return
+ if not self.findParrotZikMac():
+ print "Lost connection"
+ self.connected = False
+ else:
+ print "Connection already established"
else:
mac=self.findParrotZikMac()
if mac:
self.parrot = ParrotZik.ParrotZik(mac)
self.connected = True
+ self.name = self.parrot.getFriendlyName()
+ self.version = self.parrot.getVersion()
+
self.check.set_sensitive(True)
if self.parrot.getNoiseCancel() == "true":
self.check.set_active(True)
else:
self.check.set_active(False)
+
+ self.check2.set_sensitive(True)
+ if self.parrot.getAutoConnection() == "true":
+ self.check2.set_active(True)
+ else:
+ self.check2.set_active(False)
+
self.CheckBattery()
- else:
- return
+ return True
def toggleANC(self,widget):
if self.connected:
@@ -73,30 +92,43 @@ class ParrotZikIndicator:
else:
self.parrot.setNoiseCancel("false")
+ def toggleAuto(self,widget):
+ if self.connected:
+ if self.check2.get_active():
+ self.parrot.setAutoConnection("true")
+ else:
+ self.parrot.setAutoConnection("false")
+
def CheckBattery(self):
if self.connected:
- self.batteryLevel = self.parrot.getBatteryLevel()
- self.info_item.set_label("Battery "+self.batteryLevel+"%")
+ print "Updating battery"
+ self.batteryLevel = int(self.parrot.getBatteryLevel())
+ self.info_item.set_label("Connected to: "+self.name+
+ "\nFirmware version: "+self.version+
+ "\nBattery Level: "+str(self.batteryLevel)+"%")
if self.batteryLevel==100:
self.ind.set_icon("battery-100")
elif self.batteryLevel>80:
- self.ind.set_icon("battery-80")
+ self.ind.set_icon("battery-080")
elif self.batteryLevel>60:
- self.ind.set_icon("battery-80")
+ self.ind.set_icon("battery-060")
elif self.batteryLevel>40:
- self.ind.set_icon("battery-40")
+ self.ind.set_icon("battery-040")
+ elif self.batteryLevel>20:
+ self.ind.set_icon("battery-020")
else:
- self.ind.set_icon("battery-low")
+ self.ind.set_icon("battery-caution")
else:
- self.ind.set_icon("gtk-info")
+ self.ind.set_icon("audio-headset")
self.info_item.set_label("Parrot Zik Not connected..")
self.check.set_sensitive(False)
+ return True
def main(self):
self.EstablishConnection()
gtk.timeout_add(UPDATE_FREQUENCY * 1000, self.EstablishConnection)
gtk.timeout_add(UPDATE_FREQUENCY * 1000, self.CheckBattery)
- gtk.main()
+ gtk.main()
def quit(self, widget):
sys.exit(0)