getMenu returns a menu that is used with wx.PopupMenu. callingWindow: window (in wx' sense) which requested menu mainItem: usually, provides item which was clicked. Useful for single- item actions when user has multiple items selected selection: pr
(cls, callingWindow, mainItem, selection, *fullContexts)
| 53 | |
| 54 | @classmethod |
| 55 | def getMenu(cls, callingWindow, mainItem, selection, *fullContexts): |
| 56 | """ |
| 57 | getMenu returns a menu that is used with wx.PopupMenu. |
| 58 | |
| 59 | callingWindow: window (in wx' sense) which requested menu |
| 60 | mainItem: usually, provides item which was clicked. Useful for single- |
| 61 | item actions when user has multiple items selected |
| 62 | selection: provides a list of what was selected. If only 1 item was |
| 63 | selected, it's is a 1-item list or tuple. Can also be None for |
| 64 | contexts without selection, such as statsPane or projected view |
| 65 | fullContexts: a number of tuples of the following tuple: |
| 66 | srcContext - context were menu was spawned, eg: projectedFit, |
| 67 | cargoItem, etc |
| 68 | itemContext - usually the name of the item's category |
| 69 | |
| 70 | eg: |
| 71 | (('fittingModule', 'Module'), ('fittingShip', 'Ship')) |
| 72 | (('marketItemGroup', 'Implant'),) |
| 73 | (('fittingShip', 'Ship'),) |
| 74 | """ |
| 75 | ContextMenu._idxid = -1 |
| 76 | debug_start = len(ContextMenu._ids) |
| 77 | |
| 78 | # Control being pressed forces all hidden menu items to be shown |
| 79 | visibilitySettingOverride = wx.GetMouseState().GetModifiers() == wx.MOD_CONTROL |
| 80 | cmSettings = ContextMenuSettings.getInstance() |
| 81 | |
| 82 | rootMenu = wx.Menu() |
| 83 | rootMenu.info = {} |
| 84 | rootMenu.selection = (selection,) if not hasattr(selection, "__iter__") else selection |
| 85 | rootMenu.mainItem = mainItem |
| 86 | empty = True |
| 87 | for i, fullContext in enumerate(fullContexts): |
| 88 | display_amount = 0 |
| 89 | srcContext = fullContext[0] |
| 90 | try: |
| 91 | itemContext = fullContext[1] |
| 92 | except IndexError: |
| 93 | itemContext = None |
| 94 | for menuHandler in cls.menus: |
| 95 | # loop through registered menus |
| 96 | m = menuHandler() |
| 97 | if m.visibilitySetting: |
| 98 | visible = visibilitySettingOverride or cmSettings.get(m.visibilitySetting) |
| 99 | else: |
| 100 | visible = True |
| 101 | if visible and m._baseDisplay(callingWindow, srcContext, mainItem, selection): |
| 102 | display_amount += 1 |
| 103 | texts = m._baseGetText(callingWindow, itemContext, mainItem, selection) |
| 104 | |
| 105 | if isinstance(texts, str): |
| 106 | texts = (texts,) |
| 107 | |
| 108 | bitmap = m._baseGetBitmap(callingWindow, srcContext, mainItem, selection) |
| 109 | multiple = not isinstance(bitmap, wx.Bitmap) |
| 110 | for it, text in enumerate(texts): |
| 111 | id = ContextMenu.nextID() |
| 112 | check = m.isChecked(it) |
no test coverage detected