Esempio n. 1
0
    def applyConfig(self, configdict, depth=None):
        """
        Reimplemented from BaseConfigurableClass to manage the config
        properties of the trendsets attached to this plot
        """
        try:
            # Temporarily register trendsets as delegates
            tmpreg = []
            tsets = []
            for name in configdict['__orderedConfigNames__']:
                if name.startswith('__TaurusTrendSet_'):
                    # Instantiate empty TaurusTrendSet
                    tset = TaurusTrendSet()
                    tsets.append(tset)
                    self.registerConfigDelegate(tset, name)
                    tmpreg.append(name)

            # remove the trendsets from the second axis (Y2) to avoid dups
            self._y2.clearItems()

            TaurusBaseComponent.applyConfig(self,
                                            configdict=configdict,
                                            depth=depth)

            plot_item = self.getPlotItem()
            legend = plot_item.legend

            # keep a dict of existing trendsets (to use it for avoiding dups)
            currentTrendSets = dict()
            curveNames = []
            for tset in plot_item.listDataItems():
                if isinstance(tset, TaurusTrendSet):
                    currentTrendSets[tset.getFullModelName()] = tset
                    curveNames.extend([c.name for c in tset])

            # remove trendsets that exists in currentTrendSets from plot
            # (to avoid duplicates). Also remove curves from the legend
            for tset in tsets:
                ts = currentTrendSets.get(tset.getFullModelName(), None)
                if ts is not None:
                    plot_item.removeItem(ts)

            # Add to plot **after** their configuration has been applied
            for tset in tsets:
                # First we add all the trendsets to self. This way the plotItem
                # can keep a list of dataItems (PlotItem.listDataItems())
                self.addItem(tset)

                # Add trendsets to Y2 axis, when the trendset configurations
                # have been applied.
                # Ideally, the Y2ViewBox class must handle the action of adding
                # trendsets to itself, but we want add the trendsets when they
                # are restored with all their properties.
                if tset.getFullModelName() in self._y2.getCurves():
                    plot_item.getViewBox().removeItem(tset)
                    self._y2.addItem(tset)
        finally:
            # Ensure that temporary delegates are unregistered
            for n in tmpreg:
                self.unregisterConfigurableItem(n, raiseOnError=False)
Esempio n. 2
0
    def applyConfig(self, configdict, depth=None):
        """
        Reimplemented from BaseConfigurableClass to manage the config
        properties of the curves attached to this plot
        """
        try:
            # Temporarily register curves as delegates
            tmpreg = []
            curves = []
            for name in configdict['__orderedConfigNames__']:
                if name.startswith('__TaurusPlotDataItem_'):
                    # Instantiate empty TaurusPlotDataItem
                    curve = TaurusPlotDataItem()
                    curves.append(curve)
                    self.registerConfigDelegate(curve, name)
                    tmpreg.append(name)

            # remove the curves from the second axis (Y2) for avoid dups
            self._y2.clearItems()

            TaurusBaseComponent.applyConfig(self,
                                            configdict=configdict,
                                            depth=depth)

            # keep a dict of existing curves (to use it for avoiding dups)
            currentCurves = dict()
            for curve in self.getPlotItem().listDataItems():
                if isinstance(curve, TaurusPlotDataItem):
                    currentCurves[curve.getFullModelNames()] = curve

            # remove curves that exists in currentCurves, also remove from
            # the legend (avoid duplicates)
            for curve in curves:
                c = currentCurves.get(curve.getFullModelNames(), None)
                if c is not None:
                    self.getPlotItem().legend.removeItem(c.name())
                    self.getPlotItem().removeItem(c)

            # Add to plot **after** their configuration has been applied
            for curve in curves:
                # First we add all the curves in self. This way the plotItem
                # can keeps a list of dataItems (plotItem.listDataItems())
                self.addItem(curve)

                # Add curves to Y2 axis, when the curve configurations
                # have been applied.
                # Ideally, the Y2ViewBox class must handle the action of adding
                # curves to itself, but we want add the curves when they are
                # restored with all their properties.
                if curve.getFullModelNames() in self._y2.getCurves():
                    self.getPlotItem().getViewBox().removeItem(curve)
                    self._y2.addItem(curve)

        finally:
            # Ensure that temporary delegates are unregistered
            for n in tmpreg:
                self.unregisterConfigurableItem(n, raiseOnError=False)