Ejemplo n.º 1
0
    def run(self, events):
        self.events = events
        self.mouse_pos = pygame.mouse.get_pos()

        # Bliting on the screen title name
        size = pygame.font.Font.size(self.font, 'Voterpy')
        line = self.font.render('Voterpy', True, Color.white3.value)
        self.screen.blit(line,
                         (self.screen_size[0] / 2 + 225 - size[0] / 2, 30))
        # Bliting on the screen app name
        size = pygame.font.Font.size(self.font1, 'Manager-App')
        line = self.font1.render('Manager-App', True, Color.white.value)
        self.screen.blit(line,
                         (self.screen_size[0] / 2 + 225 - size[0] / 2, 70))
        # Bliting the surface and the line
        self.screen.blit(self.surface,
                         (self.screen_size[0] / 2 + 280 - 165, 110))
        pygame.draw.rect(
            self.screen, Color.white.value,
            pygame.Rect(self.screen_size[0] / 2 + 280 - 165, 110, 230, 350), 2)
        pygame.draw.line(self.screen, Color.white3.value, (40, 110),
                         (420, 110), 2)

        # Calling method that draw the screen content according to the buttons
        self.drawbuttonContent()

        # Drwing buttons on the screen
        self.active = verticalButtonsDisplay(self.screen, self.buttons.keys(),170,(481, 180),(198, 40), self.mouse_pos,self.active,\
             pygame.font.SysFont("arial", 20))

        return "homePage"
Ejemplo n.º 2
0
    def draw(self):
        # drawing tittle
        size = pygame.font.Font.size(self.font, 'Voterpy')
        line = self.font.render('Voterpy', True, cs.white3.value)
        self.screen.blit(line,
                         (int(self.screen_size[0] / 2 - size[0] / 2), 10))
        # drawing sub tittle
        size = pygame.font.Font.size(self.font1, 'Front App')
        line = self.font1.render('Front App', True, cs.white.value)
        self.screen.blit(line,
                         (int(self.screen_size[0] / 2 - size[0] / 2), 55))
        # Called Method that draw the button start on the screen
        self.active = verticalButtonsDisplay(self.screen, self.button,100,(int(self.screen_size[0]/2)-100, 110),(200, 40), self.mouse_pos,self.active,\
                                            pygame.font.SysFont("arial", 20))
        if self.active != '':  # to check if the user chose one app to start
            self.startApp(self.active.split(" ")[0].lower())
            self.active = ''
            self.delay = 0

        if self.delay > 250:  # to refresh the apps open
            self.display = 0
            self.appsOpen = []
        self.delay += 1

        # drawinghelp message
        size = pygame.font.Font.size(
            pygame.font.SysFont("arial", 15),
            'Chose the app you wanna start and click on it.')
        line = pygame.font.SysFont("arial", 15).render(
            'Chose the app you wanna start and click on it.', True,
            cs.white.value)
        self.screen.blit(line,
                         (int(self.screen_size[0] / 2 - size[0] / 2), 255))
Ejemplo n.º 3
0
    def run(self, events, id):
        self.id = id
        self.events = events
        self.mouse_pos = pygame.mouse.get_pos()
        # draw the tittle
        size = pygame.font.Font.size(self.font, 'Voterpy')
        line = self.font.render('Voterpy', True, Color.white3.value)
        self.screen.blit(line, (self.screen_size[0] / 2 - size[0] / 2, 130))
        # draw the sub tittle
        size = pygame.font.Font.size(self.font1, 'Voter App')
        line = self.font1.render('Voter App', True, Color.white.value)
        self.screen.blit(line, (self.screen_size[0] / 2 - size[0] / 2, 175))

        # draw the text
        size = pygame.font.Font.size(self.font2,
                                     'Your vote was successfully registered.')
        line = self.font2.render('Your vote was successfully registered.',
                                 True, Color.white.value)
        self.screen.blit(line, (self.screen_size[0] / 2 - size[0] / 2, 230))
        # Drawing the animation
        self.animation()
        # Called Method that draw the button on the screen
        self.active = verticalButtonsDisplay(self.screen, self.button,300,(int(self.screen_size[0]/2-100), 317),(200, 60), self.mouse_pos,self.active,\
                                                pygame.font.SysFont("arial", 25))
        if self.active == "Finish" and self.id == None:
            self.active = ""
            return "login", self.id

        # Turning the id to None
        self.id = None

        return "voted", self.id
