示例#1
0
 def test_init(self):
     selection_item_1 = SelectionItem("selection_item_1", 1, self.menu)
     selection_item_2 = SelectionItem(text="selection_item_2", index=2, menu=self.menu)
     self.assertEqual(selection_item_1.text, "selection_item_1")
     self.assertEqual(selection_item_2.text, "selection_item_2")
     self.assertEqual(selection_item_1.menu, self.menu)
     self.assertEqual(selection_item_2.menu, self.menu)
     self.assertTrue(selection_item_1.should_exit)
     self.assertTrue(selection_item_2.should_exit)
示例#2
0
	def __init__(self, strings, title=None, subtitle=None, show_exit_option=True):
		"""
		:ivar list[str] strings: The list of strings this menu should be built from
		"""
		super(MultiSelect, self).__init__(title, subtitle, show_exit_option)
		for index, item in enumerate(strings):
			self.append_item(SelectionItem(item, index, self))
示例#3
0
def parse_old_menu(menu_data):
    """
    Take an old-style menuData dictionary and return a CursesMenu

    :param dict menu_data:
    :return: A new CursesMenu
    :rtype: CursesMenu
    """
    menu_title = menu_data['title']
    menu = CursesMenu(menu_title)
    for item in menu_data["options"]:
        item_type = item["type"]
        item_title = item["title"]
        if item_type == menuItem.COMMAND:
            item_command = item["command"]
            menu.append_item(CommandItem(item_title, item_command, menu))
        elif item_type == menuItem.FUNCTION:
            item_function = item["function"]
            menu.append_item(FunctionItem(item_title, item_function, menu))
        elif item_type == menuItem.EXITMENU:
            menu.append_item(ExitItem(item_title, menu))
        elif item_type == menuItem.NUMBER:
            menu.append_item(SelectionItem(item_title, menu))
        elif item_type == menuItem.MENU:
            new_menu = parse_old_menu(item)
            menu.append_item(SubmenuItem(item_title, menu, new_menu))

    return menu
示例#4
0
    def display_commands(self, user=None):
        """[displats all commands for user]
        """

        if user:
            menu = CursesMenu("Spotify Collobrative Playlist",
                              "User: "******"Spotify Collobrative Playlist",
                              "User",
                              show_exit_option=True)
        sl1 = SelectionItem("Choose Active Playlist", 1)
        sl2 = SelectionItem("Add new song to playlist", 2)
        sl3 = SelectionItem("List Playlists", 3)
        sl4 = SelectionItem("Print Songs in Playlist", 4)
        sl5 = SelectionItem("Create Playlist", 5)
        sl6 = SelectionItem("Exit", 6)
        menu.append_item(sl1)
        menu.append_item(sl2)
        menu.append_item(sl3)
        menu.append_item(sl4)
        menu.append_item(sl5)
        menu.append_item(sl6)
        menu.start()
        menu.join()
        return menu.returned_value
示例#5
0
 def __init__(self,
              strings,
              title=None,
              subtitle=None,
              show_exit_option=True,
              with_border=True,
              tight=False):
     """
     :ivar list[str] strings: The list of strings this menu should be built from
     """
     super(SelectionMenu, self).__init__(title, subtitle, show_exit_option,
                                         with_border, tight)
     for index, item in enumerate(strings):
         self.append_item(SelectionItem(item, index, self))
示例#6
0
	def append_string(self, string):
		self.append_item(SelectionItem(string))