Пример #1
0
def main():
    #Show window
    lucia.show_window("1d Sound Example.")
    #Create the player
    listener = player()
    #Play a sound on a 1d grid.
    #Must use 2d playing function in order for the sound to actually pan
    sound_pool.play_2d("ding.ogg", listener.x, 0, 0, 0, True)
    while 1:
        #Allow lucia to update it's internal queues and events
        lucia.process_events()
        #Check for key presses
        if lucia.key_pressed(lucia.K_LEFT):
            #Move the player 1 step to the left
            listener.x -= 1
            #Update the sound pool with the new player position
            sound_pool.update_listener_1d(listener.x)
        elif lucia.key_pressed(lucia.K_RIGHT):
            #Move the player 1 step to the right
            listener.x += 1
            #Update the sound pool with the new player position
            sound_pool.update_listener_1d(listener.x)
        elif lucia.key_pressed(lucia.K_c):
            #Output x coordinate
            lucia.output.output(str(listener.x))
        elif lucia.key_pressed(lucia.K_ESCAPE):
            #Exit
            lucia.quit()
            sys.exit()
        #Sleep for 2 milliseconds
        lucia.pygame.time.wait(2)
Пример #2
0
def main():
    #Show window
    lucia.show_window("2d Sound Example.")
    #Create the player
    listener = player()
    #Play a sound on a 2d grid.
    sound_pool.play_2d("ding.ogg", listener.x, listener.y, 0, 0, True)
    while 1:
        #Allow lucia to update it's internal queues and events
        lucia.process_events()
        #Check for key presses
        if lucia.key_pressed(lucia.K_LEFT):
            #Move the player 1 step to the left
            move_object(listener, 3)
        elif lucia.key_pressed(lucia.K_RIGHT):
            #Move the player 1 step to the right
            move_object(listener, 1)
        elif lucia.key_pressed(lucia.K_UP):
            #Move the player one step forward
            move_object(listener, 0)
        elif lucia.key_pressed(lucia.K_DOWN):
            #Move the player one step backwards
            move_object(listener, 2)
        elif lucia.key_pressed(lucia.K_c):
            #Output coordinates
            lucia.output.output(str(listener.x) + ", " + str(listener.y))
        elif lucia.key_pressed(lucia.K_ESCAPE):
            #Exit
            lucia.quit()
            sys.exit()
        #Sleep for 2 milliseconds
        lucia.pygame.time.wait(2)
Пример #3
0
    def run(self, intro, isfile=False):
        try:
            self._running = True

            self.__play__("open")
            if self._title: lucia.output.speak(self._title)
            if not isfile:
                lucia.output.speak(intro, False)
            else:
                intro = self.__load__(intro)
                intro.volume = self._volume
                print(intro.volume)
                intro.play()

            while self._running:
                time.sleep(0.005)  # Be kind to processors
                lucia.process_events()

                if lucia.key_pressed(lucia.K_UP):
                    self.__change_position__(1, intro, isfile)
                elif lucia.key_pressed(lucia.K_DOWN):
                    self.__change_position__(-1, intro, isfile)
                elif lucia.key_pressed(lucia.K_RETURN):
                    self.__play__("enter")
                    self._running = False
                    return True
            print("end")
        except Exception as e:
            lucia.logger.exception(e)
        else:
            return False
Пример #4
0
def main():
    #Create a game window
    lucia.show_window("Timer Example.")
    #Create a timer
    countdown_timer = lucia.utils.timer.Timer()
    #Loop for 2 seconds
    while countdown_timer.elapsed <= 2000:
        #Allow lucia to update it's internal queues and events
        lucia.process_events()
        #Sleep for 2 milliseconds
        lucia.pygame.time.wait(2)
    #Output a message
    lucia.output.output("Now you see me...")
    #Restart the timer before continuing to loop
    countdown_timer.restart()
    #Loop for another 2 seconds
    while countdown_timer.elapsed <= 2000:
        #Allow lucia to update it's internal queues and events
        lucia.process_events()
        #Sleep for 2 milliseconds
        lucia.pygame.time.wait(2)
    #Output another message
    lucia.output.output("Now you don't!")
    lucia.quit()
    sys.exit()
