Exemple #1
0
def run():
	signal.signal(signal.SIGINT, signal.SIG_IGN)

	# Initialize our possible input devices
	devio.initialize()

	# Set up our filters and callbacks
	devio.add_handler("interface_game_buttons", filter_buttons, handle_buttons)
	devio.add_handler("interface_stdin", filter_stdin, handle_stdin)
	devio.add_handler("patchmessages", filter_patch, handle_patch)

	# Loop forever
	while 1:

		# If we get an exception, show the error and start over
		try:

			# Show welcome message and sleep for 1s
			displaymodel.display_line_one("nw2s:b2/dsp v0.1")
			displaymodel.display_line_two("")

			time.sleep(1.0)

			# Show the main menu
			oledmenuservice.navigateroot()

			# Hand off control to the input manager
			devio.process()

		except Exception as e:

			logservice.log(logservice.LOG_ERR, 'Error in interface worker thread: {0}'.format(e))
			logservice.log(logservice.LOG_ERR, traceback.format_exc())

			# Reset the menu
			oledmenuservice.reset()

			# Show the error:
			displaymodel.display_line_one('Error:')
			displaymodel.display_line_two(str(e)[:16])

			time.sleep(2.0)
Exemple #2
0
def navigate(navigation):    
    
    # This code performs the actual menu navigation until we get to a command that has it's own handlers
    global menu_node
    global current_level
    
    changed = False
    
    # Move to the right in the menu    
    #if event["number"] == gamepadmodel.DPAD_LEFT:
    if (navigation == menumodel.NAVIGATE_LEFT):
            
        current_index[current_level] = (current_index[current_level] - 1) % len(menu_node["items"])
        
        # TODO: not necessarily
        changed = True

    # Move to the left in the menu
    #elif event["number"] == gamepadmodel.DPAD_RIGHT:
    elif (navigation == menumodel.NAVIGATE_RIGHT):
        
        current_index[current_level] = (current_index[current_level] + 1) % len(menu_node["items"])
        
        # TODO: not necessarily
        changed = True

    # Run a command to give us the next single item
    #elif event["number"] == gamepadmodel.BUTTON_X and "itemcommand" in menu_node["items"][current_index[current_level]]:
    elif navigation == menumodel.NAVIGATE_SELECT and "itemcommand" in menu_node["items"][current_index[current_level]]:
    
        # Remember where we are in the tree for navigating back up later
        current_stack[current_level + 1] = menu_node

        # Run the command and get the next layer item, turn it into a list, generally for information only
        menu_node["items"][current_index[current_level]]["items"] = [ { "text" : menu_node["items"][current_index[current_level]]["itemcommand"]() } ]

        # Make our node pointer point to the selected menu item
        menu_node = menu_node["items"][current_index[current_level]]
        
        # Increment the current level by 1
        current_level += 1
        
        # Reset the current index for our new level to zero
        current_index[current_level] = 0
    
        changed = True

    # Run a command to give us the next multiple items
    elif navigation == menumodel.NAVIGATE_SELECT and "itemscommand" in menu_node["items"][current_index[current_level]]:

        # Remember where we are in the tree for navigating back up later
        current_stack[current_level + 1] = menu_node

        # Run the command and get the next layer items - in the same format that any other menu choice would be
        menu_node["items"][current_index[current_level]]["items"] = menu_node["items"][current_index[current_level]]["itemscommand"](menu_node["items"][current_index[current_level]])

        # Make our node pointer point to the selected menu item
        menu_node = menu_node["items"][current_index[current_level]]
        
        # Increment the current level by 1
        current_level += 1
        
        # Reset the current index for our new level to zero
        current_index[current_level] = 0
    
        changed = True
        

    # Load a patch
    elif navigation == menumodel.NAVIGATE_SELECT and "loadcommand" in menu_node["items"][current_index[current_level]]:

        # Remember where we are in the tree for navigating back up later
        current_stack[current_level + 1] = menu_node

        # This is a patch that needs to be loaded
        menu_node["items"][current_index[current_level]]["items"] = menu_node["items"][current_index[current_level]]["loadcommand"](menu_node["items"][current_index[current_level]])

        # Make our node pointer point to the selected menu item
        menu_node = menu_node["items"][current_index[current_level]]
        
        # Increment the current level by 1
        current_level += 1
        
        # Reset the current index for our new level to zero
        current_index[current_level] = 0
    
        changed = True
        

    # Move to the next lower level of menu
    elif navigation == menumodel.NAVIGATE_SELECT and "items" in menu_node["items"][current_index[current_level]] and len(menu_node["items"][current_index[current_level]]["items"]) > 0:

        # Remember where we are in the three for navigating back up later
        current_stack[current_level + 1] = menu_node
        
        # Make our node pointer point to the selected menu item
        menu_node = menu_node["items"][current_index[current_level]]
        
        # Increment the current level by 1
        current_level += 1
        
        # Reset the current index for our new level to zero
        current_index[current_level] = 0
    
        changed = True

    elif navigation == menumodel.NAVIGATE_ESCAPE and current_level > 0:
        
        # Make our node pointer point to the selected menu item
        menu_node = current_stack[current_level]

        current_level -= 1
        
        changed = True


    # Only update if a change was made - to avoid flicker
    if changed:

        displaymodel.display_line_one(menu_node["text"])

        if current_level >= 0:

            displaymodel.display_line_two(menu_node["items"][current_index[current_level]]["text"])
    
        else:
            
            displaymodel.display_line_two("")
Exemple #3
0
def navigateroot():
    
    # Show the main menu: 
    displaymodel.display_line_one(menu_node["text"])
    displaymodel.display_line_two(menu_node["items"][current_index[current_level]]["text"])