Example #1
0
 def save(self, fname, format, draft):
     if is_text_string(fname):
         if format == "pdf":
             self.app = guidata.qapplication()
             if draft:
                 mode = QPrinter.ScreenResolution
             else:
                 mode = QPrinter.HighResolution
             printer = QPrinter(mode)
             printer.setOutputFormat(QPrinter.PdfFormat)
             printer.setOrientation(QPrinter.Landscape)
             printer.setOutputFileName(fname)
             printer.setCreator('guiqwt.pyplot')
             self.print_(printer)
         else:
             if self.win is None:
                 self.show()
             if PYQT5:
                 pixmap = self.win.centralWidget().grab()
             else:
                 pixmap = QPixmap.grabWidget(self.win.centralWidget())
             pixmap.save(fname, format.upper())
     else:
         # Buffer
         fd = fname
         assert hasattr(fd, 'write'), "object is not file-like as expected"
         if self.win is None:
             self.show()
         pixmap = QPixmap.grabWidget(self.win.centralWidget())
         buff = QBuffer()
         buff.open(QIODevice.ReadWrite)
         pixmap.save(buff, format.upper())
         fd.write(buff.data())
         buff.close()
         fd.seek(0)
Example #2
0
 def save(self, fname, format, draft):
     if is_text_string(fname):
         if format == "pdf":
             self.app = guidata.qapplication()
             if draft:
                 mode = QPrinter.ScreenResolution
             else:
                 mode = QPrinter.HighResolution
             printer = QPrinter(mode)
             printer.setOutputFormat(QPrinter.PdfFormat)
             printer.setOrientation(QPrinter.Landscape)
             printer.setOutputFileName(fname)
             printer.setCreator('guiqwt.pyplot')
             self.print_(printer)
         else:
             if self.win is None:
                 self.show()
             if PYQT5:
                 pixmap = self.win.centralWidget().grab()
             else:
                 pixmap = QPixmap.grabWidget(self.win.centralWidget())
             pixmap.save(fname, format.upper())
     else:
         # Buffer
         fd = fname
         assert hasattr(fd, 'write'), "object is not file-like as expected"
         if self.win is None:
             self.show()
         pixmap = QPixmap.grabWidget(self.win.centralWidget())
         buff = QBuffer()
         buff.open(QIODevice.ReadWrite)
         pixmap.save(buff, format.upper())
         fd.write(buff.data())
         buff.close()
         fd.seek(0)
Example #3
0
 def update(self, value):
     """Reimplement LineEditWidget method"""
     LineEditWidget.update(self, value)
     color = text_to_qcolor(value)
     if color.isValid():
         bitmap = QPixmap(16, 16)
         bitmap.fill(color)
         icon = QIcon(bitmap)
     else:
         icon = get_icon("not_found")
     self.button.setIcon(icon)
Example #4
0
 def copy_to_clipboard(self):
     """Copy widget's window to clipboard"""
     clipboard = QApplication.clipboard()
     if PYQT5:
         pixmap = self.grab()
     else:
         pixmap = QPixmap.grabWidget(self)
     clipboard.setPixmap(pixmap)
Example #5
0
 def copy_to_clipboard(self):
     """Copy widget's window to clipboard"""
     clipboard = QApplication.clipboard()
     if PYQT5:
         pixmap = self.grab()
     else:
         pixmap = QPixmap.grabWidget(self)
     clipboard.setPixmap(pixmap)
Example #6
0
def get_image_label(name, default="not_found.png"):
    """
    Construct a QLabel from the file with specified name
    name, default: filenames with extensions
    """
    label = QLabel()
    pixmap = QPixmap(get_image_file_path(name, default))
    label.setPixmap(pixmap)
    return label
Example #7
0
def build_icon_from_cmap(cmap, width=32, height=32):
    """
    Builds an icon representing the colormap
    """
    data = zeros((width, height), uint8)
    line = linspace(0, 255, width)
    data[:, :] = line[:, newaxis]
    img = toQImage(data)
    img.setColorTable(cmap.colorTable(FULLRANGE))
    return QIcon(QPixmap.fromImage(img))
Example #8
0
def build_icon_from_cmap(cmap, width=32, height=32):
    """
    Builds an icon representing the colormap
    """
    data = zeros((width, height), uint8)
    line = linspace(0, 255, width)
    data[:,:] = line[:, newaxis]
    img = toQImage(data)
    img.setColorTable(cmap.colorTable(FULLRANGE))
    return QIcon(QPixmap.fromImage(img))
Example #9
0
 def save_widget(self, fname):
     """Grab widget's window and save it to filename (*.png, *.pdf)"""
     fname = to_text_string(fname)
     if fname.lower().endswith('.pdf'):
         printer = QPrinter()
         printer.setOutputFormat(QPrinter.PdfFormat)
         printer.setOrientation(QPrinter.Landscape)
         printer.setOutputFileName(fname)
         printer.setCreator('guidata')
         self.print_(printer)
     elif fname.lower().endswith('.png'):
         pixmap = QPixmap.grabWidget(self)
         pixmap.save(fname, 'PNG')
     else:
         raise RuntimeError(_("Unknown file extension"))
Example #10
0
 def save_widget(self, fname):
     """Grab widget's window and save it to filename (\*.png, \*.pdf)"""
     fname = to_text_string(fname)
     if fname.lower().endswith('.pdf'):
         printer = QPrinter()
         printer.setOutputFormat(QPrinter.PdfFormat)
         printer.setOrientation(QPrinter.Landscape)
         printer.setOutputFileName(fname)
         printer.setCreator('guidata')
         self.print_(printer)
     elif fname.lower().endswith('.png'):
         if PYQT5:
             pixmap = self.grab()
         else:
             pixmap = QPixmap.grabWidget(self)
         pixmap.save(fname, 'PNG')
     else:
         raise RuntimeError(_("Unknown file extension"))
Example #11
0
 def copy_to_clipboard(self):
     """Copy widget's window to clipboard"""
     clipboard = QApplication.clipboard()
     clipboard.setPixmap(QPixmap.grabWidget(self))