Beispiel #1
0
    def two_button_screen(self,
                          banner_text=None,
                          button_txt1=None,
                          button_txt2=None,
                          x_offset=0,
                          y_offset=0):
        self.make_banner(self.body.render(banner_text, True,
                                          self.header_color))
        left_button = TaskButton(rect=(self.left_center_x-70,self.center_y, 140,70),\
            caption=button_txt2,  fgcolor=self.background_color, bgcolor=self.button_color, font=self.button)
        right_button = TaskButton(rect=(self.right_center_x-60,self.center_y, 140,70),\
            caption=button_txt1, fgcolor=self.background_color, bgcolor=self.button_color, font=self.button)
        left_button.draw(self.screen)
        right_button.draw(self.screen)

        pygame.display.update()

        # Choice phase
        playing = True
        while playing:
            pygame.time.wait(20)
            for event in pygame.event.get():
                if event.type == QUIT or (event.type == KEYDOWN
                                          and event.key == K_ESCAPE):
                    pygame.quit()

                if event.type in (MOUSEMOTION, MOUSEBUTTONUP, MOUSEBUTTONDOWN):
                    if 'click' in left_button.handleEvent(event):
                        button_clicked = ['left']
                        playing = False
                    if 'click' in right_button.handleEvent(event):
                        button_clicked = ['right']
                        playing = False
                elif event.type == KEYDOWN:
                    pressedKey = pygame.key.name(event.key)
                    if pressedKey == 'left':
                        left_button.buttonDown = True
                        left_button.draw(self.screen)
                        pygame.display.update()
                        button_clicked = ['left']
                        self.wait_fun(200)
                        playing = False
                    elif pressedKey == 'right':
                        right_button.buttonDown = True
                        right_button.draw(self.screen)
                        pygame.display.update()
                        button_clicked = ['right']
                        self.wait_fun(200)
                        playing = False

            left_button.draw(self.screen)
            right_button.draw(self.screen)
            pygame.display.update()

        self.wait_fun(milliseconds=300)
        return button_clicked
