def __init__(self, resource, frame, kernel): self.resource = resource self.frame = frame self.kernel = kernel self.addin_dir = None self.main_tab = xrc.XRCCTRL(self.frame, "PYSPEC_MAIN_TAB") self.inspect_tab = xrc.XRCCTRL(self.frame, "PYSPEC_INSPECT_TAB") menubar = self.frame.GetMenuBar() self.addin_menu = menubar.GetMenu(menubar.FindMenu("Addin")) self.graphviz_dialog = WxGraphVizDialog(self.resource, self.frame) self.graphviz_dialog.bind_event_handler()
class AddinManager(object): def __init__(self, resource, frame, kernel): self.resource = resource self.frame = frame self.kernel = kernel self.addin_dir = None self.main_tab = xrc.XRCCTRL(self.frame, "PYSPEC_MAIN_TAB") self.inspect_tab = xrc.XRCCTRL(self.frame, "PYSPEC_INSPECT_TAB") menubar = self.frame.GetMenuBar() self.addin_menu = menubar.GetMenu(menubar.FindMenu("Addin")) self.graphviz_dialog = WxGraphVizDialog(self.resource, self.frame) self.graphviz_dialog.bind_event_handler() def load_addin(self): loader = AddinLoader() loader.load_addin() for filename, addin in AddinLoader.addin_list.iteritems(): #print filename, addin self.addin_dir = addin.dirname for entry_point in addin.entry_points: addin.addin = entry_point(self) for menu_id, menu in addin.addin_menu.iteritems(): function, title = menu self.addin_menu.Append(menu_id, title, title) self.frame.Bind(wx.EVT_MENU, self.menu_handle, id=menu_id) def menu_handle(self, event): menu_id = event.GetId() for addin in AddinLoader.addin_list.itervalues(): if menu_id in addin.addin_menu: function, title = addin.addin_menu[menu_id] function(addin.addin) def add_menu_in_addin_menubar(self, name, function): menuid = "WXADDIN_" + name.replace("&", "") self.menu_handler_list[self.menu_id] = (function, argv) self.addin_menu.Append(self.menu_id, name, description) self.frame.Bind(wx.EVT_MENU, self.menu_handle, id=self.menu_id) self.menu_id += 1 def add_main_tab(self, resource, xrckey, name): panel = resource.LoadPanel(self.main_tab, xrckey) self.main_tab.AddPage(panel, name) def get_new_main_tab(self, name): panel = wx.Panel(self.main_tab) self.main_tab.AddPage(panel, name) return panel def add_inspect_tab(self, resource, xrckey, name): panel = resource.LoadPanel(self.inspect_tab, xrckey) self.inspect_tab.AddPage(panel, name) def get_new_inspect_tab(self, name): panel = wx.Panel(self.inspect_tab) self.inspect_tab.AddPage(panel, name) return panel def add_listener(self, aspect, ModuleType, ClassType=None, MethodType=None, *init_arg): self.kernel.modules.add_listener(aspect, ModuleType, ClassType, MethodType, *init_arg) def get_module_observer(self): return self.kernel.modules