Show all the needed controls on the panel

This commit is contained in:
DarkPhoenix
2019-06-24 16:15:35 +03:00
parent 5e7fcc32b6
commit 03183827a6
4 changed files with 138 additions and 122 deletions

View File

@@ -20,7 +20,7 @@
import re
from abc import ABCMeta, abstractmethod
from collections import namedtuple
from collections import OrderedDict, namedtuple
class Graph(metaclass=ABCMeta):
@@ -45,15 +45,27 @@ class Graph(metaclass=ABCMeta):
def yDefs(self):
raise NotImplementedError
@property
def yDefMap(self):
return OrderedDict((y.handle, y) for y in self.yDefs)
@property
@abstractmethod
def xDefs(self):
raise NotImplementedError
@property
def xDefMap(self):
return OrderedDict((x.handle, x) for x in self.xDefs)
@property
def inputs(self):
raise NotImplementedError
@property
def inputMap(self):
return OrderedDict((i.handle, i) for i in self.inputs)
@property
def hasTargets(self):
return False

View File

@@ -18,8 +18,6 @@
# =============================================================================
from collections import OrderedDict
from eos.graph.fitDpsVsRange import FitDpsVsRangeGraph as EosGraph
from .base import Graph, XDef, YDef, Input
@@ -34,28 +32,28 @@ class FitDamageStatsGraph(Graph):
@property
def xDefs(self):
return OrderedDict([
('distance', XDef(handle='distance', label='Distance', unit='km', mainInputHandle='distance')),
('time', XDef(handle='time', label='Time', unit='s', mainInputHandle='time')),
('tgtSpeedAbs', XDef(handle='tgtSpeedAbs', label='Target speed', unit='m/s', mainInputHandle='tgtSpeed')),
('tgtSpeedRel', XDef(handle='tgtSpeedRel', label='Target speed', unit='%', mainInputHandle='tgtSpeed')),
('tgtSigRadAbs', XDef(handle='tgtSigRadAbs', label='Target signature radius', unit='m', mainInputHandle='tgtSigRad')),
('tgtSigRadRel', XDef(handle='tgtSigRadRel', label='Target signature radius', unit='%', mainInputHandle='tgtSigRad'))])
return [
XDef(handle='distance', label='Distance', unit='km', mainInputHandle='distance'),
XDef(handle='time', label='Time', unit='s', mainInputHandle='time'),
XDef(handle='tgtSpeedAbs', label='Target speed', unit='m/s', mainInputHandle='tgtSpeed'),
XDef(handle='tgtSpeedRel', label='Target speed', unit='%', mainInputHandle='tgtSpeed'),
XDef(handle='tgtSigRadAbs', label='Target signature radius', unit='m', mainInputHandle='tgtSigRad'),
XDef(handle='tgtSigRadRel', label='Target signature radius', unit='%', mainInputHandle='tgtSigRad')]
@property
def yDefs(self):
return OrderedDict([
('dps', YDef(handle='dps', label='DPS', unit=None, eosGraph='eosGraph')),
('volley', YDef(handle='volley', label='Volley', unit=None, eosGraph='eosGraph')),
('damage', YDef(handle='damage', label='Damage inflicted', unit=None, eosGraph='eosGraph'))])
return [
YDef(handle='dps', label='DPS', unit=None, eosGraph='eosGraph'),
YDef(handle='volley', label='Volley', unit=None, eosGraph='eosGraph'),
YDef(handle='damage', label='Damage inflicted', unit=None, eosGraph='eosGraph')]
@property
def inputs(self):
return OrderedDict([
('time', Input(handle='time', label='Time', unit='s', iconID=1392, defaultValue=None, defaultRange=(0, 80))),
('distance', Input(handle='distance', label='Distance', unit='km', iconID=1391, defaultValue=50, defaultRange=(0, 100))),
('tgtSpeed', Input(handle='tgtSpeed', label='Target speed', unit='%', iconID=1389, defaultValue=100, defaultRange=(0, 100))),
('tgtSigRad', Input(handle='tgtSigRad', label='Target signature radius', unit='%', iconID=1390, defaultValue=100, defaultRange=(100, 200)))])
return [
Input(handle='time', label='Time', unit='s', iconID=1392, defaultValue=None, defaultRange=(0, 80)),
Input(handle='distance', label='Distance', unit='km', iconID=1391, defaultValue=50, defaultRange=(0, 100)),
Input(handle='tgtSpeed', label='Target speed', unit='%', iconID=1389, defaultValue=100, defaultRange=(0, 100)),
Input(handle='tgtSigRad', label='Target signature radius', unit='%', iconID=1390, defaultValue=100, defaultRange=(100, 200))]
@property
def hasTargets(self):

View File

