Hello,
I think what I am trying to do should be doable,
I would like to override the export to csv feature of a PlotWidget that I
usally build this way:
self.main_plot = pg.PlotWidget(name="main_plot")
self.main_plot.seLogMode..
self.main_plot.showGrid..
because I would like the new function to only write the content of curves
objects (plotDataItems) that do not have a specific name,
here's how I usually build my curves objects:
self.curve = self.main_plot.plot(pen=color)
So I looked into the library code, and if I got it right, I need to create
a custom PlotItem class with proper inheritance, because I do not want to
break any functionality, so far I wrote something like this:
class CustomPlotItem(pg.PlotItem):
# use very same arguments
def __init__(self, parent=None, name=None, labels=None, title=None,
viewBox=None, axisItems=None, enableMenu=True, **kargs):
# pass all arguments to super so I do not break anything
super(customPlotItem, self).__init__(parent=parent, name=name, )
# use very same name to override
def writeCsv(self, fileName=None):
# >> previous code
if fileName is None:
self.fileDialog = FileDialog()
if PlotItem.lastFileDir is not None:
self.fileDialog.setDirectory(PlotItem.lastFileDir)
self.fileDialog.setFileMode(QtGui.QFileDialog.AnyFile)
self.fileDialog.setAcceptMode(QtGui.QFileDialog.AcceptSave)
self.fileDialog.show()
self.fileDialog.fileSelected.connect(self.writeCsv)
return
# new functionality
fileName = str(fileName)
PlotItem.lastFileDir = os.path.dirname(fileName)
fd = open(fileName, 'w')
data = [c.getData() for c in self.curves]
data = []
for c in self.curves:
if (c.name() != "name_to_drop_out"):
data.append(c.getData())
# previous code
i = 0
while True:
done = True
for d in data:
if i < len(d[0]):
fd.write('%g,%g,'%(d[0][i], d[1][i]))
done = False
else:
fd.write(' , ,')
fd.write('\n')
if done:
break
i += 1
fd.close()
so my problem is, I am using a pg.PlotWidget in my code, how can I make
this pg.PlotWidget not to build a usual pg.PlotItem but a custom one?
I tried something dirty so far:
self.main_plot = pg.PlotWidget(name="test")
customClass = CustomPlotItem() # could use some args?
self.main_plot.plotItem = customClass # kill default pointer,
point to custom stuff
self.curve = self.main_plot.plot() # try to use it
I guess you guys get the idea,
- Is this the right approach, do I got the class tree right?
- since the functionality I want to override is located in plotItem, How
do I get my plotWidget class (which is eventually what I use) to actually
use it?
- note: I might be wrong & the functionality writeCsv might be located
somewhere else
>> Just want to acknowledge how cool and impressive PyQtGraph is, I have
been using it for years now, and it's just flawless. Keep up the good work
guys
thank you
--
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/pyqtgraph/72499450-ca05-48ce-8fa6-90b4957e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.