From 4a65966c6c102a9ecf87596069dc3aab9ebbaf42 Mon Sep 17 00:00:00 2001 From: abn Date: Wed, 16 Jan 2019 10:35:43 +0100 Subject: [PATCH] Bug fix : ability to change curve name --- .../CurvePlot/src/python/model/PlotManager.py | 36 +++++----- .../src/python/ui/CurveTreeDockWidget.py | 2 +- tools/CurvePlot/src/python/ui/PlotSettings.py | 21 +++--- tools/CurvePlot/src/python/ui/PlotSettings.ui | 72 ++----------------- tools/CurvePlot/src/python/ui/PlotWidget.py | 2 +- tools/CurvePlot/src/python/views/XYView.py | 9 ++- 6 files changed, 46 insertions(+), 96 deletions(-) diff --git a/tools/CurvePlot/src/python/model/PlotManager.py b/tools/CurvePlot/src/python/model/PlotManager.py index 45c665d2d..e90cb0abc 100644 --- a/tools/CurvePlot/src/python/model/PlotManager.py +++ b/tools/CurvePlot/src/python/model/PlotManager.py @@ -11,52 +11,52 @@ class PlotManager(Model): # when removing elemetns, we can easily re-select the last-but-one. self._lockRepaint = False # if True, repaint routines are blocked. self._plotSetsRepaint = set() # plot waiting for repaint/update while repaint is locked - + def isEmpty(self): return len(self._plotSets) == 0 - + def setCurrentPlotSet(self, plotSetID, silent=False): if plotSetID not in self._plotSets and plotSetID != -1: raise ValueError("Invalid plot set ID (%d)!" % plotSetID) self._currentPlotSet = self._plotSets.get(plotSetID, None) if not silent: - self.notifyChange("CurrentPlotSetChange") - + self.notifyChange("CurrentPlotSetChange") + def getCurrentPlotSet(self): return self._currentPlotSet - + def getPlotSetContainingCurve(self, curveID): for ps in list(self._plotSets.values()): if curveID in ps._curves: return ps return None - + def setCurrentCurve(self, curveId): ps = self.getPlotSetContainingCurve(curveId) if ps is None and curveId != -1: raise ValueError("Invalid curve ID (%d)!" % curveId) self.clearAllCurrentCurve() - if curveId == -1: + if curveId == -1: return -1 ps_id = ps.getID() currPs = self.getCurrentPlotSet() - if currPs is None or currPs.getID() != ps_id: + if currPs is None or currPs.getID() != ps_id: self.setCurrentPlotSet(ps_id) ps.setCurrentCurve(curveId) return ps_id - + def getCurrentCurve(self): ps = self.getCurrentPlotSet() if ps is None: return None return ps.getCurrentCurve() - + def clearAllCurrentCurve(self, silent=False): for psID in self._plotSets: self._plotSets[psID].setCurrentCurve(-1) if not silent: self.notifyChange("CurrentCurveChange") - + def createXYPlotSet(self, silent=False): cv = XYPlotSetModel(self._controller) self._plotSets[cv.getID()] = cv @@ -64,7 +64,7 @@ class PlotManager(Model): if not silent: self.notifyChange("NewPlotSet") return cv - + def removeXYPlotSet(self, plotSetID): Logger.Debug("====> PlotManager::removeXYPlotSet() %d" % plotSetID) if plotSetID not in self._plotSets: @@ -75,25 +75,25 @@ class PlotManager(Model): self._currentPlotSet = None self.notifyChange("RemovePlotSet") return ps - + def clearAll(self): self._plotSets = {} self._currentPlotSet = None self.notifyChange("ClearAll") - + def lockRepaint(self): self._lockRepaint = True self._plotSetsRepaint = set() - + def isRepaintLocked(self): return self._lockRepaint - + def registerRepaint(self, ps_id): self._plotSetsRepaint.add(ps_id) - + def unlockRepaint(self): self._lockRepaint = False for obj in self._plotSetsRepaint: obj.notifyChange() self._plotSetsRepaint = set() - \ No newline at end of file + diff --git a/tools/CurvePlot/src/python/ui/CurveTreeDockWidget.py b/tools/CurvePlot/src/python/ui/CurveTreeDockWidget.py index d6b6d2263..01bd1e5c8 100644 --- a/tools/CurvePlot/src/python/ui/CurveTreeDockWidget.py +++ b/tools/CurvePlot/src/python/ui/CurveTreeDockWidget.py @@ -10,7 +10,7 @@ class CurveTreeDockWidget(QtWidgets.QDockWidget): self.treeWidget.sortByColumn(0, QtCore.Qt.AscendingOrder) self.treeWidget.setSortingEnabled(True); self.treeWidget.setColumnHidden(1, True); - + def getTreeWidget(self): """ :returns: QTreeWidget -- the (curve) browser diff --git a/tools/CurvePlot/src/python/ui/PlotSettings.py b/tools/CurvePlot/src/python/ui/PlotSettings.py index 201e5074e..174fd021a 100644 --- a/tools/CurvePlot/src/python/ui/PlotSettings.py +++ b/tools/CurvePlot/src/python/ui/PlotSettings.py @@ -1,8 +1,8 @@ from pyqtside.QtWidgets import QDialog, QColorDialog, QMessageBox from pyqtside.QtGui import QIcon, QPixmap, QColor -from pyqtside.QtCore import pyqtSlot +from pyqtside.QtCore import pyqtSlot from pyqtside.uic import loadUiGen -from .utils import completeResPath +from .utils import completeResPath, Logger class PlotSettings(QDialog): def __init__(self): @@ -16,38 +16,41 @@ class PlotSettings(QDialog): self._r = 0 self._g = 0 self._b = 1 - + @pyqtSlot(int) def onShowLegend(self, index): if index > 0 : self.legendPositionComboBox.setEnabled(True) else : self.legendPositionComboBox.setEnabled(False) - - @pyqtSlot() + + @pyqtSlot() def onChangeColor(self): col = QColorDialog.getColor() if col.isValid(): r, g, b = [c/255.0 for c in col.getRgb()[:3]] self.setRGB(r, g, b) - + def setSelectedCurveName(self, name): + self.nameCurve.setText(name) if name : + Logger.Debug("show curve panel") self.selectedCurvePanel.setTitle("Selected curve : " + name) self.selectedCurvePanel.show() else : + Logger.Debug("hide curve panel") self.selectedCurvePanel.hide() - + def setRGB(self, r, g, b): self._r = r self._g = g self._b = b self.colorCurve.setIcon(QIcon(self.drawColorPixmap(int(r*255), int(g*255), int(b*255)))) - + def getRGB(self): return self._r, self._g, self._b - + def drawColorPixmap(self, r, g, b): pix = QPixmap( 16, 16 ) color = QColor(r, g, b) diff --git a/tools/CurvePlot/src/python/ui/PlotSettings.ui b/tools/CurvePlot/src/python/ui/PlotSettings.ui index 687e47a20..0672d6f55 100644 --- a/tools/CurvePlot/src/python/ui/PlotSettings.ui +++ b/tools/CurvePlot/src/python/ui/PlotSettings.ui @@ -147,7 +147,7 @@ 11 35 291 - 57 + 74 @@ -162,72 +162,14 @@ - - - - - - - 145 - 145 - 145 - - - - - - - 105 - 105 - 105 - - - - - - - - - 145 - 145 - 145 - - - - - - - 105 - 105 - 105 - - - - - - - - - 149 - 151 - 153 - - - - - - - 158 - 158 - 158 - - - - - + + true + + + - true + false diff --git a/tools/CurvePlot/src/python/ui/PlotWidget.py b/tools/CurvePlot/src/python/ui/PlotWidget.py index 7a8a87fa4..61d06f027 100644 --- a/tools/CurvePlot/src/python/ui/PlotWidget.py +++ b/tools/CurvePlot/src/python/ui/PlotWidget.py @@ -6,7 +6,7 @@ class PlotWidget(QtWidgets.QMainWindow): def __init__(self): QtWidgets.QMainWindow.__init__(self) loadUiGen(completeResPath("PlotWidget.ui"), self) - + def clearAll(self): """ In test context, the PlotWidget is never fully deleted (because the PyQt binding of QTabWidget doesn't remove completly the references it holds). diff --git a/tools/CurvePlot/src/python/views/XYView.py b/tools/CurvePlot/src/python/views/XYView.py index b4682ce71..e327a143e 100644 --- a/tools/CurvePlot/src/python/views/XYView.py +++ b/tools/CurvePlot/src/python/views/XYView.py @@ -484,7 +484,7 @@ class XYView(View): dlg.colorCurve.setEnabled(True) dlg.markerCurve.setEnabled(True) name = curr_crv.getTitle() - dlg.nameCurve.setText(name) + dlg.setSelectedCurveName(name) view = self._curveViews[curr_crv.getID()] marker = view.getMarker() color = view.getColor() @@ -495,7 +495,7 @@ class XYView(View): else : dlg.colorCurve.setEnabled(False) dlg.markerCurve.setEnabled(False) - dlg.nameCurve.setText("") + dlg.setSelectedCurveName("") view = None if self._legend is None: dlg.showLegendCheckBox.setChecked(False) @@ -544,6 +544,10 @@ class XYView(View): if view: view.setColor(dlg.getRGB()) view.setMarker(self.CURVE_MARKERS[dlg.markerCurve.currentIndex()]) + crvModel = view._model + if dlg.nameCurve.text() != crvModel.getTitle(): + Logger.Debug("XYView : about to cahnge crv title after settings") + view._model.setTitle(dlg.nameCurve.text()) self.showHideLegend(repaint=True) self._mplCanvas.draw() pass @@ -560,6 +564,7 @@ class XYView(View): pass def onCurrentCurveChange(self): + Logger.Debug("XYView::onCurrentCurveChange()") curr_crv2 = self._model.getCurrentCurve() if curr_crv2 != self._currCrv: if self._currCrv is not None: -- 2.39.2