Ejemplo n.º 4
0
    def run(self, events, id):
        self.events = events
        self.id = id
        self.mouse_pos = pygame.mouse.get_pos()
        # draw the tittle
        size = pygame.font.Font.size(self.font, 'Voterpy')
        line = self.font.render('Voterpy', True, Color.white3.value)
        self.screen.blit(line, (self.screen_size[0] / 2 - size[0] / 2, 40))
        # draw the sub tittle
        size = pygame.font.Font.size(self.font1, 'Voter App')
        line = self.font1.render('Voter App', True, Color.white.value)
        self.screen.blit(line, (self.screen_size[0] / 2 - size[0] / 2, 85))

        # Draw all the candidates on the screen
        self.viewCandidatesOnRegister()

        # Called Method that draw the button on the screen
        self.active = verticalButtonsDisplay(self.screen, self.components,400,(225, 417),(250, 60), self.mouse_pos,self.active,\
                                                pygame.font.SysFont("arial", 25))

        # controling the vote buttom press
        if self.active == "Vote" and self.choice == None:
            self.active = ""

        # Drawing the surface on the screen
        self.screen.blit(
            self.surface1,
            (self.screen_size[0] / 2 - 260, self.screen_size[1] / 2 - 120))
        self.screen.blit(
            self.surface,
            (self.screen_size[0] / 2 - 250, self.screen_size[1] / 2 - 100))

        if self.choice != None:
            pygame.draw.line(self.screen, Color.red1.value,
                             (self.choice[0] - 1, self.choice[1] - 1),
                             (self.choice[2] + 1, self.choice[3] + 1), 5)
            pygame.draw.line(self.screen, Color.red1.value,
                             (self.choice[2] + 1, self.choice[1] - 1),
                             (self.choice[0] - 1, self.choice[3] + 1), 5)

        if (self.active == "Vote") and self.choice != None:
            # request = "jsonFileName/putById id,atribute,value"
            request = self.sendToServer(
                f"candidates/putById {self.voteChoice[0]},voterCounts,{int(self.voteChoice[1])+1}"
            )
            request1 = self.sendToServer(
                f"voters/putById {self.id},voted,{True}")
            if request and request1:
                self.choice = None
                self.voteChoice = None
                return "voted", self.id

        return "homePage", self.id
Ejemplo n.º 5
0
    def countVotes(self,events, mouse_pos, refresh):
        self.events, self.mouse_pos = events, mouse_pos
        # to get connect whit server just one time and get all the data
        if refresh:
            aux = self.sendToServer("voters/get") # just to count all the vouters
            self.totalVoters = len(self.response)
            del aux # cause we do not need it anymore
            self.connectionSent = self.sendToServer("candidates/get")
            self.totalCandidates = len(self.response)
            self.determineVotersMatrixResulte() # to determinathe the result percentage and the number of pixel that wil be used in the screen
            self.active = ''
            self.pixel = 0

        # Called Method that draw the button on the screen
        if self.counted and self.connectionSent: # Do this just if the button count is press
            y = 370
            if not self.voteCounted: # If the voted were not counted yet
                while True: # this is to make the effect of the voted been counted
                    y = 370
                    for result in self.votersCountMatrix:
                        if self.pixel > result[3]: # to not overpass the real result
                            pygame.draw.rect(self.screen, Color.green.value, pygame.Rect(52, y, result[3], 40))
                        else:
                            pygame.draw.rect(self.screen, Color.green.value, pygame.Rect(52, y, self.pixel, 40))
                        y -= 50
                    if self.delay > 20: # delay to the effect
                        self.pixel +=1
                        self.delay = 0
                    else:
                        self.delay += 1
                    self.drawGraph()# draw the graph lines.
                    if self.pixel > self.maximo:
                        self.voteCounted = not self.voteCounted
                        break

                    pygame.display.update() # to update the screen pixels
            else: # if the votes were already count there is no need to counte them again
                for result in self.votersCountMatrix: 
                    pygame.draw.rect(self.screen, Color.green.value, pygame.Rect(52, y, result[3], 40))
                    text_surface = pygame.font.SysFont("arial", 12).render(result[0]+" - "+str(format(result[1], ' .2f'))+"%", True, Color.white.value)
                    size = pygame.font.Font.size(pygame.font.SysFont("arial", 15), result[0]+" - "+str(format(result[1], ' .2f'))+"%")
                    self.screen.blit(text_surface, (62+result[3],y+size[1]))
                    y -= 50
            self.drawGraph()# draw the graph lines.   
        else:
            self.active = ''
            self.active = verticalButtonsDisplay(self.screen, self.countButton,250,(145, 263),(180, 50), self.mouse_pos,self.active,\
             pygame.font.SysFont("arial", 25)) # the button register on the screen
            if self.active != '':
                self.counted = not self.counted
        
        return "Count Votes"
