Advertisement
Guest User

Untitled

a guest
Nov 28th, 2016
776
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.85 KB | None | 0 0
  1. import wx
  2. import os
  3. import fnmatch
  4. import importlib
  5. import sys
  6. import ConfigParser
  7. from plugins.__util import GetConfigParser
  8.  
  9.  
  10. class TaskBarIcon(wx.TaskBarIcon):
  11.     def __init__(self):
  12.         super(TaskBarIcon, self).__init__()
  13.         icon = wx.IconFromBitmap(wx.Bitmap('resources\\icon.png'))
  14.         self.SetIcon(icon, 'Pirate''s!')
  15.         self.menuID = {}
  16.         self.plugins = []
  17.  
  18.         config = GetConfigParser()
  19.        
  20.         sys.path.append(config.get('TrayHelper', 'plugins_root'))
  21.        
  22.         for subdir, dirs, files in os.walk(config.get('TrayHelper', 'plugins')):
  23.             for filename in fnmatch.filter(files, '*.py'):
  24.                 plugin_name = os.path.splitext(filename)[0]
  25.                 if plugin_name.startswith('__') or plugin_name == 'exit':
  26.                     continue
  27.                 self.plugins.append(importlib.import_module('plugins.{0}'.format(plugin_name)))
  28.             # keep exit last
  29.             self.plugins.append(importlib.import_module('plugins.exit'))
  30.  
  31.     def AddMenu(self, menu, name, bindmethod=None):
  32.         menu_key = menu.GetTitle() + ':' + name
  33.         if menu_key not in self.menuID:
  34.             self.menuID[menu_key] = wx.NewId()
  35.         menuitem = menu.Append(self.menuID[menu_key], name)
  36.         self.Bind(wx.EVT_MENU, bindmethod, id=self.menuID[menu_key])
  37.         return menuitem
  38.  
  39.     def CreatePopupMenu(self):
  40.         config = GetConfigParser()
  41.         mainMenu = wx.Menu()
  42.         for plugin in self.plugins:
  43.             try:
  44.                 plugin.RegisterMenu(self, mainMenu)
  45.             except ConfigParser.NoSectionError:
  46.                 if config.get('TrayHelper', 'showNonConfiguredPlugins') == '1':
  47.                     self.AddMenu(mainMenu, '- {0} - not configured'.format(plugin))
  48.  
  49.         return mainMenu
  50.  
  51. app = wx.App(False)
  52. TaskBarIcon()
  53. app.MainLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement