Just a class that draws a grid. _COLS & _ROWS determine the grid size. Also in the init function where the buttons are created have a var __USE_COPY. if True is consistently , 80, 90% faster on my iPad Air 2.
import ui
import copy
import time
_ROWS = 16
_COLS = 16
# class, just to draw a grid of button, also
# should rotate.
class grid(ui.View):
def __init__(self):
self.btns = []
# just create the buttons rows * columns
__USE_COPY = False
if not __USE_COPY:
start = time.time()
for i in range((_COLS * _ROWS) ):
btn = ui.Button(title = str(i))
btn.action = self.hit_test
self.btns.append(btn)
self.add_subview(btn)
finish = time.time()
else:
start = time.time()
btn = ui.Button()
for i in range((_COLS * _ROWS) ):
new_btn = copy.copy(btn)
new_btn.title = str(i)
new_btn.action = self.hit_test
self.btns.append(new_btn)
self.add_subview(new_btn)
finish = time.time()
print finish - start
self.style()
def style(self):
self.background_color = 'white'
for btn in self.btns:
btn.background_color = 'red'
btn.tint_color = 'white'
btn.border_width = .5
def layout(self):
if self.superview:
self.frame = superview.bounds
w,h = self.width / _COLS, self.height / _ROWS
x = y = 0
for btn in self.btns:
btn.width, btn.height = w,h
btn.x, btn.y = x * w, y * h
x += 1
if not x % _COLS :
x = 0
y += 1
def hit_test(self, sender):
print 'hit - ', sender.title
if __name__ == '__main__':
x = grid().present('')