Browse Source

Fix precision on "set value" dialogs, closes #208

tags/1.9.6
falkTX 10 years ago
parent
commit
a5128df47e
3 changed files with 47 additions and 15 deletions
  1. +20
    -5
      source/carla_skin.py
  2. +3
    -2
      source/carla_widgets.py
  3. +24
    -8
      source/widgets/paramspinbox.py

+ 20
- 5
source/carla_skin.py View File

@@ -1123,13 +1123,28 @@ class AbstractPluginSlot(QFrame, PluginEditParentMeta):

if actSelected == actSet:
if index < PARAMETER_NULL:
value, ok = QInputDialog.getInteger(self, self.tr("Set value"), label, round(current*100), round(minimum*100), round(maximum*100), 1)
if ok: value = float(value)/100.0
value, ok = QInputDialog.getInt(self, self.tr("Set value"), label, round(current*100), round(minimum*100), round(maximum*100), 1)

if not ok:
return

value = float(value)/100.0

else:
value, ok = QInputDialog.getDouble(self, self.tr("Set value"), label, current, minimum, maximum, 3) # FIXME - 3 decimals
paramInfo = self.host.get_parameter_info(self.fPluginId, index)
paramRanges = self.host.get_parameter_ranges(self.fPluginId, index)
scalePoints = []

if not ok:
return
for i in range(paramInfo['scalePointCount']):
scalePoints.append(self.host.get_parameter_scalepoint_info(self.fPluginId, index, i))

dialog = CustomInputDialog(self, label, current, minimum, maximum,
paramRanges['step'], paramRanges['stepSmall'], scalePoints)

if not dialog.exec_():
return

value = dialog.returnValue()

elif actSelected == actMinimum:
value = minimum


+ 3
- 2
source/carla_widgets.py View File

@@ -43,6 +43,7 @@ import ui_carla_parameter

from carla_shared import *
from carla_utils import *
from paramspinbox import CustomInputDialog
from pixmapkeyboard import PixmapKeyboardHArea

# ------------------------------------------------------------------------------------------------------------
@@ -1408,14 +1409,14 @@ class PluginEdit(QDialog):
menu.addSeparator()
actSet = menu.addAction(self.tr("Set value..."))

if label not in ("Balance-Left", "Balance-Right"):
if label not in ("Balance-Left", "Balance-Right", "Panning"):
menu.removeAction(actCenter)

actSelected = menu.exec_(QCursor.pos())

if actSelected == actSet:
current = minimum + (maximum-minimum)*(float(sender.value())/10000)
value, ok = QInputDialog.getInteger(self, self.tr("Set value"), label, round(current*100.0), round(minimum*100.0), round(maximum*100.0), 1)
value, ok = QInputDialog.getInt(self, self.tr("Set value"), label, round(current*100.0), round(minimum*100.0), round(maximum*100.0), 1)
if ok: value = float(value)/100.0

if not ok:


+ 24
- 8
source/widgets/paramspinbox.py View File

@@ -24,7 +24,7 @@ from carla_config import *
# ------------------------------------------------------------------------------------------------------------
# Imports (Global)

from math import isnan
from math import isnan, modf
from random import random

if config_UseQt5:
@@ -59,16 +59,31 @@ def geFixedValue(name, value, minimum, maximum):
# Custom InputDialog with Scale Points support

class CustomInputDialog(QDialog):
def __init__(self, parent, label, current, minimum, maximum, step, scalePoints):
def __init__(self, parent, label, current, minimum, maximum, step, stepSmall, scalePoints):
QDialog.__init__(self, parent)
self.ui = ui_inputdialog_value.Ui_Dialog()
self.ui.setupUi(self)

# calculate num decimals from stepSmall
if stepSmall >= 1.0:
decimals = 0
elif step >= 1.0:
decimals = 2
else:
decfrac, decwhole = modf(stepSmall)

if "000" in str(decfrac):
decfrac = round(decfrac, str(decfrac).find("000"))
else:
decfrac = round(decfrac, 12)

decimals = abs(len(str(decfrac))-len(str(decwhole))-1)

self.ui.label.setText(label)
self.ui.doubleSpinBox.setMinimum(minimum)
self.ui.doubleSpinBox.setMaximum(maximum)
self.ui.doubleSpinBox.setValue(current)
self.ui.doubleSpinBox.setDecimals(decimals)
self.ui.doubleSpinBox.setRange(minimum, maximum)
self.ui.doubleSpinBox.setSingleStep(step)
self.ui.doubleSpinBox.setValue(current)

if not scalePoints:
self.ui.groupBox.setVisible(False)
@@ -316,11 +331,11 @@ class ParamSpinBox(QAbstractSpinBox):

def setScalePoints(self, scalePoints, useScalePoints):
if len(scalePoints) == 0:
self.fScalePoints = None
self.fScalePoints = None
self.fUseScalePoints = False
return

self.fScalePoints = scalePoints
self.fScalePoints = scalePoints
self.fUseScalePoints = useScalePoints

if not useScalePoints:
@@ -482,7 +497,8 @@ class ParamSpinBox(QAbstractSpinBox):
self.setValue(pasteValue)

elif actSel == actSet:
dialog = CustomInputDialog(self, self.fName, self.fValue, self.fMinimum, self.fMaximum, self.fStep, self.fScalePoints)
dialog = CustomInputDialog(self, self.fName, self.fValue, self.fMinimum, self.fMaximum,
self.fStep, self.fStepSmall, self.fScalePoints)
if dialog.exec_():
value = dialog.returnValue()
self.setValue(value)


Loading…
Cancel
Save