Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python
#1
import pygame, os, time, sys, picture, text
from pygame.locals import * #These are to import the classes.
from sys import exit as sysExit

os.environ['SDL_VIDEO_WINDOW_POS'] = "%d,%d" % (10,30) #This code is to draw the window in the corner of the screen so it fits within the window.


# Set up pygame
pygame.init()

# set up the window
mywindow = pygame.display.set_mode((1270,740), pygame.FULLSCREEN) #The numbers are the size of the window. The fisrt one is the width and the second one is the legnth. 
pygame.display.set_caption("GUI") #Name of this program is GUI.

# Set up the colors
RED = (255, 0,0) #These are codes for colours.
GREEN = (0,255,0)
BLUE = (0,0,255)
WHITE = (255,255,255)
BLACK = (0,0,0)

basicFont = pygame.font.SysFont(None,48)

title = basicFont.render("Smart Home Consoles System",True,BLACK)
titlerect = title.get_rect()
titlerect.left = 30
titlerect.top = 25


#Create backgroung Image 
background = picture.pictureclass(0,0, "backGround_house.jpg") #This is the name of the background image.

#Create Object Help Button
#button1 = text.textclass(1200,20, "Help", 48) #This for the help button along with the positioning of the text.
#help_infoBox = text.textclass(120,300, "", 20) #This is the respnse information for the Dr along with the positioning of the text.

class panels:

    solarOn =False 

    def __init__(self,):
        self = windows_class

    def getSolarPanelOn(self):
        return self.solarOn

    def setSolarPanelOn(self,openingSolarOn):
        self.solarOn = openingSolarOn

class classwindow1:

    bathroomOffpic = False 
        
    def getbathroomWindowOn(self):
        return self.bathroomOffpic

    def setbathroomWindowOn(self,openingwindow):
        self.bathroomOffpic = openingwindow

class livingRoom:

    livingRoomOffpic = False

    def getlivingroomwindowOn(self):
        return self.livingRoomOffpic

    def setlivingroomwindowOn(self,openingLiving):
        self.livingRoomOffpic = openingLiving

class TV_Room:

    tv = False

    def getTvOn(self):
        return self.tv

    def setTvOn(self,openingTv):
        self.tv = openingTv

class garageRoom:

    garage = False

    def getgarageOn(self):
        return self.garage

    def setgarageOn(self,openingGarage):
        self.garage = openingGarage

class Help:

    helpButton = False

    def getHelpOn(self):
        return self.helpButton

    def setHelpOn(self,openingHelp):
        self.helpButton = openingHelp

class Doctor:

    doctorButton = False

    def getDoctorOn(self):
        return self.doctorButton

    def setDoctorOn(self,openingDoctor):
        self.doctorButton = openingDoctor




#create help button
button1 = basicFont.render("Help", True,BLACK, WHITE)
button1Rect = button1.get_rect()

#position of help button
button1Rect.left = 1150
button1Rect.top = 30


#outcome of click
helptext = basicFont.render("Click on the pictures to switch them on and off", True, BLACK, WHITE)
helptextRect = helptext.get_rect()


#position of outcome
helptextRect.left = 280
helptextRect.top = 650

#Create Object Doctor Response
contact_doctorpic = picture.pictureclass(150,60, "doctor_call.jpg") #This is the for the Dr's image to draw on the screen along with the positioning using the numbers and the picture file.  
respnd_doctor = text.textclass(120,300,"respond",32) #This is for the text responded by the Dr.


#create quit button
quit_Button = basicFont.render("QUIT", True,BLACK, WHITE)
quit_ButtonRect = quit_Button.get_rect()
 

#position of quit button
quit_ButtonRect.left = 1150
quit_ButtonRect.top = 640

#create help button
#car = picture.pictureclass(40,1200, "car.png")
#y = -1
#carPosition  = carPosition.get_rect()
#carPositionRect = carRect.left = 40
#carPositionRect = carRect.top = 1200


#Create Object Doctor Response
#exit = text.textclass(150,60, "leave_page") #This is the for the Dr's image to draw on the screen along with the positioning using the numbers and the picture file.  
#back = text.textclass(120,300,"go back",32) #This is for the text responded by the Dr.


x = 0
y = -1
FPS = 6


#create Objects
#Objects
solarOn = panels
bathroomWindowOn = classwindow1
doctorResponseOn = Doctor
livingroomWindowOn = livingRoom
tvOn = TV_Room
openGarageDoorOn = garageRoom
help_button = Help

           