Beispiel #2
0
    def subject_information_screen(self):

        self.make_banner(
            self.body.render("Please enter your information below", True,
                             self.header_color))
        question = "PPID: CSTCG_"
        current_string = []
        self.text_input(question + " " + string.join(current_string, ""))

        continue_button= TaskButton(rect=(self.center_x-120,self.center_y, 200,70),\
         caption="Continue",  bgcolor=self.button_color, fgcolor=self.background_color, font=self.button)

        continue_button.draw(self.screen)

        pygame.display.update()
        filling = True
        while filling:
            pygame.time.wait(20)
            if pygame.event.peek(MOUSEBUTTONDOWN) or pygame.event.peek(
                    MOUSEBUTTONUP) or pygame.event.peek(
                        QUIT) or pygame.event.peek(KEYDOWN):
                for event in pygame.event.get():
                    if event.type == MOUSEBUTTONDOWN and len(
                            current_string) > 0:
                        continue_button.handleEvent(event)
                    elif event.type == MOUSEBUTTONUP and len(
                            current_string) > 0:
                        if 'click' in continue_button.handleEvent(event):
                            self.press_sound.play()
                            filling = False
                    elif event.type == KEYDOWN:
                        if event.key == K_BACKSPACE:
                            current_string = current_string[0:-1]
                        elif event.key == K_MINUS:
                            current_string.append("_")
                        elif event.key != 13:
                            current_string.append(event.unicode)
                        elif event.key == K_RETURN:
                            filling = False
                    elif event.type == pygame.QUIT:
                        pygame.quit()
                        exit()
                    self.text_input(question + "" +
                                    string.join(current_string, ""))

                continue_button.draw(self.screen)
                pygame.display.update()
                # self.wait_fun(milliseconds=300)
            elif 0 < round(time.time() * 1000) % 700 < 350 and len(
                    current_string) == 0:
                self.text_input(question + " ")
            elif 350 < round(time.time() * 1000) % 700 < 700 and len(
                    current_string) == 0:
                self.text_input(question + "| ")
        return (string.join(current_string, ""))
    def two_button_screen(self,banner_text=None,button_txt1=None, button_txt2=None, x_offset=0, y_offset=0):
        self.make_banner(self.body.render(banner_text,True,self.header_color))
        left_button = TaskButton(rect=(self.left_center_x-70,self.center_y, 140,70),\
            caption=button_txt2,  fgcolor=self.background_color, bgcolor=self.button_color, font=self.button)
        right_button = TaskButton(rect=(self.right_center_x-60,self.center_y, 140,70),\
            caption=button_txt1, fgcolor=self.background_color, bgcolor=self.button_color, font=self.button)
        left_button.draw(self.screen)
        right_button.draw(self.screen)
        
        pygame.display.update()

        # Choice phase
        playing = True
        while playing:
            pygame.time.wait(20)
            for event in pygame.event.get():
                if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE):
                    pygame.quit()

                if event.type in (MOUSEMOTION, MOUSEBUTTONUP, MOUSEBUTTONDOWN):
                    if 'click' in left_button.handleEvent(event):               
                        button_clicked = ['left']
                        playing = False
                    if 'click' in right_button.handleEvent(event):
                        button_clicked = ['right']
                        playing = False
                elif event.type == KEYDOWN:
                    pressedKey = pygame.key.name(event.key)
                    if pressedKey == 'left':
                        left_button.buttonDown = True;
                        left_button.draw(self.screen)
                        pygame.display.update()
                        button_clicked = ['left']
                        self.wait_fun(200)
                        playing = False
                    elif pressedKey == 'right':
                        right_button.buttonDown = True;
                        right_button.draw(self.screen)
                        pygame.display.update()
                        button_clicked = ['right']
                        self.wait_fun(200)
                        playing = False

       
            left_button.draw(self.screen)
            right_button.draw(self.screen)
            pygame.display.update()

        self.wait_fun(milliseconds=300)    
        return button_clicked
    def subject_information_screen(self):

        self.make_banner(self.body.render("Please enter your information below",True,self.header_color))
        question = "PPID: CSTCG_"
        current_string = []
        self.text_input(question + " " + string.join(current_string,""))
        
        continue_button= TaskButton(rect=(self.center_x-120,self.center_y, 200,70),\
         caption="Continue",  bgcolor=self.button_color, fgcolor=self.background_color, font=self.button)

        continue_button.draw(self.screen)

        pygame.display.update()
        filling = True
        while filling:
            pygame.time.wait(20) 
            if pygame.event.peek(MOUSEBUTTONDOWN) or pygame.event.peek(MOUSEBUTTONUP) or pygame.event.peek(QUIT) or pygame.event.peek(KEYDOWN):
                for event in pygame.event.get():
                    if event.type==MOUSEBUTTONDOWN and len(current_string)>0:
                        continue_button.handleEvent(event)
                    elif event.type==MOUSEBUTTONUP and len(current_string)>0:
                        if 'click' in continue_button.handleEvent(event): 
                            self.press_sound.play()
                            filling=False
                    elif event.type == KEYDOWN:
                        if event.key == K_BACKSPACE:
                            current_string = current_string[0:-1]
                        elif event.key == K_MINUS:
                            current_string.append("_")
                        elif event.key != 13:
                            current_string.append(event.unicode)
                        elif event.key ==  K_RETURN:
                            filling = False
                    elif event.type == pygame.QUIT:
                        pygame.quit()
                        exit()
                    self.text_input(question + "" + string.join(current_string,""))

                continue_button.draw(self.screen)
                pygame.display.update()
                # self.wait_fun(milliseconds=300)
            elif 0 < round(time.time()*1000) % 700 < 350 and len(current_string)==0:
                self.text_input(question + " ")
            elif 350 < round(time.time()*1000) % 700 < 700 and len(current_string)==0:
                self.text_input(question + "| ")
        return (string.join(current_string,""))
