aardio 编辑GUI界面,调用 python 脚本示例

news/2024/7/7 19:39:42

aardio 中调用 python 的方法有两种,py3 和 process.python 模块
py3 模块:如果经常要拿到python返回的值或从aardio中传数据给python去处理,aardio和python的交互比较多的话,可以考虑使用py3模块,缺点是:py3模块使用起来比较麻烦些,尤其是在异步多线程操作的话,中间需要学习的东西比较绕。
process.python 模块:如果aardio和python的交互不多(比如aardio负责做界面,python负责做爬虫或负责下载文件之类程序),只需后台由python负责完成相关工作的,用process.python来处理是非常方便的,而且使用logRespone可以完整回传Python中print或loggin打印出的信息给aardio的界面控件。 缺点:一般直接指定执行.py脚本,中间不好做交互,参数传递一般在execfile()命令执行时传递给python脚本,然后待脚本执行完成。
 

aardio 编辑GUI界面,调用 python 脚本示例。

编写 main.aardio  如下

import win.ui;
/*DSG{{*/
mainForm = win.form(text="读取PDF目录";right=899;bottom=511)
mainForm.add(
button1={cls="button";text="打开文件";left=627;top=21;right=702;bottom=43;z=2};
button2={cls="button";text="读取PDF目录";left=23;top=63;right=139;bottom=92;z=3};
button3={cls="button";text="读取目录.txt转换为FreeMind文件";left=153;top=62;right=352;bottom=91;z=4};
button4={cls="button";text="读取目录.txt文件转换为.json文件";left=365;top=63;right=563;bottom=91;z=5};
button5={cls="button";text="读取目录.txt转换为jstree模板所需的文件";left=581;top=64;right=815;bottom=91;z=6};
edit1={cls="edit";left=19;top=21;right=601;bottom=44;edge=1;z=1};
edit2={cls="edit";left=14;top=118;right=888;bottom=498;edge=1;multiline=1;readonly=1;vscroll=1;z=7}
)
/*}}*/

import io;
import sys;
import fsys.dlg;

//aardio调用python
import process.python;
import process.python.pip;
//process.python.pip("install pypdf2==2.12.1");
//process.python.pip("install xmltodict");
//process.python.pip("install jinja2");

var f1, f2, tpath, py, txt;
// 打开文件
mainForm.button1.oncommand = function(id,event){
	mainForm.button1.disabled = true;
	f1 = fsys.dlg.open("pdf,文本文件|*.pdf;*.txt");
	if (io.exist(f1)){
		mainForm.edit1.text = f1;
		tpath = io.splitpath(f1);
		if (tpath.ext =='.txt'){
			txt = string.load(f1);
			mainForm.edit2.text = txt;
		}
	} else {
		mainForm.msgbox("file not found.");
	}	
	mainForm.button1.disabled = false;
}

// 读取PDF目录,生成PDF目录.txt
mainForm.button2.oncommand = function(id,event){
	mainForm.button2.disabled = true;
	f1 = mainForm.edit1.text;
	if (io.exist(f1)){
		tpath = io.splitpath(f1);
		if (tpath.ext =='.pdf'){
			py = process.python.execfile("\res\pdf_read_dir.py", f1);
			py.logResponse(mainForm.edit2)
		}
	}
	sleep(1000);
	f2 = string.replace(f1,'.pdf','.txt',1);
	if (io.exist(f2)){
		mainForm.edit1.text = f2;
		tpath = io.splitpath(f2);
		if (tpath.ext =='.txt'){
			txt = string.load(f2);
			mainForm.edit2.text = txt;
		}
	} else {
		mainForm.msgbox(f2++" not found.");
	}
	mainForm.button2.disabled = false;	
}

// 读取目录.txt转换为FreeMind(.mm)文件
mainForm.button3.oncommand = function(id,event){
	mainForm.button3.disabled = true;
	f1 = mainForm.edit1.text;
	if (io.exist(f1)){
		mainForm.edit1.text = f1;
		tpath = io.splitpath(f1);
		if (tpath.ext =='.txt'){
			py = process.python.execfile("\res\txt_xml_etree_mm.py", f1);
			py.logResponse(mainForm.edit2)
		}
	} else {
		mainForm.msgbox("file not found.");
	}
	mainForm.button3.disabled = false;	
}

