Beispiel #1
0
	def step(self):
		"""
		Execute the script line by line
		"""
		if not self.play_cmd:
			return False		
		
		line = self.get()
		self.warn_observers('step')
		if(line):
			if line[0]!='#':
				line = line.split('#')

				comment = ""
				if len(line) > 1:
					comment = line[1]
					
				line = line[0]
				if self.parse(line, comment):
					self.wait_exec()
				else:
					self.show_message("Stopped! Box returns error", 'error', self.line_number)
					self.warn_observers('stop')					
			else:
				self.show_message("#     " + line[1:])
				self.step()
		else:
			self.show_message("End.")
			m = MessageBox('info')
			m.mostrar('Process Finished', '')
			self.warn_observers('stop')
Beispiel #2
0
	def wait_exec(self):
		"""
		Really wait for the time_ defined or by a click on the box
		"""
		sec_time = self.sec_time

		if sec_time < 0:
			self.show_message("Waiting a click")
			m = MessageBox('info')
			m.mostrar('Wait Box','Click to continue')
			self.next_step = timeout_add(50, self.step)

		else:
			self.show_message("Waiting ddd "+ str(sec_time) + " seconds")
			self.next_step = timeout_add(int(sec_time * 1000), self.step)
	def add_ip(self):
		wdg = self.get_wdg("txtIP")
		ip = wdg.get_text()
		if is_valid_ip(ip):
			cb = self.get_wdg("cbIP")
			model = cb.get_model()
			model.append([ip])
			cb.set_model(model)
			cb.show()
			self.stbip.append(ip)
			if cb.get_active() == -1:
				cb.set_active(0)
		else:
			m = MessageBox('error')
			m.mostrar('Error', 'Invalid IP')
		wdg.set_text('')
	def send(self, key, hold=None):
		"""
		Prepare, send and check return of a remote command to Remote class

		@param key string defines the remote button used
		@param hold enum (0,1,2) represents Button Press Down or UP
		@returns bool the request was successful and the return is valid
		"""
		if len(self.stbip) == 0:
			mb = MessageBox('error')
			mb.mostrar("Set an ip", "Please set an ip to send a command")
			return False

		for ip in self.stbip:
			wdg_retorno = self.get_wdg("txtRetorno")
			if(self.first_command):
				self.first_command = False
				
			if hold is None:
				hold = self.get_wdg("cbRemoteType").get_active()
			rem = Remote(ip)

			ret = rem.send(hold, key)
			msg = "ip: %s\n" % (ip)

			if ret is not None:
				if(rem.return_is_valid(ret, key, hold)):
					complete="Success!"
					tag = "success"
					
					self.show_message(msg + self.__make_rem_readable(ret) + "\n" + complete, tag)
				else:
					complete="Fail."
					tag = "error"
					self.stbip.remove(ip)
			else:
				complete = 'Fail.'
				tag = 'error'
				self.stbip.remove(ip)
				msg += "Timeout Connection\n"
				self.show_message(msg + complete, tag)


			
		
		return True if len(self.stbip) else False
	def sendSerial(self,command):
		"""
		Prepare and send a serial command to Serial class

		@param cmd string command
		"""
		wdg_retorno = self.get_wdg("txtRetorno")
		if(self.first_command):
			self.first_command=False
			buffer = gtk.TextBuffer()
			wdg_retorno.set_buffer(buffer)

		command = self.get_wdg("cbSerialCommand").get_active_text()
		for ip in self.stbip:
			ser = Serial(ip)
			cmds = serial_commands[command]['serial']

			if (serial_commands[command]['complemento'] == False):
				retorno = ser.process(cmds)
				msg = "ip: %s\n"%(ip)
				self.show_message(msg + self.__make_serial_readable(command, retorno) + "\n")
			else:
				mb = MessageBox('error')
				mb.mostrar('Not implemented yet')