add pre-data dialog
This commit is contained in:
7
app.json
Normal file
7
app.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"btn-data01": {
|
||||
"title": "握手包",
|
||||
"value": "hello\n",
|
||||
"hex":1
|
||||
}
|
||||
}
|
||||
39
data.json
Normal file
39
data.json
Normal file
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"Label": {
|
||||
"name":"label-dtitle",
|
||||
"text":"数据标题",
|
||||
"column": 1,
|
||||
"row": 1
|
||||
},
|
||||
"Entry": {
|
||||
"name":"entry-dfile",
|
||||
"bg":"gold",
|
||||
"width":10,
|
||||
"column": 2,
|
||||
"row": 1
|
||||
},
|
||||
"Text":{
|
||||
"name":"text-dsetting",
|
||||
"bg":"#cccccc",
|
||||
"width":30,
|
||||
"height":3,
|
||||
"column": 1,
|
||||
"columnspan": 3,
|
||||
"rowweight": 1,
|
||||
"row": 2
|
||||
},
|
||||
"Checkbutton":{
|
||||
"name":"ckbtn-dhex",
|
||||
"text":"HEX格式",
|
||||
"sticky": "w",
|
||||
"column": 1,
|
||||
"row": 3
|
||||
},
|
||||
"Button":{
|
||||
"name":"btn-dsave",
|
||||
"text":"保存",
|
||||
"column": 3,
|
||||
"colweight": 1,
|
||||
"row": 3
|
||||
}
|
||||
}
|
||||
30
scomm.json
30
scomm.json
@@ -105,6 +105,20 @@
|
||||
"sticky": "w",
|
||||
"column": 4,
|
||||
"row": 4
|
||||
},
|
||||
{
|
||||
"name":"ckbtn-split",
|
||||
"text":"分帧间隔",
|
||||
"sticky": "w",
|
||||
"column": 5,
|
||||
"row": 3
|
||||
},
|
||||
{
|
||||
"name":"ckbtn-cycle",
|
||||
"text":"循环发送",
|
||||
"sticky": "w",
|
||||
"column": 5,
|
||||
"row": 4
|
||||
}
|
||||
],
|
||||
"Entry": [
|
||||
@@ -123,6 +137,20 @@
|
||||
"column": 4,
|
||||
"row": 1
|
||||
},
|
||||
{
|
||||
"name":"entry-split",
|
||||
"bg":"gold",
|
||||
"width":10,
|
||||
"column": 6,
|
||||
"row": 3
|
||||
},
|
||||
{
|
||||
"name":"entry-cycle",
|
||||
"bg":"gold",
|
||||
"width":10,
|
||||
"column": 6,
|
||||
"row": 4
|
||||
},
|
||||
{
|
||||
"name":"entry-sendText",
|
||||
"bg":"gold",
|
||||
@@ -146,7 +174,7 @@
|
||||
"Label":[
|
||||
{
|
||||
"name":"label-rscript",
|
||||
"text":"解帧脚本:",
|
||||
"text":"解析脚本:",
|
||||
"column": 2,
|
||||
"row": 1
|
||||
},
|
||||
|
||||
64
scomm.py
64
scomm.py
@@ -1,8 +1,70 @@
|
||||
#! /usr/bin/env python3
|
||||
|
||||
import os,json
|
||||
import tkgen.gengui
|
||||
import tkinter
|
||||
|
||||
|
||||
def open_wm_data(root,btn):
|
||||
def _save_dfile():
|
||||
pass
|
||||
print('debug: toplevel=%s'%btn)
|
||||
root.toplevel('data.json', title='预置数据')
|
||||
_cfg = root.usercfg.get(btn)
|
||||
if _cfg:
|
||||
root.entry('entry-dfile').set(_cfg.get('title', btn))
|
||||
root.get('text-dsetting').insert('end', _cfg.get('value'))
|
||||
if _cfg.get('hex'):
|
||||
root.get('ckbtn-dhex').select()
|
||||
else:
|
||||
root.get('ckbtn-dhex').deselect()
|
||||
root.button('btn-dsave', cmd=_save_dfile, focus=True)
|
||||
def open_wm_pack(root,btn):
|
||||
print('debug: toplevel=%s'%btn)
|
||||
#root.toplevel('pack.json', title='组帧脚本')
|
||||
def open_wm_unpack(root,btn):
|
||||
print('debug: toplevel=%s'%btn)
|
||||
#root.toplevel('unpack.json', title='解析脚本')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
root = tkgen.gengui.TkJson('scomm.json', title='scomm串口调试助手')
|
||||
#root = tkgen.gengui.TkJson('rsa_ui.json', title='scomm串口调试助手')
|
||||
|
||||
cfg_file = 'app.json'
|
||||
root.usercfg = json.load(open(cfg_file)) if os.path.isfile(cfg_file) else {}
|
||||
|
||||
# 预置数据回调函数
|
||||
for i in range(10):
|
||||
name = 'btn-data%02d'%(i+1)
|
||||
try:
|
||||
btn = root.get(name)
|
||||
root.button(name, lambda x=name: open_wm_data(root,x))
|
||||
_cfg = root.usercfg.get(name)
|
||||
if _cfg and btn:
|
||||
btn.config(text=_cfg.get('title',name))
|
||||
except:
|
||||
pass
|
||||
# 组帧脚本回调函数
|
||||
for i in range(10):
|
||||
name = 'btn-pack%02d'%(i+1)
|
||||
try:
|
||||
btn = root.get(name)
|
||||
root.button(name, lambda x=name: open_wm_pack(root,x))
|
||||
_cfg = root.usercfg.get(name)
|
||||
if _cfg and btn:
|
||||
btn.config(text=_cfg.get('title',name))
|
||||
except:
|
||||
pass
|
||||
# 解析脚本回调函数
|
||||
for i in range(10):
|
||||
name = 'btn-unpack%02d'%(i+1)
|
||||
try:
|
||||
btn = root.get(name)
|
||||
root.button(name, lambda x=name: open_wm_unpack(root,x))
|
||||
_cfg = root.usercfg.get(name)
|
||||
if _cfg and btn:
|
||||
btn.config(text=_cfg.get('title',name))
|
||||
except:
|
||||
pass
|
||||
|
||||
root.mainloop()
|
||||
|
||||
@@ -284,6 +284,7 @@ class TkJson(tkinter.Tk):
|
||||
var = tkinter.IntVar()
|
||||
item = self.get(name)
|
||||
item.config(variable=var)
|
||||
item.var = var
|
||||
|
||||
if focus:
|
||||
item.focus_set()
|
||||
@@ -303,6 +304,7 @@ class TkJson(tkinter.Tk):
|
||||
|
||||
item = self.get(name)
|
||||
item.config(textvariable=var)
|
||||
item.var = var
|
||||
|
||||
if focus:
|
||||
item.focus_set()
|
||||
@@ -321,6 +323,7 @@ class TkJson(tkinter.Tk):
|
||||
var = tkinter.StringVar()
|
||||
item = self.get(name)
|
||||
item.config(textvariable=var)
|
||||
item.var = var
|
||||
return var
|
||||
|
||||
def get(self, name):
|
||||
|
||||
Reference in New Issue
Block a user