Ejemplo n.º 6
0
    def run(self, events, id):
        self.id = id
        self.events = events
        self.mouse_pos = pygame.mouse.get_pos()
        # draw the tittle
        size = pygame.font.Font.size(self.font, 'Voterpy')
        line = self.font.render('Voterpy', True, Color.white3.value)
        self.screen.blit(line, (self.screen_size[0] / 2 - size[0] / 2, 10))

        size = pygame.font.Font.size(self.font1, 'Voter App')
        line = self.font1.render('Voter App', True, Color.white.value)
        self.screen.blit(line, (self.screen_size[0] / 2 - size[0] / 2, 50))

        # Draw the imput box's background
        self.screen.blit(self.surface, (self.screen_size[0] / 2 - 165, 90))
        # draw the input box
        self.inputBoxs = drawInputBoxs(self.screen,self.inputBoxs,20,self.events,self.mouse_pos,130,\
                                        int(self.screen_size[0]/2-125),(250,40),70)
        # Called Method that draw the button on the screen
        self.active = verticalButtonsDisplay(self.screen, self.components,410,(225, 417),(250, 40), self.mouse_pos,self.active,\
                                                pygame.font.SysFont("arial", 25))
        # verify the input when submited
        if self.active == "Registe":
            if verifyInput(self.inputBoxs):
                if not self.checkIfUserAlreadyExist():
                    self.sendToServer()
                self.refreshInputsAndAtributes()
            self.active = ''
            if self.connectionSent:
                # request = "jsonFileName/get"
                request = self.client.connectingToServer("voters/get")
                self.id = request[len(request) - 1]["id"]
                self.refreshInputsAndAtributes()
                self.connectionSent = False
                return "homePage", self.id
            else:
                self.messageNotSentError()

        # show to error message in a period of time
        if self.error:
            if self.count < 550:
                return self.messageNotSentError()
            else:
                self.error = False
                self.count = 0

        return "login", self.id
Ejemplo n.º 7
0
    def run(self, events):
        self.mouse_pos = pygame.mouse.get_pos()
        self.events = events
        
        # Bliting on the screen title name
        size = pygame.font.Font.size(self.font, 'Voterpy')
        line = self.font.render('Voterpy', True, Color.white3.value)
        self.screen.blit(line, (self.screen_size[0]/2-size[0]/2, 30))
        # Bliting on the screen app name
        size = pygame.font.Font.size(self.font1, 'Manager-App')
        line = self.font1.render('Manager-App', True, Color.white.value)
        self.screen.blit(line, (self.screen_size[0]/2-size[0]/2, 70))

        # bliting the box input surface
        self.screen.blit(self.surface,(self.screen_size[0]/2-150,110))

        # calling the method to add the boxs
        self.inputBoxs = drawInputBoxs(self.screen,self.inputBoxs,20,self.events,self.mouse_pos,170,int(self.screen_size[0]/2-125)\
                                            ,(250, 40), 80)
        
        # Called Method that draw the button on the screen
        self.active = verticalButtonsDisplay(self.screen, self.components,330,(225, 337),(250, 40), self.mouse_pos,self.active,\
             pygame.font.SysFont("arial", 25))
        
        # verify the input when submited
        if self.active == "Login":
            if verifyInput(self.inputBoxs):
                self.sendToServer()
                self.refreshInputsAndAtributes()
            self.active = ''

            return "homePage" if self.connectionSent else self.messageNotSentError()
        # show to error message in a period of time
        if self.error:
            if self.count < 350:
                return self.messageNotSentError()
            else:
                self.error = False
                self.count = 0

        return "login"
Ejemplo n.º 8
0
    def newCandidateRegistration(self,events, mouse_pos, refresh):
        self.events, self.mouse_pos = events, mouse_pos
        # Draw all the input box's 
        self.inputBoxs = drawInputBoxs(self.screen, self.inputBoxs,36, self.events,self.mouse_pos,150,40,(380,40),60)
        # Called Method that draw the button on the screen
        self.active = verticalButtonsDisplay(self.screen, self.registerButton,410,(80, 423),(300, 50), self.mouse_pos,self.active,\
             pygame.font.SysFont("arial", 25))
        
        if self.active == "Register":
            if verifyInput(self.inputBoxs):
                self.connectionSent = self.sendToServer(f"candidates/post firstName={self.inputBoxs['First Name'][0]},lastName={self.inputBoxs['Last Name'][0]},\
age={self.inputBoxs['Age'][0]},color={self.inputBoxs['Color'][0]},voterCounts=0")
                self.connectionMessage()
                self.refreshInputsAndAtributes()
            self.active = ''          
        
        self.supportToBlitErrorAndSuccessMessage()
        if self.success:
            self.success = False
            return "Candidates"
        else:
            return "Register"