kivy/kivy — pull request #1996 by Nykakin (2014-03-21 14:48:06+00:00)
Title: created method flip_horizontal() for kivy.graphics.texture.Texture

Backing issue https://github.com/kivy/kivy/issues/944

Tested with code:

#!/usr/bin/python
# -*- coding: utf-8 -*-

from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.widget import Widget
from kivy.graphics import Rectangle
from kivy.graphics.texture import Texture

class TestWidget(Widget):
def __init__(self, **kwargs):
super(TestWidget, self).__init__(**kwargs)

# create a 64x64 texture, default to rgb / ubyte
texture = Texture.create(size=(64, 64))

# create 64x64 rgb tab, and fill with value from 0 to 255
# we'll have a gradient from black to white
size = 64 * 64 * 3
buf = [x for y in xrange(64) for x in xrange(size/64) ]

# then, convert the array to a ubyte string
buf = ''.join(map(chr, buf))

# then blit the buffer
texture.blit_buffer(buf, colorfmt='rgb', bufferfmt='ubyte')

with self.canvas:
Rectangle(texture=texture, pos=(0, 0), size=(64, 64))

texture.flip_horizontal()

with self.canvas:
Rectangle(texture=texture, pos=(64, 0), size=(64, 64))

class MyApp(App):
def build(self):
root = GridLayout(cols=2, padding=50, spacing=50)
root.add_widget(TestWidget())
return root

if __name__ == '__main__':
MyApp().run()