Beispiel #5
0
    def button_screen(self,
                      choice_image=None,
                      choice_text=None,
                      button_txt=None,
                      x_offset=0,
                      y_offset=0):

        self.screen.blit(choice_image,(self.center_x-x_offset-choice_image.get_width()/2,\
        self.center_y+y_offset-choice_image.get_height()/2))

        if choice_text is not None:
            self.text_screen(text=choice_text,
                             font=self.choice_text,
                             maxwidth=int(self.screen_width / 3),
                             valign='bottom',
                             halign='left',
                             wait_time=None)

        center_button = TaskButton(rect=(self.center_x-70,self.bottom_y+160, 140,70),\
             caption=button_txt,  fgcolor=self.button_color, bgcolor=self.background_color, font=self.button)

        center_button.draw(self.screen)
        pygame.display.update()
        self.of.write('ButtonScreen on ' + repr(time.time()) + '\n')

        # Choice phase
        playing = True
        while playing:
            pygame.time.wait(20)
            for event in pygame.event.get():
                if event.type == QUIT or (event.type == KEYDOWN
                                          and event.key == K_ESCAPE):
                    pygame.quit()

                if event.type in (MOUSEMOTION, MOUSEBUTTONUP, MOUSEBUTTONDOWN):
                    if button_txt is not None:
                        if 'click' in center_button.handleEvent(event):
                            self.press_sound.play()
                            self.log('Left button clicked \n')
                            button_clicked = ['left']
                            playing = False
                elif event.type == KEYDOWN:
                    pressedKey = pygame.key.name(event.key)
                    if pressedKey == 'left':
                        center_button.buttonDown = True
                        center_button.draw(self.screen)
                        pygame.display.update()
                        button_clicked = ['left']
                        self.wait_fun(200)
                        playing = False
            center_button.draw(self.screen)
            pygame.display.update()

        self.wait_fun(milliseconds=300)
        return button_clicked
    def button_screen(self,choice_image=None, choice_text=None, button_txt=None, x_offset=0, y_offset=0):
        
        self.screen.blit(choice_image,(self.center_x-x_offset-choice_image.get_width()/2,\
        self.center_y+y_offset-choice_image.get_height()/2))

        if choice_text is not None:
            self.text_screen(text=choice_text,font=self.choice_text,
                 maxwidth=int(self.screen_width/3),valign='bottom',halign='left',wait_time=None)

        center_button = TaskButton(rect=(self.center_x-70,self.bottom_y+160, 140,70),\
             caption=button_txt,  fgcolor=self.button_color, bgcolor=self.background_color, font=self.button)

        center_button.draw(self.screen)
        pygame.display.update()
        self.of.write('ButtonScreen on ' + repr(time.time()) + '\n')
        
        # Choice phase
        playing = True
        while playing:
            pygame.time.wait(20)
            for event in pygame.event.get():
                if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE):
                    pygame.quit()

                if event.type in (MOUSEMOTION, MOUSEBUTTONUP, MOUSEBUTTONDOWN):
                    if button_txt is not None:
                        if 'click' in center_button.handleEvent(event):   
                            self.press_sound.play()              
                            self.log('Left button clicked \n')
                            button_clicked = ['left']
                            playing = False
                elif event.type == KEYDOWN:
                    pressedKey = pygame.key.name(event.key)
                    if pressedKey == 'left':
                        center_button.buttonDown = True;
                        center_button.draw(self.screen)
                        pygame.display.update()
                        button_clicked = ['left']
                        self.wait_fun(200)
                        playing = False
            center_button.draw(self.screen)
            pygame.display.update()

        self.wait_fun(milliseconds=300)    
        return button_clicked
