Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
friendan committed Apr 13, 2024
1 parent 183a095 commit 2e26a61
Show file tree
Hide file tree
Showing 110 changed files with 1,823 additions and 598 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ import process.python;
/*
如果指定 process.python.path = "python.exe"
则调用系统安装的 Python,没安装会自动下载安装,
否则调用绝色嵌入版 Python ,没下载也会自动下载。
否则调用绿色嵌入版 Python ,没下载也会自动下载。
*/

/*
执行 Python 代码,支持任意版本 python ( 支持 64位 Python )。
调用 32 / 64 位 python.exe 都可以在发布 aardio 程序时打包为独立 EXE 文件。

参数也可以是(*.py, *.aardio 文件路径,支持内存加载资源文件)
如果 Python 代码开始为 aardio 模板标记,则启用模板语法:
chm://the%20language/template_syntax.html
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@ console.log('
\e[46;1m 亮青色背景
\e[47;1m 亮白色背景

\e[0m 恢复默认样式

\e[4m 下划线
\e[1m 粗体
\e[7m 反色

\e[0m 默认颜色
\e[0m 恢复默认样式

光标上移2行:\e[2A
光标下移2行:\e[2B
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ plus={cls="plus";left=390;top=108;right=643;bottom=361;notify=1;z=1}
)
/*}}*/

//教程: https://bbs.aardio.com/forum.php?mod=redirect&goto=findpost&ptid=11486&pid=64075
winform.plus.setPieRange(1,360)
winform.plus.progressPos = 1;
winform.plus.foreground = 0x80ffff00;//也可以改为图像,图像应设为center显示模式以居中对齐
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ plus={cls="plus";left=161;top=282;right=707;bottom=316;bgcolor=6447459;forecolor
//设置进度区间,可自动切换到进度条显示模式
winform.plus.setProgressRange(1,50);

/*
进度条可以是横向的(宽度大于高度),也可以是竖向的(高度大于宽度),
plus 控件会根据设计时的宽高比自动判断进度条的方向,不需要设置其他参数。
教程: https://bbs.aardio.com/forum.php?mod=redirect&goto=findpost&ptid=11486&pid=64074
*/

winform.button.oncommand = function(id,event){
winform.button.disabledText = "测试一下"
winform.plus.startProgress(50);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ trackbar={cls="plus";left=225;top=266;right=667;bottom=281;bgcolor=14265123;bord
)
/*}}*/

//创建滑尺控件教程: https://bbs.aardio.com/forum.php?mod=viewthread&tid=11486&page=1#pid64076

//设置滑尺范围,切换到滑尺模式
winform.trackbar.setTrackbarRange(1,100);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//禁止刷新
import win.ui;

/*DSG{{*/
var winform = win.form(text="Edge 浏览器控件 - 禁止按 F5,Ctrl + R 刷新";right=759;bottom=469;bgcolor=16777215)
winform.add()
/*}}*/

import web.view;
var wb = web.view(winform);

//所有网页自动注入以下 JavaScript
wb.preloadScript(`
document.onkeydown = function (e) {
if (e.key == "F5" || (e.ctrlKey && e.key == "r") ) {
e.preventDefault();
}
} `
)

wb.html = /**
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<script >alert("网页每加载一次,显示一次弹框")</script>
</head>
<body></body>
</html>
**/

winform.show();
win.loopMessage();
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//通用代码块
//原理https://mp.weixin.qq.com/s/BhFTemG3D3i6Ttvzag25XQ
//原理: https://mp.weixin.qq.com/s/BhFTemG3D3i6Ttvzag25XQ
import win.ui;
/*DSG{{*/
var winform = win.form(text="HTML 代码块生成工具 - 本工具使用 aardio 语言编写";right=1055;bottom=674;bgcolor=16777215)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,42 @@
import win.ui;
/*DSG{{*/
var winform = win.form(text="web.view - event-stream";right=753;bottom=434)
winform.add(
)
winform.add()
/*}}*/

import web.view;
var wb = web.view(winform);

//启动多线程 HTTP 服务器
import wsock.tcp.simpleHttpServer;
wb.eventSourceUrl = wsock.tcp.simpleHttpServer.startUrl(function(response,request,session){
response.headers["Access-Control-Allow-Origin"] = "*"

while (true) {
wb.eventSourceUrl = wsock.tcp.simpleHttpServer.startUrl(
function(response,request,session){
response.headers["Access-Control-Allow-Origin"] = "*"

response.eventStream(
event = "ping";
data = { time = time() };
)

sleep(1000);
}
})
while (true) {

response.eventStream(
event = "ping";
data = { time = time() };
)

sleep(1000);
}
}
)

//HTML 支持 aardio 模板语法(可嵌入 aardio 代码,owner 参数为 wb 对象)
wb.html = /**
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<style type="text/css">
html,body{ height:100%; margin:0; }
html,body{ height:100%; margin:50; }
</style>
<script type="text/javascript">
<script src="https://lib.baomitu.com/dayjs/1.11.10/dayjs.min.js"></script>
<script>

const evtSource = new EventSource("<?=owner.eventSourceUrl?>");

evtSource.onerror = function(err) {
Expand All @@ -41,16 +46,14 @@ wb.html = /**

evtSource.addEventListener("ping", function(event) {
const data = JSON.parse(event.data);
document.body.insertAdjacentHTML("beforeEnd","<div>" + "ping at " + data.time + "</div>");
document.body.insertAdjacentHTML("beforeEnd","<div>" + "ping at " + dayjs(data.time).format("YYYY-MM-DD HH:mm:ss") + "</div>");
});

evtSource.onmessage = (event) => {
};
evtSource.onmessage = (event) => {};

</script>
</head>
<body>
</body>
<body></body>
</html>
**/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@ web.view 所有能实现的功能都有范例文档,不需要到处找。

其实这是一个根本就没有答案的问题。

别人能写出来,你不一定能写出来。
写人写不出来,你不一定就写不出来。
我写 web.view 的目的是为了化繁为简,
不是为了大而全,更不是为了变得比 WebView2 更复杂。

你能不能用什么编程语言做什么,这是你自己首先要搞清楚的事情。
如果连这一点也搞不清楚,那你就不应该使用这个编程语言。

aardio 能给的答案就是:
aardio 所有能实现的功能都提供了现成的范例。
如果您确实有这样的需求,可自行封装 WebView2 。
aardio 封装第三方组件并不会太难,我们提供了很多这样的例子。
16 changes: 10 additions & 6 deletions aardio/codes/范例程序/7) Web 界面/4) Chrome/driver.aardio
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import chrome.driver;
自动检测 chromeDriver 版本,并在必要时自动下载匹配版本的chromeDriver。
*/
var driver = chrome.driver();
//协议文档 https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol
//协议文档 https://w3c.github.io/webdriver
//更多用法 https://bbs.aardio.com/forum.php?mod=viewthread&tid=22544

