Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import wx
- import os
- import fnmatch
- import importlib
- import sys
- import ConfigParser
- from plugins.__util import GetConfigParser
- class TaskBarIcon(wx.TaskBarIcon):
- def __init__(self):
- super(TaskBarIcon, self).__init__()
- icon = wx.IconFromBitmap(wx.Bitmap('resources\\icon.png'))
- self.SetIcon(icon, 'Pirate''s!')
- self.menuID = {}
- self.plugins = []
- config = GetConfigParser()
- sys.path.append(config.get('TrayHelper', 'plugins_root'))
- for subdir, dirs, files in os.walk(config.get('TrayHelper', 'plugins')):
- for filename in fnmatch.filter(files, '*.py'):
- plugin_name = os.path.splitext(filename)[0]
- if plugin_name.startswith('__') or plugin_name == 'exit':
- continue
- self.plugins.append(importlib.import_module('plugins.{0}'.format(plugin_name)))
- # keep exit last
- self.plugins.append(importlib.import_module('plugins.exit'))
- def AddMenu(self, menu, name, bindmethod=None):
- menu_key = menu.GetTitle() + ':' + name
- if menu_key not in self.menuID:
- self.menuID[menu_key] = wx.NewId()
- menuitem = menu.Append(self.menuID[menu_key], name)
- self.Bind(wx.EVT_MENU, bindmethod, id=self.menuID[menu_key])
- return menuitem
- def CreatePopupMenu(self):
- config = GetConfigParser()
- mainMenu = wx.Menu()
- for plugin in self.plugins:
- try:
- plugin.RegisterMenu(self, mainMenu)
- except ConfigParser.NoSectionError:
- if config.get('TrayHelper', 'showNonConfiguredPlugins') == '1':
- self.AddMenu(mainMenu, '- {0} - not configured'.format(plugin))
- return mainMenu
- app = wx.App(False)
- TaskBarIcon()
- app.MainLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement