Changeset 4509


Ignore:
Timestamp:
07/07/08 12:40:01 (5 years ago)
Author:
erin_yueh
Message:

add number keyboard, clear callback, button clicked callback (Erin Yueh)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • developers/erin_yueh/pythonEFL-sudoku/src/sudoku_ui.py

    r4506 r4509  
    1010WINDOW_HEIGHT = 640 
    1111 
    12 def button_cb(zoom_in, emission, source): 
    13     print 'emission,source:',emission,source 
     12def checkRow(row,value): 
     13    isOK = True 
     14     
     15    return isOK 
     16     
     17def checkLine(line,value): 
     18    isOK = True 
     19     
     20    return isOK 
     21 
     22def checkGroup(group,value): 
     23    isOK = True 
     24     
     25    return isOK 
     26     
     27def analyze(button,value): 
     28    isOK = False 
     29    puzzle = ee.data["puzzle"] 
     30    # button40 2 
     31    addr = button[6:] 
     32    print addr, value 
     33    i = int(addr) / 9 
     34    j = int(addr) % 9 
     35    g = (i/3)*3 + (j/3) 
     36    print i,j,g 
     37    if not(checkRow(i,value) or checkLine(j,value) or checkGroup(g,value)): 
     38        isOK = True 
     39    return isOK 
     40     
     41def number_key_cb(zoom_in, emission, source): 
     42    print 'number_key_cb emission,source:',emission,source 
     43     
     44    if(source == 'clear'): 
     45        puzzle = ee.data["puzzle"] 
     46        for i in xrange (9): 
     47            for j in xrange(9): 
     48                value = puzzle[i][j] 
     49                addr = i + j *9 
     50                text_data = "button" + str(addr) 
     51                text = ee.data[text_data]  
     52                text.data["value"] = value 
     53                text.text_set(str(value)) 
     54                if(value>0): 
     55                    text.color_set(10,10,10,200) 
     56                elif(value==0): 
     57                    text.color_set(0,255,255,255) 
     58        print 'clear all data!!' 
     59    elif(source =='undo' or source == 'redo'): 
     60        print 'undo or redo' 
     61    elif(source == 'solve'): 
     62        print 'solve' 
     63    else:  
     64        # fill in key number 
     65        if(ee.data["clicking"]): 
     66            text = ee.data[ee.data["clicking"]] 
     67            text.text_set(source) 
     68            text.data["value"] = int(source) 
     69            if(analyze(ee.data["clicking"],source) == False): 
     70                text.color_set(255,0,0,255) 
     71            else:  
     72                text.color_set(255,255,255,255) 
     73    return True 
     74 
     75def puzzle_key_cb(zoom_in, emission, source): 
     76    print 'puzzle_key_cb emission,source:',emission,source 
     77     
     78    text = ee.data[source] 
     79    if(int(text.data["value"]) ==0 ): 
     80        text.color_set(255,255,255,255) 
     81        ee.data["clicking"] = source 
    1482     
    1583    return True 
    1684 
    17      
    18 def puzzle_but_number_cb(zoom_in, emission, source): 
    19     print 'emission,source:',emission,source 
    20      
    21     return True 
    22      
    2385def get_puzzle(): 
    24      
     86 
    2587        file_name = "/usr/share/sudoku/puzzle/1000" 
    2688        fIn = open(file_name, 'r') 
    2789        fIn.seek(82*(random.randint(1, 1000))) 
    2890        l = fIn.readline() 
    29      
     91 
    3092        if (len(l) != 82): 
    31             print "xxx" 
     93            print "the puzzle is wrong!!" 
    3294 
    3395        p = [] 
     
    3799                t.append(int(l[i * 9 + j])) 
    38100            p.append(t) 
    39          
    40          
     101 
    41102        return p 
    42      
     103 
    43104def main(): 
    44105 
     
    59120    # create puzzle and icons 
    60121    area = edje.Edje(canvas, file="/usr/share/sudoku/sudoku.edj", group="pythonEFL-sudoku/panel") 
     122    area.signal_callback_add("mouse,clicked,*", "*", number_key_cb) 
    61123    area.pos = (0, 0) 
    62124    area.size = canvas.size 
    63125    area.show() 
    64126    area.data["area"] = area 
    65     # set a signal callback for all buttons 
    66     area.signal_callback_add("mouse,clicked,*", "*", button_cb) 
    67127 
    68128    # create puzzle and icons 
    69129    board = edje.Edje(canvas, file="/usr/share/sudoku/sudoku.edj", group="pythonEFL-sudoku/board") 
    70     board.signal_callback_add("mouse,clicked,*", "*", puzzle_but_number_cb) 
     130    board.signal_callback_add("mouse,clicked,*", "*", puzzle_key_cb) 
    71131    board.pos = (0, 0) 
    72     #test.size = canvas.size 
    73132    board.show() 
    74133     
    75134    puzzle = get_puzzle() 
     135    ee.data["puzzle"] = puzzle 
    76136    print puzzle 
    77137     
    78     element_w = 480 / 9 
    79     element_h = 480 / 9  
     138    element_w = 455 / 9 
     139    element_h = 455 / 9  
    80140    # put all elements to Text objects 
    81141    for i in xrange (9): 
    82142        for j in xrange(9): 
    83             x = 5 + (element_w * (i)) 
    84             y = 5 + (element_h * (j)) 
     143            x = 15 + (element_w * (i)) 
     144            y = 15 + (element_h * (j)) 
    85145            #print i,j 
    86146            value = puzzle[i][j] 
    87147            display = str(value) 
    88             addr = i*9 + j 
     148            addr = i + j *9 
    89149            text = canvas.Text(text=display, font=("sans serif", 16), color=(0,255,255,255)) 
    90150            #print i,j,x,y 
     151            if(value>0): 
     152                text.color_set(10,10,10,200) 
    91153            text.pos_set(x,y) 
    92154            text.show() 
     155            text.data["value"] = value 
    93156            text_data = "button" + str(addr) 
    94157            ee.data[text_data] = text 
Note: See TracChangeset for help on using the changeset viewer.