Пример #5
0
    def run(self, intro, isfile=False):
        # Overrides the run function in menu

        try:
            self._running = True

            self.__play__("open")
            if self._title: lucia.output.speak(self._title)
            if not isfile:
                lucia.output.speak(intro, False)
            else:
                intro = self.__load__(intro)
                intro.play()

            while self._running:
                time.sleep(0.005)
                lucia.process_events()

                if lucia.key_pressed(lucia.K_DOWN) and not self.orientation:
                    self.__change_position__(1)
                elif lucia.key_pressed(lucia.K_UP) and not self.orientation:
                    self.__change_position__(-1)
                elif lucia.key_pressed(lucia.K_LEFT) and self.orientation:
                    self.__change_position__(-1)
                elif lucia.key_pressed(lucia.K_RIGHT) and self.orientation:
                    self.__change_position__(1)
                elif lucia.key_pressed(lucia.K_RETURN):
                    return self.__return_selection__()
        except Exception:
            self._running = False
            lucia.logger.exception(e)
Пример #6
0
def MainLoop():
    global x, oldX, y, oldY, direction, oldDirection
    timer = utils.Timer(
    )  # Prevents the user from walking faster than the sound can play. You're not the Flash.
    WALK_SPEED = 300  # milliseconds
    timer.elapsed = WALK_SPEED  # So the user can walk straight away
    xAxis, yAxis = (0, 0)

    while True:
        time.sleep(0.005)  # Be kind to processors
        lucia.process_events()

        # Set the movement coordinate changes
        if lucia.key_down(lucia.K_UP): yAxis = 1
        if lucia.key_down(lucia.K_DOWN): yAxis = -1
        if lucia.key_up(lucia.K_UP) and lucia.key_up(lucia.K_DOWN): yAxis = 0
        if lucia.key_down(lucia.K_RIGHT): xAxis = 1
        if lucia.key_down(lucia.K_LEFT): xAxis = -1
        if lucia.key_up(lucia.K_RIGHT) and lucia.key_up(lucia.K_LEFT):
            xAxis = 0

        if (not xAxis == 0 or not yAxis == 0) and timer.elapsed >= WALK_SPEED:
            timer.restart()

            # Set the direction
            if xAxis == 0 and yAxis == 1: direction = 90
            elif xAxis == 1 and yAxis == 1: direction = 45
            elif xAxis == 1 and yAxis == 0: direction = 0
            elif xAxis == 1 and yAxis == -1: direction = 315
            elif xAxis == 0 and yAxis == -1: direction = 270
            elif xAxis == -1 and yAxis == -1: direction = 225
            elif xAxis == -1 and yAxis == 0: direction = 180
            elif xAxis == -1 and yAxis == 1: direction = 135

            # set new coordinates
            x, y = (x + xAxis, y + yAxis)

            # Update the listener
            pool.update_listener_3d(x, y, 0, direction)

            if not direction == oldDirection:
                squeak.play()
                oldDirection = direction

            if (not oldX == x) or (not oldY == y):
                step.play()
                oldX, oldY = (x, y)

        if lucia.key_pressed(lucia.K_q):
            break
        elif lucia.key_pressed(lucia.K_c):
            lucia.output.speak(
                f"you are at x: {x}, y: {y}, facing {textDirections[direction]}"
            )
        elif lucia.key_pressed(lucia.K_z):
            x = 0
            y = 0
            direction = 90
            pool.update_listener_3d(x, y, 0, direction)
Пример #7
0
 def play_wait(self):
     if not self.is_active:
         return False
     self.handle.looping = False
     #return bool(self.handle.play_blocking())
     # We can't block, we need to make a hack, to keep the ui responsive
     result = bool(self.handle.play())
     while self.handle.is_playing:
         lucia.process_events()
     return result
