def __init__(self, graphFrame, parent): super().__init__(graphFrame, parent) self.Bind(wx.EVT_CONTEXT_MENU, self.spawnMenu) self.appendItem(TargetProfile.getIdeal()) self.updateView()
def importPatterns(self, text): imports, num = es_TargetProfile.importPatterns(text) lenImports = len(imports) if lenImports == 0: raise ImportError("No patterns found for import") if lenImports != num: raise ImportError( "%d patterns imported from clipboard; %d had errors" % (num, num - lenImports))
def display(self, callingWindow, srcContext, mainItem): if srcContext != 'graphTgtList': return False if not isinstance(mainItem, TargetWrapper): return False if not mainItem.isProfile: return False if mainItem.item is TargetProfile.getIdeal(): return False return True
def makeMenu(container, parentMenu, first=False): menu = wx.Menu() if first: idealProfile = TargetProfile.getIdeal() mitem = self._addProfile(rootMenu if msw else parentMenu, idealProfile, idealProfile.fullName) menu.Append(mitem) for name, pattern in container[0].items(): menuItem = self._addProfile(rootMenu if msw else parentMenu, pattern, name) menu.Append(menuItem) for name, subcontainer in container[1].items(): menuItem = self._addCategory(rootMenu if msw else parentMenu, name) subMenu = makeMenu(subcontainer, menu) menuItem.SetSubMenu(subMenu) menu.Append(menuItem) menu.Bind(wx.EVT_MENU, self.handleProfileAdd) return menu
def getSubMenu(self, callingWindow, context, rootMenu, i, pitem): self.profileIds = {} self.subMenus = OrderedDict() self.singles = [] sub = wx.Menu() for profile in chain([TargetProfile.getIdeal()], self.profiles): start, end = profile.name.find('['), profile.name.find(']') if start is not -1 and end is not -1: currBase = profile.name[start + 1:end] # set helper attr setattr(profile, '_name', profile.name[end + 1:].strip()) if currBase not in self.subMenus: self.subMenus[currBase] = [] self.subMenus[currBase].append(profile) else: self.singles.append(profile) # Single items, no parent msw = 'wxMSW' in wx.PlatformInfo for profile in self.singles: sub.Append(self.addProfile(rootMenu if msw else sub, profile)) # Items that have a parent for menuName, profiles in list(self.subMenus.items()): # Create parent item for root menu that is simply name of parent item = wx.MenuItem(rootMenu, ContextMenuUnconditional.nextID(), menuName) # Create menu for child items grandSub = wx.Menu() # Apply child menu to parent item item.SetSubMenu(grandSub) # Append child items to child menu for profile in profiles: grandSub.Append( self.addProfile(rootMenu if msw else grandSub, profile)) sub.Append(item) # finally, append parent item to root menu return sub
def exportPatterns(self): patterns = self.getUserTargetProfileList() patterns.sort(key=lambda p: p.name) return es_TargetProfile.exportPatterns(*patterns)
def getBuiltinTargetProfileList(): return es_TargetProfile.getBuiltinList()