@@ -179,90 +179,90 @@ class GraphFrame(wx.Frame):
pyfalog.warning('GraphFrame handled event, however GraphFrame no longer exists. Ignoring event')
return
values = self.ctrlPanel.getValues()
view = self.getView()
self.subplot.clear()
self.subplot.grid(True)
legend = []
min_y = 0 if self.ctrlPanel.showY0 else None
max_y = 0 if self.ctrlPanel.showY0 else None
xRange = values['x']
extraInputs = {ih: values[ih] for ih in view.extraInputs}
try:
chosenY = [i for i in view.yDefs.keys()][self.ctrlPanel.selectedY or 0]
except IndexError:
chosenY = [i for i in view.yDefs.keys()][0]
self.subplot.set(xlabel=view.xDef.axisLabel, ylabel=view.yDefs[chosenY].axisLabel)
for fit in self.ctrlPanel.fitList.fits:
try:
xs, ys = view.getPlotPoints(fit, extraInputs, xRange, 100, chosenY)
# Figure out min and max Y
min_y_this = min(ys, default=None)
if min_y is None:
min_y = min_y_this
elif min_y_this is not None:
min_y = min(min_y, min_y_this)
max_y_this = max(ys, default=None)
if max_y is None:
max_y = max_y_this
elif max_y_this is not None:
max_y = max(max_y, max_y_this)
self.subplot.plot(xs, ys)
legend.append('{} ({})'.format(fit.name, fit.ship.item.getShortName()))
except Exception as ex:
pyfalog.warning('Invalid values in "{0}"', fit.name)
self.canvas.draw()
return
# Special case for when we do not show Y = 0 and have no fits
if min_y is None:
min_y = 0
if max_y is None:
max_y = 0
# Extend range a little for some visual space
y_range = max_y - min_y
min_y -= y_range * 0.05
max_y += y_range * 0.05
if min_y == max_y:
min_y -= min_y * 0.05
max_y += min_y * 0.05
if min_y == max_y:
min_y -= 5
max_y += 5
self.subplot.set_ylim(bottom=min_y, top=max_y)
legend2 = []
legend_colors = {
0: 'blue',
1: 'orange',
2: 'green',
3: 'red',
4: 'purple',
5: 'brown',
6: 'pink',
7: 'grey',
}
for i, i_name in enumerate(legend):
try:
selected_color = legend_colors[i]
except:
selected_color = None
legend2.append(Patch(color=selected_color, label=i_name), )
if len(legend2) > 0:
leg = self.subplot.legend(handles=legend2)
for t in leg.get_texts():
t.set_fontsize('small')
for l in leg.get_lines():
l.set_linewidth(1)
# values = self.ctrlPanel.getValues()
# view = self.getView()
# self.subplot.clear()
# self.subplot.grid(True)
# legend = []
#
# min_y = 0 if self.ctrlPanel.showY0 else None
# max_y = 0 if self.ctrlPanel.showY0 else None
#
# xRange = values['x']
# extraInputs = {ih: values[ih] for ih in view.extraInputs}
# try:
# chosenY = [i for i in view.yDefs.keys()][self.ctrlPanel.selectedY or 0]
# except IndexError:
# chosenY = [i for i in view.yDefs.keys()][0]
#
# self.subplot.set(xlabel=view.xDef.axisLabel, ylabel=view.yDefs[chosenY].axisLabel)
#
# for fit in self.ctrlPanel.fitList.fits:
# try:
# xs, ys = view.getPlotPoints(fit, extraInputs, xRange, 100, chosenY)
#
# # Figure out min and max Y
# min_y_this = min(ys, default=None)
# if min_y is None:
# min_y = min_y_this
# elif min_y_this is not None:
# min_y = min(min_y, min_y_this)
# max_y_this = max(ys, default=None)
# if max_y is None:
# max_y = max_y_this
# elif max_y_this is not None:
# max_y = max(max_y, max_y_this)
#
# self.subplot.plot(xs, ys)
# legend.append('{} ({})'.format(fit.name, fit.ship.item.getShortName()))
# except Exception as ex:
# pyfalog.warning('Invalid values in "{0}"', fit.name)
# self.canvas.draw()
# return
#
# # Special case for when we do not show Y = 0 and have no fits
# if min_y is None:
# min_y = 0
# if max_y is None:
# max_y = 0
# # Extend range a little for some visual space
# y_range = max_y - min_y
# min_y -= y_range * 0.05
# max_y += y_range * 0.05
# if min_y == max_y:
# min_y -= min_y * 0.05
# max_y += min_y * 0.05
# if min_y == max_y:
# min_y -= 5
# max_y += 5
# self.subplot.set_ylim(bottom=min_y, top=max_y)
#
# legend2 = []
# legend_colors = {
# 0: 'blue',
# 1: 'orange',
# 2: 'green',
# 3: 'red',
# 4: 'purple',
# 5: 'brown',
# 6: 'pink',
# 7: 'grey',
# }
#
# for i, i_name in enumerate(legend):
# try:
# selected_color = legend_colors[i]
# except:
# selected_color = None
# legend2.append(Patch(color=selected_color, label=i_name), )
#
# if len(legend2) > 0:
# leg = self.subplot.legend(handles=legend2)
# for t in leg.get_texts():
# t.set_fontsize('small')
#
# for l in leg.get_lines():
# l.set_linewidth(1)
self.canvas.draw()
self.Refresh()

