(self, callingWindow, context, mainItem, rootMenu, i, pitem)
| 37 | return _t("Spoolup Cycles") |
| 38 | |
| 39 | def getSubMenu(self, callingWindow, context, mainItem, rootMenu, i, pitem): |
| 40 | m = wx.Menu() |
| 41 | if "wxMSW" in wx.PlatformInfo: |
| 42 | bindmenu = rootMenu |
| 43 | else: |
| 44 | bindmenu = m |
| 45 | |
| 46 | isNotDefault = self.mod.spoolType is not None and self.mod.spoolAmount is not None |
| 47 | cycleDefault = self.mod.getSpoolData(spoolOptions=SpoolOptions(SpoolType.SPOOL_SCALE, eos.config.settings['globalDefaultSpoolupPercentage'], True))[0] |
| 48 | cycleCurrent = self.mod.getSpoolData(spoolOptions=SpoolOptions(SpoolType.SPOOL_SCALE, eos.config.settings['globalDefaultSpoolupPercentage'], False))[0] |
| 49 | cycleMin = self.mod.getSpoolData(spoolOptions=SpoolOptions(SpoolType.SPOOL_SCALE, 0, True))[0] |
| 50 | cycleMax = self.mod.getSpoolData(spoolOptions=SpoolOptions(SpoolType.SPOOL_SCALE, 1, True))[0] |
| 51 | cycleTotalMin = min(cycleDefault, cycleCurrent, cycleMin) |
| 52 | cycleTotalMax = max(cycleDefault, cycleCurrent, cycleMax) |
| 53 | |
| 54 | def findCycles(val1, val2): |
| 55 | # Try to compose list of 21 steps max (0-20) |
| 56 | maxSteps = 20 |
| 57 | valDiff = val2 - val1 |
| 58 | valScale = valDiff / maxSteps |
| 59 | minStep = math.ceil(round(valScale, 9)) |
| 60 | maxStep = math.floor(round(valDiff / 4, 9)) |
| 61 | # Check steps from smallest to highest and see if we can go from min value |
| 62 | # to max value using those |
| 63 | for currentStep in range(minStep, maxStep + 1): |
| 64 | if valDiff % currentStep == 0: |
| 65 | return set(range(val1, val2 + currentStep, currentStep)) |
| 66 | # Otherwise just split range in halves and go both ends using min values |
| 67 | else: |
| 68 | cycles = set() |
| 69 | while val2 >= val1: |
| 70 | cycles.add(val1) |
| 71 | cycles.add(val2) |
| 72 | val1 += minStep |
| 73 | val2 -= minStep |
| 74 | return cycles |
| 75 | |
| 76 | self.cycleMap = {} |
| 77 | cyclesToShow = findCycles(cycleMin, cycleMax) |
| 78 | for cycle in range(cycleTotalMin, cycleTotalMax + 1): |
| 79 | menuId = ContextMenuSingle.nextID() |
| 80 | |
| 81 | # Show default only for current value and when not overriden |
| 82 | if not isNotDefault and cycle == cycleDefault: |
| 83 | text = _t("{} (default)").format(cycle) |
| 84 | # Always show current selection and stuff which we decided to show via the cycles function |
| 85 | elif cycle == cycleCurrent or cycle in cyclesToShow: |
| 86 | text = "{}".format(cycle) |
| 87 | # Ignore the rest to not have very long menu |
| 88 | else: |
| 89 | continue |
| 90 | |
| 91 | item = wx.MenuItem(m, menuId, text, kind=wx.ITEM_CHECK) |
| 92 | bindmenu.Bind(wx.EVT_MENU, self.handleSpoolChange, item) |
| 93 | m.Append(item) |
| 94 | item.Check(isNotDefault and cycle == cycleCurrent) |
| 95 | self.cycleMap[menuId] = cycle |
| 96 |
nothing calls this directly
no test coverage detected