Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if value is not None:
self.control.setValue(self.lookup.index(value))
class CallFrontLogSlider(ControlledCallFront):
def action(self, value):
if value is not None:
if value < 1e-30:
print(
"unable to set %s to %s (value too small)" % (self.control, value)
)
else:
self.control.setValue(math.log10(value))
class CallFrontLineEdit(ControlledCallFront):
def action(self, value):
self.control.setText(str(value))
class CallFrontRadioButtons(ControlledCallFront):
def action(self, value):
if value < 0 or value >= len(self.control.buttons):
value = 0
self.control.buttons[value].setChecked(1)
class CallFrontListView(ControlledCallFront):
def action(self, values):
view = self.control
model = view.model()
sel_model = view.selectionModel()
if value == "": # the latter accomodates PyListModel
value = None
if value is None and None not in self.model:
return # e.g. attribute x in uninitialized scatter plot
if value in self.model:
self.control.setCurrentIndex(self.model.indexOf(value))
return
elif isinstance(value, str):
for i, val in enumerate(self.model):
if value == str(val):
self.control.setCurrentIndex(i)
return
raise ValueError("Combo box does not contain item " + repr(value))
class CallFrontHSlider(ControlledCallFront):
def action(self, value):
if value is not None:
self.control.setValue(value)
class CallFrontLabeledSlider(ControlledCallFront):
def __init__(self, control, lookup):
super().__init__(control)
self.lookup = lookup
def action(self, value):
if value is not None:
self.control.setValue(self.lookup.index(value))
class CallFrontLogSlider(ControlledCallFront):
class CallFrontDoubleSpin(ControlledCallFront):
def action(self, value):
if value is not None:
self.control.setValue(value)
class CallFrontCheckBox(ControlledCallFront):
def action(self, value):
if value is not None:
values = [Qt.Unchecked, Qt.Checked, Qt.PartiallyChecked]
self.control.setCheckState(values[value])
class CallFrontButton(ControlledCallFront):
def action(self, value):
if value is not None:
self.control.setChecked(bool(value))
class CallFrontComboBox(ControlledCallFront):
def __init__(self, control, valType=None, emptyString=""):
super().__init__(control)
self.valType = valType
self.emptyString = emptyString
def action(self, value):
if value in ("", None):
value = self.emptyString
if self.valType:
for i in range(self.control.count()):
for i in range(self.control.count()):
self.control.item(i).setSelected(i == value)
else:
if not isinstance(value, ControlledList):
setattr(
self.control.ogMaster,
self.control.ogValue,
ControlledList(value, self.control),
)
for i in range(self.control.count()):
shouldBe = i in value
if shouldBe != self.control.item(i).isSelected():
self.control.item(i).setSelected(shouldBe)
class CallFrontListBoxLabels(ControlledCallFront):
unknownType = None
def action(self, values):
self.control.clear()
if values:
for value in values:
if isinstance(value, tuple):
text, icon = value
if isinstance(icon, int):
item = QtWidgets.QListWidgetItem(attributeIconDict[icon], text)
else:
item = QtWidgets.QListWidgetItem(icon, text)
elif isinstance(value, Variable):
item = QtWidgets.QListWidgetItem(*attributeItem(value))
else:
item = QtWidgets.QListWidgetItem(value)
search_role = TableVariable
else:
search_role = Qt.DisplayRole
value = str(value)
for i in range(model.rowCount()):
if model.data(model.index(i), search_role) == value:
index = i
break
else:
index = value
if index is not None:
selection.select(model.index(index), model.index(index))
sel_model.select(selection, sel_model.ClearAndSelect)
class CallFrontListBox(ControlledCallFront):
def action(self, value):
if value is not None:
if isinstance(value, int):
for i in range(self.control.count()):
self.control.item(i).setSelected(i == value)
else:
if not isinstance(value, ControlledList):
setattr(
self.control.ogMaster,
self.control.ogValue,
ControlledList(value, self.control),
)
for i in range(self.control.count()):
shouldBe = i in value
if shouldBe != self.control.item(i).isSelected():
self.control.item(i).setSelected(shouldBe)
return
if value:
log.warning(
"Unable to set %s to '%s'. Possible values are: %s",
self.control,
value,
", ".join(
self.control.itemText(i) for i in range(self.control.count())
),
)
else:
if value < self.control.count():
self.control.setCurrentIndex(value)
class CallFrontComboBoxModel(ControlledCallFront):
def __init__(self, control, model):
super().__init__(control)
self.model = model
def action(self, value):
if value == "": # the latter accomodates PyListModel
value = None
if value is None and None not in self.model:
return # e.g. attribute x in uninitialized scatter plot
if value in self.model:
self.control.setCurrentIndex(self.model.indexOf(value))
return
elif isinstance(value, str):
for i, val in enumerate(self.model):
if value == str(val):
self.control.setCurrentIndex(i)
return
elif isinstance(value, str):
for i, val in enumerate(self.model):
if value == str(val):
self.control.setCurrentIndex(i)
return
raise ValueError("Combo box does not contain item " + repr(value))
class CallFrontHSlider(ControlledCallFront):
def action(self, value):
if value is not None:
self.control.setValue(value)
class CallFrontLabeledSlider(ControlledCallFront):
def __init__(self, control, lookup):
super().__init__(control)
self.lookup = lookup
def action(self, value):
if value is not None:
self.control.setValue(self.lookup.index(value))
class CallFrontLogSlider(ControlledCallFront):
def action(self, value):
if value is not None:
if value < 1e-30:
print(
"unable to set %s to %s (value too small)" % (self.control, value)
)
def __call__(self, *args):
if not self.disabled:
opposite = getattr(self, "opposite", None)
if opposite:
try:
for op in opposite:
op.disabled += 1
self.action(*args)
finally:
for op in opposite:
op.disabled -= 1
else:
self.action(*args)
class CallFrontSpin(ControlledCallFront):
def action(self, value):
if value is not None:
self.control.setValue(value)
class CallFrontDoubleSpin(ControlledCallFront):
def action(self, value):
if value is not None:
self.control.setValue(value)
class CallFrontCheckBox(ControlledCallFront):
def action(self, value):
if value is not None:
values = [Qt.Unchecked, Qt.Checked, Qt.PartiallyChecked]
self.control.setCheckState(values[value])
self.action(*args)
class CallFrontSpin(ControlledCallFront):
def action(self, value):
if value is not None:
self.control.setValue(value)
class CallFrontDoubleSpin(ControlledCallFront):
def action(self, value):
if value is not None:
self.control.setValue(value)
class CallFrontCheckBox(ControlledCallFront):
def action(self, value):
if value is not None:
values = [Qt.Unchecked, Qt.Checked, Qt.PartiallyChecked]
self.control.setCheckState(values[value])
class CallFrontButton(ControlledCallFront):
def action(self, value):
if value is not None:
self.control.setChecked(bool(value))
class CallFrontComboBox(ControlledCallFront):
def __init__(self, control, valType=None, emptyString=""):
super().__init__(control)
self.valType = valType
op.disabled += 1
self.action(*args)
finally:
for op in opposite:
op.disabled -= 1
else:
self.action(*args)
class CallFrontSpin(ControlledCallFront):
def action(self, value):
if value is not None:
self.control.setValue(value)
class CallFrontDoubleSpin(ControlledCallFront):
def action(self, value):
if value is not None:
self.control.setValue(value)
class CallFrontCheckBox(ControlledCallFront):
def action(self, value):
if value is not None:
values = [Qt.Unchecked, Qt.Checked, Qt.PartiallyChecked]
self.control.setCheckState(values[value])
class CallFrontButton(ControlledCallFront):
def action(self, value):
if value is not None:
self.control.setChecked(bool(value))