From 4c976d9f35a435bed10cc7e11a200cd4844072f4 Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Fri, 3 May 2019 14:56:59 +0300 Subject: [PATCH 1/2] Scroll mutated item stats with mousewheel over spincontrol not just on GTK --- gui/builtinItemStatsViews/attributeSlider.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/gui/builtinItemStatsViews/attributeSlider.py b/gui/builtinItemStatsViews/attributeSlider.py index 9e3585ea9..159981a82 100644 --- a/gui/builtinItemStatsViews/attributeSlider.py +++ b/gui/builtinItemStatsViews/attributeSlider.py @@ -96,8 +96,10 @@ class AttributeSlider(wx.Panel): self.ctrl = wx.SpinCtrlDouble(self, min=minValue, max=maxValue, inc=getStep(maxValue - minValue)) self.ctrl.SetDigits(getDigitPlaces(minValue, maxValue)) - self.ctrl.Bind(wx.EVT_SPINCTRLDOUBLE, self.UpdateValue) + # GTK scrolls spinboxes with mousewheel, others do not + if "wxGTK" not in wx.PlatformInfo: + self.ctrl.Bind(wx.EVT_MOUSEWHEEL, self.OnMouseWheel) self.slider = AttributeGauge(self, size=(-1, 8)) @@ -124,6 +126,16 @@ class AttributeSlider(wx.Panel): if post_event: wx.PostEvent(self, ValueChanged(self, None, value, None, slider_percentage)) + def OnMouseWheel(self, evt): + if evt.GetWheelRotation() > 0 and evt.GetWheelAxis() == wx.MOUSE_WHEEL_VERTICAL: + self.ctrl.Value = self.ctrl.Value + self.ctrl.Increment + self.SetValue(self.ctrl.GetValue()) + elif evt.GetWheelRotation() < 0 and evt.GetWheelAxis() == wx.MOUSE_WHEEL_VERTICAL: + self.ctrl.Value = self.ctrl.Value - self.ctrl.Increment + self.SetValue(self.ctrl.GetValue()) + else: + evt.Skip() + class TestAttributeSlider(wx.Frame): From bb9b3780ae2e867f002ab15f3b7ba8b7ff84b862 Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Fri, 3 May 2019 16:22:18 +0300 Subject: [PATCH 2/2] Fix context submenu activation --- gui/contextMenu.py | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/gui/contextMenu.py b/gui/contextMenu.py index 470757cc4..6e6a4f462 100644 --- a/gui/contextMenu.py +++ b/gui/contextMenu.py @@ -67,8 +67,8 @@ class ContextMenu(metaclass=ABCMeta): (('marketItemGroup', 'Implant'),) (('fittingShip', 'Ship'),) """ - cls._idxid = -1 - debug_start = len(cls._ids) + ContextMenu._idxid = -1 + debug_start = len(ContextMenu._ids) rootMenu = wx.Menu() rootMenu.info = {} @@ -95,7 +95,7 @@ class ContextMenu(metaclass=ABCMeta): bitmap = m._baseGetBitmap(srcContext, mainItem, selection) multiple = not isinstance(bitmap, wx.Bitmap) for it, text in enumerate(texts): - id = cls.nextID() + id = ContextMenu.nextID() check = m.checked rootItem = wx.MenuItem(rootMenu, id, text, kind=wx.ITEM_NORMAL if m.checked is None else wx.ITEM_CHECK) rootMenu.info[id] = (m, fullContext, it) @@ -104,7 +104,7 @@ class ContextMenu(metaclass=ABCMeta): if sub is None: # if there is no sub menu, bind the handler to the rootItem - rootMenu.Bind(wx.EVT_MENU, cls.handler, rootItem) + rootMenu.Bind(wx.EVT_MENU, ContextMenu.handler, rootItem) elif sub: # If sub exists and is not False, set submenu. # Sub might return False when we have a mix of @@ -141,14 +141,14 @@ class ContextMenu(metaclass=ABCMeta): if display_amount > 0 and i != len(fullContexts) - 1: rootMenu.AppendSeparator() - debug_end = len(cls._ids) + debug_end = len(ContextMenu._ids) if debug_end - debug_start: pyfalog.debug("{} new IDs created for this menu".format(debug_end - debug_start)) return rootMenu if empty is False else None - @classmethod - def handler(cls, event): + @staticmethod + def handler(event): menu = event.EventObject stuff = menu.info.get(event.Id) if stuff is not None: @@ -162,21 +162,22 @@ class ContextMenu(metaclass=ABCMeta): else: event.Skip() - @classmethod - def nextID(cls): + @staticmethod + def nextID(): """ Fetches an ID from the pool of IDs allocated to Context Menu. If we don't have enough ID's to fulfill request, create new ID and add it to the pool. - See GH Issue #589 + See GH Issue #589. + Has to be static method to properly handle modifications of primitives from subclasses (_idxid). """ - cls._idxid += 1 + ContextMenu._idxid += 1 - if cls._idxid >= len(cls._ids): # We don't ahve an ID for this index, create one - cls._ids.append(wx.NewId()) + if ContextMenu._idxid >= len(ContextMenu._ids): # We don't ahve an ID for this index, create one + ContextMenu._ids.append(wx.NewId()) - return cls._ids[cls._idxid] + return ContextMenu._ids[ContextMenu._idxid] @property def checked(self):