ParticlePanel: set reasonable max values for integer sliders

Fixes #672
This commit is contained in:
rdb 2019-07-10 12:01:55 +02:00
parent 11990833fe
commit 2c9d16f62e

View File

@ -214,23 +214,23 @@ class ParticlePanel(AppShell):
('System', 'Pool Size', ('System', 'Pool Size',
'Max number of simultaneous particles', 'Max number of simultaneous particles',
self.setSystemPoolSize, self.setSystemPoolSize,
1.0, 1.0), 1.0, 2000000, 1.0),
('System', 'Birth Rate', ('System', 'Birth Rate',
'Seconds between particle births', 'Seconds between particle births',
self.setSystemBirthRate, self.setSystemBirthRate,
0.0, None), 0.0, None, None),
('System', 'Litter Size', ('System', 'Litter Size',
'Number of particle created at each birth', 'Number of particle created at each birth',
self.setSystemLitterSize, self.setSystemLitterSize,
1.0, 1.0), 1.0, 0x7fffffff, 1.0),
('System', 'Litter Spread', ('System', 'Litter Spread',
'Variation in litter size', 'Variation in litter size',
self.setSystemLitterSpread, self.setSystemLitterSpread,
0.0, 1.0), 0.0, 0x7fffffff, 1.0),
('System', 'Lifespan', ('System', 'Lifespan',
'Age in seconds at which the system (vs. particles) should die', 'Age in seconds at which the system (vs. particles) should die',
self.setSystemLifespan, self.setSystemLifespan,
0.0, None) 0.0, None, None)
) )
self.createFloaters(systemPage, systemFloaterDefs) self.createFloaters(systemPage, systemFloaterDefs)
@ -269,27 +269,27 @@ class ParticlePanel(AppShell):
('Factory', 'Life Span', ('Factory', 'Life Span',
'Average particle lifespan in seconds', 'Average particle lifespan in seconds',
self.setFactoryLifeSpan, self.setFactoryLifeSpan,
0.0, None), 0.0, None, None),
('Factory', 'Life Span Spread', ('Factory', 'Life Span Spread',
'Variation in lifespan', 'Variation in lifespan',
self.setFactoryLifeSpanSpread, self.setFactoryLifeSpanSpread,
0.0, None), 0.0, None, None),
('Factory', 'Mass', ('Factory', 'Mass',
'Average particle mass', 'Average particle mass',
self.setFactoryParticleMass, self.setFactoryParticleMass,
0.001, None), 0.001, None, None),
('Factory', 'Mass Spread', ('Factory', 'Mass Spread',
'Variation in particle mass', 'Variation in particle mass',
self.setFactoryParticleMassSpread, self.setFactoryParticleMassSpread,
0.0, None), 0.0, None, None),
('Factory', 'Terminal Velocity', ('Factory', 'Terminal Velocity',
'Cap on average particle velocity', 'Cap on average particle velocity',
self.setFactoryTerminalVelocity, self.setFactoryTerminalVelocity,
0.0, None), 0.0, None, None),
('Factory', 'Terminal Vel. Spread', ('Factory', 'Terminal Vel. Spread',
'Variation in terminal velocity', 'Variation in terminal velocity',
self.setFactoryTerminalVelocitySpread, self.setFactoryTerminalVelocitySpread,
0.0, None), 0.0, None, None),
) )
self.createFloaters(factoryPage, factoryWidgets) self.createFloaters(factoryPage, factoryWidgets)
@ -966,19 +966,29 @@ class ParticlePanel(AppShell):
def createFloaters(self, parent, widgetDefinitions): def createFloaters(self, parent, widgetDefinitions):
widgets = [] widgets = []
for category, label, balloonHelp, command, min, resolution in widgetDefinitions: for category, label, balloonHelp, command, min, max, resolution in widgetDefinitions:
widgets.append( widgets.append(
self.createFloater(parent, category, label, balloonHelp, self.createFloater(parent, category, label, balloonHelp,
command, min, resolution) command, min, max, resolution)
) )
return widgets return widgets
def createFloater(self, parent, category, text, balloonHelp, def createFloater(self, parent, category, text, balloonHelp,
command = None, min = 0.0, resolution = None, command = None, min = 0.0, max = None, resolution = None,
numDigits = 3, **kw): numDigits = None, **kw):
kw['text'] = text kw['text'] = text
kw['min'] = min kw['min'] = min
if max is not None:
kw['max'] = max
kw['resolution'] = resolution kw['resolution'] = resolution
if numDigits is None:
# If this is apparently an integer setting, show no decimals.
if resolution is not None and int(resolution) == resolution and \
(min is None or int(min) == min) and \
(max is None or int(max) == max):
numDigits = 0
else:
numDigits = 3
kw['numDigits'] = numDigits kw['numDigits'] = numDigits
widget = Floater.Floater(parent, **kw) widget = Floater.Floater(parent, **kw)
# Do this after the widget so command isn't called on creation # Do this after the widget so command isn't called on creation