backup codes

This commit is contained in:
vc4
2021-08-24 15:28:05 +08:00
parent 2c50267b46
commit 72dcf7ed05
3 changed files with 17 additions and 11 deletions

6
app.ui
View File

@@ -226,7 +226,7 @@
"row": 31 "row": 31
} }
], ],
"Button":[ "Checkbutton":[
{ {
"name":"btn-unpack01", "name":"btn-unpack01",
"text":"unpack-01", "text":"unpack-01",
@@ -256,7 +256,9 @@
"text":"unpack-05", "text":"unpack-05",
"column": 2, "column": 2,
"row": 6 "row": 6
}, }
],
"Button":[
{ {
"name":"btn-data01", "name":"btn-data01",
"text":"data-01", "text":"data-01",

View File

@@ -252,9 +252,10 @@ class TopWin():
self.root.get('ckbtn-shex').var.set(_cfg.get('hex') and 1 or 0) self.root.get('ckbtn-shex').var.set(_cfg.get('hex') and 1 or 0)
self.root.get('btn-send').invoke() self.root.get('btn-send').invoke()
def set_pack(self, btn): def set_pack(self, btn):
pass self.root.pack = self.root.usercfg.get(btn,{}).get('value')
def set_unpack(self, btn): def set_unpack(self, btn):
pass self.root.unpack = self.root.usercfg.get(btn,{}).get('value')
print(self.root.unpack)
def save_cfg(self, btn, dat): def save_cfg(self, btn, dat):
with open('usercfg.json', 'wb+') as f: with open('usercfg.json', 'wb+') as f:
self.root.usercfg[btn] = dat self.root.usercfg[btn] = dat
@@ -318,7 +319,7 @@ if __name__ == '__main__':
name = 'btn-data%02d'%(i+1) name = 'btn-data%02d'%(i+1)
try: try:
btn = root.get(name) btn = root.get(name)
root.button(name, lambda x=name: wm.set_send_data(x)) root.button(name, cmd=lambda x=name: wm.set_send_data(x))
btn.bind('<Button-2>', wm.win_data) btn.bind('<Button-2>', wm.win_data)
btn.bind('<Button-3>', wm.win_data) btn.bind('<Button-3>', wm.win_data)
_cfg = root.usercfg.get(name) _cfg = root.usercfg.get(name)
@@ -331,7 +332,7 @@ if __name__ == '__main__':
name = 'btn-pack%02d'%(i+1) name = 'btn-pack%02d'%(i+1)
try: try:
btn = root.get(name) btn = root.get(name)
root.button(name, lambda x=name: wm.set_pack(x)) root.button(name, cmd=lambda x=name: wm.set_pack(x))
btn.bind('<Button-2>', wm.win_pack) btn.bind('<Button-2>', wm.win_pack)
btn.bind('<Button-3>', wm.win_pack) btn.bind('<Button-3>', wm.win_pack)
_cfg = root.usercfg.get(name) _cfg = root.usercfg.get(name)
@@ -340,16 +341,19 @@ if __name__ == '__main__':
except: except:
pass pass
# 解析脚本回调函数 # 解析脚本回调函数
var = tkinter.IntVar()
for i in range(10): for i in range(10):
name = 'btn-unpack%02d'%(i+1) name = 'btn-unpack%02d'%(i+1)
try: try:
btn = root.get(name) btn = root.get(name)
root.button(name, lambda x=name: wm.set_unpack(x)) root.button(name, cmd=lambda x=name: wm.set_unpack(x))
btn.bind('<Button-2>', wm.win_unpack) btn.bind('<Button-2>', wm.win_unpack)
btn.bind('<Button-3>', wm.win_unpack) btn.bind('<Button-3>', wm.win_unpack)
btn.var = var
_cfg = root.usercfg.get(name) _cfg = root.usercfg.get(name)
if _cfg and btn: if _cfg and btn:
btn.config(text=_cfg.get('title',name)) btn.config(text=_cfg.get('title',name))
root.checkbox(name).set(0)
except: except:
pass pass
# UI相关设置 # UI相关设置
@@ -362,8 +366,8 @@ if __name__ == '__main__':
root.checkbox('ckbtn-cycle').set(0) root.checkbox('ckbtn-cycle').set(0)
root.checkbox('ckbtn-time').set(1) root.checkbox('ckbtn-time').set(1)
root.checkbox('ckbtn-sendshow').set(1) root.checkbox('ckbtn-sendshow').set(1)
root.entry('entry-split').set('100ms') root.entry('entry-split').set('99ms')
root.entry('entry-cycle').set('1000ms') root.entry('entry-cycle').set('1024ms')
root.entry('entry-baud').set('9600') root.entry('entry-baud').set('9600')
root.entry('entry-encoding').set('gbk') root.entry('entry-encoding').set('gbk')
root.entry('entry-sendText', key='<Return>', cmd=lambda x:comm.sendData()).set('') root.entry('entry-sendText', key='<Return>', cmd=lambda x:comm.sendData()).set('')

View File

@@ -27,8 +27,8 @@
"value": "" "value": ""
}, },
"btn-unpack01": { "btn-unpack01": {
"title": "btn-unpack01", "title": "HEX print",
"value": "" "value": "''.join(['%02X'%x for x in data])"
}, },
"btn-unpack03": { "btn-unpack03": {
"title": "btn-unpack03", "title": "btn-unpack03",