Dan
2014-11-21 21:03:53 UTC
I'm running into a bit of an issue with the indexing of plots added to the
GraphicsLayoutWidget.
I basically have a plotting app that has a list (using QComboBox) of all of
the plots that were created along with the actually widget that contains
the plots.
So, for example, if I had 4 plots, which are stacked on top of each other,
I have a combobox with the items:
Plot1
Plot2
Plot3
Plot4
Those items have indexes:
(0,0)
(1,0)
(2,0)
(3,0)
since I'm adding them using nextRow()
In the combo box, the index values are 0, 1, 2, 3.
My app allows the user to remove a plot by selecting it in the combo box. I
pass the index of the combo box to
item = GraphicsLayoutWidget.getItem(combo_box_index, 0)
And then use
GraphicsLayoutWidget.removeItem(item)
This works on the first time that the clear plot button is pressed.
However, because I update the combo box on removing a plot I'm running into
an index issue.
So, for example, if I remove plot 3, the combo box now has index values 0,
1, 2 (where "Plot 4" is now in the 2 index position vs. its previous spot
in the 3 position)
If I then go to remove Plot4, I get an error of:
Exception: Could not determine index of item None
It seems that the GraphicsLayoutWidget does not update the index value of
the other items in the widget if a plot is removed from the widget.
I.e.
Rather than Plot1, Plot2, and Plot4 having index: (0,0), (1,0), (2,0) they
return their original indexing of (0,0), (1,0), (3,0)
Is this correct? Is there any way to return the index values of all the
items currently in the GraphicsLayoutWidget?
relevant bits of code:
self.plotWidget = pg.GraphicsLayoutWidget(Form)
self.plotWidget.setObjectName("plotWidget")
def add_new_plot(self):
name = "Plot" + str(self.counter)
#plt = self.plotWidget.addPlot(row=self.counter, col=0, name=name,
title=name)
plt = self.plotWidget.addPlot(name=name, title=name)
self.plotWidget.nextRow()
self.plot_data(plt)
plt.setXLink("Plot1")
self.plotNum_dropdown.addItem(name)
self.clearPlot_dropdown.addItem(name)
self.counter += 1
def clear_plot(self):
index = self.clearPlot_dropdown.currentIndex()
if index == 0:
self.plotWidget.clear()
self.plotNum_dropdown.clear()
self.clearPlot_dropdown.clear()
self.clearPlot_dropdown.addItem("All")
self.counter = 1
elif index > 0:
plt = self.plotWidget.getItem(index, 0)
self.plotWidget.removeItem(plt)
self.clearPlot_dropdown.removeItem(index)
self.plotNum_dropdown.removeItem(index)
GraphicsLayoutWidget.
I basically have a plotting app that has a list (using QComboBox) of all of
the plots that were created along with the actually widget that contains
the plots.
So, for example, if I had 4 plots, which are stacked on top of each other,
I have a combobox with the items:
Plot1
Plot2
Plot3
Plot4
Those items have indexes:
(0,0)
(1,0)
(2,0)
(3,0)
since I'm adding them using nextRow()
In the combo box, the index values are 0, 1, 2, 3.
My app allows the user to remove a plot by selecting it in the combo box. I
pass the index of the combo box to
item = GraphicsLayoutWidget.getItem(combo_box_index, 0)
And then use
GraphicsLayoutWidget.removeItem(item)
This works on the first time that the clear plot button is pressed.
However, because I update the combo box on removing a plot I'm running into
an index issue.
So, for example, if I remove plot 3, the combo box now has index values 0,
1, 2 (where "Plot 4" is now in the 2 index position vs. its previous spot
in the 3 position)
If I then go to remove Plot4, I get an error of:
Exception: Could not determine index of item None
It seems that the GraphicsLayoutWidget does not update the index value of
the other items in the widget if a plot is removed from the widget.
I.e.
Rather than Plot1, Plot2, and Plot4 having index: (0,0), (1,0), (2,0) they
return their original indexing of (0,0), (1,0), (3,0)
Is this correct? Is there any way to return the index values of all the
items currently in the GraphicsLayoutWidget?
relevant bits of code:
self.plotWidget = pg.GraphicsLayoutWidget(Form)
self.plotWidget.setObjectName("plotWidget")
def add_new_plot(self):
name = "Plot" + str(self.counter)
#plt = self.plotWidget.addPlot(row=self.counter, col=0, name=name,
title=name)
plt = self.plotWidget.addPlot(name=name, title=name)
self.plotWidget.nextRow()
self.plot_data(plt)
plt.setXLink("Plot1")
self.plotNum_dropdown.addItem(name)
self.clearPlot_dropdown.addItem(name)
self.counter += 1
def clear_plot(self):
index = self.clearPlot_dropdown.currentIndex()
if index == 0:
self.plotWidget.clear()
self.plotNum_dropdown.clear()
self.clearPlot_dropdown.clear()
self.clearPlot_dropdown.addItem("All")
self.counter = 1
elif index > 0:
plt = self.plotWidget.getItem(index, 0)
self.plotWidget.removeItem(plt)
self.clearPlot_dropdown.removeItem(index)
self.plotNum_dropdown.removeItem(index)
--
You received this message because you are subscribed to the Google Groups "pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyqtgraph+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/f1f97312-e272-42ba-8efa-5a3be224b23e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyqtgraph+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/f1f97312-e272-42ba-8efa-5a3be224b23e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.