From bf437ef8a71c51031c647c0c50b0bbcdac894658 Mon Sep 17 00:00:00 2001 From: Dominik Demuth Date: Fri, 30 Dec 2022 14:06:25 +0100 Subject: [PATCH] weird bug for log-scaling fixed; fixes T248 --- src/gui_qt/data/shift_graphs.py | 17 ++++++++++++++--- src/gui_qt/graphs/graphwindow.py | 2 +- src/gui_qt/lib/pg_objects.py | 11 ++++++++--- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/gui_qt/data/shift_graphs.py b/src/gui_qt/data/shift_graphs.py index fdbd033..3e0edb2 100644 --- a/src/gui_qt/data/shift_graphs.py +++ b/src/gui_qt/data/shift_graphs.py @@ -25,6 +25,9 @@ class QShift(QtWidgets.QDialog, Ui_shift_dialog): self.data = {} self._colors = cycle(Tab10) + self.graphicsView.plotItem.ctrl.logXCheck.blockSignals(True) + self.graphicsView.plotItem.ctrl.logYCheck.blockSignals(True) + delegate = SpinBoxDelegate() delegate.valueChanged.connect(self.shift) self.shift_table.setItemDelegate(delegate) @@ -40,10 +43,10 @@ class QShift(QtWidgets.QDialog, Ui_shift_dialog): def add_item(self, idx, name, x, y): color = mkColor(next(self._colors).rgb()) if np.iscomplexobj(y): - pl = [PlotItem(x, y.real, name=name, pen=mkPen(color=color)), - PlotItem(x, y.imag, name=name, pen=mkPen(color=color))] + pl = [PlotItem(x=x, y=y.real, name=name, pen=mkPen(color=color)), + PlotItem(x=x, y=y.imag, name=name, pen=mkPen(color=color))] else: - pl = [PlotItem(x, y, name=name, pen=mkPen(color=color))] + pl = [PlotItem(x=x, y=y, name=name, symbol='t', pen=mkPen(color=color))] self.data[idx] = (pl, x, y) @@ -123,10 +126,18 @@ class QShift(QtWidgets.QDialog, Ui_shift_dialog): def set_log(self, state: int): if self.sender() == self.xlog_checkbox: log_state = self.graphicsView.plotItem.ctrl.logXCheck + func = self.graphicsView.setXRange else: log_state = self.graphicsView.plotItem.ctrl.logYCheck + func = self.graphicsView.setYRange + log_state.setCheckState(state) self.graphicsView.plotItem.updateLogMode() + # For some combinations of Python, pyqt, and pyqtgraph, updateLogMode does not update + # view range to log values and logTickValues generates LOTS of ticks, which freezes everything. + # -> Call setRange to interrupt the loop. + func(0, 1) + self.graphicsView.enableAutoRange() def on_overwrite_checkbox_stateChanged(self, state: int): self.data_newgraph.setVisible(state != QtCore.Qt.Checked) diff --git a/src/gui_qt/graphs/graphwindow.py b/src/gui_qt/graphs/graphwindow.py index f1040da..8dd2c45 100644 --- a/src/gui_qt/graphs/graphwindow.py +++ b/src/gui_qt/graphs/graphwindow.py @@ -419,7 +419,7 @@ class QGraphWindow(QtWidgets.QGraphicsView, Ui_GraphWindow): self.plotItem.updateLogMode() - self.set_range(x=r[0], y=r[1]) + self.plotItem.enableAutoRange() def enable_picking(self, enabled: bool): if enabled: diff --git a/src/gui_qt/lib/pg_objects.py b/src/gui_qt/lib/pg_objects.py index 5412aca..c8626e0 100644 --- a/src/gui_qt/lib/pg_objects.py +++ b/src/gui_qt/lib/pg_objects.py @@ -179,8 +179,12 @@ class PlotItem(PlotDataItem): self.opts['linecolor'] = c.red(), c.green(), c.blue() if self.symbol != SymbolStyle.No: - c = self.opts['symbolBrush'].color() - self.opts['symbolcolor'] = c.red(), c.green(), c.blue() + brush = self.opts['symbolBrush'] + if isinstance(brush, tuple): + self.opts['symbolcolor'] = brush + else: + c = brush.color() + self.opts['symbolcolor'] = c.red(), c.green(), c.blue() def __getitem__(self, item): return self.opts.get(item, None) @@ -229,7 +233,7 @@ class PlotItem(PlotDataItem): else: return lc - def updateItems(self): + def updateItems(self, styleUpdate=True): """ We override this function so that curves with nan/inf values can be displayed. Newer versions close this bug differently (https://github.com/pyqtgraph/pyqtgraph/pull/1058) @@ -261,6 +265,7 @@ class PlotItem(PlotDataItem): # remove all bad values x = x[is_finite] y = y[is_finite] + curveArgs['connect'] = 'all' self.curve.setData(x=x, y=y, **curveArgs) self.curve.show() else: