mcarrara3
Apr 30, 2015 - 23:06
Hello,
I have a simple view with a button and a subview where I want to draw. I want that the drawing happens when I press the button. I set up the following code
# coding: utf-8
import ui
class DrawView (ui.View):
def __init__(self):
self.path = ui.Path()
def draw(self):
if self.path:
self.path.stroke()
def showDrawing(sender):
v = sender.superview
v['secondView'].path = ui.Path()
v['secondView'].path.move_to(20,20)
v['secondView'].path.line_to(400,400)
v['secondView'].path.line_width = 5
# Global View
h, v = ui.get_screen_size()
myView = ui.View()
myView.background_color = 'red'
myView.present('full_screen',hide_title_bar=True)
# Adding Button
myButton = ui.Button()
myButton.frame = (50,50,v/3,100)
myButton.title = 'Show Mesh'
myButton.background_color = 'white'
myButton.action = showDrawing
myView.add_subview(myButton)
# Adding Draw View
drawView = DrawView()
drawView.name='secondView'
drawView.frame = (h/2,50,v/3,800)
drawView.background_color = 'pink'
#drawView.path = ui.Path()
#drawView.path.move_to(20,20)
#drawView.path.line_to(400,400)
#drawView.path.line_width = 5
#drawView.path.stroke()
myView.add_subview(drawView)
but nothing happens if I handle the paths inside the action linked to the button. Any hint? Thank you in advance!