diff options
author | Dmitry Moiseev <m0sia@m0sia.ru> | 2013-10-31 16:25:41 +0600 |
---|---|---|
committer | Dmitry Moiseev <m0sia@m0sia.ru> | 2013-10-31 16:25:41 +0600 |
commit | 6dab1fd561371aaec155781f6ba269c0def7804b (patch) | |
tree | ad4bb2c6a30a89d9990cecd32218f2542486f19e | |
parent | 1b2aeb4afc86c0b0b30d0d70f31d699c58d627f9 (diff) | |
download | pyParrotZikTCP-6dab1fd561371aaec155781f6ba269c0def7804b.tar.xz pyParrotZikTCP-6dab1fd561371aaec155781f6ba269c0def7804b.zip |
Fixed updating battery status. Added adition info. Added toggle for auto connection.
-rwxr-xr-x[-rw-r--r--] | ParrotZikTray.py | 58 |
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) |