NovaBryan/EVE_Dump
Log | Files | 📦 下载最新源码 (.zip) | Refs | README

menuMerge.py (6763B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\services\menuMerge.py
      2 import log
      3 import uthread
      4 from carbonui.control.contextMenu.menuEntryData import MenuEntryData
      5 from eve.client.script.ui.services.menuSvcExtras import invItemFunctions
      6 from menu import MenuList, MenuLabel, NO_ARGUMENTS, CaptionIsInMultiFunctions
      7 
      8 def MergeMenus(menus):
      9     if not menus:
     10         return MenuList()
     11     allLabels, allReasons = _GetAllLabelsAndReasons(menus)
     12     menus = filter(None, [ filter(None, each) for each in menus ])
     13     ret = MenuList()
     14     ret.reasonsWhyNotAvailable = allReasons
     15     for menuLabel in allLabels:
     16         if menuLabel is None:
     17             ret.append(None)
     18         else:
     19             menuEntry = _GetMergedMenuEntry(menuLabel, menus)
     20             if menuEntry:
     21                 ret.append(menuEntry)
     22 
     23     return ret
     24 
     25 
     26 def _GetMergedMenuEntry(menuLabel, menus):
     27     if isinstance(menuLabel, MenuLabel):
     28         caption = menuLabel[0]
     29         keywords = menuLabel[1]
     30     else:
     31         caption = menuLabel
     32         keywords = {}
     33     lst = []
     34     isList = None
     35     icon = None
     36     menuClass = None
     37     internalName = ''
     38     typeID = None
     39     menuEntryDataLst = []
     40     for menu in menus:
     41         for entry in menu:
     42             if isinstance(entry, MenuEntryData):
     43                 entryCaption = entry.GetLabelPath() or entry.GetText()
     44                 if caption == entryCaption:
     45                     menuEntryDataLst.append(entry)
     46             elif _IsSame(caption, keywords, entry, menuLabel):
     47                 if type(entry[1]) in (str, unicode):
     48                     return (menuLabel, entry[1])
     49                 if type(entry[1]) == tuple and entry[1][0] == 'isDynamic' and len(entry) == 2:
     50                     return (menuLabel, entry[1])
     51                 if len(entry) > 3:
     52                     icon = entry[3]
     53                 if isList is None:
     54                     isList = isinstance(entry[1], list)
     55                 if isList != isinstance(entry[1], list):
     56                     return
     57                 if isList:
     58                     lst.append(entry[1])
     59                     internalName = entry[5] if len(entry) > 5 else ''
     60                     typeID = entry[6] if len(entry) > 6 else None
     61                 elif len(entry) > 2:
     62                     func = entry[1]
     63                     arguments = entry[2]
     64                     lst.append([func, arguments])
     65                     menuClass = entry[4] if len(entry) > 4 else None
     66                     internalName = entry[5] if len(entry) > 5 else ''
     67                     typeID = entry[6] if len(entry) > 6 else None
     68                 else:
     69                     lst.append(entry[1:])
     70                 break
     71 
     72     if menuEntryDataLst:
     73         if len(menuEntryDataLst) > 1:
     74             return _MergeMenuEntryDataList(menuEntryDataLst)
     75         else:
     76             return menuEntryDataLst[0]
     77     extraArgsTuple = (icon,
     78      menuClass,
     79      internalName,
     80      typeID)
     81     if isList:
     82         menuEntryArgs = (menuLabel, MergeMenus(lst), NO_ARGUMENTS) + extraArgsTuple
     83         return menuEntryArgs
     84     elif CaptionIsInMultiFunctions(caption) or _IsDeliverToCorpHangarFolderEntry(lst):
     85         return _GetMergedMenuEntryArgs(caption, extraArgsTuple, lst, menuLabel)
     86     else:
     87         return (menuLabel, _ExecMulti, lst) + extraArgsTuple
     88 
     89 
     90 def _MergeMenuEntryDataList(menuEntryDataLst):
     91     menuEntryData = menuEntryDataLst[0]
     92     if CaptionIsInMultiFunctions(menuEntryData.GetActionID()):
     93         functions = [ m.func for m in menuEntryDataLst ]
     94         menuEntryData.func = lambda : _CallMultipleFunctions(functions)
     95         menuEntryData.quantity = len(functions)
     96     return menuEntryData
     97 
     98 
     99 def _CallMultipleFunctions(functions):
    100     for func in functions:
    101         func()
    102 
    103 
    104 def _GetMergedMenuEntryArgs(caption, extraArgsTuple, lst, menuLabel):
    105     mergedArgs = []
    106     rest = []
    107     for entry in lst:
    108         args = entry[1]
    109         rest = entry[2:]
    110         if isinstance(args, list):
    111             mergedArgs += args
    112         else:
    113             log.LogWarn('unsupported format of arguments for MergeMenu, function label: ', caption)
    114 
    115     if isinstance(rest, tuple):
    116         rest = list(rest)
    117     extraArgs = rest or extraArgsTuple
    118     if isinstance(extraArgs, tuple):
    119         extraArgs = list(extraArgs)
    120     if mergedArgs:
    121         if type(lst[0][0]) == tuple and lst[0][0][0] == 'isDynamic':
    122             return [menuLabel, ('isDynamic', lst[0][0][1], lst[0][0][2] + (mergedArgs,))] + rest
    123         else:
    124             return [menuLabel, _CheckLocked, (lst[0][0], mergedArgs)] + extraArgs
    125 
    126 
    127 def _IsSame(caption, keywords, entry, menuLabel):
    128     if isinstance(menuLabel, MenuLabel):
    129         entryCaption = entry[0][0]
    130         entryKeywords = entry[0][1]
    131     else:
    132         entryCaption = entry[0]
    133         entryKeywords = {}
    134     return entryCaption == caption and entryKeywords == keywords
    135 
    136 
    137 def _GetAllLabelsAndReasons(menus):
    138     allCaptionsAndKeywords = []
    139     allLabels = []
    140     allReasons = {}
    141     for menu in menus:
    142         i = 0
    143         if getattr(menu, 'reasonsWhyNotAvailable', {}):
    144             allReasons.update(menu.reasonsWhyNotAvailable)
    145         for each in menu:
    146             if each is None:
    147                 if len(allLabels) <= i:
    148                     allLabels.append(None)
    149                 else:
    150                     while allLabels[i] is not None:
    151                         i += 1
    152                         if i == len(allLabels):
    153                             allLabels.append(None)
    154                             break
    155 
    156             else:
    157                 if isinstance(each, MenuEntryData):
    158                     label = each.GetMenuLabel()
    159                     labelPath = each.GetLabelPath()
    160                     labelKeywords = each.GetLabelKeywords()
    161                 else:
    162                     label = each[0]
    163                     if isinstance(label, MenuLabel):
    164                         labelPath = label[0]
    165                         labelKeywords = label[1]
    166                     else:
    167                         labelPath = label
    168                         labelKeywords = {}
    169                 if (labelPath, labelKeywords) not in allCaptionsAndKeywords:
    170                     allLabels.insert(i, label)
    171                     allCaptionsAndKeywords.append((labelPath, labelKeywords))
    172             i += 1
    173 
    174     return (allLabels, allReasons)
    175 
    176 
    177 def _IsDeliverToCorpHangarFolderEntry(lst):
    178     try:
    179         return len(lst) and len(lst[0]) and lst[0][0] is invItemFunctions.DeliverToCorpHangarFolder
    180     except TypeError:
    181         return False
    182 
    183 
    184 def _ExecAction(action):
    185     apply(*action)
    186 
    187 
    188 def _ExecMulti(*actions):
    189     for each in actions:
    190         uthread.new(_ExecAction, each)
    191 
    192 
    193 def _CheckLocked(func, invItemsOrIDs):
    194     return invItemFunctions.CheckLocked(func, invItemsOrIDs, sm.GetService('invCache'))