Python(PyS60)做的簡單語音整點報時的實現

來源:互聯網
上載者:User
主要的技術特殊點在於PyS60的定時器最多隻能定2147秒。在手機上直接寫的。import e32import audioimport timeimport appuifwimport sysimport os.pathimport marshaldef say(oclock):    """say the time in English"""    c = oclock    if c > 12:        c -= 12    cs = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve'][c]    audio.say("it's " + cs + " o'clock.")    def say_current():    global Sayflags    t = time.localtime()    # say according to configuration    if Sayflags[int(t[3])] == 1:        say(t[3])    def on_oclock():    """when an o'clock arrived"""    say_current()    start_timer()    def start_timer():    """start a timer that will be reached at next o'clock"""    global Timer    lt = time.localtime()    d = 60 * (59 - lt[4]) + 61 - lt[5]    if d>2147:        Timer.after(2147, lambda :  Timer.after(d-2147, on_oclock))     else:        Timer.after(d, on_oclock)    def clock_names():    return [u'0:00', u'1:00', u'2:00', u'3:00', u'4:00', u'5:00', u'6:00', u'7:00', u'8:00', u'9:00', u'10:00', u'11:00', u'12:00', u'13:00', u'14:00', u'15:00', u'16:00', u'17:00', u'18:00', u'19:00', u'20:00', u'21:00', u'22:00', u'23:00']    def list_handler():    """set flag and refresh the listbox"""    global Lb    global Sayflags    c = Lb.current()    Sayflags[c] = 1 - Sayflags[c]    Lb.set_list(list_content(), c)def list_content():    global Sayflags    icons = [appuifw.Icon(u"z:\\resource\\apps\\avkon2.mif", 16506, 16507), appuifw.Icon(u"z:\\resource\\apps\\avkon2.mif", 16504, 16505)] # unchecked, unchecked    return map(lambda s, f: tuple([s, icons[f]]), clock_names(), Sayflags)    def exit_handler():    global Lock    global Timer    global Standalone    Timer.cancel()    save_cfg()    if not Standalone:        Lock.signal()    else:        appuifw.app.set_exit()def save_cfg():    global Sayflags    try:        f = open(Configfile, 'wb')        marshal.dump(Sayflags, f)        f.close()    except:        pass    def load_cfg():    global Sayflags    try:        f = open(Configfile, 'rb')        Sayflags = marshal.load(f)        f.close()    except:        pass# Testing codedef test():    say_current()    #on_oclock()    #for n in range(1,13):    #    say(n)#test()def main():    global Standalone    appuifw.app.title = u'Audio Clock'    appuifw.app.exit_key_handler = exit_handler    appuifw.app.body = Lb    if time.localtime()[4] == 0:        say_current()    start_timer()    if not Standalone:        Lock.wait()    Standalone = TrueTimer = e32.Ao_timer()Lock = e32.Ao_lock()Configfile = os.path.abspath(os.path.dirname(sys.argv[0])) + '\\audioclock.cfg'Sayflags = [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1] #24 clocks' flagsload_cfg()Lb = appuifw.Listbox(list_content(), list_handler)main()
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.