#Create graphical Objects 
clickpic = picture.pictureclass(620,20, "closedSolar.jpg") #This is to draw the closed solar panel picture on the screen with the name file.
solarpic = picture.pictureclass(620,20, "open_solar_panel.jpg") #This is to draw the open solar panel picture on the screen with the name file.
bathroomOffpic = picture.pictureclass(1000,250, "closed_Bathroom.jpg") #This is to draw the open bathroom picture on the screen with the name file
bathroomOnpic = picture.pictureclass(1000,250, "open_Bathroom.jpg") #This is to draw the closed bathroom picture on the screen with the name file
livingRoomOffpic = picture.pictureclass(670,400, "closed_Window.jpg")   #This is to draw the open living room picture on the screen with the name file
livingroomOnpic = picture.pictureclass(670,400, "open_Window.jpg")  #This is to draw the closed living room picture on the screen with the name file
tvOffpic = picture.pictureclass(620,250, "tv_off.png")    #This is to draw the TV on picture on the screen with the name file
tvOnpic = picture.pictureclass(620,250, "tv_on.jpg")   #This is to draw the TV off picture on the screen with the name file
garageDoorOffpic = picture.pictureclass(150,395, "closed_garage.jpg")  #This is to draw the closed garage picture on the screen with the name file
#garageDoorOnpic = picture.pictureclass(150,395, "garage_Open.png")   #This is to draw the open garage picture on the screen with the name file
carPosition = picture.pictureclass(180,640, "car.png")

#Create variables

solarOn.setSolarPanelOn(solarOn, False) #Solar panel On is False at the begenning before the loop starts to render.
bathroomWindowOn.setbathroomWindowOn(bathroomWindowOn, False)  #Bathroom Window On is False at the begenning before the loop starts to render.
doctorResponseOn.setDoctorOn(doctorResponseOn, False) #Doctor Response On is False at the begenning before the loop starts to render.
livingroomWindowOn.setlivingroomwindowOn(livingroomWindowOn, False) #Living Room Window On is False at the begenning before the loop starts to render.
tvOn.setTvOn(tvOn, False)     #TV On is False at the begenning before the loop starts to render.
openGarageDoorOn.setgarageOn(openGarageDoorOn, False) #Open Garage On is False at the begenning before the loop starts to render.
help_button.setHelpOn(help_button, False) #Help Button On is False at the begenning before the loop starts to render.

#carImg = False

quitOn = False


#While loop and event function to renderif garageDoorOffpic.picRect.collidepoint(event.pos):