def main():
    #Show window
    lucia.show_window("Simple Sound Example.")
    #Play a stationary sound
    #Stationary means that the sound cannot move, regardless of what the player does
    #The first parameter is the filename, while the second one dictates whether the sound can loop or not
    sound_pool.play_stationary("ding.ogg", True)
    while 1:
        #Allow lucia to update it's internal queues and events
        lucia.process_events()
        #No extra code is needed to handle when the user presses alt f4, Lucia does this on it's own.
        #Sleep for 2 milliseconds
        lucia.pygame.time.wait(2)
Пример #9
0
    def run(self, message, callback=None):
        """Retrieves user input
		Parameters:
			message (str): The message to be shown as the input pops up
			callback (callable): What will be called every iteration of the input loop. The input will pass in itself as the only parameter to the callback
		Return Value:
			self.current_text (str): What the user entered
		"""
        lucia.output.output(message, True)
        self.clear()
        while not self.is_at_character_limit:
            events = lucia.process_events()
            if callable(callback): callback(self)
            for event in events:
                if event.type == lucia.KEYDOWN:
                    if self.repeating_keys and event.key not in self._key_times:
                        self._key_times[event.key] = [
                            self.key_repeat_timer.elapsed +
                            self.initial_key_repeating_time, event.unicode
                        ]
                    if self.can_exit and event.key == lucia.K_RETURN:
                        return self.current_text
                    elif self.can_escape and event.key == lucia.K_ESCAPE:
                        return ""
                    elif event.key == lucia.K_BACKSPACE:
                        self.remove_character()
                    elif event.key == lucia.K_TAB:
                        lucia.output.output(self.current_string, True)
                    elif event.key == lucia.K_LEFT:
                        self.move_in_string(-1)
                        self.speak_character(self.get_character())
                    elif event.key == lucia.K_RIGHT:
                        self.move_in_string(1)
                        self.speak_character(self.get_character())
                    elif event.key == lucia.K_HOME:
                        self.snap_to_top()
                    elif event.key == lucia.K_END:
                        self.snap_to_bottom()
                    elif event.key == lucia.K_F2:
                        lucia.output.output(
                            "Character repeat on"
                        ) if self.toggle_character_repetition(
                        ) else lucia.output.output("Character repeat off")
                    else:
                        if event.unicode in self.whitelisted_characters:
                            self.insert_character(event.unicode)
                elif event.type == lucia.KEYUP:
                    if event.key in self._key_times:
                        del self._key_times[event.key]
            for key in self._key_times:
                if self.key_repeat_timer.elapsed >= self._key_times[key][0]:
                    self._key_times[key][0] += self.repeating_increment
                    lucia.pygame.event.post(
                        lucia.pygame.event.Event(
                            lucia.KEYDOWN,
                            key=key,
                            unicode=self._key_times[key][1]))
            lucia.pygame.time.wait(2)
        return self.current_text
Пример #10
0
def main():
    #Show window
    lucia.show_window("Speaking Example.")
    while 1:
        #Allow lucia to update it's internal queues and events
        lucia.process_events()
        #Check for key presses
        if lucia.key_pressed(lucia.K_SPACE):
            lucia.output.output("Hello, world!")
        if lucia.key_pressed(lucia.K_RETURN):
            lucia.output.output("Good bye, world!")
            #Account for slower screen readers
            lucia.pygame.time.wait(1500)
            lucia.quit()
            sys.exit()
        #Sleep for 2 milliseconds
        lucia.pygame.time.wait(2)
Пример #11
0
def main():
    #Show window
    lucia.show_window("Keyboard Example.")
    while 1:
        #Allow lucia to update it's internal queues and events
        lucia.process_events()
        #Check for key presses
        #Typically this should be done in a separate function, but we will keep this as simple as possible
        if lucia.key_pressed(lucia.K_SPACE):
            print("You pressed space!")
            sys.exit()
        #Check for key holds
        if lucia.key_down(lucia.K_RETURN):
            print("You held enter!")
            lucia.quit()
            sys.exit()
        #Sleep for 2 milliseconds
        lucia.pygame.time.wait(2)
