wd_pys60 / wd_start_uc_quick_mark.py

import keypress
from key_codes import *
import e32
import laa
import clipboard_CHN
import graphics



Ecancel=868
Escan=846


def have_got_one_qrcode():
    img=graphics.Image.new((40,20))
    # print graphics.screenshot().size
    img.blit(graphics.screenshot(),source=((200,300),(240,320)))
    img.save("e:\\BUG_BUG_BUG_temp.jpg",quality=50,compression="fast")
    
    f=file("e:\\BUG_BUG_BUG_temp.jpg","rb")
    if len(f.read())==Ecancel:
        return True
    elif len(f.read())==Escan:
        return False
    f.close()

def wd_key_press(*args):
    keypress.simulate_key(*args)
    #e32.ao_sleep(0.1)
def back_to_last_screen():
    keypress.simulate_keyMenu() # Simulates Right Softkey
    # e32.ao_sleep(0.1)

def launch_qrscanner():
    laa.execute(0x20004FFE)


def get_qr_result():
    #select all
    wd_key_press(EKeyLeftSoftkey, EScancodeLeftSoftkey) # Simulates Left Softkey
    wd_key_press(EKeyDownArrow, EScancodeDownArrow) # Simulate Down arrow
    wd_key_press(EKeyDownArrow, EScancodeDownArrow) # Simulate Down arrow
    wd_key_press(EKeyDownArrow, EScancodeDownArrow) # Simulate Down arrow
    wd_key_press(EKeyRightArrow, EScancodeRightArrow) # Simulates Right arrow
    wd_key_press(EKeySelect, EScancodeSelect) # Simulates Select key
    #copy
    wd_key_press(EKeyLeftSoftkey, EScancodeLeftSoftkey) # Simulates Left Softkey
    wd_key_press(EKeyDownArrow, EScancodeDownArrow) # Simulate Down arrow
    wd_key_press(EKeyDownArrow, EScancodeDownArrow) # Simulate Down arrow
    wd_key_press(EKeyDownArrow, EScancodeDownArrow) # Simulate Down arrow
    wd_key_press(EKeyRightArrow, EScancodeRightArrow) # Simulates Right arrow
    wd_key_press(EKeyDownArrow, EScancodeDownArrow) # Simulate Down arrow
    wd_key_press(EKeyDownArrow, EScancodeDownArrow) # Simulate Down arrow
    wd_key_press(EKeySelect, EScancodeSelect) # Simulates Select key
    #return
    result=_check_qrscan()
    if result:
        return result
    else:
        back_to_last_screen()
        return None
def _check_qrscan():
    _clip=clipboard_CHN.Get()
    if _clip!="PreTty_UnNormale00__0":
        clipboard_CHN.Set("PreTty_UnNormale00__0")
        return _clip
    else:
        return None


# import lightblue

# class Blue:
    # def __init__(self,targetMac='00:11:03:07:05:92',targetPort=1):
        # self.blue=lightblue.socket()
        # self.blue.connect((targetMac,targetPort))
        # self.recv=86
    # def send(self,data):
        # self.blue.send(data)
import socket
class Blue:
    def __init__(self,targetMac='00:11:03:07:05:92',targetPort=1):
        self.conn = socket.socket(socket.AF_BT, socket.SOCK_STREAM)
        # self.address,self.services = socket.bt_discover()
        self.conn.connect((targetMac,targetPort))
        print "Connected to server!"
        self.fd = self.conn.makefile("rw", 0)
    def send(self,data):
        print >> self.fd, data
def test_blue(mac):
    b=Blue(mac)
    for byte in "你好woQ是手机".decode("utf8").encode("gbk"):
        b.send(byte)
# import appuifw
# MAC=['00:11:03:07:05:92','00:11:04:29:02:65']
# choices = [u"wd", u"yyb"]
# index = appuifw.popup_menu(choices, u"Select:") 
# test_blue(MAC[index])

#('00:11:04:29:02:65', u'linvor', 7936)
#'00:11:04:29:02:65'yyb
def main():
    b=Blue('00:11:04:29:02:65')
    launch_qrscanner()
    e32.ao_sleep(2)

    while 1:
        e32.ao_sleep(0.1)
        if have_got_one_qrcode():
            result=get_qr_result()
            if  result:
                #print result
                b.send((result+u"\r\n\a").encode("gbk"))
                back_to_last_screen()
            #e32.ao_sleep(0)

main()
#get_qr_result()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.