def METHOD_NAME(self, callingWindow, context, rootMenu, i, pitem):
    sTR = svc_TargetProfile.getInstance()
    profiles = list(chain(sTR.getBuiltinTargetProfileList(), sTR.getUserTargetProfileList()))
    profiles.sort(key=lambda p: smartSort(p.fullName))
    self.profileEventMap = {}
    items = (OrderedDict(), OrderedDict())
    for profile in profiles:
        container = items
        for categoryName in profile.hierarchy:
            categoryName = _t(categoryName) if profile.builtin else categoryName
            container = container[1].setdefault(categoryName, (OrderedDict(), OrderedDict()))
        shortName = _t(profile.shortName) if profile.builtin else profile.shortName
        container[0][shortName] = profile
    # Category as menu item - expands further
    msw = "wxMSW" in wx.PlatformInfo
    def makeMenu(container, parentMenu, first=False):
        menu = wx.Menu()
        if first:
            mitem, checked = self._addProfile(rootMenu if msw else parentMenu, None, _t('No Profile'))
            menu.Append(mitem)
            mitem.Check(checked)
            if len(container[0]) > 0 or len(container[1]) > 0:
                menu.AppendSeparator()
        for name, pattern in container[0].items():
            menuItem, checked = self._addProfile(rootMenu if msw else parentMenu, pattern, name)
            menu.Append(menuItem)
            menuItem.Check(checked)
        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.handleResistSwitch)
        return menu
    subMenu = makeMenu(items, rootMenu, first=True)
    return subMenu