This is the solution I came up with. It seems to work.
Basically I suspend listeners and write the formula again using setFormuls()
and Calc treats it like a dirty cell.
def dispatch(self, url: URL, args: Tuple[PropertyValue, ...]) -> None:
self._logger.debug(f"dispatch(): url={url}")
doc = CalcDoc.from_current_doc()
sheet = doc.sheets[self._sheet]
cell = sheet[self._cell]
cc = CellCache(doc) # singleton
cell_obj = cell.cell_obj
sheet_idx = sheet.sheet_index
if not cc.has_cell(cell=cell_obj, sheet_idx=sheet_idx):
self._logger.error(f"Cell {self._cell} is not in the cache.")
return
with cc.set_context(cell=cell_obj, sheet_idx=sheet_idx):
result = self._edit_code(doc=doc, cell_obj=cell_obj)
if result:
if doc.component.isAutomaticCalculationEnabled():
cm = CellMgr(doc) # singleton. Tracks all Code cells
# suspend the listeners for this cell
with cm.listener_context(cell.component):
s = cell.component.getFormula()
if not s:
self._logger.error(f"Cell {self._cell} has no formula.")
return
s = s.lstrip("=") # just in case there are multiple equal signs
cell.component.setFormula(f"={s}")
doc.component.calculate()
And in My log File it show cell formula being fired.
2024-06-10 02:10:00,009 - DispatchEditPY - DEBUG - Displaying dialog
2024-06-10 02:10:07,012 - DispatchEditPY - DEBUG - Dialog returned with OK
2024-06-10 02:10:07,013 - DispatchEditPY - DEBUG - Code has changed, updating ...
2024-06-10 02:10:07,013 - libre_pythonista - DEBUG - PySourceManager - update_source()
2024-06-10 02:10:07,013 - libre_pythonista - DEBUG - PySourceManager - update_source() sheet index: 0 col: 2, row: 2
2024-06-10 02:10:07,018 - libre_pythonista - DEBUG - PySourceManager - update_source() is last index updating from index 3
2024-06-10 02:10:07,018 - libre_pythonista - DEBUG - PySourceManager - update_from_index(3) Entered.
2024-06-10 02:10:07,018 - libre_pythonista - DEBUG - PySourceManager - update_from_index(3). Is last index.
2024-06-10 02:10:07,018 - libre_pythonista - DEBUG - PySourceManager - _update_item() Entered.
2024-06-10 02:10:07,018 - libre_pythonista - DEBUG - PySourceManager - _update_item() sheet index: 0 col: 2, row: 2
2024-06-10 02:10:07,018 - libre_pythonista - DEBUG - PySourceManager - _update_item() Leaving.
2024-06-10 02:10:07,019 - libre_pythonista - DEBUG - PySourceManager - update_from_index(3) Leaving.
2024-06-10 02:10:07,019 - DispatchEditPY - DEBUG - Cell Code updated for C3
2024-06-10 02:10:07,019 - libre_pythonista - DEBUG - PySourceManager - update_all() Entered.
2024-06-10 02:10:07,020 - libre_pythonista - DEBUG - PySourceManager - update_all() Leaving.
2024-06-10 02:10:07,021 - DispatchEditPY - DEBUG - Code updated
2024-06-10 02:10:07,021 - CellMgr - DEBUG - Listener context for cell: $Sheet1.$C$3
2024-06-10 02:10:07,021 - CellMgr - DEBUG - Un-subscribing listeners for cell: $Sheet1.$C$3
2024-06-10 02:10:07,023 - PyImpl - DEBUG - pyc entered
2024-06-10 02:10:07,025 - PyImpl - DEBUG - Doc UID: 2
2024-06-10 02:10:07,025 - PyImpl - DEBUG - pyc - sheet_num: arg 1
2024-06-10 02:10:07,025 - PyImpl - DEBUG - pyc - cell_address: arg $C$3
2024-06-10 02:10:07,025 - PyImpl - DEBUG - pyc -args: (510.0,)
2024-06-10 02:10:07,036 - PyImpl - DEBUG - pyc - Cell C3 has custom properties: True
2024-06-10 02:10:07,036 - PyImpl - DEBUG - Py: py cell has code
2024-06-10 02:10:07,036 - PyImpl - DEBUG - Py: py sheet_num: 1, cell_address: $C$3
2024-06-10 02:10:07,036 - PyImpl - DEBUG - pyc exiting
2024-06-10 02:10:07,037 - PyImpl - DEBUG - pyc entered
2024-06-10 02:10:07,039 - PyImpl - DEBUG - Doc UID: 2
2024-06-10 02:10:07,039 - PyImpl - DEBUG - pyc - sheet_num: arg 1
2024-06-10 02:10:07,039 - PyImpl - DEBUG - pyc - cell_address: arg $C$3
2024-06-10 02:10:07,039 - PyImpl - DEBUG - pyc -args: (510.0,)
2024-06-10 02:10:07,053 - PyImpl - DEBUG - pyc - Cell C3 has custom properties: True
2024-06-10 02:10:07,053 - PyImpl - DEBUG - Py: py cell has code
2024-06-10 02:10:07,053 - PyImpl - DEBUG - Py: py sheet_num: 1, cell_address: $C$3
2024-06-10 02:10:07,053 - PyImpl - DEBUG - pyc exiting
2024-06-10 02:10:07,054 - CellMgr - DEBUG - Subscribing to listeners for cell: $Sheet1.$C$3
I marked you suggestion and the solution seeing as it pointed me in this direction?