功能不全,有喜欢的可以自己补下
import win.ui;
/*DSG{{*/
mainForm = win.form(text="PyWin";right=959;bottom=591)
mainForm.add(
cls={cls="button";text="清屏";left=496;top=11;right=545;bottom=43;z=3};
pycode={cls="edit";left=41;top=52;right=477;bottom=586;db=1;dl=1;dr=1;dt=1;edge=1;font=LOGFONT(h=-16;name='宋体');hscroll=1;multiline=1;vscroll=1;z=1};
pylines={cls="listbox";left=4;top=52;right=35;bottom=559;bgcolor=15790320;color=32768;integralHeight=0;items={};z=6};
pyload={cls="button";text="读入";left=282;top=12;right=328;bottom=43;z=7};
pypath={cls="edit";left=42;top=16;right=279;bottom=43;edge=1;z=8};
pyrun={cls="button";text="运行";left=425;top=12;right=471;bottom=43;z=2};
pysave={cls="button";text="保存";left=329;top=12;right=372;bottom=43;z=9};
pysaveto={cls="button";text="另存为";left=377;top=12;right=424;bottom=43;z=10};
pyshow={cls="edit";text="Edit";left=485;top=52;right=957;bottom=587;bgcolor=0;color=65280;edge=1;hscroll=1;multiline=1;vscroll=1;z=4};
sts={cls="static";left=560;top=17;right=950;bottom=40;align="center";transparent=1;z=5}
)
/*}}*/
import py3;
import py3.export.aardio;
import fsys.dlg;
mainForm.pycode.text="";
mainForm.pyshow.text="";
py3.main.qjval="全局";
//var pyMain = py3.import("pyMain");
var keywords=eval($"/res/keys.txt");
/* keys.txt
//行尾加 ":",下一行要自动缩进
{
"def",//定义函数
"for",//范围循环
"if",//如果...
"while",//条件循环
"class",//定义类
"elif",//否则如果..
"else"//否则...
}
//
{
"("=")",
"{"="}",
"["="]"
}
*/
//重定向输出...>>>>>
var pyCode = /**
import sys
#写个输出信息的类
class CatchOutErr:
def __init__(self):
self.value = ''
def write(self, txt):
self.value += txt
#创建有输出功能的对象
catchOutErr = CatchOutErr()
#标准输出重定向到 catchOutErr (不再输出到默认的『控制台命令行黑窗口』)
sys.stdout = catchOutErr
#标准错误输出重定向到 catchOutErr(不再输出到默认的『控制台命令行黑窗口』)
sys.stderr = catchOutErr
**/
py3.exec( pyCode )
//重定向输出...<<<<<
if(#_ARGV && !_STUDIO_INVOKED){
var agv=_ARGV;
for(i=1;#agv;1){
mainForm.pyshow.print(agv[i]);
py.run(agv[i])
}
}
mainForm.pylines.setFont(point=11;name="宋体";);
/*
mainForm.pycode.addCtrl(
splitter={cls="splitter";left=0;top=0;right=20;bottom=540;frame=1;z=7};
)
a=[2,3,4,5,6,2]
b=[]
for v in a:
if(v%2==0):
b.append(v)
print(a)
print(b)
for v in range(1,10):
for k in range(v,10):
print(f"{v}x{k}=",v*k,end=" ")
print()
*/
mainForm.pyrun.oncommand = function(id,event){
py3.main.catchOutErr.value="";//清除错误信息
var pycode=mainForm.pycode.text;
py3.exec(pycode);
var pyrtn=tostring(py3.main.catchOutErr.value );//获取控制台输出信息
mainForm.pyshow.print(pyrtn);//显示到指定窗口
}
mainForm.cls.oncommand = function(id,event){
mainForm.pyshow.text="";
//py3.exec('sys.stderr=""');
//py3.exec('sys.stdout=""');
py3.main.catchOutErr.value="";
}
mainForm.pycode.wndproc = function(hwnd,message,wParam,lParam){
if(message==0x100/*_WM_KEYDOWN*/ && wParam==0xD){//按下回车键
var lt=owner.lineText(owner.selLine);//
var k=string.split(string.trim(lt),' ')[1];
if(table.find(keywords,k)){owner.selText=":";}//特定关键字开始的行,行尾自动加 冒号
}
if(message==0x101 && wParam==0xD){//回车键弹起,加入自动缩进,一段代码只能使用一种缩进符
var lt=owner.lineText(owner.selLine-1);
var lts=string.match(lt,"^[ ]*");
owner.selText=lts;
lts=string.match(lt,"^\t*");
owner.selText=lts;
}
if(message==0x101 && wParam==0x9){//当前光标处插入 一个TAB键
owner.selText=' ';
}
if(message==0x101){
mainForm.pylines.selIndex=owner.selLine;
mainForm.sts.text=""++owner.selLine++"/"++owner.lineCount;
}
//mainForm.pyshow.print(message);
if(message==514){//鼠标弹起结束
mainForm.sts.text=owner.selText;
mainForm.pylines.selIndex=owner.selLine;
mainForm.sts.text=""++owner.selLine++"/"++owner.lineCount;
}
//无返回值则继续调用默认回调函数
}
mainForm.pycode.onChange = function(){
if(owner.onModified)owner.onModified(true);
mainForm.pylines.clear();
//owner.validateText("<\d+\.\d\d>|<\d+\.\d>|<\d+\.>|<\d+>"/,"请输入金额,小数点后不能超过 2 位!");
for(i=1;owner.lineCount+1;1){
mainForm.pylines.add(tostring(i));
}
mainForm.pylines.selIndex=owner.selLine;
}
mainForm.pyload.oncommand = function(id,event){
var ph=fsys.dlg.open("Python源文件|*.py","选择打开",,,,mainForm.pypath.text);
if(io.exist(ph)){
mainForm.pypath.text=ph;
mainForm.pycode.text=string.load(ph);
}
}
mainForm.pysave.oncommand = function(id,event){
var pph=mainForm.pypath.text;
if(string.trim(pph)=="" || string.upper(string.match(pph,"[^.]+$"))!="PY"){
var ph=fsys.dlg.save("Python源文件|*.py","保存为....");
pph=io.fullpath(ph);
mainForm.pypath.text=pph;
}
if(win.msgboxTest("确认保存修改?")){
string.save(pph,mainForm.pycode.text);
}
}
mainForm.pysaveto.oncommand = function(id,event){
var pph=mainForm.pypath.text;
var ph=fsys.dlg.save("Python源文件|*.py","另存为..",,,,pph);
if(#ph){
mainForm.sts.text=ph;
pph=io.fullpath(ph);
mainForm.pypath.text=pph;
string.save(pph,mainForm.pycode.text);
}
}
mainForm.show();
return win.loopMessage();
4413

被折叠的 条评论
为什么被折叠?