Пример #12
0
    def run(self, intro="", isfile=False):
        """ Displayes the menu and waits for a selection

		This function blocks until the menu is closed, either by selecting an item or pressing escape.
		Available controls are up/down arrows, enter, and escape. Wrapping is not supported.

		args:
		        intro (str, optional): Some brief instructions spoken after the menu title.
		    isfile (bool, optional): Set to True if the intro is the name of an audio file that contains the intro

		returns:
		        Either the item name, its value, or -1 if escape is allowed.
		"""

        try:
            self._running = True

            self.__play__("open")
            if self._title: lucia.output.speak(self._title)
            if intro:
                if not isfile:
                    lucia.output.speak(intro, False)
                else:
                    intro = self.__load__(intro)
                    intro.play()

            while self._running:
                time.sleep(0.005)  # Be kind to processors
                lucia.process_events()

                if callable(self._callback):
                    self._callback(self)

                if lucia.key_pressed(lucia.K_ESCAPE) and self.exit_on_escape:
                    self._running = False
                    self.__play__(self._sounds["cancel"])
                    return "-1"
                elif lucia.key_pressed(lucia.K_DOWN):
                    self.__change_position__(1)
                elif lucia.key_pressed(lucia.K_UP):
                    self.__change_position__(-1)
                elif lucia.key_pressed(lucia.K_LEFT) and callable(
                        self._items[self._item_position].slider_function):
                    self._items[self._item_position].slider_function(self, -1)
                elif lucia.key_pressed(lucia.K_RIGHT) and callable(
                        self._items[self._item_position].slider_function):
                    self._items[self._item_position].slider_function(self, 1)
                elif lucia.key_pressed(lucia.K_SPACE) and self._items[
                        self._item_position].can_be_toggled:
                    self.__change_toggle__()
                elif (lucia.key_pressed(lucia.K_LSHIFT)
                      or lucia.key_pressed(lucia.K_RSHIFT)
                      ) and self._items[self._item_position].enter_value:
                    self.__get_input__()
                elif lucia.key_pressed(lucia.K_RETURN):
                    self._running = False
                    return self.__return_selection__()
        except Exception as e:
            lucia.logger.exception(e)
        finally:
            self._running = False
Пример #13
0
def MainLoop():
    global x, y, width, height
    timer = utils.Timer(
    )  # Prevents the user from walking faster than the sound can play. You're not the Flash.
    WALK_SPEED = 300  # milliseconds
    timer.elapsed = WALK_SPEED  # So the user can walk straight away
    xAxis, yAxis = (0, 0)

    # Define the shapes
    # Each vertice followed by a fill value (True fills the shape in, False plots only the outline)
    sky = utils.Rectangle(0, 29, 29, 19,
                          True)  # Top left corner to bottom left corner
    ground = utils.Rectangle(0, 18, 29, 0, True)
    sun = utils.Circle(4, 25, 3,
                       True)  # The center point followed by the radius
    roof = utils.Triangle(11, 22, 25, 22, 18, 27,
                          True)  # The three corner vertices of the triangle
    house = utils.Rectangle(13, 21, 23, 13, True)

    # Draw each shape one by one
    for v in sky:
        field[v[0]][v[1]] = "blue"
    for v in ground:
        field[v[0]][v[1]] = "green"
    for v in sun:
        field[v[0]][v[1]] = "yellow"
    for v in roof:
        field[v[0]][v[1]] = "red"
    for v in house:
        field[v[0]][v[1]] = "brown"

    # Main action loop
    while True:
        time.sleep(0.005)  # Be kind to processors
        lucia.process_events()

        # Set the movement coordinate changes
        if lucia.key_down(lucia.K_UP): yAxis = 1
        if lucia.key_down(lucia.K_DOWN): yAxis = -1
        if lucia.key_up(lucia.K_UP) and lucia.key_up(lucia.K_DOWN): yAxis = 0
        if lucia.key_down(lucia.K_RIGHT): xAxis = 1
        if lucia.key_down(lucia.K_LEFT): xAxis = -1
        if lucia.key_up(lucia.K_RIGHT) and lucia.key_up(lucia.K_LEFT):
            xAxis = 0

        # Only do something if the keys are pressed and slow down any change based on the speed of movement
        if (not xAxis == 0 or not yAxis == 0) and timer.elapsed >= WALK_SPEED:
            timer.restart()

            # set new coordinates
            if x + xAxis >= 0 and y + yAxis >= 0 and x + xAxis < width and y + yAxis < height:  # Check to be sure the coordinates are within the field
                x, y = (x + xAxis, y + yAxis)
                lucia.output.speak(str(field[x][y]))
            else:
                lucia.output.speak("bump")

        # Some other function keys (These are not restricted by the walk speed)
        if lucia.key_pressed(lucia.K_q):  # Quit the program
            break
        elif lucia.key_pressed(lucia.K_z):  # Speak the coordinates of the user
            lucia.output.speak(f"you are at x: {x}, y: {y}")
