The writeCsv method is actually not called by the export system (this is just leftover from long before there was an export system at all). I suggest looking over the classes in pyqtgraph.exporters.
1. Within your project, define a new Exporter subclass 2. Call YourExporter.register() to make it available from the list of exporters 3. If you want, modify the Exporter.Exporters list to remove or reorder as needed On Wed, Dec 6, 2017 at 2:11 AM, Guillaume William Bres < [email protected]> wrote: > 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 [email protected]. > To view this discussion on the web visit https://groups.google.com/d/ > msgid/pyqtgraph/72499450-ca05-48ce-8fa6-903333b4957e%40googlegroups.com > <https://groups.google.com/d/msgid/pyqtgraph/72499450-ca05-48ce-8fa6-903333b4957e%40googlegroups.com?utm_medium=email&utm_source=footer> > . > 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/CACZXET8KDkDmOkQS%3D-aOkfrbysQXsZeayJvA%3DqY%2Bm%2BnNP1DMzQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
