Esempio n. 1
0
    def do_execute_direct(self, code):
        if self._first:
            self._first = False
            self.handle_plot_settings()
            self._do_execute_direct(self._setup)

        self._skipping = os.name != 'nt'
        super(ScilabKernel, self).do_execute_direct(code, self.Print)
        if self.plot_settings.get('backend', None) == 'inline':
            plot_dir = tempfile.mkdtemp()
            self._make_figs(plot_dir)
            width, height = 0, 0
            for fname in os.listdir(plot_dir):
                filename = os.path.join(plot_dir, fname)
                try:
                    if fname.lower().endswith('.svg'):
                        im = SVG(filename)
                        if ',' in self.plot_settings['size']:
                            size = self.plot_settings['size']
                            width, height = size.split(',')
                            width, height = int(width), int(height)
                            im.data = self._fix_svg_size(im.data,
                                size=(width, height))
                    else:
                        im = Image(filename)
                    self.Display(im)
                except Exception as e:
                    self.Error(e)
Esempio n. 2
0
    def do_execute_direct(self, code):
        if self._first:
            self._first = False
            self.handle_plot_settings()
            self._do_execute_direct(self._setup)

        self._skipping = os.name != 'nt'
        super(ScilabKernel, self).do_execute_direct(code, self.Print)
        if self.plot_settings.get('backend', None) == 'inline':
            plot_dir = tempfile.mkdtemp()
            self._make_figs(plot_dir)
            width, height = 0, 0
            for fname in os.listdir(plot_dir):
                filename = os.path.join(plot_dir, fname)
                try:
                    if fname.lower().endswith('.svg'):
                        im = SVG(filename)
                        if ',' in self.plot_settings['size']:
                            size = self.plot_settings['size']
                            width, height = size.split(',')
                            width, height = int(width), int(height)
                            im.data = self._fix_svg_size(im.data,
                                                         size=(width, height))
                    else:
                        im = Image(filename)
                    self.Display(im)
                except Exception as e:
                    self.Error(e)
Esempio n. 3
0
 def _handle_svg(self, filename):
     """
     Handle special considerations for SVG images.
     """
     # Gnuplot can create invalid characters in SVG files.
     with codecs.open(filename, 'r', encoding='utf-8', errors='replace') as fid:
         data = fid.read()
     im = SVG(data=data)
     try:
         im.data = self._fix_svg_size(im.data)
     except Exception:
         pass
     return im
Esempio n. 4
0
 def _handle_svg(self, filename):
     """
     Handle special considerations for SVG images.
     """
     # Gnuplot can create invalid characters in SVG files.
     with codecs.open(filename, 'r', encoding='utf-8',
                      errors='replace') as fid:
         data = fid.read()
     im = SVG(data=data)
     try:
         im.data = self._fix_svg_size(im.data)
     except Exception:
         pass
     return im
Esempio n. 5
0
    def do_execute_direct(self, code):
        if self._first:
            self._first = False
            if sys.platform == "darwin":
                self.plot_settings["format"] = "svg"
            self.handle_plot_settings()
            super(OctaveKernel, self).do_execute_direct(self._setup)
            if os.name != "nt":
                msg = (
                    "may not be able to display plots properly "
                    "without gnuplot, please install it "
                    "(gnuplot-x11 on Linux)"
                )
                try:
                    subprocess.check_call(["gnuplot", "--version"])
                except subprocess.CalledProcessError:
                    self.Error(msg)

        resp = super(OctaveKernel, self).do_execute_direct(code)

        if self.plot_settings.get("backend", None) == "inline":
            plot_dir = tempfile.mkdtemp()
            self._make_figs(plot_dir)
            width, height = 0, 0
            for fname in os.listdir(plot_dir):
                filename = os.path.join(plot_dir, fname)
                try:
                    if fname.lower().endswith(".svg"):
                        im = SVG(filename)
                        if "," in self.plot_settings["size"]:
                            size = self.plot_settings["size"]
                            width, height = size.split(",")
                            width, height = int(width), int(height)
                            im.data = self._fix_gnuplot_svg_size(im.data, size=(width, height))
                    else:
                        im = Image(filename)
                    self.Display(im)
                except Exception as e:
                    self.Error(e)

        return resp or None
Esempio n. 6
0
    def do_execute_direct(self, code):
        if self._first:
            self._first = False
            self.handle_plot_settings()
            super(OctaveKernel, self).do_execute_direct(self._setup)
            if os.name != 'nt':
                msg = ('may not be able to display plots properly '
                       'without gnuplot, please install it '
                       '(gnuplot-x11 on Linux)')
                try:
                    subprocess.check_call(['gnuplot', '--version'])
                except subprocess.CalledProcessError:
                    self.Error(msg)

        super(OctaveKernel, self).do_execute_direct(code, self.Print)
        if self.plot_settings.get('backend', None) == 'inline':
            plot_dir = tempfile.mkdtemp()
            self._make_figs(plot_dir)
            width, height = 0, 0
            for fname in os.listdir(plot_dir):
                filename = os.path.join(plot_dir, fname)
                try:
                    if fname.lower().endswith('.svg'):
                        im = SVG(filename)
                        size = self.plot_settings['size']
                        if not (isinstance(size, tuple)):
                            size = 560, 420
                        width, height = size
                        width, height = int(width), int(height)
                        im.data = self._fix_gnuplot_svg_size(im.data,
                                                             size=(width,
                                                                   height))
                    else:
                        im = Image(filename)
                    self.Display(im)
                except Exception as e:
                    import traceback
                    traceback.print_exc(file=sys.__stderr__)
                    self.Error(e)
            shutil.rmtree(plot_dir, True)
Esempio n. 7
0
    def do_execute_direct(self, code):
        if self._first:
            self._first = False
            self.handle_plot_settings()
            super(OctaveKernel, self).do_execute_direct(self._setup)
            if os.name != 'nt':
                msg = ('may not be able to display plots properly '
                       'without gnuplot, please install it '
                       '(gnuplot-x11 on Linux)')
                try:
                    subprocess.check_call(['gnuplot', '--version'])
                except subprocess.CalledProcessError:
                    self.Error(msg)

        super(OctaveKernel, self).do_execute_direct(code, self.Print)
        if self.plot_settings.get('backend', None) == 'inline':
            plot_dir = tempfile.mkdtemp()
            self._make_figs(plot_dir)
            width, height = 0, 0
            for fname in os.listdir(plot_dir):
                filename = os.path.join(plot_dir, fname)
                try:
                    if fname.lower().endswith('.svg'):
                        im = SVG(filename)
                        size = self.plot_settings['size']
                        if not (isinstance(size, tuple)):
                            size = 560, 420
                        width, height = size
                        width, height = int(width), int(height)
                        im.data = self._fix_gnuplot_svg_size(im.data,
                            size=(width, height))
                    else:
                        im = Image(filename)
                    self.Display(im)
                except Exception as e:
                    import traceback
                    traceback.print_exc(file=sys.__stderr__)
                    self.Error(e)