View File

@@ -89,43 +89,49 @@ class GraphControlPanel(wx.Panel):
child.Destroy()
self.fields.clear()
selectedXRb = wx.RadioBox(self, -1, 'Axis X', wx.DefaultPosition, wx.DefaultSize, [x.label for x in view.xDefs], 1, wx.RA_SPECIFY_COLS)
def formatAxisLabel(axisDef):
if axisDef.unit is None:
return axisDef.label
return '{}, {}'.format(axisDef.label, axisDef.unit)
selectedXRb = wx.RadioBox(self, -1, 'Axis X', wx.DefaultPosition, wx.DefaultSize, [formatAxisLabel(x) for x in view.xDefs], 1, wx.RA_SPECIFY_COLS)
self.graphSubselSizer.Add(selectedXRb, 0, wx.ALL | wx.EXPAND, 0)
selectedYRb = wx.RadioBox(self, -1, 'Axis Y', wx.DefaultPosition, wx.DefaultSize, [y.label for y in view.yDefs], 1, wx.RA_SPECIFY_COLS)
selectedYRb = wx.RadioBox(self, -1, 'Axis Y', wx.DefaultPosition, wx.DefaultSize, [formatAxisLabel(y) for y in view.yDefs], 1, wx.RA_SPECIFY_COLS)
self.graphSubselSizer.Add(selectedYRb, 0, wx.ALL | wx.EXPAND, 0)
vectorHandles = set()
if view.hasSrcVector:
vectorHandles.add(view.srcVectorLengthHandle)
vectorHandles.add(view.srcVectorAngleHandle)
if view.hasTgtVector:
vectorHandles.add(view.tgtVectorLengthHandle)
vectorHandles.add(view.tgtVectorAngleHandle)
# Setup inputs
for fieldHandle, fieldDef in ((view.xDefs[0].handle, view.xDefs[0]), *view.extraInputs.items()):
shownHandles = set()
if view.hasSrcVector:
shownHandles.add(view.srcVectorLengthHandle)
shownHandles.add(view.srcVectorAngleHandle)
if view.hasTgtVector:
shownHandles.add(view.tgtVectorLengthHandle)
shownHandles.add(view.tgtVectorAngleHandle)
for inputHandle in (view.xDefs[0].mainInputHandle, *(i.handle for i in view.inputs)):
if inputHandle in shownHandles:
continue
shownHandles.add(inputHandle)
inputDef = view.inputMap[inputHandle]
textBox = wx.TextCtrl(self, wx.ID_ANY, style=0)
self.fields[fieldHandle] = textBox
textBox.Bind(wx.EVT_TEXT, self.OnFieldChanged)
self.inputsSizer.Add(textBox, 1, wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 3)
if fieldDef.inputDefault is not None:
inputDefault = fieldDef.inputDefault
if inputDef.defaultValue is not None:
inputDefault = inputDef.defaultValue
if not isinstance(inputDefault, str):
inputDefault = ('%f' % inputDefault).rstrip('0')
if inputDefault[-1:] == '.':
inputDefault += '0'
textBox.ChangeValue(inputDefault)
imgLabelSizer = wx.BoxSizer(wx.HORIZONTAL)
if fieldDef.inputIconID:
icon = BitmapLoader.getBitmap(fieldDef.inputIconID, 'icons')
if inputDef.iconID is not None:
icon = BitmapLoader.getBitmap(inputDef.iconID, 'icons')
if icon is not None:
static = wx.StaticBitmap(self)
static.SetBitmap(icon)
imgLabelSizer.Add(static, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 1)
imgLabelSizer.Add(wx.StaticText(self, wx.ID_ANY, fieldDef.inputLabel), 0,
imgLabelSizer.Add(wx.StaticText(self, wx.ID_ANY, inputDef.label), 0,
wx.LEFT | wx.RIGHT | wx.ALIGN_CENTER_VERTICAL, 3)
self.inputsSizer.Add(imgLabelSizer, 0, wx.ALIGN_CENTER_VERTICAL)
self.Layout()