예제 #1
0
 def new_files(root="./"):
     import os
     import sys
     new_files = []
     for top, dirs, files in os.walk(root):
         for dir in dirs:
             if dir.endswith(".jmol"):
                 dirs.remove(dir)
         for name in files:
             path = os.path.join(top, name)
             if path.startswith("./"):
                 path = path[2:]
             mtime = os.stat(path).st_mtime
             if (path == "sagemathcell.py"
                 or path in sys._sage_.sent_files
                 and sys._sage_.sent_files[path] >= mtime):
                 continue
             if (path.startswith("Rplot")
                 and path[-4:] in [".bmp", "jpeg", ".png", ".svg"]):
                 misc.display_file(path, "text/image-filename")
                 continue
             if path == "octave.png":
                 misc.display_file(path, "text/image-filename")
                 continue
             new_files.append(path)
             sys._sage_.sent_files[path] = mtime
     ip = user_ns["get_ipython"]()
     ip.payload_manager.write_payload({"new_files": new_files})
     return ""
예제 #2
0
 def new_files(root="./"):
     import os
     import sys
     new_files = []
     for top, dirs, files in os.walk(root):
         for dir in dirs:
             if dir.endswith(".jmol"):
                 dirs.remove(dir)
         for name in files:
             path = os.path.join(top, name)
             if path.startswith("./"):
                 path = path[2:]
             mtime = os.stat(path).st_mtime
             if (path == "sagemathcell.py" or path in sys._sage_.sent_files
                     and sys._sage_.sent_files[path] >= mtime):
                 continue
             if (path.startswith("Rplot")
                     and path[-4:] in [".bmp", "jpeg", ".png", ".svg"]):
                 misc.display_file(path, "text/image-filename")
                 continue
             if path == "octave.png":
                 misc.display_file(path, "text/image-filename")
                 continue
             new_files.append(path)
             sys._sage_.sent_files[path] = mtime
     ip = user_ns["get_ipython"]()
     ip.payload_manager.write_payload({"new_files": new_files})
     return ""
예제 #3
0
파일: receiver.py 프로젝트: nw0awu/sagecell
 def new_files(root='./'):
     import os
     import sys
     new_files = []
     for top, dirs, files in os.walk(root):
         for dir in dirs:
             if dir.endswith(".jmol"):
                 dirs.remove(dir)
         for name in files:
             path = os.path.join(top, name)
             if path.startswith('./'):
                 path = path[2:]
             mtime = os.stat(path).st_mtime
             if (path == "sagemathcell.py"
                     or path in sys._sage_.sent_files
                     and sys._sage_.sent_files[path] >= mtime):
                 continue
             if (path.startswith('Rplot')
                     and path[-4:] in ['.bmp', 'jpeg', '.png', '.svg']):
                 display_file(path, 'text/image-filename')
                 continue
             new_files.append(path)
             sys._sage_.sent_files[path] = mtime
     ip = user_ns['get_ipython']()
     ip.payload_manager.write_payload({"new_files": new_files})
     return ''
예제 #4
0
    def display_immediately(self, plain_text, rich_output):
        """
        Show output immediately.

        This method is similar to the rich output :meth:`displayhook`,
        except that it can be invoked at any time.

        INPUT:

        Same as :meth:`displayhook`.

        EXAMPLES::

            sage: from sage.repl.rich_output.output_basic import OutputPlainText
            sage: plain_text = OutputPlainText.example()
            sage: from sage.repl.rich_output.backend_cell import BackendCell
            sage: backend = BackendCell()
            sage: _ = backend.display_immediately(plain_text, plain_text)
            Example plain text output
        """
        if isinstance(rich_output, OutputPlainText):
            return {u'text/plain': rich_output.text.get_unicode()}, {}
        if isinstance(rich_output, OutputAsciiArt):
            return {u'text/plain': rich_output.ascii_art.get_unicode()}, {}

        if isinstance(rich_output, OutputLatex):
            display_html(rich_output.mathjax())
        elif isinstance(rich_output, OutputHtml):
            display_html(rich_output.html.get_unicode())

        elif isinstance(rich_output, OutputImageGif):
            display_file(rich_output.gif.filename(), 'text/image-filename')
        elif isinstance(rich_output, OutputImageJpg):
            display_file(rich_output.jpg.filename(), 'text/image-filename')
        elif isinstance(rich_output, OutputImagePdf):
            display_file(rich_output.pdf.filename(), 'text/image-filename')
        elif isinstance(rich_output, OutputImagePng):
            display_file(rich_output.png.filename(), 'text/image-filename')
        elif isinstance(rich_output, OutputImageSvg):
            display_file(rich_output.svg.filename(), 'text/image-filename')

        elif isinstance(rich_output, OutputSceneJmol):
            path = tempfile.mkdtemp(suffix=".jmol", dir=".")
            os.chmod(path, stat.S_IRWXU + stat.S_IXGRP + stat.S_IXOTH)
            rich_output.scene_zip.save_as(os.path.join(path, 'scene.zip'))
            rich_output.preview_png.save_as(os.path.join(path, 'preview.png'))
            display_message({
                'text/plain': 'application/x-jmol file',
                'application/x-jmol': path
            })
        elif isinstance(rich_output, OutputSceneThreejs):
            path = tempfile.mkstemp(suffix='.html', dir='.')[1]
            path = os.path.relpath(path)
            rich_output.html.save_as(path)
            os.chmod(path, stat.S_IRUSR + stat.S_IRGRP + stat.S_IROTH)
            display_html("""
                <iframe
                    scrolling="no"
                    src="cell://{}"
                    style="
                        border: 1px silver solid;
                        height: 500px;
                        min-width: 500px;
                        width: 75%;
                        "
                    >
                </iframe>
                """.format(path))
            sys._sage_.sent_files[path] = os.path.getmtime(path)

        else:
            raise TypeError(
                'rich_output type not supported, got {0}'.format(rich_output))
        return {u'text/plain': None}, {}
