Exemplo n.º 1
0
def logviewer(logfilepath,warning=None):
    root = Tk()

    # Prompts begin
    prompts = Frame(root)
    prompts_rowindex = 0

    lblTimeMark = Label(prompts,text='当前时间:',justify=RIGHT)
    currentTime = Label(prompts,bd=1,text='2000-10-10',justify=LEFT)

    lblTimeMark.grid(row=prompts_rowindex,column=0,sticky=N+S+W+E,pady=5)
    currentTime.grid(row=prompts_rowindex,column=1,columnspan=2,sticky=N+S+W+E,pady=5)
    prompts_rowindex += 1

    msgbox = Text(prompts,height=25,width=100,bd=3)
    msgbox.config(state=DISABLED)
    msgbox['background'] = '#11d'
    msgbox['foreground'] = '#fff'
    msgbox.grid(row=prompts_rowindex,column=0,columnspan=3)

    yscroll = Scrollbar(prompts)
    msgbox['yscrollcommand'] = yscroll.set
    yscroll['command'] = msgbox.yview
    yscroll.grid(row=prompts_rowindex,column=3,sticky=N+S+W+E)

    prompts_rowindex += 1

    if warning != None:
        warn = Label(prompts,text=warning,bd=5)
        warn['background'] = '#ee2'
        warn['foreground'] = '#f00'
        warn.grid(row=prompts_rowindex,column=0,sticky=N+S+W+E)
        prompts_rowindex += 1

    prompts.grid(row=0,column=0,columnspan=2,sticky=N+S+W+E)
    # Prompts End

    def refresh(*args):
        if yscroll.get()[1] == 1.0:
            newcontent = ''
            if os.path.isfile(logfilepath):
                newcontent = open(logfilepath,'r').read()
            if newcontent != '':
                msgbox['state'] = NORMAL
                msgbox.delete(1.0,END)
                msgbox.insert(END,newcontent)
                msgbox['state'] = DISABLED
                msgbox.see(END)
            else:
                log.warning('No logfile found. Try logging to create one.')
        currentTime['text'] = time.strftime('%Y-%m-%d %H:%M:%S')
        root.after(500,refresh)

    root.after(0,refresh)

    root.title('ξ系统 - 系统日志')

    _utils.center_window(root)
    root.resizable(0,0)
    root.mainloop()
Exemplo n.º 2
0
def senderconfirm(message,warning=None):
    global ret,readyconfirm
    root = Tk()
    ret = False

    prompts = Frame(root)
    prompts_rowindex = 0

    msglbl = Label(prompts,text='\n系统准备接收新密钥\n请仔细检查以便决定是否接收:\n')
    msgbox = Text(prompts,height=25,width=100,bd=3)
    msgbox.insert(END,message)
    msgbox.config(state=DISABLED)
    msgbox['background'] = '#11d'
    msgbox['foreground'] = '#ff1'
    msglbl.grid(row=prompts_rowindex,column=0)
    msgbox.grid(row=prompts_rowindex+1,column=0)
    prompts_rowindex += 2

    if warning != None:
        warn = Label(prompts,text=warning,bd=5)
        warn['background'] = '#ee2'
        warn['foreground'] = '#f00'
        warn.grid(row=prompts_rowindex,column=0,sticky=N+S+W+E)
        prompts_rowindex += 1

    btnOK = Button(text='确认 - 请谨慎!')
    btnOK['background'] = '#f00'
    btnOK['foreground'] = '#fff'
    def okcommand(r=root,b=btnOK):
        global ret,readyconfirm
        if readyconfirm:
            ret = True
            r.destroy()
        else:
            b['text'] = '请再次点击确认'
            b.update_idletasks()
            readyconfirm=True
    btnOK['command'] = okcommand

    btnCancel = Button(text='取消 - 拒绝接收')
    btnCancel['background'] = '#0a0'
    btnCancel['foreground'] = '#fff'
    def cancelcommand(r=root):
        global ret
        ret = False
        r.destroy()
    btnCancel['command'] = cancelcommand

    btnOK.grid(row=2,column=0)
    btnCancel.grid(row=2,column=1)
    prompts.grid(row=0,column=0,columnspan=2,sticky=N+S+W+E)

    root.title('ξ系统 - 准备接收密钥')

    _utils.center_window(root)
    root.resizable(0,0)
    root.mainloop()

    try:
        root.quit()
    except:
        pass

    return ret
Exemplo n.º 3
0
    def pinreader(checktwice=False,**argv):
        global ret
        root = Tk()
        ret = None

        prompts = Frame(root)
        prompts_rowindex = 0

        if 'warning' in argv.keys():
            warn = Label(prompts,text=argv['warning'],bd=5)
            warn['background'] = '#ffb'
            warn.grid(row=prompts_rowindex,column=0,sticky=N+S+W+E)
            prompts_rowindex += 1

        if 'message' in argv.keys():
            msglbl = Label(prompts,text='下面是本次请求的信息:')
            msgbox = Text(prompts,height=15,width=50)
            msgbox.insert(END,argv['message'])
            msgbox.config(state=DISABLED)
            msglbl.grid(row=prompts_rowindex,column=0)
            msgbox.grid(row=prompts_rowindex+1,column=0)
            prompts_rowindex += 2

        prompt = Label(prompts,text='请您输入密码,以便继续操作。',bd=5)
        prompt.grid(row=prompts_rowindex,column=0)


        passphrase_region = Frame(root)
        if 'prompt1' in argv.keys():
            prompt1 = argv['prompt1']
        else:
            prompt1 = '请输入口令:'
        inputlabel1 = Label(passphrase_region,text=prompt1)
        inputbox1 = Entry(passphrase_region,show='*')
        inputlabel1.grid(row=0,column=0)
        inputbox1.grid(row=0,column=1)

        if checktwice:
            if 'prompt2' in argv.keys():
                prompt2 = argv['prompt2']
            else:
                prompt2 = '请确认口令:'
            inputbox2 = Entry(passphrase_region,show='*')
            inputlabel2 = Label(passphrase_region,text=prompt2)
            inputlabel2.grid(row=1,column=0)
            inputbox2.grid(row=1,column=1)

            def get_value(i1=inputbox1,i2=inputbox2):
                return (i1.get(),i2.get())
        else:
            def get_value(i=inputbox1):
                return (i.get(),)

        btnOK = Button(text='确认')
        def okcommand(r=root,b=btnOK):
            global ret
            ret = get_value()
            if len(ret) > 1:
                t = ret[0]
                ok = True
                for x in ret:
                    if x != t:
                        ok = False
                        break
                if not ok:
                    old = b['text']
                    b['text'] = '两次密码不一致'
                    b.update_idletasks()
                    time.sleep(1)
                    b['text'] = old
                    b.update_idletasks()
                    return
            r.destroy()
        btnOK['command'] = okcommand

        btnCancel = Button(text='取消')
        def cancelcommand(r=root):
            global ret
            ret = None
            r.destroy()
        btnCancel['command'] = cancelcommand

        btnOK.grid(row=2,column=0)
        btnCancel.grid(row=2,column=1)
        prompts.grid(row=0,column=0,columnspan=2,sticky=N+S+W+E)
        passphrase_region.grid(row=1,column=0,columnspan=2)

        root.title('ξ系统 - 请求口令')

        _utils.center_window(root)
        root.resizable(0,0)
        root.mainloop()

        try:
            root.quit()
        except:
            pass

        if ret == None:
            return False
        return ret[0]