Python: Improve Struct mapping

When reading, create the local equivalent of a dataclass, so that access
doesn't require ["foo"] key syntax.

Also implement the copy protocol, so that we can safely make clones of
the references returned by the ListModel.
This commit is contained in:
Simon Hausmann 2024-03-09 20:56:37 +01:00
parent 0b6381d012
commit e3aab79fdb
7 changed files with 103 additions and 25 deletions

View file

@ -5,6 +5,7 @@ from slint import Color, ListModel, Timer, TimerMode
import slint
from datetime import timedelta, datetime
import os
import copy
import sys
sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
@ -48,13 +49,13 @@ class MainWindow(slint.loader.ui.printerdemo.MainWindow):
def update_jobs(self):
if len(self.printer_queue) <= 0:
return
top_item = self.printer_queue[0]
top_item["progress"] += 1
if top_item["progress"] >= 100:
top_item = copy.copy(self.printer_queue[0])
top_item.progress += 1
if top_item.progress >= 100:
del self.printer_queue[0]
if len(self.printer_queue) == 0:
return
top_item = self.printer_queue[0]
top_item = copy.copy(self.printer_queue[0])
self.printer_queue[0] = top_item