直接上图,
import fonts.fontAwesome;
import win.ui;
/*DSG{{*/
var winform = win.form(text="设置";right=984;bottom=589;bgcolor=5921370;composited=1)
winform.add(
btnReset={cls="plus";text='\uF0E2 重置';left=509;top=529;right=690;bottom=565;bgcolor=11580047;db=1;dr=1;font=LOGFONT(h=-16;name='FontAwesome');notify=1;tabstop=1;z=4};
btnSave={cls="plus";text='\uF0C7 保存';left=703;top=528;right=887;bottom=564;bgcolor=11580047;db=1;dr=1;font=LOGFONT(h=-16;name='FontAwesome');notify=1;tabstop=1;z=3};
chkTest={cls="plus";text='\uF0C8 某选项';left=372;top=439;right=812;bottom=470;align="left";color=15793151;dl=1;dt=1;font=LOGFONT(h=-16;name='FontAwesome');notify=1;z=2};
edit={cls="edit";text="Edit";left=618;top=17;right=961;bottom=243;edge=1;multiline=1;z=5};
lbTip={cls="static";left=63;top=523;right=695;bottom=572;db=1;dl=1;dr=1;transparent=1;z=1};
listbox={cls="listbox";left=621;top=262;right=953;bottom=463;edge=1;items={};z=8};
plus={cls="plus";left=116;top=53;right=516;bottom=453;clipBk=false;foreRepeat="stretch";notify=1;repeat="center";z=6};
plus2={cls="plus";text='\uF0E2 重置';left=236;top=516;right=417;bottom=552;bgcolor=11580047;db=1;dr=1;font=LOGFONT(h=-16;name='FontAwesome');notify=1;tabstop=1;z=7}
)
/*}}*/
pyServerThread = function(winform){
import thread.command
import py3
import py3.lib.PIL
import py3.lib.numpy
import py3.lib.systemSitePackages
/*
import console
console.open()
*/
var cmd = thread.command();
var pyCode = /**
import numpy as np
import PIL.Image as Image
import io
#标准输出
import sys
class CatchOutErr:
def __init__(self):
self.value = ''
def write(self, txt):
self.value += txt
catchOutErr = CatchOutErr()
sys.stdout = catchOutErr
sys.stderr = catchOutErr
def getImage(i,winform):
i = int(i)
height = int(winform.plus.height)
pngSize = (height,height)
img = Image.new(mode='RGBA',size = (100,100),color = (255,255,0,255))
n = np.array(img)
c = 255 / 400
n[::i,::i,0] = c*i
#n[:i,:i,1] = 255 - c*i
#n[:i,:i,2] = 255 - c*i
img = Image.fromarray(n)
f = io.BytesIO()
#print(pngSize)
#img = img.resize((pngSize),Image.NEAREST)
#img.show()
img.save(f,format = "png")
#print(f)
#winform.plus.setBackground(f,False)
#print(f.getvalue())
return f.getvalue()
def gett():
return 3
**/
py3.exec(pyCode)
cmd.setImg = function(){
for(i=1;2;1){
winform.edit.log( i,'\r\n' )
imgBytes = py3.main.getImage(i,py3.export(winform))
imgBytes = imgBytes.parseValue()
winform.plus.setForeground(imgBytes,false)
//python标准输出
/*
var pyStdoutStr = tostring( py3.main.catchOutErr.value );
console.log( pyStdoutStr )
*/
//i = i+ i/10
}
winform.btnSave.disabledText = null
}
cmd.onMouseMove = function(x){
winform.edit.log( x,'\r\n' )
imgBytes = py3.main.getImage(tonumber(x) % 100 + 1 ,py3.export(winform))
imgBytes = imgBytes.parseValue()
winform.plus.setForeground(imgBytes,false)
}
cmd.test = function(){
var pyStr = py3.main.gett()
winform.msgbox(pyStr,tostring(pyStr))
}
cmd.pyExit = function(){
win.quitMessage();
}
win.loopMessage();
}
//启动python服务端线程
thread.create( pyServerThread,winform )
import thread.command
winform.btnSave.oncommand = function(id,event){
//禁用按钮,避免重复提交
winform.btnSave.disabledText = {'\uF254';'\uF251';'\uF252';'\uF253';'\uF250';text='运行中'}
//异步调用python线程的函数,不等待返回
thread.command.post("setImg")
//winform.bkplus.background = gdip.bitmap(img.parseValue)
}
winform.btnReset.oncommand = function(id,event){
thread.command.post("test")
}
winform.plus2.skin(
background = {
hover = "/res/images/btn-hover.png";
focus = "/res/images/btn-focus.jpg";
active = "/res/images/btn-active.png";
disabled = "/res/images/btn-disabled.png";
}
)
winform.plus.onMouseMove = function(wParam,lParam){
if( wParam & 0x1/*_MK_LBUTTON*/ ){
var x,y = win.getMessagePos(lParam);
/*鼠标点住不放移动*/
//这个坐标参照父窗口的坐标
thread.command.post("onMouseMove",x)
}
}
winform.plus2.oncommand = function(id,event){
n = {
adrr n = 3
}
winform.msgbox(type(n.n))
}
/*
winform.plus.skin(
background = {
hover = "/res/images/btn-hover.png";
focus = "/res/images/btn-focus.jpg";
active = "/res/images/btn-active.png";
disabled = "/res/images/btn-disabled.png";
}
)
*/
winform.listbox.items = {0,1,2,3,4,5,6,7}
winform.listbox.onSelChange = function(){
//winform.msgbox(tonumber(winform.listbox.selIndex))
//设置图像缩放插值算法
winform.plus.interpolationMode = tonumber(winform.listbox.selText)
//重绘图像
winform.plus.redraw()
}
import style;
winform.chkTest.skin(style.checkBox);
winform.btnSave.skin(style.button);
winform.btnReset.skin(style.button);
winform.show();
win.loopMessage();
return winform;