Ejemplo n.º 1
0
    def __init__(self, gks_state_list, data, n):
        if n >= 250:
            print("Maximum number of HTML output files reached")
            sys.exit(0)
        if n > 1:
            self.filename = 'gks-%d.html' % (n)
        else:
            self.filename = 'gks.html'
        self.title = 'GKS'
        self.gkss = gks_state_list
        self.p = ws_state_list()
        self.file = open(self.filename, 'w')
        self.p.width = 500
        self.p.height = 500
        self.p.window = [0.0, 1.0, 0.0, 1.0]
        self.p.viewport = [
            self.p.width * MWIDTH / WIDTH, 0., self.p.height * MHEIGHT / HEIGHT
        ]
        self.p.rgb = [[] for i in range(MAX_COLOR)]
        self.p.dashes = []
        self.indentation = 0
        self.p.rect = [() for i in range(MAX_TNR)]
        self.p.clip_rect = ()
        self.transparency = 1.0

        self.set_xform()
        self.init_norm_xform()
        self.init_colors()

        if not self.file:
            print("Can't open HTML output file")

        self.write('<!DOCTYPE html>\n')
        self.write('<html>\n')
        self.write('  <head>\n')
        self.write('    <meta charset="utf-8" />\n')
        self.write('    <title>{0}</title>\n'.format(self.title))
        self.write('  </head>\n')
        self.write('  <script src="modernizr.js"></script>\n')
        self.write('  <body>\n')
        self.write(
            '    <canvas id="html-canvas" width="{0}" height="{1}" tabindex="1" style="outline-style:none;"></canvas>\n'
            .format(self.p.width, self.p.height))
        self.write('\n')
        self.write('<script src="gks.js"></script>\n')
        self.write('<script type="text/javascript">\n')
        self.indentation = 1
        self.init_canvas()

        gks.set_fill_callback(self.fill_routine)
        gks.set_line_callback(self.line_routine)

        self.write('base_width = canvas.width;\n')
        self.write('base_height = canvas.height;\n')

        self.write('function draw() {\n')

        self.footer = '''  }
  draw();
</script>
<div id="buttons"></div>
<script>
    if (Modernizr.touch) {
        var container = document.getElementById("buttons");
            container.innerHTML = "<table border='0'><tr><td><button onclick='zoom_in();'>Zoom In</button></td><td><button onclick='zoom_out();'>Zoom Out</button></td><td><button onclick='reset_zoom();'>Reset</button></td></tr></table>";
        }
</script>
</body>
</html>
'''
        for d in data:
            getattr(self, d[0])(*d[1])

        self.file.write(self.footer)
        self.file.close()
Ejemplo n.º 2
0
Archivo: html5.py Proyecto: vleo/gr
    def __init__(self, gks_state_list, data, n):
        if n >= 250:
            print("Maximum number of HTML output files reached")
            sys.exit(0)
        if n > 1:
            self.filename = 'gks-%d.html' % (n)
        else:
            self.filename = 'gks.html'
        self.title = 'GKS'
        self.gkss = gks_state_list
        self.p = ws_state_list()
        self.file = open(self.filename, 'w')
        self.p.width = 500
        self.p.height = 500
        self.p.window = [0.0, 1.0, 0.0, 1.0]
        self.p.viewport = [self.p.width * MWIDTH / WIDTH, 0.,
                           self.p.height * MHEIGHT / HEIGHT]
        self.p.rgb = [[] for i in range(MAX_COLOR)]
        self.p.dashes = []
        self.indentation = 0
        self.p.rect = [() for i in range(MAX_TNR)]
        self.p.clip_rect = ()
        self.transparency = 1.0

        self.set_xform()
        self.init_norm_xform()
        self.init_colors()

        if not self.file:
            print("Can't open HTML output file")

        self.write('<!DOCTYPE html>\n')
        self.write('<html>\n')
        self.write('  <head>\n')
        self.write('    <meta charset="utf-8" />\n')
        self.write('    <title>{0}</title>\n'.format(self.title))
        self.write('  </head>\n')
        self.write('  <script src="modernizr.js"></script>\n')
        self.write('  <body>\n')
        self.write(
            '    <canvas id="html-canvas" width="{0}" height="{1}" tabindex="1" style="outline-style:none;"></canvas>\n'.format(
                self.p.width, self.p.height))
        self.write('\n')
        self.write('<script src="gks.js"></script>\n')
        self.write('<script type="text/javascript">\n')
        self.indentation = 1
        self.init_canvas()

        gks.set_fill_callback(self.fill_routine)
        gks.set_line_callback(self.line_routine)

        self.write('base_width = canvas.width;\n')
        self.write('base_height = canvas.height;\n')

        self.write('function draw() {\n')

        self.footer = '''  }
  draw();
</script>
<div id="buttons"></div>
<script>
    if (Modernizr.touch) {
        var container = document.getElementById("buttons");
            container.innerHTML = "<table border='0'><tr><td><button onclick='zoom_in();'>Zoom In</button></td><td><button onclick='zoom_out();'>Zoom Out</button></td><td><button onclick='reset_zoom();'>Reset</button></td></tr></table>";
        }
</script>
</body>
</html>
'''
        for d in data:
            getattr(self, d[0])(*d[1])

        self.file.write(self.footer)
        self.file.close()