From 4edfd6caa45a10349f0bc6bf2dbc5c9b994f17d4 Mon Sep 17 00:00:00 2001 From: Robert Jordens Date: Tue, 5 Apr 2016 17:16:16 +0800 Subject: [PATCH] qui/models: add LocalModelManager --- artiq/gui/models.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/artiq/gui/models.py b/artiq/gui/models.py index 74f17d6f2..4d4c08b67 100644 --- a/artiq/gui/models.py +++ b/artiq/gui/models.py @@ -3,9 +3,8 @@ from PyQt5 import QtCore from artiq.protocols.sync_struct import Subscriber -class ModelSubscriber(Subscriber): - def __init__(self, notifier_name, model_factory): - Subscriber.__init__(self, notifier_name, self._create_model) +class ModelManager: + def __init__(self, model_factory): self.model = None self._model_factory = model_factory self._setmodel_callbacks = [] @@ -22,6 +21,24 @@ class ModelSubscriber(Subscriber): cb(self.model) +class ModelSubscriber(ModelManager, Subscriber): + def __init__(self, notifier_name, model_factory): + ModelManager.__init__(self, model_factory) + Subscriber.__init__(self, notifier_name, self._create_model) + + +class LocalModelManager(ModelManager): + def __init__(self, model_factory): + ModelManager.__init__(self, model_factory) + self.notify_cbs = [] + + def init(self, struct): + self._create_model(struct) + mod = {"action": "init", "struct": struct} + for notify_cb in self.notify_cbs: + notify_cb(mod) + + class _SyncSubstruct: def __init__(self, update_cb, ref): self.update_cb = update_cb