Esempio n. 1
0
class PlotWidget2(qt.QWidget):
    """This widget overloads PlotWidget with methods enabling drag and drop 
    of data files into this widget. At the moment, only CSV files are supported.
    The first column will be assumed to be data for the x axis. All other columns
    will be plotted against the first one.
    """
    def __init__(self, parent=None, backend=None,
                 legends=False, callback=None, **kw):
        qt.QWidget.__init__(self, parent)
        
        layout = qt.QVBoxLayout(self)
        layout.setContentsMargins(0, 0, 0, 0)
        layout.setSpacing(0)
        
        self.plotwidget = PlotWidget(self, backend,
                                legends, callback, **kw)
        layout.addWidget(self.plotwidget)
        
        self.setAcceptDrops(True)
        
    def dragEnterEvent(self, e):
        if e.mimeData().hasUrls():
            e.accept()

    def dropEvent(self, e):
        data_file_path = None
        if e.mimeData().hasUrls():
            # we accept only single files
            if e.mimeData().urls()[0].path().lower().endswith('.csv'):
                data_file_path = e.mimeData().urls()[0].path()
        if data_file_path is not None:
            if sys.platform.startswith("win") and \
               data_file_path.startswith("/") and \
               ":/" in data_file_path:
                data_file_path = data_file_path[1:]              
            data = CSVData(data_file_path)
            x = data.get_xcol(0)
            ys = data.get_ycols()
            hdrs = data.get_hdrs()
            (xhdr, yhdrs) = (hdrs[0], hdrs[1:])
            for (y, yhdr) in zip(ys, yhdrs):
                self.plotwidget.addCurve(x, y, legend=yhdr, xlabel=xhdr, ylabel=yhdr)
                
    def keyPressEvent(self, event):
        if (event.modifiers() & qt.Qt.ShiftModifier) and (event.modifiers() & qt.Qt.ControlModifier):
            if event.key() == qt.Qt.Key_C:
                #print("Shift + Ctrl + C pressed")
                self.renderToClipboard()
        qt.QWidget.keyPressEvent(self, event)
                
    def renderToClipboard(self):
        pixmap = qt.QPixmap(self.size())
        self.render(pixmap)
        qt.QApplication.clipboard().setPixmap(pixmap)
Esempio n. 2
0
 def __init__(self, parent=None, backend=None,
              legends=False, callback=None, **kw):
     qt.QWidget.__init__(self, parent)
     
     layout = qt.QVBoxLayout(self)
     layout.setContentsMargins(0, 0, 0, 0)
     layout.setSpacing(0)
     
     self.plotwidget = PlotWidget(self, backend,
                             legends, callback, **kw)
     layout.addWidget(self.plotwidget)
     
     self.setAcceptDrops(True)