diff options
author | Dmitry Moiseev <m0sia@m0sia.ru> | 2013-12-13 17:01:38 +0600 |
---|---|---|
committer | Dmitry Moiseev <m0sia@m0sia.ru> | 2013-12-13 17:01:38 +0600 |
commit | e90a39bbbd7a4592babafdbae63123c71e4f10ae (patch) | |
tree | cb5981bd8d1fb05bc521475354f750e45f2fb7bd | |
parent | db29fcb24521c4ab1c2bab3e7ffb512afdb74978 (diff) | |
download | pyParrotZikTCP-e90a39bbbd7a4592babafdbae63123c71e4f10ae.tar.xz pyParrotZikTCP-e90a39bbbd7a4592babafdbae63123c71e4f10ae.zip |
SysIndicator wrapper on top of appindicator/pygtk/rumps for cross-platfrom system indicator
-rw-r--r-- | SysIndicator.py | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/SysIndicator.py b/SysIndicator.py new file mode 100644 index 0000000..a847863 --- /dev/null +++ b/SysIndicator.py @@ -0,0 +1,115 @@ +#!/usr/bin/env python + +import sys +import re +import os + +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": + self.menu = menu.gtk_menu + import appindicator + self.icon_directory = os.path.sep + 'usr' + os.path.sep+ 'share' + os.path.sep+'icons' + os.path.sep+'zik'+ os.path.sep + self.statusicon = appindicator.Indicator("new-parrotzik-indicator", + "indicator-messages", + appindicator.CATEGORY_APPLICATION_STATUS) + self.statusicon.set_status(appindicator.STATUS_ACTIVE) + self.statusicon.set_icon_theme_path(self.icon_directory) + self.statusicon.set_menu(self.menu) + + elif sys.platform=="win32": + self.menu = menu.gtk_menu + self.icon_directory = os.path.dirname(os.path.realpath(sys.argv[0])) + os.path.sep+ 'share' + os.path.sep+'icons' + os.path.sep+'zik'+ os.path.sep + self.statusicon = gtk.StatusIcon() + self.statusicon.connect("popup-menu", self.gtk_right_click_event) + self.statusicon.set_tooltip("Parrot Zik") + self.menu_shown=False + sys.stdout = open("debug.log", "w") + sys.stderr = open("debug.log", "w") + + self.setIcon(icon) + return + + def setIcon(self, name): + if sys.platform=="linux2": + self.statusicon.set_icon(name) + elif sys.platform=="win32": + self.statusicon.set_from_file(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) + else: + self.menu_shown=False + self.menu.popdown() + + def main(self): + if sys.platform=="linux2" or sys.platform=="win32": + gtk.main() + elif sys.platform=="darwin": + 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() + + + +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) + + 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) + +class MenuItem: + def __init__(self,name,action,sensitive = True, checkitem = False): + if sys.platform=="linux2" or sys.platform=="win32": + if checkitem: + self.gtk_item=gtk.CheckMenuItem(name) + else: + self.gtk_item=gtk.MenuItem(name) + self.gtk_item.show() + if action: + self.gtk_item.connect("activate", action) + + if not sensitive: + self.set_sensitive(sensitive) + + def set_sensitive(self,option): + if sys.platform=="linux2" or sys.platform=="win32": + return self.gtk_item.set_sensitive(option) + + def set_active(self,option): + if sys.platform=="linux2" or sys.platform=="win32": + return self.gtk_item.set_active(option) + + def get_active(self): + if sys.platform=="linux2" or sys.platform=="win32": + return self.gtk_item.get_active() + + def set_label(self,option): + if sys.platform=="linux2" or sys.platform=="win32": + return self.gtk_item.set_label(option) |