|
1 | 1 | import CLProject as clp |
2 | 2 | from qtpy.QtWidgets import QWidget, QHBoxLayout, QVBoxLayout, QLabel, QLineEdit, QComboBox, QDoubleSpinBox, QAbstractSpinBox, QPushButton, QFileDialog, QCheckBox |
3 | 3 | import numpy as np |
| 4 | +from CLGui import undo_stack |
4 | 5 |
|
5 | 6 | # collection of combination classes for displaying and entering configuration parameters |
6 | 7 | # typically a label on the left, text box or similar element in the middle, and sometimes a unit label or dropdown on the right |
@@ -95,9 +96,11 @@ def valueChanged(new_val): # can also catch textChanged. textChanged and valueCh |
95 | 96 | new_val = int(round(new_val)) |
96 | 97 | #self.spin_box.setValue(self.value) # fires an extra callback, call self.set_value() instead |
97 | 98 | self.set_value(min(max(new_val, self.min), self.max)) # update if rounded or changed to min/max |
98 | | - if not self.update_callback is None: |
| 99 | + if self.update_callback is not None: |
99 | 100 | self.update_callback(self.value) |
| 101 | + undo_stack.push(self.undo_redo, self.last_value) |
100 | 102 | self.last_value = self.value |
| 103 | + |
101 | 104 | self.spin_box.valueChanged.connect(valueChanged) |
102 | 105 |
|
103 | 106 | # Only add a unit label if the unit is specified |
@@ -148,6 +151,12 @@ def set_numtype(self, new_type): |
148 | 151 | self.spin_box.setDecimals(0) |
149 | 152 | # default step value should still be 1 |
150 | 153 |
|
| 154 | + def undo_redo(self, undo_redo, value): |
| 155 | + self.set_value(value) |
| 156 | + self.last_value = value |
| 157 | + if self.update_callback is not None: |
| 158 | + self.update_callback(self.value) |
| 159 | + |
151 | 160 |
|
152 | 161 | class CLParamDropdown(QWidget): |
153 | 162 | def __init__(self, label_text, item_list, unit=None, editable=False): |
|
0 commit comments