Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # modeswitch.py
- import e32, audio, appuifw, graphics, os, sys, key_codes, time, math, random
- app_lock=e32.Ao_lock()
- appuifw.app.orientation='landscape'
- appuifw.app.directional_pad=False
- appuifw.app.screen='large' # 'large' for testing
- appuifw.app.title=u"Text and Graphic Mode Toggle"
- btn_t,btn_b=270,360
- btn01=(20,btn_t,120,btn_b) # YES
- btn02=(120,btn_t,220,btn_b) # NO
- btn03=(520,0,640,69) # quit button
- def e_callback(event):
- global select,btn_t
- if event['type'] == key_codes.EButton1Down:
- if event['pos'][1] > btn_t:
- if event['pos'][0] > 20 and event['pos'][0] < 120:
- select=0 # means NO
- elif event['pos'][0] > 120 and event['pos'][0] < 220:
- select=1 # means YES
- elif event['pos'][0] > 520 and event['pos'][1] < 69:
- quit()
- def quit():
- gfx_on(0)
- appuifw.app.exit_key_handler=quit
- canvas=img=None
- def cb_resize(aSize=(0,0,0,0)):
- global img
- img=graphics.Image.new((640,360)) ### ZZZ to be canvas.size instead of 640:360
- def handle_redraw(rect):
- if img: ### Skips only at first pass as "None"
- canvas.blit(img)
- canvas=appuifw.Canvas(resize_callback=cb_resize,
- event_callback=e_callback,redraw_callback=handle_redraw)
- appuifw.app.body=canvas
- txt=appuifw.Text()
- appuifw.app.body=txt
- txt.clear()
- txt.set(u"'Select Option' > 'Graphic Mode' to activate the graphics mode \
- and then the green rectangle at the top left should switch it right back to \
- this unaltered 'Text Mode'\n\n")
- COLOR_BLACK=(0,0,0)
- COLOR_WHITE=(255,255,255)
- COLOR_GRAYLIGHT=(211,211,211)
- COLOR_GRAY=(128,128,128)
- COLOR_GRAYDARK=(169,169,169)
- COLOR_REDDARK=(169,0,0)
- COLOR_RED=(255,0,0)
- COLOR_ORANGE=(255,165,0)
- COLOR_YELLOW=(255,255,0)
- COLOR_GREEN=(0,128,0)
- COLOR_BLUE=(0,0,255)
- COLOR_CYAN=(0,255,255)
- COLOR_PURPLE=(128,0,128)
- COLOR_DARKBLUE=(0,0,139)
- COLOR_DARKGREEN=(0,100,0)
- COLOR_DEEPPINK=(255,20,147)
- COLOR_PINK=(255,192,203)
- COLOR_INDIGO=(75,0,130)
- COLOR_LIGHTBLUE=(173,216,230)
- COLOR_LIME=(0,255,0)
- COLOR_OLIVE=(107,142,35)
- COLOR_TAN=(210,180,140)
- COLOR_BROWN=(139,69,19)
- COLOR_GOLD=(255,215,0)
- COLOR_SILVER=(192,192,192)
- def circle(x,y,radius=5,outline=0,fill=0xffff00,width=1):
- c.ellipse((x-radius,y-radius,x+radius,y+radius),outline,fill,width)
- PYTHON_ROOT=u"e:\\data\\Python\\000misc\\"
- BkgdImage=graphics.Image.open(PYTHON_ROOT+u"640x360img.png")
- def gfx_on(mode):
- if mode == 1:
- appuifw.app.screen='full'
- appuifw.app.body=canvas
- if mode == 0:
- appuifw.app.screen='large'
- appuifw.app.body=txt
- def star5pt((x,y),size,outline=None,fill=None,width=1):
- s=size
- img.polygon(((0+x,0.7*s+y),(0.75*s+x,0.7*s+y),(1*s+x,0+y),(1.25*s+x,0.7*s+y),(2*s+x,0.7*s+y),
- (1.4*s+x,1.15*s+y),(1.65*s+x,1.95*s+y),(1*s+x,1.45*s+y),(0.35*s+x,1.95*s+y),(0.6*s+x,1.15*s+y)),
- outline,fill,width)
- def exit():
- app_lock.signal()
- def graphics_mode():
- gfx_on(1)
- img.blit(BkgdImage,target=(0,0))
- img.rectangle((btn03),outline=None,fill=COLOR_GREEN)
- img.line((250,250,480,320),COLOR_PURPLE,width=5)
- star5pt((390,5),60,fill=COLOR_GOLD)
- img.point((140,50),COLOR_BLACK,width=80)
- img.ellipse((520,210,620,340),outline=COLOR_DARKBLUE,fill=COLOR_CYAN,width=2)
- img.line(((40,275),(200,152),(174,259),(320,80),(374,240),(400,152),(569,274)),
- outline=COLOR_ORANGE,width=2)
- img.pieslice((200,20,320,80),0,320,width=1,outline=COLOR_BROWN,fill=COLOR_TAN)
- img.arc((60,180,180,300),320,90,width=10,outline=COLOR_DARKBLUE) # ??? *
- ### * re: arc/pieslice -- for bypassing the zero degree mark... 90 degrees as to what?
- ### may have to write a method to correct this
- img.text((100,320),u"Sample Text On Canvas",fill=(255,0,0),font='title')
- img.text((536,30),u"Touch Here")
- img.text((536,50),u"To Switch")
- handle_redraw(())
- appuifw.app.menu=[(u"Graphic On",graphics_mode),(u"Exit",exit)]
- app_lock.wait()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement