from PyQt5 import QtCore, QtWidgets
from PyQt5.QtGui import * 
from wired_module import * 

import numpy as np
#	Generated By WiredQT for Python: by <NAME>, 2021 Phils
class Handler(QtWidgets.QWidget,usercontrol):
	def __init__(self, *param):    
		super(Handler, self).__init__(None)
		initUI(self,param,w=800,h=400,title="WiredQTv5.0",controlbox=True,startpos=(0,30),timeoutdestroy=-1)
		self.GTKForms()
		self.timer=QtCore.QTimer()
		self.timer.timeout.connect(self.loop)
		self.timer.start(10)       

		self.sch=Scheduler(5000)#500 ms
		self.sch.Start()

		
	def loop(self):
		if self.form_load==False:
			self.form_load=True
		if self.sch.Event():#timer routine
			#code here
			if self.timeoutdestroy!=-1:
				self.timeoutdestroy-=1
				if self.timeoutdestroy==0:
					self.unload(None)
			self.sch.Start()#restart scheduler
		return True	#return true so that main_loop can call it again 
	def createwidget(self,prop,control,parent,event=[]):
		createWidget(self,prop,control,parent,event)
	def GTKForms(self):
		self.createwidget("{'Name': 'Button2', 'Text': 'DigitalWrite(18,LOW)', 'Top': '220', 'Left': '75', 'Width': '100', 'Height': '50', 'Visible': 'True', 'Enable': 'True', 'Font': '', 'BackColor': '(1,1,1,1)', 'ForeColor': '(0,0,0,1)', 'Picture': '', 'Events': '[clicked]', 'Tag': '', 'ParentsType': '', 'Var': '', 'Help': ''}",'QPushButton','usercontrol',"[['clicked', 'self,e']]")
		self.createwidget("{'Name': 'Button1', 'Text': 'DigitalWrite(18,HIGH)', 'Top': '165', 'Left': '75', 'Width': '180', 'Height': '50', 'Visible': 'True', 'Enable': 'True', 'Font': '', 'BackColor': '(1,1,1,1)', 'ForeColor': '(0,0,0,1)', 'Picture': '', 'Events': '[clicked]', 'Tag': '', 'ParentsType': '', 'Var': '', 'Help': ''}",'QPushButton','usercontrol',"[['clicked', 'self,e']]")
		self.createwidget("{'Name': 'Button3', 'Text': 'digitalRead(18)', 'Top': '220', 'Left': '324', 'Width': '140', 'Height': '50', 'Visible': 'True', 'Enable': 'True', 'Font': '', 'BackColor': '(1,1,1,1)', 'ForeColor': '(0,0,0,1)', 'Picture': '', 'Events': '[clicked]', 'Tag': '', 'ParentsType': '', 'Var': '', 'Help': ''}",'QPushButton','usercontrol',"[['clicked', 'self,e'], ['clicked', 'self,arg1']]")
		self.createwidget("{'Name': 'CheckButton1', 'Text': 'False', 'Top': '185', 'Left': '325', 'Width': '80', 'Height': '30', 'Visible': 'True', 'Enable': 'True', 'Font': '', 'BackColor': '(1,1,1,1)', 'ForeColor': '(0,0,0,1)', 'Picture': '', 'Events': [], 'Tag': '', 'ParentsType': '', 'Var': '', 'Help': ''}",'QCheckBox','usercontrol',"[]")
		self.createwidget("{'Name': 'Button4', 'Text': 'digitalRead(21)', 'Top': '220', 'Left': '500', 'Width': '140', 'Height': '50', 'Visible': 'True', 'Enable': 'True', 'Font': '', 'BackColor': '(1,1,1,1)', 'ForeColor': '(0,0,0,1)', 'Picture': '', 'Events': '[clicked]', 'Tag': '', 'ParentsType': '', 'Var': '', 'Help': ''}",'QPushButton','usercontrol',"[['clicked', 'self,e']]")
		self.createwidget("{'Name': 'CheckButton2', 'Text': 'False', 'Top': '185', 'Left': '500', 'Width': '80', 'Height': '30', 'Visible': 'True', 'Enable': 'True', 'Font': '', 'BackColor': '(1,1,1,1)', 'ForeColor': '(0,0,0,1)', 'Picture': '', 'Events': [], 'Tag': '', 'ParentsType': '', 'Var': '', 'Help': ''}",'QCheckBox','usercontrol',"[]")
		self.createwidget("{'Name': 'Button5', 'Text': 'Blink 18', 'Top': '300', 'Left': '71', 'Width': '100', 'Height': '50', 'Visible': 'True', 'Enable': 'True', 'Font': '', 'BackColor': '(1,1,1,1)', 'ForeColor': '(0,0,0,1)', 'Picture': '', 'Events': '[clicked]', 'Tag': '', 'ParentsType': '', 'Var': '', 'Help': ''}",'QPushButton','usercontrol',"[['clicked', 'self,e'], ['clicked', 'self,arg1']]")
	def Widget(self):
		return self
	def Hide(self):
		self._window.hide()
	def Button1_clicked(self,e):
		pinMode(18,OUTPUT)# can be place  in 	Handler __init__
		digitalWrite(18,HIGH)
		pass
	def Button2_clicked(self,e):
		pinMode(18,OUTPUT)# can be place  in 	Handler __init__
		digitalWrite(18,LOW)
		pass
	def Button3_clicked(self,e):
		pinMode(18,INPUT)# can be place  in 	Handler __init__
		if digitalRead(18)==HIGH:
			self.CheckButton1.Active=True
		else:
			self.CheckButton1.Active=False
			
		pass
	def Button4_clicked(self,e):
		pinMode(21,INPUT)# can be place  in 	Handler __init__
		if digitalRead(21)==HIGH:
			self.CheckButton2.Active=True
		else:
			self.CheckButton2.Active=False
			
		pass		
	def Button5_clicked(self,e):
		pinMode(18,OUTPUT)
		for a in range(5):
			digitalWrite(18,HIGH)
			delay(500)#500ms
			digitalWrite(18,LOW)
			delay(500)#500ms
			self.Button5.Text=str(a)
			self.repaint()#need so that form can refresh while on loop
		self.Button5.Text="Blink 18"
		pass
if __name__ == '__main__':
	import sys
	app = QtWidgets.QApplication(sys.argv)
	w = Handler()
	w.show()
	sys.exit(app.exec_())
