Exemple #1
0
def convert_cml2png(formula, output): 
    space = SpaceMock()
    batch = pyglet.graphics.Batch()
    img = Molecule(formula, space, batch, pos=(32,32), render_only=True)
    w, h, _ = img.cml.max_pos()
    width = int(w*64) + 64
    height = int(h*64) + 64
    config = gl.Config(double_buffer=True)
    window = pyglet.window.Window(width=width,height=height,visible=True,config=config)
    window.minimize()
    gl.glClearColor(250/256.0, 250/256.0, 250/256.0, 0)
    gl.glLineWidth(4)
    gl.glHint(gl.GL_LINE_SMOOTH_HINT, gl.GL_NICEST)
    img.update()
    @window.event
    def on_draw():
        window.clear()
        batch.draw()
        pyglet.image.get_buffer_manager().get_color_buffer().save(output)
        window.close()
        pyglet.app.exit()
    pyglet.app.run()