예제 #5
0
    def display_immediately(self, plain_text, rich_output):
        """
        Show output immediately.

        This method is similar to the rich output :meth:`displayhook`,
        except that it can be invoked at any time.

        INPUT:

        Same as :meth:`displayhook`.

        EXAMPLES::

            sage: from sage.repl.rich_output.output_basic import OutputPlainText
            sage: plain_text = OutputPlainText.example()
            sage: from sage.repl.rich_output.backend_cell import BackendCell
            sage: backend = BackendCell()
            sage: _ = backend.display_immediately(plain_text, plain_text)
            Example plain text output
        """
        if isinstance(rich_output, OutputPlainText):
            return {u'text/plain': rich_output.text.get()}, {}
        if isinstance(rich_output, OutputAsciiArt):
            return {u'text/plain': rich_output.ascii_art.get()}, {}

        if isinstance(rich_output, OutputLatex):
            display_html(rich_output.mathjax())
        elif isinstance(rich_output, OutputHtml):
            display_html(rich_output.html.get())

        elif isinstance(rich_output, OutputImageGif):
            display_file(rich_output.gif.filename(), 'text/image-filename')
        elif isinstance(rich_output, OutputImageJpg):
            display_file(rich_output.jpg.filename(), 'text/image-filename')
        elif isinstance(rich_output, OutputImagePdf):
            display_file(rich_output.pdf.filename(), 'text/image-filename')
        elif isinstance(rich_output, OutputImagePng):
            display_file(rich_output.png.filename(), 'text/image-filename')
        elif isinstance(rich_output, OutputImageSvg):
            display_file(rich_output.svg.filename(), 'text/image-filename')
            
        elif isinstance(rich_output, OutputSceneCanvas3d):
            display_file(
                rich_output.canvas3d.filename(), 'application/x-canvas3d')
        elif isinstance(rich_output, OutputSceneJmol):
            path = tempfile.mkdtemp(suffix=".jmol", dir=".")
            os.chmod(path, stat.S_IRWXU + stat.S_IXGRP + stat.S_IXOTH)
            rich_output.scene_zip.save_as(os.path.join(path, 'scene.zip'))
            rich_output.preview_png.save_as(os.path.join(path, 'preview.png'))
            display_message({'text/plain': 'application/x-jmol file',
                             'application/x-jmol': path})
        elif isinstance(rich_output, OutputSceneThreejs):
            path = tempfile.mkstemp(suffix='.html', dir='.')[1]
            path = os.path.relpath(path)
            rich_output.html.save_as(path)
            os.chmod(path, stat.S_IRUSR + stat.S_IRGRP + stat.S_IROTH)
            display_html("""
                <iframe
                    scrolling="no"
                    src="cell://{}"
                    style="
                        border: 1px silver solid;
                        height: 500px;
                        min-width: 500px;
                        width: 75%;
                        "
                    >
                </iframe>
                """.format(path))
            sys._sage_.sent_files[path] = os.path.getmtime(path)
            
        else:
            raise TypeError('rich_output type not supported, got {0}'.format(rich_output))
        return {u'text/plain': None}, {}