//排除参数,不显示"正受到自动测试软件的控制",老版本 Chrome 可能会有更大的弹框,新版没问题
Expand Down Expand Up @@ -35,21 +35,25 @@ var browser = driver.startBrowser( {
//打开网页
browser.go("http://www.baidu.com")

//查找文本输入框,返回的DOM对象也可以使用ququerySelector继续查找子节点
//查找文本输入框,返回的 DOM 对象也可以使用ququerySelector继续查找子节点
var ele = browser.querySelector("body").querySelector("#kw");

//在网页输入框输入内容
ele.setValue( "ChromeDriver" )
//在网页输入文本,并发送按键。
ele.sendKeys( "ChromeDriver","ENTER" )
/*
可用键名定义于 chrome.driver.keys ,键名与 key,key.VK 库基本兼容。
如果要将键名设为普通文本,可改用 ele.setValue( "ChromeDriver","ENTER" )
*/

//调用JS,并且可以返回值(也可以返回DOM节点对象
//调用 JS,并且可以返回值(也可以返回 DOM 节点对象
var searchButton = browser.doScript(`
//可以使用arguments访问aardio传来的参数
return arguments[0].querySelector("#su");
`
,browser.querySelector("body")//可以传任意个调用参数给JS,还可以直接传DOM节点对象
)

//JS返回的DOM节点对象也可以操作控制
//JS 返回的 DOM 节点对象也可以操作控制
searchButton.click();

//等待网址
Expand Down
7 changes: 5 additions & 2 deletions aardio/codes/范例程序/8) Web 应用/1) REST/8) sse.aardio
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ thread.invoke(
var http = web.rest.jsonLiteClient();

var eventSource = http.api(url)
eventSource.get(,, function(message){
winform.edit.print("HTTP 服务端推送了事件")

//参数 @2 或 参数@3 指定接收数据回调函数则自动支持 SSE,兼容 ndjson 流。
eventSource.get( , function(message){
//注意这里的 message 已经由 JSON 解析为对象
winform.edit.print("HTTP 服务端推送了事件",type(message))
winform.edit.print(message);
} )

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,12 @@ for(i=1;#dmSegMobileReply.elems){
//console.more(1000);
}

import web.json;

//不需要任何封装,所有 Protobuf 消息对象都可以直接转换为 json
var json = web.json.stringify(dmSegMobileReply);

//Protobuf 消息对象可通过 JSON 转换为纯 table 对象
var tab = web.json.strip(dmSegMobileReply)

console.pause(true);
Original file line number Diff line number Diff line change
@@ -1,36 +1,27 @@
//BT 下载
//BT 下载
import win.ui;
/*DSG{{*/
var winform = win.form(text="aria下载器";right=1250;bottom=704;border="none")
var winform = win.form(text="aria下载器";right=1010;bottom=607;border="none")
winform.add(
bk={cls="bk";left=0;top=0;right=1251;bottom=31;bgcolor=11841964;dl=1;dr=1;dt=1;forecolor=5392444;linearGradient=0;z=2};
custom={cls="custom";text="自定义控件";left=0;top=28;right=1251;bottom=706;bgcolor=16777215;db=1;dl=1;dr=1;dt=1;z=1}
bk={cls="bk";left=0;top=0;right=1012;bottom=31;bgcolor=11841964;dl=1;dr=1;dt=1;forecolor=5392444;linearGradient=0;z=2};
custom={cls="custom";text="自定义控件";left=0;top=30;right=1012;bottom=609;bgcolor=16777215;db=1;dl=1;dr=1;dt=1;z=1}
)
/*}}*/

//启动 aria2
import process.aria2;
var aria2 = process.aria2();

//启动服务器
aria2.startServer("--max-connection-per-server=16");

import web.view;
var wb = web.view(winform.custom);

//导入网页前端服务器
import web.ariaNg;
var url = web.ariaNg.getUrl("/index.html#!/settings/rpc/set/ws/127.0.0.1/"+aria2.rpcPort
+"/jsonrpc/"+crypt.bin.encodeBase64(aria2.rpcToken))
var aria2 = process.aria2();
aria2.startServer( maxConcurrentDownloads = 10 );

//导入网页前端
import web.ariaNg;

//打开网页
wb.go(url);

//关闭窗口前关闭 aria2
winform.onDestroy = function(){
aria2.stop();
}
import web.view;
var wb = web.view(winform.custom);
wb.go( web.ariaNg.defaultUrl );

//添加窗口标题栏、边框、阴影等
//自绘标题栏、阴影边框
import win.ui.simpleWindow;
win.ui.simpleWindow(winform);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//RUNAS//禁用设备
import console;
import sys.device;
import process.devcon;

//查找所有鼠标设备
var devices = sys.device("{4D36E96F-E325-11CE-BFC1-08002BE10318}"/*_GUID_DEVCLASS_MOUSE*/);

//遍历找到的鼠标设备
for( index,deviceDesc,hardwareId,T in devices.each(
0/*_SPDRP_DEVICEDESC*/, //添加返回值 deviceDesc
1/*_SPDRP_HARDWAREID*/ //添加返回值 hardwareId
) ){

process.devcon.disable(hardwareId[1]);
}

console.pause(,"已禁用鼠标,按任意键启用鼠标");

for( index,deviceDesc,hardwareId,T in devices.each(0,1) ){

process.devcon.enable(hardwareId[1]);
}

console.pause(,"已启用鼠标,按任意键继续");

/*
//禁用蓝牙
var devices = sys.device("{E0CBF06C-CD8B-4647-BB8A-263B43F0F974}" );
for( index,deviceDesc,hardwareId in devices.each(0,1) ){
process.devcon.disable(hardwareId[1]);
}
*/

Loading

0 comments on commit 2e26a61

Please sign in to comment.