Beispiel #7
0
    def choice_screen(self,
                      choice_image1=None,
                      choice_text1=None,
                      button_txt1="Choose",
                      choice_image2=None,
                      choice_text2=None,
                      button_txt2=None):

        # This function sets up the canonical choice screen. Can be given on or two images.
        if choice_image1 is not None and choice_image2 is not None:
            self.screen.blit(choice_image1, (self.left_center_x, self.top_y))
            self.screen.blit(choice_image2, (self.right_center_x, self.top_y))
        elif choice_image1 is not None and choice_image2 is None:
            self.screen.blit(choice_image1,(self.center_x-choice_image1.get_width()/2,\
                self.top_y-choice_image1.get_height()/2))
        elif choice_image2 is not None and choice_image1 is None:
            self.screen.blit(choice_image1,(self.center_x-choice_image2.get_width()/2,\
                self.top_y-choice_image2.get_height()/2))

        # Write text (TODO: add condition for only one piece of text)
        if choice_text1 is not None:
            self.text_screen(text=choice_text1,
                             font=self.choice_text,
                             maxwidth=int(self.screen_width / 3),
                             valign='bottom',
                             halign='left',
                             wait_time=None)

        if choice_text2 is not None:
            self.text_screen(text=choice_text2,
                             font=self.choice_text,
                             maxwidth=int(self.screen_width / 3),
                             valign='bottom',
                             halign='right',
                             wait_time=None)

        # Make buttons
        if button_txt1 is not None and button_txt2 is not None:
            left_button = TaskButton(rect=(self.left_center_x-70,self.bottom_y+70, 140,70),\
             caption=button_txt2,  fgcolor=self.background_color, bgcolor=self.button_color, font=self.button)
            right_button = TaskButton(rect=(self.right_center_x-60,self.bottom_y+70, 140,70),\
             caption=button_txt1, fgcolor=self.background_color, bgcolor=self.button_color, font=self.button)
            left_button.draw(self.screen)
            right_button.draw(self.screen)
        elif button_txt1 is not None and button_txt2 is None:
            right_button = TaskButton(rect=(self.center_x-60,self.bottom_y+70, 140,70),\
             caption=button_txt1, fgcolor=self.background_color, bgcolor=self.button_color, font=self.button)
            right_button.draw(self.screen)
        elif button_txt2 is not None and button_txt1 is None:
            left_button = TaskButton(rect=(self.center_x-70,self.bottom_y+70, 140,70),\
             caption=button_txt2,  fgcolor=self.background_color, bgcolor=self.button_color, font=self.button)
            left_button.draw(self.screen)

        pygame.display.update()
        self.of.write('ChoiceScreen on ' + repr(time.time()) + '\n')

        # Choice phase
        playing = True
        while playing:
            pygame.time.wait(20)
            for event in pygame.event.get():
                if event.type == QUIT or (event.type == KEYDOWN
                                          and event.key == K_ESCAPE):
                    pygame.quit()

                if event.type in (MOUSEMOTION, MOUSEBUTTONUP, MOUSEBUTTONDOWN):
                    if button_txt2 is not None:
                        if 'click' in left_button.handleEvent(event):
                            self.press_sound.play()
                            self.log('Left button clicked \n')
                            button_clicked = ['left']
                            playing = False
                    if button_txt1 is not None:
                        if 'click' in right_button.handleEvent(event):
                            self.press_sound.play()
                            button_clicked = ['right']
                            self.log('Right button clicked \n')
                            playing = False
                elif event.type == KEYDOWN:
                    pressedKey = pygame.key.name(event.key)
                    if pressedKey == 'left':
                        self.press_sound.play()
                        left_button.buttonDown = True
                        left_button.draw(self.screen)
                        pygame.display.update()
                        button_clicked = ['left']
                        self.wait_fun(200)
                        playing = False
                    elif pressedKey == 'right':
                        self.press_sound.play()
                        right_button.buttonDown = True
                        right_button.draw(self.screen)
                        pygame.display.update()
                        button_clicked = ['right']
                        self.wait_fun(200)
                        playing = False

            if button_txt1 is not None and button_txt2 is not None:
                left_button.draw(self.screen)
                right_button.draw(self.screen)
            elif button_txt1 is not None and button_txt2 is None:
                right_button.draw(self.screen)
            elif button_txt2 is not None and button_txt1 is None:
                left_button.draw(self.screen)
            pygame.display.update()

        self.wait_fun(milliseconds=300)
        return button_clicked
    def choice_screen(self,choice_image1=None, choice_text1=None, button_txt1="Choose", choice_image2=None, choice_text2=None, button_txt2=None):
       
        # This function sets up the canonical choice screen. Can be given on or two images.
        if choice_image1 is not None and choice_image2 is not None:
            self.screen.blit(choice_image1,(self.left_center_x,self.top_y))
            self.screen.blit(choice_image2,(self.right_center_x,self.top_y))
        elif choice_image1 is not None and choice_image2 is None:
            self.screen.blit(choice_image1,(self.center_x-choice_image1.get_width()/2,\
                self.top_y-choice_image1.get_height()/2))
        elif choice_image2 is not None and choice_image1 is None:
            self.screen.blit(choice_image1,(self.center_x-choice_image2.get_width()/2,\
                self.top_y-choice_image2.get_height()/2))

        # Write text (TODO: add condition for only one piece of text)
        if choice_text1 is not None:
            self.text_screen(text=choice_text1,font=self.choice_text,
             maxwidth=int(self.screen_width/3),valign='bottom',halign='left',wait_time=None)

        if choice_text2 is not None:
            self.text_screen(text=choice_text2,font=self.choice_text,
             maxwidth=int(self.screen_width/3),valign='bottom',halign='right',wait_time=None)

        # Make buttons
        if button_txt1 is not None and button_txt2 is not None:
            left_button = TaskButton(rect=(self.left_center_x-70,self.bottom_y+70, 140,70),\
             caption=button_txt2,  fgcolor=self.background_color, bgcolor=self.button_color, font=self.button)
            right_button = TaskButton(rect=(self.right_center_x-60,self.bottom_y+70, 140,70),\
             caption=button_txt1, fgcolor=self.background_color, bgcolor=self.button_color, font=self.button)
            left_button.draw(self.screen)
            right_button.draw(self.screen)
        elif button_txt1 is not None and button_txt2 is None:
            right_button = TaskButton(rect=(self.center_x-60,self.bottom_y+70, 140,70),\
             caption=button_txt1, fgcolor=self.background_color, bgcolor=self.button_color, font=self.button)
            right_button.draw(self.screen)
        elif button_txt2 is not None and button_txt1 is None:
            left_button = TaskButton(rect=(self.center_x-70,self.bottom_y+70, 140,70),\
             caption=button_txt2,  fgcolor=self.background_color, bgcolor=self.button_color, font=self.button)
            left_button.draw(self.screen)

        pygame.display.update()
        self.of.write('ChoiceScreen on ' + repr(time.time()) + '\n')
        
        # Choice phase
        playing = True
        while playing:
            pygame.time.wait(20)
            for event in pygame.event.get():
                if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE):
                    pygame.quit()

                if event.type in (MOUSEMOTION, MOUSEBUTTONUP, MOUSEBUTTONDOWN):
                    if button_txt2 is not None:
                        if 'click' in left_button.handleEvent(event):   
                            self.press_sound.play()               
                            self.log('Left button clicked \n')
                            button_clicked = ['left']
                            playing = False
                    if button_txt1 is not None:
                        if 'click' in right_button.handleEvent(event):
                            self.press_sound.play() 
                            button_clicked = ['right']
                            self.log('Right button clicked \n')
                            playing = False
                elif event.type == KEYDOWN:
                    pressedKey = pygame.key.name(event.key)
                    if pressedKey == 'left':
                        self.press_sound.play() 
                        left_button.buttonDown = True;
                        left_button.draw(self.screen)
                        pygame.display.update()
                        button_clicked = ['left']
                        self.wait_fun(200)
                        playing = False
                    elif pressedKey == 'right':
                        self.press_sound.play() 
                        right_button.buttonDown = True;
                        right_button.draw(self.screen)
                        pygame.display.update()
                        button_clicked = ['right']
                        self.wait_fun(200)
                        playing = False

            if button_txt1 is not None and button_txt2 is not None:           
                left_button.draw(self.screen)
                right_button.draw(self.screen)
            elif button_txt1 is not None and button_txt2 is None:
                right_button.draw(self.screen)
            elif button_txt2 is not None and button_txt1 is None:
                left_button.draw(self.screen)
            pygame.display.update()

        self.wait_fun(milliseconds=300)    
        return button_clicked