From 419e24ce24087a3f0159fb5c7527eab766987155 Mon Sep 17 00:00:00 2001 From: Marek Siarkowicz Date: Fri, 12 Jun 2015 13:40:17 +0200 Subject: Replace tabs with 4 spaces. --- SysIndicator.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'SysIndicator.py') diff --git a/SysIndicator.py b/SysIndicator.py index 3c79286..1b344c8 100644 --- a/SysIndicator.py +++ b/SysIndicator.py @@ -22,7 +22,7 @@ class SysIndicator: import appindicator self.icon_directory = os.path.sep + 'usr' + os.path.sep+ 'share' + os.path.sep+'icons' + os.path.sep+'zik'+ os.path.sep if not os.path.isdir(self.icon_directory): - self.icon_directory = os.path.dirname(sys.argv[0]) + os.path.sep + 'share' + os.path.sep+'icons' + os.path.sep+'zik'+ os.path.sep + self.icon_directory = os.path.dirname(sys.argv[0]) + 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) @@ -152,4 +152,4 @@ if __name__ == "__main__": menu.append(quit_item) indicator = SysIndicator(icon = "zik-audio-headset",menu = menu) - indicator.main() \ No newline at end of file + indicator.main() -- cgit v1.2.1 From c6442c2eb44c38d6cbe64f8ebe7b4132c70a6326 Mon Sep 17 00:00:00 2001 From: Marek Siarkowicz Date: Fri, 12 Jun 2015 13:45:42 +0200 Subject: Remove unused imports. --- SysIndicator.py | 2 -- 1 file changed, 2 deletions(-) (limited to 'SysIndicator.py') diff --git a/SysIndicator.py b/SysIndicator.py index 1b344c8..145f0bd 100644 --- a/SysIndicator.py +++ b/SysIndicator.py @@ -1,14 +1,12 @@ #!/usr/bin/env python import sys -import re import os import tempfile if sys.platform=="linux2" or sys.platform=="win32": import gtk elif sys.platform=="darwin": - import objc from Foundation import * from AppKit import * from PyObjCTools import AppHelper -- cgit v1.2.1 From b7ccaa7015df61c101b3aa40e44feb2b5da287a0 Mon Sep 17 00:00:00 2001 From: Marek Siarkowicz Date: Fri, 12 Jun 2015 14:07:20 +0200 Subject: Fix pep8. --- SysIndicator.py | 122 +++++++++++++++++++++++++++++++------------------------- 1 file changed, 68 insertions(+), 54 deletions(-) (limited to 'SysIndicator.py') diff --git a/SysIndicator.py b/SysIndicator.py index 145f0bd..ea93677 100644 --- a/SysIndicator.py +++ b/SysIndicator.py @@ -4,9 +4,9 @@ import sys import os import tempfile -if sys.platform=="linux2" or sys.platform=="win32": +if sys.platform == "linux2" or sys.platform == "win32": import gtk -elif sys.platform=="darwin": +elif sys.platform == "darwin": from Foundation import * from AppKit import * from PyObjCTools import AppHelper @@ -14,62 +14,76 @@ elif sys.platform=="darwin": class SysIndicator: - def __init__(self, icon,menu): - if sys.platform=="linux2": + 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.icon_directory = (os.path.sep + 'usr' + os.path.sep + 'share' + + os.path.sep + 'icons' + os.path.sep+'zik' + + os.path.sep) if not os.path.isdir(self.icon_directory): - self.icon_directory = os.path.dirname(sys.argv[0]) + 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.icon_directory = (os.path.dirname(sys.argv[0]) + + 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": + 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.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(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.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.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.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 = StatusApp.sharedApplication() self.statusicon.initMenu(menu) self.setIcon(icon) def setIcon(self, name): - if sys.platform=="linux2": + if sys.platform == "linux2": 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.setIcon(name,self.icon_directory) + elif sys.platform == "win32": + self.statusicon.set_from_file(self.icon_directory + name + '.png') + elif sys.platform == "darwin": + self.statusicon.setIcon(name, self.icon_directory) def gtk_right_click_event(self, icon, button, time): if not self.menu_shown: - self.menu_shown=True - self.menu.popup(None, None, gtk.status_icon_position_menu, button, time, self.statusicon) + 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_shown = False self.menu.popdown() def main(self): - if sys.platform=="linux2" or sys.platform=="win32": + if sys.platform == "linux2" or sys.platform == "win32": gtk.main() - elif sys.platform=="darwin": + elif sys.platform == "darwin": #self.statusicon.run() AppHelper.runEventLoop() def show_about_dialog(self, widget): - if sys.platform=="linux2" or sys.platform=="win32": + 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") @@ -81,73 +95,73 @@ class SysIndicator: class UniversalMenu: def __init__(self): - if sys.platform=="linux2" or sys.platform=="win32": + if sys.platform == "linux2" or sys.platform == "win32": self.gtk_menu = gtk.Menu() - elif sys.platform=="darwin": + elif sys.platform == "darwin": self.actions = {} self.menubarMenu = NSMenu.alloc().init() self.menubarMenu.setAutoenablesItems_(False) - - def append(self,MenuItem): - if sys.platform=="linux2" or sys.platform=="win32": + def append(self, MenuItem): + if sys.platform == "linux2" or sys.platform == "win32": self.gtk_menu.append(MenuItem.gtk_item) - elif sys.platform=="darwin": + elif sys.platform == "darwin": self.actions[MenuItem.title] = MenuItem.action self.menubarMenu.addItem_(MenuItem.nsmenu_item) class MenuItem: - def __init__(self,name,action,sensitive = True, checkitem = False): - if sys.platform=="linux2" or sys.platform=="win32": + 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) + self.gtk_item = gtk.CheckMenuItem(name) else: - self.gtk_item=gtk.MenuItem(name) + self.gtk_item = gtk.MenuItem(name) self.gtk_item.show() if action: self.gtk_item.connect("activate", action) - elif sys.platform=="darwin": + elif sys.platform == "darwin": self.title = name self.action = action - self.nsmenu_item = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(name, 'clicked:', '') + self.nsmenu_item = ( + NSMenuItem.alloc().initWithTitle_action_keyEquivalent_( + name, 'clicked:', '')) self.set_sensitive(sensitive) - def set_sensitive(self,option): - if sys.platform=="linux2" or sys.platform=="win32": + def set_sensitive(self, option): + if sys.platform == "linux2" or sys.platform == "win32": return self.gtk_item.set_sensitive(option) - elif sys.platform=="darwin": + elif sys.platform == "darwin": self.nsmenu_item.setEnabled_(option) - def set_active(self,option): - if sys.platform=="linux2" or sys.platform=="win32": + def set_active(self, option): + if sys.platform == "linux2" or sys.platform == "win32": return self.gtk_item.set_active(option) - elif sys.platform=="darwin": + elif sys.platform == "darwin": self.nsmenu_item.setState_(option) def get_active(self): - if sys.platform=="linux2" or sys.platform=="win32": + if sys.platform == "linux2" or sys.platform == "win32": return self.gtk_item.get_active() - elif sys.platform=="darwin": + elif sys.platform == "darwin": print self.nsmenu_item.state return self.nsmenu_item.state - - def set_label(self,option): - if sys.platform=="linux2" or sys.platform=="win32": + def set_label(self, option): + if sys.platform == "linux2" or sys.platform == "win32": return self.gtk_item.set_label(option) - elif sys.platform=="darwin": + elif sys.platform == "darwin": self.title = option self.nsmenu_item.setTitle_(option) #self.rumps_item.title=option if __name__ == "__main__": - quit_item = MenuItem("Quit",sys.exit,True) + quit_item = MenuItem("Quit", sys.exit, True) menu = UniversalMenu() menu.append(quit_item) - indicator = SysIndicator(icon = "zik-audio-headset",menu = menu) + indicator = SysIndicator(icon="zik-audio-headset", menu=menu) indicator.main() -- cgit v1.2.1 From 215e013edafbf2688cf5dc1742716be919502ee5 Mon Sep 17 00:00:00 2001 From: Marek Siarkowicz Date: Fri, 12 Jun 2015 19:03:25 +0200 Subject: Allow adding different zik version interfaces. --- SysIndicator.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'SysIndicator.py') diff --git a/SysIndicator.py b/SysIndicator.py index ea93677..e8d59be 100644 --- a/SysIndicator.py +++ b/SysIndicator.py @@ -109,14 +109,17 @@ class UniversalMenu: self.actions[MenuItem.title] = MenuItem.action self.menubarMenu.addItem_(MenuItem.nsmenu_item) + def reposition(self): + if sys.platform == "linux2" or sys.platform == "win32": + self.gtk_menu.reposition() + class MenuItem: - def __init__(self, name, action, sensitive=True, checkitem=False): + def __init__(self, name, action, sensitive=True, checkitem=False, visible=True): 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) @@ -126,8 +129,11 @@ class MenuItem: self.nsmenu_item = ( NSMenuItem.alloc().initWithTitle_action_keyEquivalent_( name, 'clicked:', '')) - self.set_sensitive(sensitive) + if visible: + self.show() + else: + self.hide() def set_sensitive(self, option): if sys.platform == "linux2" or sys.platform == "win32": @@ -156,6 +162,18 @@ class MenuItem: self.nsmenu_item.setTitle_(option) #self.rumps_item.title=option + def show(self): + if sys.platform == "linux2" or sys.platform == "win32": + self.gtk_item.show() + elif sys.platform == "darwin": + self.nsmenu_item.show() + + def hide(self): + if sys.platform == "linux2" or sys.platform == "win32": + self.gtk_item.hide() + elif sys.platform == "darwin": + self.nsmenu_item.hide() + if __name__ == "__main__": quit_item = MenuItem("Quit", sys.exit, True) -- cgit v1.2.1 From dfb630d52ccae6c8fdd70ab7210c32b327a4fed7 Mon Sep 17 00:00:00 2001 From: Marek Siarkowicz Date: Fri, 12 Jun 2015 20:35:58 +0200 Subject: Refactor. --- SysIndicator.py | 315 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 189 insertions(+), 126 deletions(-) (limited to 'SysIndicator.py') diff --git a/SysIndicator.py b/SysIndicator.py index e8d59be..804b001 100644 --- a/SysIndicator.py +++ b/SysIndicator.py @@ -13,59 +13,12 @@ elif sys.platform == "darwin": from StatusAppMac import StatusApp -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) - if not os.path.isdir(self.icon_directory): - self.icon_directory = (os.path.dirname(sys.argv[0]) - + 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(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.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 = StatusApp.sharedApplication() - self.statusicon.initMenu(menu) - +class BaseIndicator(object): + def __init__(self, icon, menu, statusicon): + self.menu = menu + self.statusicon = statusicon self.setIcon(icon) - 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') - elif sys.platform == "darwin": - self.statusicon.setIcon(name, self.icon_directory) - def gtk_right_click_event(self, icon, button, time): if not self.menu_shown: self.menu_shown = True @@ -75,60 +28,131 @@ class SysIndicator: self.menu_shown = False self.menu.popdown() + def setIcon(self, name): + raise NotImplementedError + + def main(self): + raise NotImplementedError + + def show_about_dialog(self, widget): + raise NotImplementedError + + +class WindowsIndicator(BaseIndicator): + def __init__(self, icon, 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.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") + statusicon = gtk.StatusIcon() + statusicon.connect("popup-menu", self.gtk_right_click_event) + statusicon.set_tooltip("Parrot Zik") + super(WindowsIndicator, self).__init__(icon, menu, statusicon) + + def setIcon(self, name): + self.statusicon.set_from_file(self.icon_directory + name + '.png') + + def main(self): + gtk.main() + + 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 LinuxIndicator(BaseIndicator): + def __init__(self, icon, 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) + if not os.path.isdir(self.icon_directory): + self.icon_directory = (os.path.dirname(sys.argv[0]) + + os.path.sep + 'share' + os.path.sep + + 'icons' + os.path.sep+'zik' + + os.path.sep) + statusicon = appindicator.Indicator( + "new-parrotzik-indicator", "indicator-messages", + appindicator.CATEGORY_APPLICATION_STATUS) + statusicon.set_status(appindicator.STATUS_ACTIVE) + statusicon.set_icon_theme_path(self.icon_directory) + statusicon.set_menu(menu.gtk_menu) + super(LinuxIndicator, self).__init__(icon, menu, statusicon) + + def setIcon(self, name): + self.statusicon.set_icon(name) + def main(self): - if sys.platform == "linux2" or sys.platform == "win32": - gtk.main() - elif sys.platform == "darwin": - #self.statusicon.run() - AppHelper.runEventLoop() + gtk.main() def show_about_dialog(self, widget): - 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: + 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 DarwinIndicator(BaseIndicator): + def __init__(self, icon, 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) + statusicon = StatusApp.sharedApplication() + statusicon.initMenu(menu) + super(DarwinIndicator, self).__init__(icon, menu, statusicon) + + def setIcon(self, name): + self.statusicon.setIcon(name, self.icon_directory) + + def main(self): + AppHelper.runEventLoop() + + def show_about_dialog(self, widget): + pass + + +class NSMenu(object): def __init__(self): - if sys.platform == "linux2" or sys.platform == "win32": - self.gtk_menu = gtk.Menu() - elif sys.platform == "darwin": - self.actions = {} - self.menubarMenu = NSMenu.alloc().init() - self.menubarMenu.setAutoenablesItems_(False) - - def append(self, MenuItem): - if sys.platform == "linux2" or sys.platform == "win32": - self.gtk_menu.append(MenuItem.gtk_item) - elif sys.platform == "darwin": - self.actions[MenuItem.title] = MenuItem.action - self.menubarMenu.addItem_(MenuItem.nsmenu_item) + self.actions = {} + self.menubarMenu = NSMenu.alloc().init() + self.menubarMenu.setAutoenablesItems_(False) + + def append(self, menu_item): + self.actions[menu_item.title] = menu_item.action + self.menubarMenu.addItem_(menu_item.nsmenu_item) def reposition(self): - if sys.platform == "linux2" or sys.platform == "win32": - self.gtk_menu.reposition() + # TODO + pass -class MenuItem: - def __init__(self, name, action, sensitive=True, checkitem=False, visible=True): - if sys.platform == "linux2" or sys.platform == "win32": - if checkitem: - self.gtk_item = gtk.CheckMenuItem(name) - else: - self.gtk_item = gtk.MenuItem(name) - if action: - self.gtk_item.connect("activate", action) - - elif sys.platform == "darwin": - self.title = name - self.action = action - self.nsmenu_item = ( - NSMenuItem.alloc().initWithTitle_action_keyEquivalent_( - name, 'clicked:', '')) +class GTKMenu(object): + def __init__(self): + self.gtk_menu = gtk.Menu() + + def append(self, menu_item): + self.gtk_menu.append(menu_item.base_item) + + def reposition(self): + self.gtk_menu.reposition() + + +class MenuItemBase(object): + def __init__(self, base_item, sensitive, visible): + self.base_item = base_item self.set_sensitive(sensitive) if visible: self.show() @@ -136,49 +160,88 @@ class MenuItem: self.hide() def set_sensitive(self, option): - if sys.platform == "linux2" or sys.platform == "win32": - return self.gtk_item.set_sensitive(option) - elif sys.platform == "darwin": - self.nsmenu_item.setEnabled_(option) + raise NotImplementedError 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.nsmenu_item.setState_(option) + raise NotImplementedError def get_active(self): - if sys.platform == "linux2" or sys.platform == "win32": - return self.gtk_item.get_active() - elif sys.platform == "darwin": - print self.nsmenu_item.state - return self.nsmenu_item.state + raise NotImplementedError 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.title = option - self.nsmenu_item.setTitle_(option) - #self.rumps_item.title=option + raise NotImplementedError def show(self): - if sys.platform == "linux2" or sys.platform == "win32": - self.gtk_item.show() - elif sys.platform == "darwin": - self.nsmenu_item.show() + self.base_item.show() def hide(self): - if sys.platform == "linux2" or sys.platform == "win32": - self.gtk_item.hide() - elif sys.platform == "darwin": - self.nsmenu_item.hide() + self.base_item.hide() + +class GTKMenuItem(MenuItemBase): + def __init__(self, name, action, sensitive=True, checkitem=False, visible=True): + if checkitem: + gtk_item = gtk.CheckMenuItem(name) + else: + gtk_item = gtk.MenuItem(name) + if action: + gtk_item.connect("activate", action) + super(GTKMenuItem, self).__init__(gtk_item, sensitive, visible) + + def set_sensitive(self, option): + return self.base_item.set_sensitive(option) + + def set_active(self, option): + return self.base_item.set_active(option) + + def get_active(self): + return self.base_item.get_active() + + def set_label(self, option): + return self.base_item.set_label(option) + + +class NSMenuItem(MenuItemBase): + def __init__(self, name, action, sensitive=True, checkitem=False, visible=True): + self.title = name + self.action = action + nsmenu_item = ( + NSMenuItem.alloc().initWithTitle_action_keyEquivalent_( + name, 'clicked:', '')) + super(NSMenuItem, self).__init__(nsmenu_item, sensitive, visible) + + def set_sensitive(self, option): + self.base_item.setEnabled_(option) + + def set_active(self, option): + self.base_item.setState_(option) + + def get_active(self): + return self.base_item.state + + def set_label(self, option): + self.title = option + self.base_item.setTitle_(option) + +if sys.platform == 'linux2': + SysIndicator = LinuxIndicator + Menu = GTKMenu + MenuItem = GTKMenuItem +elif sys.platform == 'win32': + SysIndicator = WindowsIndicator + Menu = GTKMenu + MenuItem = GTKMenuItem +elif sys.platform == 'darwin': + SysIndicator = DarwinIndicator + Menu = NSMenu + MenuItem = NSMenuItem +else: + raise Exception('Platform not supported') if __name__ == "__main__": quit_item = MenuItem("Quit", sys.exit, True) - menu = UniversalMenu() + menu = Menu() menu.append(quit_item) indicator = SysIndicator(icon="zik-audio-headset", menu=menu) -- cgit v1.2.1 From 2e8383760b2f32e8d068a4b235b6379cd3f06c17 Mon Sep 17 00:00:00 2001 From: Marek Siarkowicz Date: Sat, 13 Jun 2015 00:06:19 +0200 Subject: First step of zik 2.0 feature implementation. --- SysIndicator.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'SysIndicator.py') diff --git a/SysIndicator.py b/SysIndicator.py index 804b001..6aa4686 100644 --- a/SysIndicator.py +++ b/SysIndicator.py @@ -177,6 +177,9 @@ class MenuItemBase(object): def hide(self): self.base_item.hide() + def set_submenu(self, menu): + raise NotImplementedError + class GTKMenuItem(MenuItemBase): def __init__(self, name, action, sensitive=True, checkitem=False, visible=True): if checkitem: @@ -199,6 +202,9 @@ class GTKMenuItem(MenuItemBase): def set_label(self, option): return self.base_item.set_label(option) + def set_submenu(self, menu): + self.base_item.set_submenu(menu.gtk_menu) + class NSMenuItem(MenuItemBase): def __init__(self, name, action, sensitive=True, checkitem=False, visible=True): -- cgit v1.2.1 From ac531e0ca0b17902821966530629e434d0cdf9f7 Mon Sep 17 00:00:00 2001 From: Marek Siarkowicz Date: Mon, 15 Jun 2015 03:09:17 +0200 Subject: Make names more pythonic --- SysIndicator.py | 254 -------------------------------------------------------- 1 file changed, 254 deletions(-) delete mode 100644 SysIndicator.py (limited to 'SysIndicator.py') diff --git a/SysIndicator.py b/SysIndicator.py deleted file mode 100644 index 6aa4686..0000000 --- a/SysIndicator.py +++ /dev/null @@ -1,254 +0,0 @@ -#!/usr/bin/env python - -import sys -import os -import tempfile - -if sys.platform == "linux2" or sys.platform == "win32": - import gtk -elif sys.platform == "darwin": - from Foundation import * - from AppKit import * - from PyObjCTools import AppHelper - from StatusAppMac import StatusApp - - -class BaseIndicator(object): - def __init__(self, icon, menu, statusicon): - self.menu = menu - self.statusicon = statusicon - self.setIcon(icon) - - def gtk_right_click_event(self, icon, button, time): - 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 setIcon(self, name): - raise NotImplementedError - - def main(self): - raise NotImplementedError - - def show_about_dialog(self, widget): - raise NotImplementedError - - -class WindowsIndicator(BaseIndicator): - def __init__(self, icon, 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.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") - statusicon = gtk.StatusIcon() - statusicon.connect("popup-menu", self.gtk_right_click_event) - statusicon.set_tooltip("Parrot Zik") - super(WindowsIndicator, self).__init__(icon, menu, statusicon) - - def setIcon(self, name): - self.statusicon.set_from_file(self.icon_directory + name + '.png') - - def main(self): - gtk.main() - - 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 LinuxIndicator(BaseIndicator): - def __init__(self, icon, 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) - if not os.path.isdir(self.icon_directory): - self.icon_directory = (os.path.dirname(sys.argv[0]) - + os.path.sep + 'share' + os.path.sep - + 'icons' + os.path.sep+'zik' - + os.path.sep) - statusicon = appindicator.Indicator( - "new-parrotzik-indicator", "indicator-messages", - appindicator.CATEGORY_APPLICATION_STATUS) - statusicon.set_status(appindicator.STATUS_ACTIVE) - statusicon.set_icon_theme_path(self.icon_directory) - statusicon.set_menu(menu.gtk_menu) - super(LinuxIndicator, self).__init__(icon, menu, statusicon) - - def setIcon(self, name): - self.statusicon.set_icon(name) - - def main(self): - gtk.main() - - 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 DarwinIndicator(BaseIndicator): - def __init__(self, icon, 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) - statusicon = StatusApp.sharedApplication() - statusicon.initMenu(menu) - super(DarwinIndicator, self).__init__(icon, menu, statusicon) - - def setIcon(self, name): - self.statusicon.setIcon(name, self.icon_directory) - - def main(self): - AppHelper.runEventLoop() - - def show_about_dialog(self, widget): - pass - - -class NSMenu(object): - def __init__(self): - self.actions = {} - self.menubarMenu = NSMenu.alloc().init() - self.menubarMenu.setAutoenablesItems_(False) - - def append(self, menu_item): - self.actions[menu_item.title] = menu_item.action - self.menubarMenu.addItem_(menu_item.nsmenu_item) - - def reposition(self): - # TODO - pass - -class GTKMenu(object): - def __init__(self): - self.gtk_menu = gtk.Menu() - - def append(self, menu_item): - self.gtk_menu.append(menu_item.base_item) - - def reposition(self): - self.gtk_menu.reposition() - - -class MenuItemBase(object): - def __init__(self, base_item, sensitive, visible): - self.base_item = base_item - self.set_sensitive(sensitive) - if visible: - self.show() - else: - self.hide() - - def set_sensitive(self, option): - raise NotImplementedError - - def set_active(self, option): - raise NotImplementedError - - def get_active(self): - raise NotImplementedError - - def set_label(self, option): - raise NotImplementedError - - def show(self): - self.base_item.show() - - def hide(self): - self.base_item.hide() - - def set_submenu(self, menu): - raise NotImplementedError - -class GTKMenuItem(MenuItemBase): - def __init__(self, name, action, sensitive=True, checkitem=False, visible=True): - if checkitem: - gtk_item = gtk.CheckMenuItem(name) - else: - gtk_item = gtk.MenuItem(name) - if action: - gtk_item.connect("activate", action) - super(GTKMenuItem, self).__init__(gtk_item, sensitive, visible) - - def set_sensitive(self, option): - return self.base_item.set_sensitive(option) - - def set_active(self, option): - return self.base_item.set_active(option) - - def get_active(self): - return self.base_item.get_active() - - def set_label(self, option): - return self.base_item.set_label(option) - - def set_submenu(self, menu): - self.base_item.set_submenu(menu.gtk_menu) - - -class NSMenuItem(MenuItemBase): - def __init__(self, name, action, sensitive=True, checkitem=False, visible=True): - self.title = name - self.action = action - nsmenu_item = ( - NSMenuItem.alloc().initWithTitle_action_keyEquivalent_( - name, 'clicked:', '')) - super(NSMenuItem, self).__init__(nsmenu_item, sensitive, visible) - - def set_sensitive(self, option): - self.base_item.setEnabled_(option) - - def set_active(self, option): - self.base_item.setState_(option) - - def get_active(self): - return self.base_item.state - - def set_label(self, option): - self.title = option - self.base_item.setTitle_(option) - -if sys.platform == 'linux2': - SysIndicator = LinuxIndicator - Menu = GTKMenu - MenuItem = GTKMenuItem -elif sys.platform == 'win32': - SysIndicator = WindowsIndicator - Menu = GTKMenu - MenuItem = GTKMenuItem -elif sys.platform == 'darwin': - SysIndicator = DarwinIndicator - Menu = NSMenu - MenuItem = NSMenuItem -else: - raise Exception('Platform not supported') - -if __name__ == "__main__": - - quit_item = MenuItem("Quit", sys.exit, True) - - menu = Menu() - menu.append(quit_item) - - indicator = SysIndicator(icon="zik-audio-headset", menu=menu) - indicator.main() -- cgit v1.2.1