Exemplo n.º 1
0
 def writeCsv(self, fileName=None):
     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
     #if fileName is None:
         #fileName = QtGui.QFileDialog.getSaveFileName()
     fileName = str(fileName)
     PlotItem.lastFileDir = os.path.dirname(fileName)
     
     fd = open(fileName, 'w')
     data = [c.getData() for c in self.curves]
     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()
Exemplo n.º 2
0
 def writeImage(self, fileName=None):
     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.writeImage)
         return
     #if fileName is None:
     #fileName = QtGui.QFileDialog.getSaveFileName()
     if isinstance(fileName, tuple):
         raise Exception("Not implemented yet..")
     fileName = str(fileName)
     PlotItem.lastFileDir = os.path.dirname(fileName)
     self.png = QtGui.QImage(int(self.size().width()),
                             int(self.size().height()),
                             QtGui.QImage.Format_ARGB32)
     painter = QtGui.QPainter(self.png)
     painter.setRenderHints(painter.Antialiasing | painter.TextAntialiasing)
     self.scene().render(painter, QtCore.QRectF(),
                         self.mapRectToScene(self.boundingRect()))
     painter.end()
     self.png.save(fileName)
Exemplo n.º 3
0
 def fileSaveDialog(self, filter=None, opts=None):
     ## Show a file dialog, call self.export(fileName) when finished.
     if opts is None:
         opts = {}
     self.fileDialog = FileDialog()
     self.fileDialog.setFileMode(QtGui.QFileDialog.AnyFile)
     self.fileDialog.setAcceptMode(QtGui.QFileDialog.AcceptSave)
     if filter is not None:
         if isinstance(filter, basestring):
             self.fileDialog.setNameFilter(filter)
         elif isinstance(filter, list):
             self.fileDialog.setNameFilters(filter)
     global LastExportDirectory
     exportDir = LastExportDirectory
     if exportDir is not None:
         self.fileDialog.setDirectory(exportDir)
     self.fileDialog.show()
     self.fileDialog.opts = opts
     self.fileDialog.fileSelected.connect(self.fileSaveFinished)
     return
],
                  default="None")
exp_wg.setFixedSize(200, 30)
exp_wg_prev = exp_wg.currentText()

# Exit button
exit_wg = QtGui.QPushButton("Exit")
exit_wg.setFixedSize(200, 30)
exit_wg.setCheckable(True)
exit_wg.clicked.connect(lambda: gui.exit_wg_state(exit_wg, viewer_app))

# File chooser
file_button = QtGui.QPushButton("Open Image/Video")
file_button.setFixedSize(200, 30)
file_button.setCheckable(True)
file_chooser = FileDialog()
file_chooser.setFileMode(QtGui.QFileDialog.ExistingFile)
file_chooser.selectNameFilter("Image files (*.jpg *.jpeg *.png *.tiff)")
file_name = ""
file_name_prev = ""


def select_file():
    """select file."""
    global file_name
    file_name = file_chooser.getOpenFileName()


file_button.clicked.connect(select_file)

# Utitlity Layout
Exemplo n.º 5
0
    def writeSvgCurves(self, fileName=None):
        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.writeSvg)
            return
        #if fileName is None:
            #fileName = QtGui.QFileDialog.getSaveFileName()
        if isinstance(fileName, tuple):
            raise Exception("Not implemented yet..")
        fileName = str(fileName)
        PlotItem.lastFileDir = os.path.dirname(fileName)
        
        rect = self.vb.viewRect()
        xRange = rect.left(), rect.right() 
        
        svg = ""
        fh = open(fileName, 'w')

        dx = max(rect.right(),0) - min(rect.left(),0)
        ymn = min(rect.top(), rect.bottom())
        ymx = max(rect.top(), rect.bottom())
        dy = max(ymx,0) - min(ymn,0)
        sx = 1.
        sy = 1.
        while dx*sx < 10:
            sx *= 1000
        while dy*sy < 10:
            sy *= 1000
        sy *= -1

        #fh.write('<svg viewBox="%f %f %f %f">\n' % (rect.left()*sx, rect.top()*sx, rect.width()*sy, rect.height()*sy))
        fh.write('<svg>\n')
        fh.write('<path fill="none" stroke="#000000" stroke-opacity="0.5" stroke-width="1" d="M%f,0 L%f,0"/>\n' % (rect.left()*sx, rect.right()*sx))
        fh.write('<path fill="none" stroke="#000000" stroke-opacity="0.5" stroke-width="1" d="M0,%f L0,%f"/>\n' % (rect.top()*sy, rect.bottom()*sy))


        for item in self.curves:
            if isinstance(item, PlotCurveItem):
                color = fn.colorStr(item.pen.color())
                opacity = item.pen.color().alpha() / 255.
                color = color[:6]
                x, y = item.getData()
                mask = (x > xRange[0]) * (x < xRange[1])
                mask[:-1] += mask[1:]
                m2 = mask.copy()
                mask[1:] += m2[:-1]
                x = x[mask]
                y = y[mask]
                
                x *= sx
                y *= sy
                
                #fh.write('<g fill="none" stroke="#%s" stroke-opacity="1" stroke-width="1">\n' % color)
                fh.write('<path fill="none" stroke="#%s" stroke-opacity="%f" stroke-width="1" d="M%f,%f ' % (color, opacity, x[0], y[0]))
                for i in range(1, len(x)):
                    fh.write('L%f,%f ' % (x[i], y[i]))
                
                fh.write('"/>')
                #fh.write("</g>")
        for item in self.dataItems:
            if isinstance(item, ScatterPlotItem):
                
                pRect = item.boundingRect()
                vRect = pRect.intersected(rect)
                
                for point in item.points():
                    pos = point.pos()
                    if not rect.contains(pos):
                        continue
                    color = fn.colorStr(point.brush.color())
                    opacity = point.brush.color().alpha() / 255.
                    color = color[:6]
                    x = pos.x() * sx
                    y = pos.y() * sy
                    
                    fh.write('<circle cx="%f" cy="%f" r="1" fill="#%s" stroke="none" fill-opacity="%f"/>\n' % (x, y, color, opacity))
        
        fh.write("</svg>\n")