虚表 —— 绘制整行背景进度条功能

光庆 3天前 217

基础用法:

Code AardioLine:30复制
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
    • import win.ui;
    • import godking.vlistEx;
    • import thread.works
    • /*DSG{{*/
    • var mainForm = win.form(text="aardio form";right=1031;bottom=551)
    • mainForm.add(
    • button2={cls="button";text="随机进度赋值";left=408;top=480;right=560;bottom=528;z=2};
    • vlist={cls="vlistEx";left=10;top=10;right=1024;bottom=464;db=1;dl=1;dr=1;dt=1;edge=1;transparent=1;z=1}
    • )
    • /*}}*/
    • mainForm.show();
    • var t = { fields={"序号","网址","文件","进度"} };
    • for(i=1;30;1){
    • ..table.push(t,{"序号"="[@rowindex]"});
    • }
    • mainForm.vlist.setTable(t,/*列标题*/,{scale=true,1,1,1,2}/*列宽*/,1/*对齐方式*/,/*字典转为数组*/,/*字符串转为Utf8*/,/*是否克隆新表*/);
    • mainForm.vlist.fillParent(-1/*列号支持负数*/,-1/*滚动条计算方式-1或-2*/);
    • //使用下面的函数,启用绘制整行背景进度条功能
    • mainForm.vlist.enableRowProgress(true,4);
    • //设置随机进度值
    • mainForm.button2.oncommand = function(id,event){
    • //数字开头的,可转为数值。仔细对比下列几行的处理效果
    • mainForm.vlist.setCellText( 4/*行号*/,4/*列号或字典key*/,math.random(0,100)/*单元格文本*/);
    • mainForm.vlist.setCellText( 5/*行号*/,4/*列号或字典key*/,"非数值文本:"++math.random(0,100)/*单元格文本*/);
    • mainForm.vlist.setCellText( 6/*行号*/,4/*列号或字典key*/,math.random(0,100)++":我也是数值,因为我数字开头"/*单元格文本*/);
    • mainForm.vlist.setCellText( 7/*行号*/,4/*列号或字典key*/,"我是一串文本"/*单元格文本*/);
    • }
    • win.loopMessage();


    使用内置函数启用绘制整行背景进度条,多线程下载示例:


    Code AardioLine:92复制
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
  • 92.
    • import win.ui;
    • import godking.vlistEx;
    • import thread.works
    • /*DSG{{*/
    • var mainForm = win.form(text="aardio form";right=1031;bottom=551)
    • mainForm.add(
    • button={cls="button";text="停止下载";left=296;top=480;right=448;bottom=528;z=2};
    • button2={cls="button";text="开始下载";left=520;top=480;right=672;bottom=528;z=3};
    • vlist={cls="vlistEx";left=10;top=10;right=1024;bottom=464;db=1;dl=1;dr=1;dt=1;edge=1;transparent=1;z=1}
    • )
    • /*}}*/
    • var t = { fields={"序号","url","保存文件","下载进度"} };
    • for(i=1;30;1){
    • ..table.push(t,{"序号"="[@rowindex]"});
    • }
    • mainForm.vlist.setTable(t,/*列标题*/,{scale=true,0.5,5,3,2}/*列宽*/,1/*对齐方式*/,/*字典转为数组*/,/*字符串转为Utf8*/,true/*是否克隆新表*/);
    • mainForm.vlist.fillParent();
    • ..io.createDir("\down");
    • //调用默认函数,启用绘制整行背景进度条功能
    • mainForm.vlist.enableRowProgress(true,4);
    • import thread.command
    • thread.command.instance().setinfo = function(row,v,url,file){
    • if #url mainForm.vlist.setCellText(row,2,url);
    • if #file mainForm.vlist.setCellText(row,3,file);
    • mainForm.vlist.setCellText(row,4,v);
    • }
    • var work = thread.works(5,
    • function(param) {
    • if thread.var("stop").get() return ;
    • import godking.http;
    • import thread.command;
    • thread.command.setinfo(param.index,"开始 "++param.index,param.url);
    • var t,n={info = "超时或终止"},0;
    • var callback = function(id,v,all,url,file){
    • thread.command.setinfo(id,..math.round((v:0)*100/all,2)++"%",url,file);
    • return thread.var("stop").get();
    • };
    • do{
    • n++;
    • if n>3 or thread.var("stop").get() break; // 下载失败重试,共3次后结束。
    • _,_,t = godking.http({
    • url = param.url;
    • callback = callback;
    • callbackID = param.index;
    • file = "\down\QQ_"+param.index+".exe";
    • fileResume = true;
    • })
    • } while ( !t.success and t.info!=="下载被终止" )
    • if t.success===true {
    • thread.command.setinfo(param.index,"下载完毕",param.url,t.file);
    • } elseif t.success===false {
    • thread.command.setinfo(param.index,"下载失败:"++(t.info:"")++..math.round(t.downsize*100/t.allsize,2)++"%",param.url,t.file);
    • } else {
    • thread.command.setinfo(param.index,"下载失败:"++(t.info:""));
    • }
    • return ;
    • }
    • );
    • mainForm.show();
    • mainForm.button.oncommand = function(id,event){
    • thread.var("stop").set(true);
    • }
    • mainForm.button2.oncommand = function(id,event){
    • thread.var("stop").set(false);
    • mainForm.vlist.setTable(t,false/*列标题*/,/*列宽*/,/*对齐方式*/,/*字典转为数组*/,/*字符串转为Utf8*/,true/*是否克隆新表*/);
    • for(i=1;50;1){
    • if thread.var("stop").get() return ;
    • work.push({index=i,url="https://dldir1.qq.com/qqfile/qq/QQNT/Windows/QQ_9.9.15_240902_x86_01.exe"});
    • }
    • }
    • mainForm.onClose = function(hwnd,message,wParam,lParam){
    • import process
    • process().terminate();
    • }
    • // 定时刷新虚表
    • mainForm.vlist.autoRedraw = false;
    • mainForm.setInterval(
    • function(){
    • mainForm.vlist.redraw(true);
    • },200
    • )
    • win.loopMessage();


    高级点的用法,使用事件函数启用绘制整行背景进度条,多线程下载示例:


    Code AardioLine:97复制
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
  • 92.
  • 93.
  • 94.
  • 95.
  • 96.
  • 97.
    • import win.ui;
    • import godking.vlistEx;
    • import thread.works
    • /*DSG{{*/
    • var mainForm = win.form(text="aardio form";right=1031;bottom=551)
    • mainForm.add(
    • button={cls="button";text="停止下载";left=296;top=480;right=448;bottom=528;z=2};
    • button2={cls="button";text="开始下载";left=520;top=480;right=672;bottom=528;z=3};
    • vlist={cls="vlistEx";left=10;top=10;right=1024;bottom=464;db=1;dl=1;dr=1;dt=1;edge=1;transparent=1;z=1}
    • )
    • /*}}*/
    • var t = { fields={"序号","url","保存文件","下载进度"} };
    • for(i=1;30;1){
    • ..table.push(t,{"序号"="[@rowindex]"});
    • }
    • mainForm.vlist.setTable(t,/*列标题*/,{scale=true,0.5,5,3,2}/*列宽*/,1/*对齐方式*/,/*字典转为数组*/,/*字符串转为Utf8*/,true/*是否克隆新表*/);
    • mainForm.vlist.fillParent();
    • ..io.createDir("\down");
    • //使用事件函数,实现绘制整行背景进度条功能
    • mainForm.vlist.onDrawCellRectBg = function(row,col,hdc,rect,bkcolor,text,font,align,valign,recall){
    • //成功绘制进度条的直接返回
    • if mainForm.vlist.drawRowProgress(row,4,hdc,rect) return true;
    • //否则将下载完毕的单元格改变背景色
    • if owner.getCellText(row,"下载进度")=="下载完毕" return false,0xE6F0FA;
    • }
    • import thread.command;
    • thread.command.instance().setinfo = function(row,v,url,file,rowprogress){
    • if #url mainForm.vlist.setCellText(row,2,url);
    • if #file mainForm.vlist.setCellText(row,3,file);
    • mainForm.vlist.setCellText(row,4,v);
    • }
    • var work = thread.works(5,
    • function(param) {
    • if thread.var("stop").get() return ;
    • import godking.http;
    • import thread.command;
    • thread.command.setinfo(param.index,"开始 "++param.index,param.url,,true);
    • var t,n={info = "超时或终止"},0;
    • var callback = function(id,v,all,url,file){
    • thread.command.setinfo(id,..math.round((v:0)*100/all,2)++"%",url,file,null);
    • return thread.var("stop").get();
    • };
    • do{
    • n++;
    • if n>3 or thread.var("stop").get() break; // 下载失败重试,共3次后结束。
    • _,_,t = godking.http({
    • url = param.url;
    • callback = callback;
    • callbackID = param.index;
    • file = "\down\QQ_"+param.index+".exe";
    • fileResume = true;
    • })
    • } while ( !t.success and t.info!=="下载被终止" );
    • if t.success===true {
    • thread.command.setinfo(param.index,"下载完毕",param.url,t.file,false);
    • } elseif t.success===false {
    • thread.command.setinfo(param.index,"下载失败:"++(t.info:"")++..math.round(t.downsize*100/t.allsize,2)++"%",param.url,t.file,false);
    • } else {
    • thread.command.setinfo(param.index,"下载失败:"++(t.info:""),,,false);
    • }
    • return ;
    • }
    • );
    • mainForm.show();
    • mainForm.button.oncommand = function(id,event){
    • thread.var("stop").set(true);
    • }
    • mainForm.button2.oncommand = function(id,event){
    • thread.var("stop").set(false);
    • mainForm.vlist.setTable(t,false/*列标题*/,/*列宽*/,/*对齐方式*/,/*字典转为数组*/,/*字符串转为Utf8*/,true/*是否克隆新表*/);
    • for(i=1;50;1){
    • if thread.var("stop").get() return;
    • work.push({index=i,url="https://dldir1.qq.com/qqfile/qq/QQNT/Windows/QQ_9.9.15_240902_x86_01.exe"});
    • }
    • }
    • mainForm.onClose = function(hwnd,message,wParam,lParam){
    • import process;
    • process().terminate();
    • }
    • // 定时刷新虚表
    • mainForm.vlist.autoRedraw = false;
    • mainForm.setInterval(
    • function(){
    • mainForm.vlist.redraw(true);
    • },200
    • )
    • win.loopMessage();


    最新回复 (5)
    • aika107 3天前
      0 引用 2

    • kangge 1天前
      0 引用 3
      每一个用法的代码都试过了,都会报错 mainForm.vlist.enableRowProgress(true,4);都指向这一句,是什么原因呢?
    • 光庆 1天前
      0 引用 4
      kangge 每一个用法的代码都试过了,都会报错 mainForm.vlist.enableRowProgress(true,4);都指向这一句,是什么原因呢?
      升级库试试
    • kangge 1天前
      0 引用 5

      虚表升级到今天发布的最新版了,还是报错。我从官方下了个aardio,导入虚表库,也是一样的提示。

      ---------------------------

      aardio:运行时错误

      ---------------------------

      错误行号:#20

      文件:[string "import win.ui;..."]:

      不支持此操作:call

      定义类型:method(table)

      名字:'enableRowProgress'

      类型:null

      ---------------------------------------------------

      调用栈:

      [string "import win.ui;..."]:20: in main chunk

      ---------------------------

      确定   

      ---------------------------


    • 光庆 1天前
      0 引用 6
      kangge 虚表升级到今天发布的最新版了,还是报错。我从官方下了个aardio,导入虚表库,也是一样的提示。---------------------------aardio:运行时错误------------- ...
      等我再上传一次试试
    返回