#This is to switch from one image to another using picRect.the pictures once they are clicked on 
SolarPanelOn = False
drive = False

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()
        if event.type == MOUSEBUTTONDOWN: #Event to click on the picture using MOUSEBUTTONDOWN.#

        
            if clickpic.picRect.collidepoint(event.pos): #This is to switch from one image to another using picRect.
                
                
                if (solarOn.getSolarPanelOn(solarOn) == False): #If statement to show if solar panel is off, turn it on using MOUSEBUTTONDOWN otherwise turn it off.
                    clickpic.updatepic(620,20, "open_solar_panel.jpg")
                    solarOn.setSolarPanelOn(solarOn, True)
                    print("open Solar Panel True")            

                else:
                    clickpic.updatepic(620,20, "closedSolar.jpg")
                    solarOn.setSolarPanelOn(solarOn, False)
                    print ("Closed Solar panel False")

                
                    
            if bathroomOffpic.picRect.collidepoint(event.pos): #This is to switch from one image to another using picRect.
                
                if (bathroomWindowOn.getbathroomWindowOn(bathroomWindowOn) == False): #If statement to show if bathroom window is closed, turn it open it using MOUSEBUTTONDOWN otherwise close it.
                    bathroomOffpic.updatepic(1000,250, "closed_Bathroom.jpg")
                    bathroomWindowOn.setbathroomWindowOn(bathroomWindowOn, True)
                    print("open Bathroom Window True")
                                                         
                else:
                    bathroomOffpic.updatepic(1000,250, "open_Bathroom.jpg")
                    bathroomWindowOn.setbathroomWindowOn(bathroomWindowOn, False)
                    print ("Closed Bathroom Window False")

            if livingRoomOffpic.picRect.collidepoint(event.pos):  #This is to switch from one image to another using picRect.
                
                if (livingroomWindowOn.getlivingroomwindowOn(livingroomWindowOn) == False):  #If statement to show if living room window is closed, open  it on using MOUSEBUTTONDOWN otherwise close it.
                    livingRoomOffpic.updatepic(670,400, "closed_Window.jpg")
                    livingroomWindowOn.setlivingroomwindowOn(livingroomWindowOn, True)
                    print("open Living Window True")
                                
                             
                else:
                    livingRoomOffpic.updatepic(670,400, "open_Window.jpg")
                    livingroomWindowOn.setlivingroomwindowOn(livingroomWindowOn, False)
                    print ("Closed Living Window False")

            if tvOffpic.picRect.collidepoint(event.pos):   #This is to switch from one image to another using picRect.

                if (tvOn.getTvOn(tvOn) == False): #If statement to show if TV is off, then turn it on using MOUSEBUTTONDOWN otherwise turn it off.
                    tvOffpic.updatepic(620,250, "tv_off.png")
                    tvOn.setTvOn(tvOn, True)
                    print("open TV on True")
                                 
                else:
                    tvOffpic.updatepic(620,250, "tv_on.jpg")
                    tvOn.setTvOn(tvOn, False)
                    print ("Closed TV off False")

            if garageDoorOffpic.picRect.collidepoint(event.pos):  #This is to switch from one image to another using picRect.

                if (openGarageDoorOn.getgarageOn(openGarageDoorOn) == False):  #If statement to show if garage door is closed then, open it on using MOUSEBUTTONDOWN otherwise close it.
                    garageDoorOffpic.updatepic(150,395, "open_garage.jpg")
                    openGarageDoorOn.setgarageOn(openGarageDoorOn, True)

                    #print(openGarageDoorOn.getgarageOn(openGarageDoorOn))
                    drive = True
                    
                    
                    print(openGarageDoorOn.getgarageOn(openGarageDoorOn))
                                                 
                else:
                    garageDoorOffpic.updatepic(150,395, "closed_garage.jpg")
                    openGarageDoorOn.setgarageOn(openGarageDoorOn, False)
                    print ("closed Garage Door Closed")

                    
              
            if button1Rect.collidepoint(event.pos): #This is to switch from one button to text using textRect.
                help_button = True #If statemnet to set the button on the screen

        
            if contact_doctorpic.picRect.collidepoint(event.pos):  #This is to switch from image to text using picRect.
                doctorResponseOn = True  #If statement to set the doctors pictures on

           
            
        
            if quit_ButtonRect.collidepoint(event.pos):
                print("quit")
                pygame.quit()

                sys.exit()



    
        mywindow.blit(background.pic, background.picRect) #Blitting for background picture so that the picture is then visible on the screen.
        mywindow.blit(title, titlerect)
        mywindow.blit(button1,button1Rect)
    

        if help_button == True:
            mywindow.blit(helptext,helptextRect)
        
        if doctorResponseOn == True:   #Doctors picture is true so will  be shown on the screen 
            respnd_doctor.updatetext(45,320, "Please state the nature of the medical emergency")#This is the text which will appear on the screen after the Dr picture is clicked. 
            mywindow.blit(respnd_doctor.text, respnd_doctor.textRect) #This is for blitting the text making it visible on the screen after the Dr picture has been clicked. 



    if (carPosition.picRect.top > 500):
        mywindow.blit(carPosition.pic,carPosition.picRect)
        
    if (drive==True):
        if (carPosition.picRect.top > 500):
            
            print (carPosition.picRect.top)
            carPosition.picRect.top=carPosition.picRect.top - 3
        else:
            drive= False

#Blitting of the pictures to make them visisble on the GUI

    mywindow.blit(clickpic.pic, clickpic.picRect)       #Blitting for the solar on/off panel pictures
    mywindow.blit(bathroomOffpic.pic, bathroomOffpic.picRect) #Blitting for the Bathroom open/close window pictures
    mywindow.blit(livingRoomOffpic.pic, livingRoomOffpic.picRect) #Blitting for the living room window open/close pictures 
    mywindow.blit(tvOffpic.pic, tvOffpic.picRect)     #Blitting for the TV on/off pictures 
    mywindow.blit(garageDoorOffpic.pic, garageDoorOffpic.picRect) #Blitting for the garage face detection open/close pictures  
    mywindow.blit(contact_doctorpic.pic,contact_doctorpic.picRect) #Blitting of the of the conatct Dr picture
    mywindow.blit(button1,button1Rect)
    mywindow.blit(quit_Button,quit_ButtonRect)
    
    if (openGarageDoorOn.getgarageOn(openGarageDoorOn) == True):
        mywindow.blit(carPosition.pic,carPosition.picRect)
    

    
#Redraws the main dispaly surface if arguemt list is empty
    pygame.display.update()


#Time for execution of the thread 
    time.sleep(0.02)

       
Reply
#2
What is the question?
Or is it a completed project you are sharing?
Reply
#3
I want the gate to open after the car has touched the gate. Could someone please help.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020