Пример #14
0
 def loop(self):
     while 1:
         time.sleep(0.005)
         try:
             lucia.process_events()
             if callable(self.callback):
                 self.callback()
             if lucia.key_pressed(lucia.K_RETURN):
                 if self.items[self.itempos].can_return:
                     if self.entersound != "":
                         source = self.pool.play_stationary(self.entersound)
                     list_values = []
                     if self.items[self.itempos].event == CANCELEVENT:
                         if callable(
                                 self.items[self.itempos].item_function):
                             self.items[self.itempos].item_function()
                         return list_values
                     #returns results as a list of dictionaries. The currently focused item returns as the first item in the list
                     for x in self.items:
                         if x.name != self.items[self.itempos].name:
                             list_values.append({
                                 "name":
                                 x.name,
                                 "value":
                                 x.value,
                                 "toggle_value":
                                 x.toggle_value
                             })
                     list_values.insert(
                         0,
                         {
                             "name":
                             self.items[self.itempos].name,
                             "value":
                             self.items[self.itempos].value,
                             "toggle_value":
                             self.items[self.itempos].toggle_value,
                         },
                     )
                     if callable(self.items[self.itempos].item_function):
                         self.items[self.itempos].item_function()
                     else:
                         return list_values
             elif lucia.key_pressed(lucia.K_UP):
                 if self.itempos > 0:
                     self.itempos -= 1
                     if self.clicksound != "":
                         clicksound = self.pool.play_stationary(
                             self.clicksound)
                     if callable(self.on_index_change):
                         self.on_index_change()
                     if callable(self.items[self.itempos].on_focus):
                         self.items[self.itempos].on_focus(self)
                     if (self.items[self.itempos].has_value == False
                             and self.items[self.itempos].can_be_toggled
                             == False):
                         lucia.output.speak(self.items[self.itempos].name)
                     elif (self.items[self.itempos].has_value
                           and self.items[self.itempos].can_be_toggled
                           == False):
                         lucia.output.speak(
                             self.items[self.itempos].name + ": " +
                             str(self.items[self.itempos].value) +
                             ". Press left shift or right shift to change this item's value"
                         )
                     elif (self.items[self.itempos].has_value == False
                           and self.items[self.itempos].can_be_toggled):
                         if self.items[self.itempos].toggle_value == True:
                             lucia.output.speak(
                                 self.items[self.itempos].name + ": " +
                                 self.items[self.itempos].on_value + " " +
                                 self.items[
                                     self.itempos].toggle_item_message +
                                 " " + self.items[self.itempos].off_value)
                         else:
                             lucia.output.speak(
                                 self.items[self.itempos].name + ": " +
                                 self.items[self.itempos].off_value + " " +
                                 self.items[
                                     self.itempos].toggle_item_message +
                                 " " + self.items[self.itempos].on_value)
                     elif (self.items[self.itempos].has_value
                           and self.items[self.itempos].can_be_toggled):
                         speakstr = (self.items[self.itempos].name +
                                     ". Value: " +
                                     str(self.items[self.itempos].value))
                         if self.items[self.itempos].toggle_value == True:
                             speakstr += ". Switch: " + self.items[
                                 self.itempos].on_value
                         else:
                             speakstr += ". Switch: " + self.items[
                                 self.itempos].off_value
                         lucia.output.speak(
                             speakstr +
                             ". Press left shift or right shift to change this item's value. "
                             + self.items[self.itempos].toggle_item_message)
             elif lucia.key_pressed(lucia.K_DOWN):
                 if self.itempos < len(self.items) - 1:
                     self.itempos += 1
                     if self.clicksound != "":
                         clicksound = self.pool.play_stationary(
                             self.clicksound)
                     if self.items[self.itempos].on_focus != None:
                         self.items[self.itempos].on_focus()
                     if self.on_index_change != None:
                         self.on_index_change()
                     if (self.items[self.itempos].has_value == False
                             and self.items[self.itempos].can_be_toggled
                             == False):
                         lucia.output.speak(self.items[self.itempos].name)
                     elif (self.items[self.itempos].has_value
                           and self.items[self.itempos].can_be_toggled
                           == False):
                         lucia.output.speak(
                             self.items[self.itempos].name + ": " +
                             str(self.items[self.itempos].value) +
                             ". Press left shift or right shift to change this item's value"
                         )
                     elif (self.items[self.itempos].has_value == False
                           and self.items[self.itempos].can_be_toggled):
                         if self.items[self.itempos].toggle_value == True:
                             lucia.output.speak(
                                 self.items[self.itempos].name + ": " +
                                 self.items[self.itempos].on_value + " " +
                                 self.items[
                                     self.itempos].toggle_item_message +
                                 " " + self.items[self.itempos].off_value)
                         else:
                             lucia.output.speak(
                                 self.items[self.itempos].name + ": " +
                                 self.items[self.itempos].off_value + " " +
                                 self.items[
                                     self.itempos].toggle_item_message +
                                 " " + self.items[self.itempos].on_value)
                     elif (self.items[self.itempos].has_value
                           and self.items[self.itempos].can_be_toggled):
                         speakstr = (self.items[self.itempos].name +
                                     ". Value: " +
                                     str(self.items[self.itempos].value))
                         if self.items[self.itempos].toggle_value == True:
                             speakstr += ". Switch: " + self.items[
                                 self.itempos].on_value
                         else:
                             speakstr += ". Switch: " + self.items[
                                 self.itempos].off_value
                         lucia.output.speak(
                             speakstr +
                             ". Press left shift or right shift to change this item's value. "
                             + self.items[self.itempos].toggle_item_message)
             elif lucia.key_pressed(lucia.K_SPACE):
                 if self.itempos > -1 and self.itempos < len(self.items):
                     if self.items[self.itempos].can_be_toggled:
                         if self.entersound != "":
                             entersound = self.pool.play_stationary(
                                 self.entersound)
                         if self.items[self.itempos].toggle_value == True:
                             lucia.output.speak(
                                 self.items[self.itempos].off_value)
                             self.items[self.itempos].toggle_value = False
                         else:
                             lucia.output.speak(
                                 self.items[self.itempos].on_value)
                             self.items[self.itempos].toggle_value = True
             elif lucia.key_down(lucia.K_LSHIFT) or lucia.key_down(
                     lucia.K_RSHIFT):
                 if self.items[self.itempos].has_value == True:
                     self.items[self.itempos].value = getinput(
                         "change value",
                         self.items[self.itempos].name + ". ",
                         value=self.items[self.itempos].value,
                         mode=self.items[self.itempos].value_mode,
                     )
                     lucia.output.speak("value set to " +
                                        str(self.items[self.itempos].value))
                     if self.entersound != "":
                         entersound = self.pool.play_stationary(
                             self.entersound)
         except Exception as e:
             lucia.output.speak(str(e))
