Merge branch 'master' into singularity

This commit is contained in:
DarkPhoenix
2019-05-03 16:30:38 +03:00
2 changed files with 28 additions and 15 deletions

View File

@@ -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):

View File

@@ -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):