示例#1
0
    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()
示例#2
0
    def _render_snapshot(self, path):
        from chaco.plot_graphics_context import PlotGraphicsContext

        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)
        from pychron.core.helpers import save_gc
        save_gc.save(gc, path)

        if p is not None:
            c.show_laser_position = p

        if was_visible:
            c.show_all()
示例#3
0
    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)
示例#4
0
    def _render_snapshot(self, path):
        from chaco.plot_graphics_context import PlotGraphicsContext

        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)
        from pychron.core.helpers import save_gc
        save_gc.save(gc, path)

        if p is not None:
            c.show_laser_position = p

        if was_visible:
            c.show_all()
示例#5
0
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)
示例#6
0
文件: graph.py 项目: jirhiker/pychron
 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)
示例#7
0
 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
示例#8
0
 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)
示例#9
0
    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)
示例#10
0
    def save_file(self, path, force_layout=True):
        _, 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 
        '''
        c.do_layout(size=letter, force=force_layout)

        _, tail = os.path.splitext(path)
        if tail == '.pdf':
            from chaco.pdf_graphics_context import PdfPlotGraphicsContext

            gc = PdfPlotGraphicsContext(filename=path)
            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)

        self.rebuild_graph()
示例#11
0
    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)
示例#12
0
    def perform(self, event):
        plot_component = self.container.component

        # Remove the toolbar before saving the plot, so the output doesn't
        # include the toolbar.
        plot_component.remove_toolbar()

        width, height = plot_component.outer_bounds

        gc = PlotGraphicsContext((width, height), dpi=72)
        gc.render_component(plot_component)

        if ETSConfig.toolkit == 'wx':
            self._perform_wx(width, height, gc)
        else:
            pass

        # Restore the toolbar.
        plot_component.add_toolbar()
示例#13
0
    def perform(self, event):
        plot_component = self.container.component

        # Remove the toolbar before saving the plot, so the output doesn't
        # include the toolbar.
        plot_component.remove_toolbar()

        width, height = plot_component.outer_bounds

        gc = PlotGraphicsContext((width, height), dpi=72)
        gc.render_component(plot_component)

        if ETSConfig.toolkit == 'wx':
            self._perform_wx(width, height, gc)
        else:
            pass

        # Restore the toolbar.
        plot_component.add_toolbar()
示例#14
0
def save(filename="chacoplot.png",
         dpi=72,
         pagesize="letter",
         dest_box=None,
         units="inch"):
    """ Saves the active plot to an file.  Currently supported file types
    are: bmp, png, jpg.
    """
    p = curplot()
    if not p:
        print("Doing nothing because there is no active plot.")
        return

    import os.path
    ext = os.path.splitext(filename)[-1]
    if ext == ".pdf":
        print("Warning: the PDF backend is still a little buggy.")
        from chaco.pdf_graphics_context import PdfPlotGraphicsContext
        # Set some default PDF options if none are provided
        if dest_box is None:
            dest_box = (0.5, 0.5, -0.5, -0.5)
        gc = PdfPlotGraphicsContext(filename=filename,
                                    pagesize=pagesize,
                                    dest_box=dest_box,
                                    dest_box_units=units)

        # temporarily turn off the backbuffer for offscreen rendering
        use_backbuffer = p.use_backbuffer
        p.use_backbuffer = False
        gc.render_component(p)
        p.use_backbuffer = use_backbuffer

        gc.save()
        del gc
        print("Saved to", filename)

    elif ext in [".bmp", ".png", ".jpg"]:
        from chaco.plot_graphics_context import PlotGraphicsContext
        gc = PlotGraphicsContext(tuple(p.outer_bounds), dpi=dpi)

        # temporarily turn off the backbuffer for offscreen rendering
        use_backbuffer = p.use_backbuffer
        p.use_backbuffer = False
        gc.render_component(p)
        p.use_backbuffer = use_backbuffer

        gc.save(filename)
        del gc
        print("Saved to", filename)
    else:
        print("Format not yet supported:", ext)
        print("Currently supported formats are: bmp, png, jpg.")
    return
示例#15
0
    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()
示例#16
0
    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()
示例#17
0
    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)
示例#18
0
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)
示例#19
0
 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")
示例#20
0
文件: graph.py 项目: sgallet/pychron
 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)
示例#21
0
 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)
示例#22
0
文件: plot_mod.py 项目: ftilmann/miic
    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")
示例#23
0
    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)
示例#24
0
 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)
示例#25
0
    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:
            _, tail = os.path.splitext(path)
            c = self.container
            if tail == '.pdf':
                from chaco.pdf_graphics_context import PdfPlotGraphicsContext

                gc = PdfPlotGraphicsContext(filename=path, pagesize='letter')

            else:
                if not tail in ('.png', '.jpg', '.tiff'):
                    path = '{}.png'.format(path)

                gc = PlotGraphicsContext(
                    (int(c.outer_width), int(c.outer_height)))
                #            c.use_backbuffer = False

            # for ci in c.components:
            #     try:
            #         ci.x_axis.visible = False
            #         ci.y_axis.visible = False
            #     except Exception:
            #         pass

            # c.use_backbuffer = False

            gc.render_component(c)
            #            c.use_backbuffer = True
            gc.save(path)
            self._name = os.path.basename(path)
示例#26
0
    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()
示例#27
0
    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")
示例#28
0
 def _get_height(self):
     gc = PlotGraphicsContext((100, 100), dpi=72)
     gc.set_font(self.label_font)
     (w, h, descent, leading) = gc.get_full_text_extent(self.label)
     return self._image.height() + h
示例#29
0
 def _get_width(self):
     gc = PlotGraphicsContext((100, 100), dpi=72)
     gc.set_font(self.label_font)
     (w, h, descent, leading) = gc.get_full_text_extent(self.label)
     return max(self._image.width(), w)
示例#30
0
 def _get_height(self):
     gc = PlotGraphicsContext((100, 100), dpi=72)
     gc.set_font(self.label_font)
     (w, h, descent, leading) = gc.get_full_text_extent(self.label)
     return self._image.height() + h
示例#31
0
 def _get_width(self):
     gc = PlotGraphicsContext((100, 100), dpi=72)
     gc.set_font(self.label_font)
     (w, h, descent, leading) = gc.get_full_text_extent(self.label)
     return max(self._image.width(), w)