// 读取目录.txt文件转换为.json文件
mainForm.button4.oncommand = function(id,event){
	mainForm.button4.disabled = true;
	f1 = mainForm.edit1.text;
	if (io.exist(f1)){
		tpath = io.splitpath(f1);
		if (tpath.ext =='.txt'){
			py = process.python.execfile("\res\txt_xml_etree_json.py", f1);
			py.logResponse(mainForm.edit2)
		}
	} else {
		mainForm.msgbox("file not found.");
	}
	f2 = string.replace(f1,'.txt','.json',1);
	mainForm.edit2.text = f2;
	mainForm.button4.disabled = false;
}

// 读取目录.txt转换为jstree模板所需的html文件
mainForm.button5.oncommand = function(id,event){
	mainForm.button5.disabled = true;
	var f1 = mainForm.edit1.text;
	if (io.exist(f1)){
		tpath = io.splitpath(f1);
		if (tpath.ext =='.txt'){
			py = process.python.execfile("\res\txt_xml_etree_html.py", f1);
			py.logResponse(mainForm.edit2)
		}
	} else {
		mainForm.msgbox("file not found.");
	}
	f2 = string.replace(f1,'.txt','.htm',1);
	mainForm.edit2.text = f2;
	mainForm.button5.disabled = false;	
}

mainForm.show();
return win.loopMessage();

运行(F5)


http://lihuaxi.xjx100.cn/news/2024117.html

相关文章

【EAI 016】VIMA: General Robot Manipulation with Multimodal Prompts

论文标题:VIMA: General Robot Manipulation with Multimodal Prompts 论文作者:Yunfan Jiang, Agrim Gupta, Zichen Zhang, Guanzhi Wang, Yongqiang Dou, Yanjun Chen, Li Fei-Fei, Anima Anandkumar, Yuke Zhu, Linxi Fan 作者单位:Stanfo…

轻薄型机型EM-T195,对移动作业so easy

由于移动工作环境特殊且不固定,不仅温差大,还会产生潮湿、干燥、灰尘等恶劣气候环境,使普通平板电脑无法适应移动工作。但三防平板电脑是设计制造的,材料特殊,可以平静面对上述恶劣环境,保证随时随地保持良…

Linux中pipe管道操作

管道的读写操作: 读操作: ​​​有数据:read正常读,返回读出的字节数无数据:1 写段全部关闭:read解除阻塞,返回0,相当于文件读到了尾部 2 写段没有全部关闭&#xf…

老兵(10)

每个人有每个人的的使命,即便还没有清晰的意识到,即便自己注定看不到所作的一切的结果,即便将来不会有人记得。 甚至,不论此间还是彼端,都不免常常会怀疑所知所为的意义。 我们可以把这个叫做觉悟,或者信念…

锐捷(十九)锐捷设备的接入安全

1、PC1的IP地址和mac地址做全局静态ARP绑定; 全局下:address-bind 192.168.1.1 mac(pc1) G0/2:ip verify source port-securityarp-check 2、PC2的IP地址和MAC地址做全局IPMAC绑定: Address-bind 192.168.1.2 0050.7966.6807Ad…

原来你也可以DDOS?

首先祝大家新年快乐 这次内容就主要是纸上谈兵(因为无法未经试验无法保证成功),而且有关这方面的科普视频也已经有很多了。 原文地址:原来你也可以DDOS? - Pleasure的博客 下面是正文内容: 前言 DDOS是一…

2024全栈元年-thinkphp-数据操作

thinkphp 数据相关操作 1.单数据查询 1、单数据查询 ,Db::table(‘tp_stu’) 必须加前缀 2、如果只是查询符合条件的使用where find,如果没有符合条件的返回null 3、使用 findOrFail 没有数据会抛出异常 4、使用 findOrEmpty 没有数据会返回【】 5、得到最近一个原生SQL …

Python 中的断点类型详解

前言 在 Python 中,断点是一种在代码中设置的标记,用于在程序执行过程中停止或中断程序的执行,以便调试和查看程序的内部状态。断点是调试工具的关键组成部分,能够帮助开发者定位和解决代码中的错误。本文将详细介绍 Python 中的…