现在的位置: 首页 > 综合 > 正文

aauto桌面小应用-简单番茄钟

2019年10月13日 ⁄ 综合 ⁄ 共 3483字 ⁄ 字号 评论关闭

近日粗略学习了aauto这一动态语言,尝试写了一个番茄钟的小应用。aauto主要面向win系统桌面小程序的快速开发,开发平台十分小巧,但是功能十分强大。

此程序给同为初学者 一个参考。

关于番茄钟

工作时间内全力工作,休息时间好好休息,帮助你劳逸结合,提高工作效率。一个番茄钟为一个工作单位,在一个番茄钟开始前设定合适工作目标,尽量在一个单位内完成这个目标。

列出两个番茄钟的相关软件,供参考:

  • 来自豆瓣的番茄土豆:https://pomotodo.com/
  • 来自chrome的休息一下:http://wzh.me/technology/chrome-take-a-rest/

简单番茄钟程序介绍:

概述:

按“开始”按键开始倒计时,按“重置”按键回到主界面。计时结束后番茄数加一,自动进入休息状态,锁住键盘和鼠标(ctrl+alt+del可解锁),休息时间结束后,恢复到主界面。

具体实现:

1、main.aau 绘制界面,处理按键响应与定时器响应
import win.ui;
import win.timer; 
import Mine.TimeSys;
import Mine.GrowUpSys;
/*DSG{{*/
mainForm = ..win.form(text="定时器";right=134;bottom=51;max=false;min=false;topmost=1)
mainForm.add(
m={cls="static";text="00";left=6;top=6;right=30;bottom=31;align="center";center=1;font=LOGFONT( h=-20 );transparent=1;z=1};
s={cls="static";text="00";left=39;top=6;right=65;bottom=31;align="center";center=1;font=LOGFONT( h=-20 );transparent=1;z=2};
start={cls="button";text="开始";left=80;top=8;right=124;bottom=42;font=LOGFONT( name='Tekton Pro Ext';h=-16;weight=700 );z=6};
static={cls="static";text=":";left=26;top=6;right=43;bottom=27;align="center";center=1;font=LOGFONT( h=-20 );transparent=1;z=5};
static5={cls="static";text="番茄  X";left=4;top=29;right=49;bottom=49;align="center";center=1;transparent=1;z=3};
南瓜值={cls="static";text="0";left=40;top=29;right=72;bottom=49;align="center";center=1;transparent=1;z=4}
)
/*}}*/

//初始化
var timesys = Mine.TimeSys(0,30,0);
timesys.initTime();
var growUp = Mine.GrowUpSys();


BlockInput := User32.api("BlockInput","BOOL (BOOL fBlockIt)");

mainForm.start.oncommand = function(id,event){
	var text = mainForm.start.text;
	if(text=="开始")//
	{
		//开始计数
		timesys.start();
		//转变为停止
		text = "重置";
	}
	elseif(text == "重置"){
		//重置时间
		timesys.initTime();
		text="开始";		
	}	
	mainForm.start.text = text;
}

var isWork = true; 
var workTimeHandle = function(){
	if(timesys.timeout())
	{
		//刷新成就
		growUp.update();
		//重置时间
		timesys.initTime();
		mainForm.start.text="开始";
			
		//锁住键盘鼠标
		BlockInput(1);
		timesys.setTime(0,5,0);
		timesys.start();	
		isWork = !isWork;	
	}
	else {
		timesys.update();
	}
	
}

var restTimeHandle = function(){
	if(timesys.timeout())
	{
		timesys.setTime(0,30,0);
		timesys.initTime();
		BlockInput(0);
		isWork = !isWork;	
	}
	else {
		timesys.update();
	}
}

Mine.TimeSys.time1.onTimer = function(hwnd,msg,id,tick){
	
	if(isWork){
		workTimeHandle();
	}
	else {
		restTimeHandle();
	}
		
}

mainForm.onClose = function(hwnd,message,wParam,lParam){
    growUp.close();
}
mainForm.show() ;
win.loopMessage(); 

2、GrowUpSys.aau 文件处理番茄计数,有个很难忍受的问题是不知道怎么把data文件内置在exe文件,现在发布后需要多出一个data.txt文件来管理计数数据。

namespace Mine;
import fsys;

class GrowUpSys{/*成长系统*/

	ctor(){
		var 番茄=0;		
		var filePath = "\data.txt";
		
		var str = ..string.load(filePath);
		if(#str)番茄 = tonumber(str);
		global.mainForm.番茄值.text = 番茄;
	};
	
	close = function(){		
		if( !..io.exist(filePath) )//若路径不存在
			..fsys.createParentDir(filePath);
		..string.save(filePath,tostring(番茄) );
	}
	
	update = function(){
		番茄++;
		global.mainForm.番茄值.text = 番茄;
	}	
}
3、TimeSys.aau 用来管理定时器
import win.ui;
import win.timer; 

namespace Mine;

class TimeSys{

	 
	ctor(h1,m1,s1){
		var h,m,s;
		var startTime;
		var tm;
		var show;
		var initTime;
		var time;
		this.h = h1;
		this.m = m1;
		this.s = s1;
		
		time1 = ..win.timer(,1000);
	};
	
	setTime = function(h1,m1,s1){
		
		this.h = h1;
		this.m = m1;
		this.s = s1;
	}
	
	show = function(){ //将时间改写到显示
		//global.mainForm.h.text = ..string.format("%02d",tm.hour);
		global.mainForm.m.text = ..string.format("%02d",tm.minute);
		global.mainForm.s.text = ..string.format("%02d",tm.second);
	}
	
	initTime = function(){
		time1.disable();
		var str = this.h+':'+this.m+':'+this.s;
		tm = ..time(str,"%H:%M:%S");
		this.show();		
	}

	start = function(){
	
		this.initTime();
		time1.enable();
	}
	
	update = function(){
		tm.addsecond(-1);
		this.show();
	}

	timeout = function(){
		if(tm.hour==0&&tm.minute==0&&tm.second==0){
			return 1; 
		}
		return 0; 
	}
	
	
}

源码下载前往:


【上篇】
【下篇】

抱歉!评论已关闭.