2 from XYView import XYView
3 from utils import Logger
5 class CurveTabsView(View):
6 def __init__(self, controller):
7 View.__init__(self, controller)
8 self._XYViews = {} # key: SALOME view ID, value: XYView
10 def closeXYView(self, salomeViewID):
11 Logger.Debug("CurveTabsView::closeXYView: %d" % salomeViewID)
12 self._controller.setCurvePlotRequestingClose(True)
13 self._controller._sgPyQt.closeView(salomeViewID)
14 self._controller.setCurvePlotRequestingClose(False)
16 self._XYViews.pop(salomeViewID)
17 Logger.Debug("CurveTabsView::closeXYView count %d" % len(self._XYViews))
19 def createXYView(self, model):
20 v = XYView(self._controller)
21 self._controller.associate(model, v)
24 def onCurrentPlotSetChange(self):
25 """ Avoid a unnecessary call to update() when just switching current plot set! """
26 cps = self._model.getCurrentPlotSet()
28 mp = self.mapModId2ViewId()
29 salomeViewID = mp[cps.getID()]
30 self._controller._sgPyQt.activateView(salomeViewID)
32 def mapModId2ViewId(self):
33 """ Gives a map from model ID (the model behind the XYView) to view ID
35 lst = [(v._model.getID(), view_id) for view_id, v in list(self._XYViews.items())]
40 Updates the list of tabs shown in the GUI
42 if self._model is None:
46 set_mod = set(self._model._plotSets.keys())
47 set_view = { v._model.getID() for v in list(self._XYViews.values()) }
48 mp = self.mapModId2ViewId()
50 # Deleted/Added curves:
51 dels = set_view - set_mod
52 added = set_mod - set_view
56 v = self._XYViews[salomeViewID]
58 self.closeXYView(salomeViewID)
62 newViews.append(self.createXYView(self._model._plotSets[a]))
64 # Now update all tabs individually (this will trigger creation of new ones if not already there):
65 for v in list(self._XYViews.values()) + newViews:
66 # The update on newViews will trigger the SALOME view creation:
69 # And complete internal structure for new views
72 self._XYViews[v._salomeViewID] = v
74 # Finally activate the proper tab:
75 self.onCurrentPlotSetChange()