def perform(self, event): plot_component = self.container.component filter = 'PNG file (*.png)|*.png|\nTIFF file (*.tiff)|*.tiff|' dialog = FileDialog(action='save as', wildcard=filter) if dialog.open() != OK: return # Remove the toolbar before saving the plot, so the output doesn't # include the toolbar. plot_component.remove_toolbar() filename = dialog.path width, height = plot_component.outer_bounds gc = PlotGraphicsContext((width, height), dpi=72) gc.render_component(plot_component) try: gc.save(filename) except KeyError as e: errmsg = ("The filename must have an extension that matches " "a graphics format, such as '.png' or '.tiff'.") if str(e.message) != '': errmsg = ("Unknown filename extension: '%s'\n" % str(e.message)) + errmsg error(None, errmsg, title="Invalid Filename Extension") # Restore the toolbar. plot_component.add_toolbar()
def save_file(self, path, force_layout=True, dest_box=None): _, tail = os.path.splitext(path) if tail not in ('.pdf', '.png'): path = '{}.pdf'.format(path) c = self.component ''' chaco becomes less responsive after saving if use_backbuffer is false and using pdf ''' from reportlab.lib.pagesizes import letter c.do_layout(size=letter, force=force_layout) _, tail = os.path.splitext(path) if tail == '.pdf': from pychron.core.pdf.save_pdf_dialog import myPdfPlotGraphicsContext gc = myPdfPlotGraphicsContext(filename=path, dest_box=dest_box) gc.render_component(c, valign='center') gc.save() else: from chaco.plot_graphics_context import PlotGraphicsContext gc = PlotGraphicsContext((int(c.outer_width), int(c.outer_height))) gc.render_component(c) gc.save(path)
def perform(self, event): plot_component = self.container.component filter = 'PNG file (*.png)|*.png|\nTIFF file (*.tiff)|*.tiff|' dialog = FileDialog(action='save as', wildcard=filter) if dialog.open() != OK: return # Remove the toolbar before saving the plot, so the output doesn't # include the toolbar. plot_component.remove_toolbar() filename = dialog.path width, height = plot_component.outer_bounds gc = PlotGraphicsContext((width, height), dpi=72) gc.render_component(plot_component) try: gc.save(filename) except KeyError as e: errmsg = ("The filename must have an extension that matches " "a graphics format, such as '.png' or '.tiff'.") if str(e.message) != '': errmsg = ("Unknown filename extension: '%s'\n" % str(e.message)) + errmsg error(None, errmsg, title="Invalid Filename Extension") # Restore the toolbar. plot_component.add_toolbar()
def save_file(self, path, force_layout=True, dest_box=None): _, tail = os.path.splitext(path) if tail not in ('.pdf', '.png'): path = '{}.pdf'.format(path) c = self.component ''' chaco becomes less responsive after saving if use_backbuffer is false and using pdf ''' from reportlab.lib.pagesizes import letter c.do_layout(size=letter, force=force_layout) _, tail = os.path.splitext(path) if tail == '.pdf': from pychron.core.pdf.save_pdf_dialog import myPdfPlotGraphicsContext gc = myPdfPlotGraphicsContext(filename=path, dest_box=dest_box) gc.render_component(c, valign='center') gc.save() else: from chaco.plot_graphics_context import PlotGraphicsContext gc = PlotGraphicsContext((int(c.outer_width), int(c.outer_height))) gc.render_component(c) gc.save(path)
def _save(self): global PlotGraphicsContext if PlotGraphicsContext==None: from chaco.plot_graphics_context import PlotGraphicsContext win_size = self.plot.outer_bounds plot_gc = PlotGraphicsContext(win_size)#, dpi=300) plot_gc.render_component(self.plot) plot_gc.save("image_test.png")
def save_plot(plot, filename): width, height = plot.outer_bounds plot.do_layout(force=True) gc = PlotGraphicsContext((width, height), dpi=72.0*2) gc.render_component(plot) gc.save(filename)
def save_plot(plot, filename): width, height = plot.outer_bounds plot.do_layout(force=True) gc = PlotGraphicsContext((width, height), dpi=72.0 * 2) gc.render_component(plot) gc.save(filename)
def _save_raster(self, dpi=300): """ Saves an image of the component.""" self.component.do_layout(force=True) # NOTE saving only works properly when dpi is a multiple of 72 gc = PlotGraphicsContext((int(self.component.outer_width), int(self.component.outer_height)), dpi=np.ceil(dpi / 72.0)*72) gc.render_component(self.component) gc.save(self.filename)
def _save_raster(self, dpi=300): """ Saves an image of the component.""" self.component.do_layout(force=True) # NOTE saving only works properly when dpi is a multiple of 72 gc = PlotGraphicsContext((int(self.component.outer_width), int(self.component.outer_height)), dpi=np.ceil(dpi / 72.0)*72) gc.render_component(self.component) gc.save(self.filename)
def _render_to_pic(self, filename): """ """ p = self.plotcontainer gc = PlotGraphicsContext((int(p.outer_width), int(p.outer_height))) # p.use_backbuffer = False gc.render_component(p) # p.use_backbuffer = True gc.save(filename)
def _render_to_pic(self, filename): """ """ p = self.plotcontainer gc = PlotGraphicsContext((int(p.outer_width), int(p.outer_height))) # p.use_backbuffer = False gc.render_component(p) # p.use_backbuffer = True gc.save(filename)
def _save_raster(self): """ Saves an image of the component. """ from chaco.plot_graphics_context import PlotGraphicsContext gc = PlotGraphicsContext((int(self.component.outer_width), int(self.component.outer_height))) self.component.draw(gc, mode="normal") gc.save(self.filename) return
def render_pic(self, obj, path): from chaco.plot_graphics_context import PlotGraphicsContext gc = PlotGraphicsContext((int(obj.outer_width), int(obj.outer_height))) # obj.use_backbuffer = False gc.render_component(obj) # obj.use_backbuffer = True if not path.endswith('.png'): path += '.png' gc.save(path)
def render_pic(self, obj, path): from chaco.plot_graphics_context import PlotGraphicsContext gc = PlotGraphicsContext((int(obj.outer_width), int(obj.outer_height))) # obj.use_backbuffer = False gc.render_component(obj) # obj.use_backbuffer = True if not path.endswith('.png'): path += '.png' gc.save(path)
def _save_LineScans_button_fired(self): dialog = FileDialog(default_filename = self.filename+"_LineScan_", action="save as", wildcard=self.file_wildcard2) dialog.open() if dialog.return_code == OK: savefiledir = dialog.directory savefilename = dialog.filename path = os.path.join(savefiledir, savefilename) self.LineScans.do_layout(force=True) plot_gc = PlotGraphicsContext(self.LineScans.outer_bounds) plot_gc.render_component(self.LineScans) plot_gc.save(path)
def save(self, path=None): print self.container.bounds if path is None: dlg = FileDialog(action='save as', default_directory=paths.data_dir) if dlg.open() == OK: path = dlg.path if path is not None: if not path.endswith('.png'): path = '{}.png'.format(path) c = self.container gc = PlotGraphicsContext((int(c.outer_width), int(c.outer_height))) # c.use_backbuffer = False gc.render_component(c) # c.use_backbuffer = True gc.save(path)
def _render_snapshot(self, path): c = self.canvas p = None was_visible = False if not self.render_with_markup: p = c.show_laser_position c.show_laser_position = False if self.points_programmer.is_visible: c.hide_all() was_visible = True gc = PlotGraphicsContext((int(c.outer_width), int(c.outer_height))) c.do_layout() gc.render_component(c) gc.save(path) if p is not None: c.show_laser_position = p if was_visible: c.show_all()
def _render_snapshot(self, path): c = self.canvas p = None was_visible = False if not self.render_with_markup: p = c.show_laser_position c.show_laser_position = False if self.points_programmer.is_visible: c.hide_all() was_visible = True gc = PlotGraphicsContext((int(c.outer_width), int(c.outer_height))) c.do_layout() gc.render_component(c) gc.save(path) if p is not None: c.show_laser_position = p if was_visible: c.show_all()
def _save_btn_fired(self): filter = 'PNG file (*.png)|*.png|\nTIFF file (*.tiff)|*.tiff|' dialog = FileDialog(action='save as', wildcard=filter) if dialog.open() != OK: return filename = dialog.path width, height = self.plot.outer_bounds gc = PlotGraphicsContext((width, height), dpi=100) gc.render_component(self.plot) try: gc.save(filename) except KeyError, e: errmsg = ("The filename must have an extension that matches " "a graphics format, such as '.png' or '.tiff'.") if str(e.message) != '': errmsg = ("Unknown filename extension: '%s'\n" % str(e.message)) + errmsg error(None, errmsg, title="Invalid Filename Extension")
def _save_btn_fired(self): filter = 'PNG file (*.png)|*.png|\nTIFF file (*.tiff)|*.tiff|' dialog = FileDialog(action='save as', wildcard=filter) if dialog.open() != OK: return filename = dialog.path width, height = self.plot.outer_bounds gc = PlotGraphicsContext((width, height), dpi=100) gc.render_component(self.plot) try: gc.save(filename) except KeyError, e: errmsg = ("The filename must have an extension that matches " "a graphics format, such as '.png' or '.tiff'.") if str(e.message) != '': errmsg = ("Unknown filename extension: '%s'\n" % str(e.message)) + errmsg error(None, errmsg, title="Invalid Filename Extension")