/* start module: pyjamas.Timer */
pyjamas.Timer = $pyjs.loaded_modules["pyjamas.Timer"] = function (__mod_name__) {
if(pyjamas.Timer.__was_initialized__) return pyjamas.Timer;
pyjamas.Timer.__was_initialized__ = true;
if (__mod_name__ == null) __mod_name__ = 'pyjamas.Timer';
var __name__ = pyjamas.Timer.__name__ = __mod_name__;
var Timer = pyjamas.Timer;

 pyjslib.__import__(['pyjamas.sys', 'sys'], 'sys', 'pyjamas.Timer')
 pyjamas.Timer.sys = $pyjs.__modules__.sys
if (pyjslib.bool(!new pyjslib.List([String('mozilla'), String('ie6'), String('opera'), String('oldmoz'), String('safari')]).__contains__(pyjamas.Timer.sys.platform))) {
	pyjslib.__import__(['pyjamas.gobject.timeout_add', 'pyjamas.gobject', 'gobject.timeout_add', 'gobject'], 'gobject.timeout_add', 'pyjamas.Timer')
	pyjamas.Timer.timeout_add = $pyjs.__modules__.gobject.timeout_add;
}
else {
	timers = new pyjslib.List([]);
}
pyjamas.Timer.Timer = (function(){
	var cls_instance = pyjs__class_instance('Timer');
	var cls_definition = new Object();
	cls_definition.__md5__ = '67aa8c5b971a2515be4d1edfd945aa96';
	cls_definition.__init__ = pyjs__bind_method(cls_instance, '__init__', function(delay, object) {
		if (this.__is_instance__ === true) {
			var self = this;
		} else {
			var self = arguments[0];
			delay = arguments[1];
			object = arguments[2];
		}
		if (typeof delay == 'undefined') delay=0;
		if (typeof object == 'undefined') object=null;

		self.isRepeating = false;
		self.timerId = 0;
		self.listener = object;
		if (pyjslib.bool((pyjslib.cmp(delay, pyjamas.Timer.Timer.MIN_PERIOD) != -1))) {
			self.schedule(delay);
		}
		return null;
	}
	, 1, [null,null,'self', 'delay', 'object']);
	cls_definition.clearInterval = pyjs__bind_method(cls_instance, 'clearInterval', function(id) {
		if (this.__is_instance__ === true) {
			var self = this;
		} else {
			var self = arguments[0];
			id = arguments[1];
		}


        $wnd.clearInterval(id);
        
	}
	, 1, [null,null,'self', 'id']);
	cls_definition.clearTimeout = pyjs__bind_method(cls_instance, 'clearTimeout', function(id) {
		if (this.__is_instance__ === true) {
			var self = this;
		} else {
			var self = arguments[0];
			id = arguments[1];
		}


        $wnd.clearTimeout(id);
        
	}
	, 1, [null,null,'self', 'id']);
	cls_definition.createInterval = pyjs__bind_method(cls_instance, 'createInterval', function(timer, period) {
		if (this.__is_instance__ === true) {
			var self = this;
		} else {
			var self = arguments[0];
			timer = arguments[1];
			period = arguments[2];
		}


        return $wnd.setInterval(function() { timer.fire(); }, period);
        
	}
	, 1, [null,null,'self', 'timer', 'period']);
	cls_definition.createTimeout = pyjs__bind_method(cls_instance, 'createTimeout', function(timer, delay) {
		if (this.__is_instance__ === true) {
			var self = this;
		} else {
			var self = arguments[0];
			timer = arguments[1];
			delay = arguments[2];
		}


        return $wnd.setTimeout(function() { timer.fire(); }, delay);
        
	}
	, 1, [null,null,'self', 'timer', 'delay']);
	cls_definition.hookWindowClosing = pyjs__bind_method(cls_instance, 'hookWindowClosing', function() {
		if (this.__is_instance__ === true) {
			var self = this;
		} else {
			var self = arguments[0];
		}

 		return null;
	}
	, 1, [null,null,'self']);
	cls_definition.notify = pyjs__bind_method(cls_instance, 'notify', function() {
		if (this.__is_instance__ === true) {
			var self = this;
			var args = new Array();
			for (var pyjs__va_arg = 0; pyjs__va_arg < arguments.length; pyjs__va_arg++) {
				var pyjs__arg = arguments[pyjs__va_arg];
				args.push(pyjs__arg);
			}
			args = pyjslib.Tuple(args);

		} else {
			var self = arguments[0];
			var args = new Array();
			for (var pyjs__va_arg = 1; pyjs__va_arg < arguments.length; pyjs__va_arg++) {
				var pyjs__arg = arguments[pyjs__va_arg];
				args.push(pyjs__arg);
			}
			args = pyjslib.Tuple(args);

		}

		if (pyjslib.bool(pyjslib.eq(self.notify_fn.func_code.co_argcount, 2))) {
			self.notify_fn(self.timer_id);
		}
		else {
			self.notify_fn();
		}
		return null;
	}
	, 1, ['args',null,'self']);
	cls_definition.cancel = pyjs__bind_method(cls_instance, 'cancel', function() {
		if (this.__is_instance__ === true) {
			var self = this;
		} else {
			var self = arguments[0];
		}

		if (pyjslib.bool(self.isRepeating)) {
			self.clearInterval(self.timerId);
		}
		else {
			self.clearTimeout(self.timerId);
		}
		if (pyjslib.bool(timers.__contains__(self))) {
			timers.remove(self);
		}
		return null;
	}
	, 1, [null,null,'self']);
	cls_definition.run = pyjs__bind_method(cls_instance, 'run', function() {
		if (this.__is_instance__ === true) {
			var self = this;
		} else {
			var self = arguments[0];
		}

		self.listener.onTimer(self.timerId);
		return null;
	}
	, 1, [null,null,'self']);
	cls_definition.schedule = pyjs__bind_method(cls_instance, 'schedule', function(delayMillis) {
		if (this.__is_instance__ === true) {
			var self = this;
		} else {
			var self = arguments[0];
			delayMillis = arguments[1];
		}

		if (pyjslib.bool((pyjslib.cmp(delayMillis, pyjamas.Timer.Timer.MIN_PERIOD) == -1))) {
			pyjamas.Timer.alert(String('Timer delay must be positive'));
		}
		if (pyjslib.bool(timers.__contains__(self))) {
			self.cancel();
		}
		self.isRepeating = false;
		self.timerId = self.createTimeout(self, delayMillis);
		timers.append(self);
		return null;
	}
	, 1, [null,null,'self', 'delayMillis']);
	cls_definition.scheduleRepeating = pyjs__bind_method(cls_instance, 'scheduleRepeating', function(periodMillis) {
		if (this.__is_instance__ === true) {
			var self = this;
		} else {
			var self = arguments[0];
			periodMillis = arguments[1];
		}

		if (pyjslib.bool((pyjslib.cmp(periodMillis, pyjamas.Timer.Timer.MIN_PERIOD) == -1))) {
			pyjamas.Timer.alert(String('Timer period must be positive'));
		}
		if (pyjslib.bool(timers.__contains__(self))) {
			self.cancel();
		}
		self.isRepeating = true;
		self.timerId = self.createInterval(self, periodMillis);
		timers.append(self);
		return null;
	}
	, 1, [null,null,'self', 'periodMillis']);
	cls_definition.fire = pyjs__bind_method(cls_instance, 'fire', function() {
		if (this.__is_instance__ === true) {
			var self = this;
		} else {
			var self = arguments[0];
		}

		self.fireImpl();
		return null;
	}
	, 1, [null,null,'self']);
	cls_definition.fireImpl = pyjs__bind_method(cls_instance, 'fireImpl', function() {
		if (this.__is_instance__ === true) {
			var self = this;
		} else {
			var self = arguments[0];
		}

		if (pyjslib.bool((!(self.isRepeating)) && (timers.__contains__(self)))) {
			timers.remove(self);
		}
		self.run();
		return null;
	}
	, 1, [null,null,'self']);
	cls_definition.getID = pyjs__bind_method(cls_instance, 'getID', function() {
		if (this.__is_instance__ === true) {
			var self = this;
		} else {
			var self = arguments[0];
		}

		return self.timerId;
	}
	, 1, [null,null,'self']);
	cls_definition.MIN_PERIOD = 1
	return pyjs__class_function(cls_instance, cls_definition, 
	                            new Array(pyjslib.object));
})();
return this;
}; /* end pyjamas.Timer */
$pyjs.modules_hash['pyjamas.Timer'] = $pyjs.loaded_modules['pyjamas.Timer'];


 /* end module: pyjamas.Timer */


/*
PYJS_DEPS: ['sys', 'gobject.timeout_add', 'gobject']
*/