Пример #15
0
def callback_test(menu):
    print("hello world")


menu = lucia.ui.Menu()
menu.add_item_tts("Hello")
menu.add_item_tts("world")
menu.add_item_tts("this")
menu.add_item_tts("is")
menu.add_item_tts("a")
menu.add_item_tts("test")
menu.set_callback(callback_test)
result = menu.run("Please select something")
print(str(result))

username = lucia.ui.VirtualInput("Enter a username")
result = username.run()
print(f"username: {result}")
password = lucia.ui.VirtualInput("Enter a password", True)
result = password.run()
print(f"password: {result}")

while True:
    lucia.process_events()
    if lucia.key_pressed(lucia.K_a):
        lucia.output.output("Hey.")
    if lucia.key_pressed(lucia.K_q):
        break

lucia.quit()
Пример #16
0
    def run(self, intro="select an option", interrupt=True):
        """presents this menu to the user.
		
		This function blocks until the menu is closed, either by selecting an item or pressing escape.
		Available controls are up/down arrows, enter, and escape. Wrapping is not supported.
		
		args:
		    intro (str, optional): The text that will be spoken when the menu is presented, this will occur at the same time as the open sound. Default is 'select an option'
		    interrupt (bool, optional): Determines if speech is interrupted when it is queued to be spoken. For your sanity, this should always be True. Defaults to True.
		
		returns:
		    str if an option was selected, containing the option's internal name. -1 if escape was pressed.
		"""
        self.count = 0
        self.running = True
        try:
            self.music.play()
        except:
            pass
        try:
            self.open_sound.play()
        except:
            pass
        if intro != "":
            self.speechMethod.speak(intro, interrupt)
        while self.running and lucia.running:
            lucia.process_events()
            if callable(self.callback):
                self.callback(self)
            time.sleep(0.005)
            if lucia.key_pressed(lucia.K_ESCAPE):
                try:
                    self.enter_sound.play()
                except:
                    pass
                try:
                    self.music.stop()
                except:  # thrown if no music was specified.
                    pass
                return "-1"
            if lucia.key_pressed(lucia.K_DOWN):
                if self.count < len(self.items) - 1:
                    self.count = self.count + 1
                    try:
                        self.scroll_sound.play()
                    except:
                        pass
                else:
                    try:
                        self.border_sound.play()
                    except:
                        pass
                self.speechMethod.speak(
                    list(self.items)[self.count], self.shouldInterrupt)
            if lucia.key_pressed(lucia.K_UP):
                if self.count > 0:
                    self.count = self.count - 1
                    try:
                        self.scroll_sound.play()
                    except:
                        pass
                else:
                    try:
                        self.border_sound.play()
                    except:
                        pass
                self.speechMethod.speak(
                    list(self.items)[self.count], self.shouldInterrupt)
            if lucia.key_pressed(lucia.K_RETURN):
                try:
                    self.enter_sound.play()
                except:
                    pass
                self.running = False
                try:
                    self.music.stop()
                except:  # thrown if no music was selected
                    pass
        return self.items[list(self.items)[self.count]]
