Rework target profile editor input boxes for better editing experience

This commit is contained in:
DarkPhoenix
2019-07-30 17:11:53 +03:00
parent 0320a16ba4
commit 4c1c15e69e
4 changed files with 107 additions and 80 deletions

View File

@@ -1,98 +0,0 @@
# =============================================================================
# Copyright (C) 2010 Diego Duclos
#
# This file is part of pyfa.
#
# pyfa is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# pyfa is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with pyfa. If not, see <http://www.gnu.org/licenses/>.
# =============================================================================
import re
import wx
def valToStr(val):
if val is None:
return ''
if int(val) == val:
val = int(val)
return str(val)
def strToFloat(val):
try:
return float(val)
except ValueError:
return None
class ConstantBox(wx.TextCtrl):
def __init__(self, parent, initial):
super().__init__(parent, wx.ID_ANY, style=0)
self.Bind(wx.EVT_TEXT, self.OnText)
self._storedValue = ''
self.ChangeValue(valToStr(initial))
def ChangeValue(self, value):
self._storedValue = value
super().ChangeValue(value)
def OnText(self, event):
currentValue = self.GetValue()
if currentValue == self._storedValue:
event.Skip()
return
if currentValue == '' or re.match('^\d*\.?\d*$', currentValue):
self._storedValue = currentValue
event.Skip()
else:
self.ChangeValue(self._storedValue)
def GetValueFloat(self):
return strToFloat(self.GetValue())
class RangeBox(wx.TextCtrl):
def __init__(self, parent, initRange):
super().__init__(parent, wx.ID_ANY, style=0)
self.Bind(wx.EVT_TEXT, self.OnText)
self._storedValue = ''
self.ChangeValue('{}-{}'.format(valToStr(min(initRange)), valToStr(max(initRange))))
def ChangeValue(self, value):
self._storedValue = value
super().ChangeValue(value)
def OnText(self, event):
currentValue = self.GetValue()
if currentValue == self._storedValue:
event.Skip()
return
if currentValue == '' or re.match('^\d*\.?\d*-?\d*\.?\d*$', currentValue):
self._storedValue = currentValue
event.Skip()
else:
self.ChangeValue(self._storedValue)
def GetValueRange(self):
parts = self.GetValue().split('-')
if len(parts) == 1:
val = strToFloat(parts[0])
return (val, val)
else:
return (strToFloat(parts[0]), strToFloat(parts[1]))

View File

@@ -27,7 +27,7 @@ from gui.bitmap_loader import BitmapLoader
from gui.contextMenu import ContextMenu
from service.const import GraphCacheCleanupReason
from service.fit import Fit
from .input import ConstantBox, RangeBox
from gui.utils.inputs import FloatBox, FloatRangeBox
from .lists import FitList, TargetList
from .vector import VectorPicker
@@ -213,9 +213,9 @@ class GraphControlPanel(wx.Panel):
handledHandles.add(inputDef.handle)
fieldSizer = wx.BoxSizer(wx.HORIZONTAL)
if mainInput:
fieldTextBox = RangeBox(self, self._storedRanges.get((inputDef.handle, inputDef.unit), inputDef.defaultRange))
fieldTextBox = FloatRangeBox(self, self._storedRanges.get((inputDef.handle, inputDef.unit), inputDef.defaultRange))
else:
fieldTextBox = ConstantBox(self, self._storedConsts.get((inputDef.handle, inputDef.unit), inputDef.defaultValue))
fieldTextBox = FloatBox(self, self._storedConsts.get((inputDef.handle, inputDef.unit), inputDef.defaultValue))
fieldTextBox.Bind(wx.EVT_TEXT, self.OnFieldChanged)
fieldSizer.Add(fieldTextBox, 0, wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, 5)
fieldIcon = None