import fonts.fontAwesome; import win.ui; /*DSG{{*/ var winform = win.form(text="aardio form";right=226;bottom=211;border="dialog frame";max=false;min=false) winform.add( pluslen={cls="plus";left=122;top=89;right=221;bottom=119;bgcolor=-5197169;dl=1;dt=1;font=LOGFONT(h=-13);z=6}; plusparity={cls="plus";left=122;top=121;right=221;bottom=151;bgcolor=-5197169;dl=1;dt=1;font=LOGFONT(h=-13);z=8}; plusport={cls="plus";left=122;top=25;right=221;bottom=55;bgcolor=12632256;dl=1;dt=1;font=LOGFONT(h=-13);z=2}; plusrate={cls="plus";left=122;top=57;right=221;bottom=87;bgcolor=-5197169;dl=1;dt=1;font=LOGFONT(h=-13);textPadding={top=6;bottom=3};z=4}; plusstop={cls="plus";left=122;top=153;right=221;bottom=183;bgcolor=-5197169;dl=1;dt=1;font=LOGFONT(h=-13);z=10}; staticlen={cls="static";text="Static";left=9;top=90;right=115;bottom=120;align="right";center=1;dl=1;dt=1;transparent=1;z=5}; staticparity={cls="static";text="Static";left=15;top=122;right=115;bottom=152;align="right";center=1;dl=1;dt=1;transparent=1;z=7}; staticport={cls="static";text="Static";left=15;top=25;right=115;bottom=55;align="right";center=1;dl=1;dt=1;transparent=1;z=1}; staticrate={cls="static";text="Static";left=15;top=58;right=115;bottom=88;align="right";center=1;dl=1;dt=1;transparent=1;z=3}; staticstop={cls="static";text="Static";left=15;top=154;right=115;bottom=184;align="right";center=1;dl=1;dt=1;transparent=1;z=9}; tab1={cls="plus";text="按钮";left=257;top=69;right=356;bottom=99;align="left";bgcolor=-5197169;font=LOGFONT(h=-13);iconStyle={align="left";font=LOGFONT(h=-13;name='FontAwesome');padding={left=20}};iconText='\uF10C';textPadding={left=39};z=11}; tab2={cls="plus";text="按钮";left=257;top=101;right=356;bottom=131;align="left";bgcolor=-5197169;font=LOGFONT(h=-13);iconStyle={align="left";font=LOGFONT(h=-13;name='FontAwesome');padding={left=20}};iconText='\uF10C';textPadding={left=39};z=12} ) /*}}*/ import console //console.log() var arg = {...};//winform,is popup,active color,hover color arg[["active"]]=arg[3] arg[["hover"]]=arg[4] if(!arg[["active"]]){ arg[["active"]] = 0xFF1E90FF } if(!arg[["hover"]]){ arg[["hover"]] = 0xFF99CCFF } if(0){//无边框 win.form.border="none" winform.add(bkplus={cls="bkplus";left=-11;top=-1;right=253;bottom=24;dl=1;dt=1;forecolor=12632256};) import win.ui.simpleWindow2 var wui = win.ui.simpleWindow2(winform,,24,24) //winform.text = "配置串口" wui.skin( background = { hover = arg[["hover"]]; active = 0xffff6666; default = 0x00000000; } color = { hover = 0xff666666; active = 0xffffffff; default = 0xffffffff; } ) } import fsys.config var cfg = fsys.config("/config/"); winform.bindConfig( cfg.serialcfg,{ //edit = "text"; //radiobutton = "checked"; //checkbox = "checked"; //combobox = "selIndex"; plus ={ //["^chk"] = "checked"; ["plus*"] = "text"; }; } ); import sio import sys.comPort var comPorts = sys.comPort.list(); //console.varDump(comPorts) var str,cfginfo = {}; ratetmp = table.map(sio.baudRates(),function(v,k,result){ result[k+1]=tostring(v) }) table.push(ratetmp,"自定义") //console.varDump(ratetmp) str={ port={ info="端口/Port"; index=1; data=table.map(comPorts,function(v,k,result){ result[k]=tostring(v) }) }; rate={ info="波特率/Baud rate"; index=12; data=ratetmp /** { "2400"; "4800"; "9600"; "38400"; "115200"; "自定义" }**/ }; len={ info="数据位数/Data bits"; index=4; data={ "5"; "6"; "7"; "8" } }; parity={ info="极性/Parity"; index=1; data={ "无/None"; "奇/Odd"; "偶/Even"; "零/Spc"; "一/Mrk"; } }; stop={ info="结束位/Stop bits"; index=1; data={ "1"; "1.5"; "2"; } }; } import win.ui.tabs var tbs=win.ui.tabs(winform.tab1,winform.tab2) //tbs.initPopup() tbs.itemMargin = 2 tbs.skin({ background={ default=0xFFD3D3D3;//0xffc0c0c0; //disabled=0xFFCCCCCC; hover=arg[["hover"]] }; checked = { iconText = '\uF05D'; background={ default=arg[["active"]]; //disabled=0xFFCCCCCC; hover=arg[["hover"]] }; } }) for(name,ctrl in winform.eachControl("static") ){ var tmp = string.replace(name,"static",""); ctrl.text = str[tmp][["info"]] } init = function(){ for(name,ctrl in winform.eachControl("plus","plus*") ){ ctrl.skin({ background={ default=0xffc0c0c0;//0x668FB2B0; active = arg[["active"]]; //disabled=0xFFCCCCCC; hover=arg[["hover"]]//0xFF928BB3 }; color={ default=0xFF000000; disabled=0xFF6D6D6D } }) var tmp = string.replace(name,"plus",""); //var idx = str[tmp].index if(ctrl.text == ""){ ctrl.text = str[tmp][["data"]][str[tmp][["index"]]] } if(!#str[tmp].data){ ctrl.text = "" } ctrl.oncommand = function(id,event){ var tmp = string.replace(name,"plus",""); tbs.clear()//清空原tbs tbs.initPopup()//必须初始化 if(tmp == "port"){ str[tmp].data=table.map(sys.comPort.list(),function(v,k,result){ result[k]=tostring(v) }) } //tbs.setItemTexts(str[tmp].data) for(i=1;#str[tmp].data;1){ //for(k,v in str[tmp].data){ tbs.add({ text=str[tmp].data[i]; }) //折叠过长的列表 var col = 6; if(#str[tmp].data < col){ continue } var tbrec = winform.tab1._defRect; var x2,y2,cx2,cy2 = tbrec.left,tbrec.top,tbrec.right-tbrec.left,tbrec.bottom-tbrec.top var rec = tbs.strips[tbs.count()]._defRect; if( i%col == 0){ //x2,y2 = win.getPos(ctrl.hwnd,true) rec.left=x2+(cx2+tbs.itemMargin)*math.floor(i/col) rec.right = rec.left+cx2 rec.top=y2-cy2-tbs.itemMargin// rec.bottom=rec.top+cy2 } } tbs.selText = ctrl.text if(!tbs.selIndex){ tbs.selText="自定义" } tbs.popup(true,ctrl,"right") } } } init() winform.getcfg = function(){//poart,baud,wordLength,stopBits,parity var ctrl = winform; cfginfo = {ctrl.plusport.text;tonumber(ctrl.plusrate.text);ctrl.pluslen.text;tonumber(ctrl.plusstop.text);string.lower(string.replace(ctrl.plusparity.text,".*/",""))} //console.varDump(cfginfo); cfg.saveAll() if(winform.parent){ return cfginfo; } } winform.getcfg() tbs.onOk = function(strip){ //console.varDump(tbs.$popBuddy) if(strip.text == "自定义"){ tbs.$popBuddy.editable = 1;//"edit"; //tbs.$popBuddy.num=1 winform.plusrate.editBox.limit=7 tbs.$popBuddy.setFocus() tbs.$popBuddy.editBox.onChange = function(){ winform.getcfg() } tbs.$popBuddy.editBox.onFocusLost = function(){ var tmp = tbs.$popBuddy.text; var rec = tbs.$popBuddy.getRect()//_defRect; tbs.$popBuddy.close() winform.add( plusrate={cls="plus";left=rec.left;top=rec.top;right=rec.right;bottom=rec.bottom;bgcolor=-5197169;dl=1;dt=1;font=LOGFONT(h=-13);textPadding={top=6;bottom=4}}; ) init() winform.plusrate.text = tmp } } else { tbs.$popBuddy.text = strip.text } winform.getcfg() } if(winform.parent != null){ //winform.doModal() } //console.varDump(winform.parent) winform.onDestroy = function(){ //console.log("12") //winform.getcfg(); } winform.show(); win.loopMessage(); return winform,cfginfo;