Add dedicated update methods
This commit is contained in:
parent
bfaae16ac4
commit
9c566412ae
@ -8,7 +8,7 @@ import logging
|
|||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
from cpdctrl.led_script import LedScript
|
from cpdctrl.led_script import LedScript, InvalidScriptUpdate
|
||||||
|
|
||||||
timedelta = [("d", 24*3600), ("h", 3600), ("m", 60), ("s", 1)]
|
timedelta = [("d", 24*3600), ("h", 3600), ("m", 60), ("s", 1)]
|
||||||
def duration_to_string(duration: float) -> str:
|
def duration_to_string(duration: float) -> str:
|
||||||
@ -126,12 +126,23 @@ class LedScriptTableModel(QAbstractTableModel):
|
|||||||
|
|
||||||
def setData(self, index: QModelIndex, value, role: int):
|
def setData(self, index: QModelIndex, value, role: int):
|
||||||
if role == Qt.ItemDataRole.EditRole:
|
if role == Qt.ItemDataRole.EditRole:
|
||||||
newscript = self.led_script.script.copy()
|
# newscript = self.led_script.script.copy()
|
||||||
newscript[self.indices[index.column()]][index.row()] = value
|
# newscript[self.indices[index.column()]][index.row()] = value
|
||||||
try:
|
try:
|
||||||
log.info(f"Updating script from {self.led_script.script} to {newscript}")
|
led = self.led_script.script["led"][index.row()]
|
||||||
self.led_script.update_from_script(newscript)
|
dt = self.led_script.script["dt"][index.row()]
|
||||||
except ValueError as e:
|
idx_name = self.indices[index.column()]
|
||||||
|
if idx_name == 'led':
|
||||||
|
led = int(value)
|
||||||
|
elif idx_name == 'dt':
|
||||||
|
dt = float(value)
|
||||||
|
else:
|
||||||
|
raise InvalidScriptUpdate(f"Invalid script update: column '{idx_name}' invalid, can only update 'dt' and 'led'")
|
||||||
|
|
||||||
|
log.info(f"Updating script row {index.row()+1} field '{idx_name}' with value '{value}'")
|
||||||
|
self.led_script.update_script_set_row(index.row(), dt, led)
|
||||||
|
except InvalidScriptUpdate as e:
|
||||||
|
log.error("Invalid script update")
|
||||||
raise e
|
raise e
|
||||||
# return False
|
# return False
|
||||||
self.dataChanged.emit(index, index) # this is for updating the view
|
self.dataChanged.emit(index, index) # this is for updating the view
|
||||||
|
Loading…
x
Reference in New Issue
Block a user