Hello, Everyone,
I was diving into a map navigation system, and you could pan the map using the left Arrow key, right Arrow key, up Arrow key or down Arrow key. you know, when you pan the map,you will get a new view, and you need to draw some poi(point of interest) icons in this new map view(canvas). But the problem is when you draw the poi icons (*.png format) in the canvas, you will get an error, it reads "Application closed: Python WSERV 10". After several days googling, it suggests that this error results from "trying to activate the already activated graphic context". What does this word mean? could anyone help me? Please see the following code:
I think this error comes from calling those "img.new(),img.load(),and canvas.blit()" methods. So Could anyone help me how to fix this problem? Please help! Thanks you guys in advance.Code:import e32 from graphics import * RGB_BACKGROUND=(200,200,200) def Pan(type): if type == 0: Map.PanRight() cb_redraw() elif type == 1: Map.PanUp() cb_redraw() elif type == 2: Map.PanLeft() cb_redraw() elif type == 3: Map.PanDown() cb_redraw() def cb_redraw(dummy=(0,0,0,0)): canvas.clear(RGB_BACKGROUND) Pois = Map.PoiInfos() for Poi in Pois: #the poi icon position tuble (x,y) position = Poi[0] #the poi icon full path name fileName = Poi[1] #please note that the size of the icon png is 32*37 img = Image.new((32,37)) img.load(fileName) canvas.blit(img,target=position) def cb_quit(): app_lock.signal() appuifw.app.exit_key_handler = cb_quit canvas = appuifw.Canvas(redraw_callback = cb_redraw) canvas.bind(EKeyRightArrow, lambda:Pan(0)) canvas.bind(EKeyUpArrow, lambda:Pan(1)) canvas.bind(EKeyLeftArrow, lambda:Pan(2)) canvas.bind(EKeyDownArrow, lambda:Pan(3)) app_lock=e32.Ao_lock() app_lock.wait()
Regards
tao

Reply With Quote



