Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

AlexAndDraw Feb 24th, 2018 83 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. from kivy.app import App
  2. from kivy.uix.button import Button
  3. from kivy.uix.boxlayout import BoxLayout
  4. from kivy.core.image import Image
  5. from kivy.uix.gridlayout import GridLayout
  6. from kivy.graphics.fbo import Fbo
  7. from kivy.graphics.texture import Texture
  8. from functools import partial
  9. from kivy.uix.widget import Widget
  10. from kivy.graphics.opengl import glReadPixels,GL_RGBA, GL_UNSIGNED_BYTE
  11. from kivy.graphics import *
  12.  
  13. class Guardar(Widget):
  14.  
  15.     def guardar_canvas2(self,widget):
  16.         if widget.parent is not None:
  17.             canvas_parent_index = widget.parent.canvas.indexof(widget.canvas)
  18.             if canvas_parent_index > -1:
  19.                 widget.parent.canvas.remove(widget.canvas)
  20.  
  21.         fbo = Fbo(size=widget.size, with_stencilbuffer=True)
  22.  
  23.         with fbo:
  24.             ClearColor(0, 0, 0, 1)
  25.             ClearBuffers()
  26.             Scale(1, -1, 1)
  27.             Translate(-widget.x, -widget.y - widget.height, 0)
  28.  
  29.         fbo.add(widget.canvas)
  30.         fbo.draw()
  31.         fbo.texture.save("gidhup.png", flipped=False)
  32.         fbo.remove(widget.canvas)
  33.  
  34.         if widget.parent is not None and canvas_parent_index > -1:
  35.             widget.parent.canvas.insert(canvas_parent_index, widget.canvas)
  36.  
  37.         return True
  38.  
  39. class TestApp(App):
  40.  
  41.     def guardar(self,ins,*args):
  42.         Guardar().guardar_canvas2(ins)
  43.  
  44.     def build(self):
  45.         self.bx=BoxLayout(orientation="vertical")
  46.         self.bx2=BoxLayout()
  47.         self.gl=GridLayout(cols=5,rows=5)
  48.         for i in range(25):
  49.             self.gl.add_widget(Button(text=str(i)))
  50.         btn=Button(on_release=partial(self.guardar, self.bx2),text='Save canvas :)')
  51.         self.bx2.add_widget(self.gl)
  52.         self.bx.add_widget(self.bx2)
  53.         self.bx.add_widget(btn)
  54.         return self.bx
  55.  
  56. TestApp().run()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top