Hi chaps,
I'm still playing around with buttons for my codeword app. Struggling now with changing the view from one view to another. How is it done please or have I got the wrong end of the stick here?
The idea is to firstly select which cells are black. Click done. Then selecting a white cell should present my second class as a view to choose number values from a grid. Trouble is the grid becomes too small when I call it from anywhere but the line not indented!
import console, ui, time
crossword_rows = 4
crossword_cols = crossword_rows
gap = 1
tupWhite = tuple([1.0,1.0,1.0,1.0]) # white values
tupBlack = tuple([1.0,1.0,1.0,1.0]) # black
status = 1
def button_tapped1(square):
global status
#print 'status = '+ str(status)
#tup = tuple([1.0,1.0,1.0,1.0]) # white values
if status==1:
#print 'status = '+ str(status)
if str(tupWhite) == str(square.bg_color):
square.bg_color = 'black'
else:
square.bg_color = 'white'
elif status==2:
#button_tapped2()
edit_cell_number(square)
print 'step 2'
#pass
def button_tapped2(button):
#add square number
global status
#print 'status = '+ str(status)
status = 2
button.title = 'Colours set.'
#print 'status = '+ str(status)
#pass
def button_tapped3(self, square):
pass
def edit_cell_number(square):
#cyvle through 1 - 26 for cell number
if str(tupWhite) == str(square.bg_color):
#square.title = str(26)
#NumberSelectionGrid()
pass
class CrosswordView(ui.View):
def __init__(self):
self.present(hide_title_bar=False )
self.background_color = (0, 1.0, 2.0, 0.4)
min_dimension = min(self.width / crossword_cols, self.height / crossword_rows)
#self.squares = []
for i in xrange(crossword_cols):
x = i * min_dimension
for j in xrange(crossword_rows):
time.sleep(.05)
y = j * min_dimension
square = ui.Button(frame = (x, y, min_dimension-gap, min_dimension-gap))
#square.alignment = #ui.ALIGN_CENTER
square.bg_color = 'white'
#square.title = 'X'
self.add_subview(square)
square.action = button_tapped1
#button = ui.Button(frame = (x-150, y+80, min_dimension*2, min_dimension*2))
button = ui.Button(frame = (0,0, min_dimension*4, min_dimension*2))
self.add_subview(button)
button.title = 'Done'
button.background_color = 'white'
button.center = (self.width * 0.5, self.height -50)
button.flex = 'LRTB'
button.action = button_tapped2
#print 'another visit'
class NumberSelectionGrid(ui.View):
def __init__(self):
self.present(hide_title_bar=False )
self.background_color = (0, 1.0, 2.0, 0.4)
min_dimension = min(self.width / 5, self.height / 6)
#self.squares = []
squareNumber = 1
for i in xrange(5):
x = i * min_dimension
for j in xrange(6):
#time.sleep(.05)
y = j * min_dimension
square = ui.Button(frame = (x, y, min_dimension-gap, min_dimension-gap))
#square.alignment = #ui.ALIGN_CENTER
square.bg_color = 'white'
square.title = str(squareNumber)
self.add_subview(square)
squareNumber = squareNumber +1
square.action = button_tapped3
CrosswordView()
NumberSelectionGrid()
#NumberSelectionGridd().present(hide_title_bar=False)
#NumberSelectionGrid().send_to_back()
#print 'status = '+ str(status)