r4509 - developers/erin_yueh/pythonEFL-sudoku/src
erin_yueh at docs.openmoko.org
erin_yueh at docs.openmoko.org
Mon Jul 7 12:40:03 CEST 2008
Author: erin_yueh
Date: 2008-07-07 12:40:01 +0200 (Mon, 07 Jul 2008)
New Revision: 4509
Modified:
developers/erin_yueh/pythonEFL-sudoku/src/sudoku_ui.py
Log:
add number keyboard, clear callback, button clicked callback (Erin Yueh)
Modified: developers/erin_yueh/pythonEFL-sudoku/src/sudoku_ui.py
===================================================================
--- developers/erin_yueh/pythonEFL-sudoku/src/sudoku_ui.py 2008-07-07 08:08:58 UTC (rev 4508)
+++ developers/erin_yueh/pythonEFL-sudoku/src/sudoku_ui.py 2008-07-07 10:40:01 UTC (rev 4509)
@@ -9,26 +9,88 @@
WINDOW_WIDTH = 455
WINDOW_HEIGHT = 640
-def button_cb(zoom_in, emission, source):
- print 'emission,source:',emission,source
+def checkRow(row,value):
+ isOK = True
+ return isOK
+
+def checkLine(line,value):
+ isOK = True
+
+ return isOK
+
+def checkGroup(group,value):
+ isOK = True
+
+ return isOK
+
+def analyze(button,value):
+ isOK = False
+ puzzle = ee.data["puzzle"]
+ # button40 2
+ addr = button[6:]
+ print addr, value
+ i = int(addr) / 9
+ j = int(addr) % 9
+ g = (i/3)*3 + (j/3)
+ print i,j,g
+ if not(checkRow(i,value) or checkLine(j,value) or checkGroup(g,value)):
+ isOK = True
+ return isOK
+
+def number_key_cb(zoom_in, emission, source):
+ print 'number_key_cb emission,source:',emission,source
+
+ if(source == 'clear'):
+ puzzle = ee.data["puzzle"]
+ for i in xrange (9):
+ for j in xrange(9):
+ value = puzzle[i][j]
+ addr = i + j *9
+ text_data = "button" + str(addr)
+ text = ee.data[text_data]
+ text.data["value"] = value
+ text.text_set(str(value))
+ if(value>0):
+ text.color_set(10,10,10,200)
+ elif(value==0):
+ text.color_set(0,255,255,255)
+ print 'clear all data!!'
+ elif(source =='undo' or source == 'redo'):
+ print 'undo or redo'
+ elif(source == 'solve'):
+ print 'solve'
+ else:
+ # fill in key number
+ if(ee.data["clicking"]):
+ text = ee.data[ee.data["clicking"]]
+ text.text_set(source)
+ text.data["value"] = int(source)
+ if(analyze(ee.data["clicking"],source) == False):
+ text.color_set(255,0,0,255)
+ else:
+ text.color_set(255,255,255,255)
return True
+def puzzle_key_cb(zoom_in, emission, source):
+ print 'puzzle_key_cb emission,source:',emission,source
-def puzzle_but_number_cb(zoom_in, emission, source):
- print 'emission,source:',emission,source
+ text = ee.data[source]
+ if(int(text.data["value"]) ==0 ):
+ text.color_set(255,255,255,255)
+ ee.data["clicking"] = source
return True
-
+
def get_puzzle():
-
+
file_name = "/usr/share/sudoku/puzzle/1000"
fIn = open(file_name, 'r')
fIn.seek(82*(random.randint(1, 1000)))
l = fIn.readline()
-
+
if (len(l) != 82):
- print "xxx"
+ print "the puzzle is wrong!!"
p = []
for i in xrange(9):
@@ -36,10 +98,9 @@
for j in xrange(9):
t.append(int(l[i * 9 + j]))
p.append(t)
-
-
+
return p
-
+
def main():
global ee
@@ -58,38 +119,40 @@
# create puzzle and icons
area = edje.Edje(canvas, file="/usr/share/sudoku/sudoku.edj", group="pythonEFL-sudoku/panel")
+ area.signal_callback_add("mouse,clicked,*", "*", number_key_cb)
area.pos = (0, 0)
area.size = canvas.size
area.show()
area.data["area"] = area
- # set a signal callback for all buttons
- area.signal_callback_add("mouse,clicked,*", "*", button_cb)
# create puzzle and icons
board = edje.Edje(canvas, file="/usr/share/sudoku/sudoku.edj", group="pythonEFL-sudoku/board")
- board.signal_callback_add("mouse,clicked,*", "*", puzzle_but_number_cb)
+ board.signal_callback_add("mouse,clicked,*", "*", puzzle_key_cb)
board.pos = (0, 0)
- #test.size = canvas.size
board.show()
puzzle = get_puzzle()
+ ee.data["puzzle"] = puzzle
print puzzle
- element_w = 480 / 9
- element_h = 480 / 9
+ element_w = 455 / 9
+ element_h = 455 / 9
# put all elements to Text objects
for i in xrange (9):
for j in xrange(9):
- x = 5 + (element_w * (i))
- y = 5 + (element_h * (j))
+ x = 15 + (element_w * (i))
+ y = 15 + (element_h * (j))
#print i,j
value = puzzle[i][j]
display = str(value)
- addr = i*9 + j
+ addr = i + j *9
text = canvas.Text(text=display, font=("sans serif", 16), color=(0,255,255,255))
#print i,j,x,y
+ if(value>0):
+ text.color_set(10,10,10,200)
text.pos_set(x,y)
text.show()
+ text.data["value"] = value
text_data = "button" + str(addr)
ee.data[text_data] = text
print 'TRY:',text_data, ee.data[text_data]
More information about the commitlog
mailing list