Пример #17
0
 def run(self):
     lucia.output.output(self.message)
     while True:
         time.sleep(0.001)
         if callable(self.callback):
             self.callback(self)
         if self.input_break:
             break
         events = lucia.process_events()
         for event in events:
             if event.type == pygame.KEYDOWN:
                 if event.key == lucia.K_UP:
                     self.charindex = 0
                     self._output_char(self.text, True)
                 elif event.key == lucia.K_DOWN:
                     self.charindex = len(self.text)
                     self._output_char(self.text, True)
                 elif event.key == lucia.K_HOME:
                     self.charindex = 0
                     self._output_char(self.text[0])
                 elif event.key == lucia.K_END:
                     self.charindex = len(self.text)
                     lucia.output.speak("Blank")
                 elif event.key == lucia.K_LEFT and len(self.text) > 0:
                     if self.charindex > 0:
                         self.charindex -= 1
                     elif self.charindex <= 0:
                         self.charindex = 0
                     self._output_char(self.text[self.charindex])
                 elif event.key == lucia.K_RIGHT and len(self.text) > 0:
                     if self.charindex < len(self.text):
                         self.charindex += 1
                         if self.charindex >= len(self.text):
                             self.charindex = len(self.text)
                             #using the default speaking function, to prevent from saying the hidden_message instead of blank when in a password field.
                             lucia.output.speak("blank")
                         elif self.charindex <= len(self.text) - 1:
                             self._output_char(self.text[self.charindex])
                     else:
                         lucia.output.speak("blank")
                 elif event.key == lucia.K_BACKSPACE:
                     if len(self.text) == 0 or self.charindex <= 0:
                         continue
                     what = self.text[self.charindex - 1]
                     temp = ""
                     if self.charindex < len(self.text):
                         temp = self.text[:self.charindex -
                                          1] + self.text[self.charindex:]
                     elif self.charindex == len(self.text):
                         temp = self.text[:self.charindex - 1]
                     self.text = temp
                     self.charindex -= 1
                     self._output_char(what)
                 elif event.key == lucia.K_RETURN:
                     return self.text
                 elif event.key == lucia.K_SPACE:
                     if self.charindex < len(self.text):
                         self.text = self.text[:self.
                                               charindex] + " " + self.text[
                                                   self.charindex:]
                         self.charindex += 1
                     elif self.charindex == len(self.text):
                         self.text += " "
                         self.charindex += 1
                     self._output_char(" ")
                 else:
                     try:
                         if event.unicode in self.allowed_characters:
                             if self.charindex < len(self.text):
                                 self.text = self.text[:self.
                                                       charindex] + event.unicode + self.text[
                                                           self.charindex:]
                                 self.charindex += 1
                             elif self.charindex == len(self.text):
                                 self.text += event.unicode
                                 self.charindex += 1
                             self._output_char(event.unicode)
                     except ValueError:
                         continue
