aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--SysIndicator.py53
1 files changed, 39 insertions, 14 deletions
diff --git a/SysIndicator.py b/SysIndicator.py
index 16a31e3..3d7adce 100644
--- a/SysIndicator.py
+++ b/SysIndicator.py
@@ -3,15 +3,13 @@
import sys
import re
import os
+import tempfile
if sys.platform=="linux2" or sys.platform=="win32":
import gtk
elif sys.platform=="darwin":
import rumps
-
-UPDATE_FREQUENCY = 30 # seconds
-
class SysIndicator:
def __init__(self, icon,menu):
if sys.platform=="linux2":
@@ -31,7 +29,12 @@ class SysIndicator:
self.statusicon = gtk.StatusIcon()
self.statusicon.connect("popup-menu", self.gtk_right_click_event)
self.statusicon.set_tooltip("Parrot Zik")
- self.menu_shown=False
+ self.menu_shown=False
+ sys.stdout = open(tempfile.gettempdir()+os.path.sep+"zik_tray_stdout.log", "w")
+ sys.stderr = open(tempfile.gettempdir()+os.path.sep+"zik_tray_stderr.log", "w")
+
+ elif sys.platform=="darwin":
+ self.statusicon = rumps.App("Parrot Zik")
self.setIcon(icon)
@@ -40,9 +43,10 @@ class SysIndicator:
self.statusicon.set_icon(name)
elif sys.platform=="win32":
self.statusicon.set_from_file(self.icon_directory+name+'.png')
+ elif sys.platform=="darwin":
+ self.statusicon.icon=self.icon_directory+name+'.png'
def gtk_right_click_event(self, icon, button, time):
- import gtk
if not self.menu_shown:
self.menu_shown=True
self.menu.popup(None, None, gtk.status_icon_position_menu, button, time, self.statusicon)
@@ -57,29 +61,32 @@ class SysIndicator:
self.app.run()
def show_about_dialog(self, widget):
- about_dialog = gtk.AboutDialog()
-
- about_dialog.set_destroy_with_parent(True)
- about_dialog.set_name("Parrot Zik Tray")
- about_dialog.set_version("0.3")
- about_dialog.set_authors(["Dmitry Moiseev m0sia@m0sia.ru"])
- about_dialog.run()
- about_dialog.destroy()
+ if sys.platform=="linux2" or sys.platform=="win32":
+ about_dialog = gtk.AboutDialog()
+ about_dialog.set_destroy_with_parent(True)
+ about_dialog.set_name("Parrot Zik Tray")
+ about_dialog.set_version("0.3")
+ about_dialog.set_authors(["Dmitry Moiseev m0sia@m0sia.ru"])
+ about_dialog.run()
+ about_dialog.destroy()
-
class UniversalMenu:
def __init__(self):
if sys.platform=="linux2" or sys.platform=="win32":
self.gtk_menu = gtk.Menu()
self.gtk_quite_item = MenuItem("Quit",sys.exit).gtk_item
self.gtk_menu.append(self.gtk_quite_item)
+ elif sys.platform=="darwin":
+ self.rumps_menu = []
def append(self,MenuItem):
if sys.platform=="linux2" or sys.platform=="win32":
self.gtk_menu.remove(self.gtk_quite_item)
self.gtk_menu.append(MenuItem.gtk_item)
self.gtk_menu.append(self.gtk_quite_item)
+ elif sys.platform=="darwin":
+ self.rumps_menu.append(self.rumps_item)
class MenuItem:
def __init__(self,name,action,sensitive = True, checkitem = False):
@@ -94,6 +101,8 @@ class MenuItem:
if not sensitive:
self.set_sensitive(sensitive)
+ elif sys.platform=="darwin":
+ self.rumps_item = rumps.MenuItem(name, callback=action)
def set_sensitive(self,option):
if sys.platform=="linux2" or sys.platform=="win32":
@@ -102,11 +111,27 @@ class MenuItem:
def set_active(self,option):
if sys.platform=="linux2" or sys.platform=="win32":
return self.gtk_item.set_active(option)
+ elif sys.platform=="darwin":
+ self.rumps_item.state = option
def get_active(self):
if sys.platform=="linux2" or sys.platform=="win32":
return self.gtk_item.get_active()
+ elif sys.platform=="darwin":
+ return self.rumps_item.state
def set_label(self,option):
if sys.platform=="linux2" or sys.platform=="win32":
return self.gtk_item.set_label(option)
+ elif sys.platform=="darwin":
+ self.rumps_item.title=option
+
+if __name__ == "__main__":
+
+ info_item = MenuItem("Parrot Zik Not connected..",None,False)
+
+ menu = UniversalMenu()
+ menu.append(info_item)
+
+ indicator = SysIndicator(icon = "audio-headset",menu = menu)
+ indicator.main() \ No newline at end of file