Пример #18
0
def test_process_events():
    if lucia.running == False:
        lucia.initialize()
    assert lucia.process_events() is not None
Пример #19
0
    def run(self, intro="", isfile=False):
        """ Displayes the menu and waits for a selection

		This function blocks until the menu is closed, either by selecting an item or pressing escape.
		Available controls are up/down arrows, tab and shift + tab, ctrl + up and down, space and enter, and escape.

		args:
		        intro (str, optional): Some brief instructions spoken after the menu title.
		    isfile (bool, optional): Set to True if the intro is the name of an audio file that contains the intro

		returns:
		        The name of a file or directory
		"""

        try:
            self._running = True

            self.__play__("open")
            if self._title: lucia.output.speak(self._title)
            if intro:
                if not isfile:
                    lucia.output.speak(intro, False)
                else:
                    intro = self.__load__(intro)
                    intro.play()

            while self._running:
                time.sleep(0.005)  # Be kind to processors
                lucia.process_events()

                if callable(self._callback):
                    self._callback(self)

                if lucia.key_pressed(lucia.K_ESCAPE) and self.exit_on_escape:
                    self._running = False
                    self.__play__("cancel")
                    return "-1"
                elif lucia.key_pressed(lucia.K_DOWN):
                    if lucia.key_down(lucia.K_LALT) or lucia.key_down(
                            lucia.K_RALT):
                        self.__forward__()
                    else:
                        self.__change_position__(1)
                elif lucia.key_pressed(lucia.K_UP):
                    if lucia.key_down(lucia.K_LALT) or lucia.key_down(
                            lucia.K_RALT):
                        self.__back__()
                    else:
                        self.__change_position__(-1)
                if lucia.key_pressed(lucia.K_TAB):
                    if lucia.key_down(lucia.K_RSHIFT) or lucia.key_down(
                            lucia.K_LSHIFT):
                        self.__change_tab__(-1)
                    else:
                        self.__change_tab__(1)
                elif lucia.key_pressed(lucia.K_RETURN) or lucia.key_pressed(
                        lucia.K_SPACE):
                    result = self.__return_selection__()
                    if result:
                        self._running = False
                        return result
        except Exception as e:
            lucia.logger.exception(e)
        finally:
            self._running = False