当前位置: 首页>>代码示例>>Python>>正文


Python UI.choice方法代码示例

本文整理汇总了Python中UI.choice方法的典型用法代码示例。如果您正苦于以下问题:Python UI.choice方法的具体用法?Python UI.choice怎么用?Python UI.choice使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UI的用法示例。


在下文中一共展示了UI.choice方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: doMenu

# 需要导入模块: import UI [as 别名]
# 或者: from UI import choice [as 别名]
    def doMenu(self):
        """Executes the menu, executes user's chosen line, returns its index"""
        while 1:
            self.Items = self.Pages[self.PageIndex].Items
            self.PossibleKeys = self.Pages[self.PageIndex].PossibleKeys
            
            if self.DoCLS: clrScr()
            self.Returned = 0

            if self.Title != "": print("********"+ self.Title+ "********")
            if self.PageIndex > 0: print("...")
            for item in self.Items:
                if item.IsSeparator:
                    print(item.Text)
                else:
                    print(item.Key.upper(), item.Text)
            if self.PageIndex < len(self.Pages)-1: print("...")
            if self.CustomText != "": print (self.CustomText)

            #Get player's choice
            if self.HasReturn:
                if len(self.Pages) > 1:
                    choice = UI.choice(self.PossibleKeys + [27, ord('\xe0')], "Enter your choice (ESC to return): ")
                else:
                    choice = UI.choice(self.PossibleKeys + [27], "Enter your choice (ESC to return): ")
            else:
                if len(self.Pages) > 1:
                    choice = UI.choice(self.PossibleKeys + [ord('\xe0')], "Enter your choice: ")
                else:
                    choice = UI.choice(self.PossibleKeys, "Enter your choice: ")

            #If user has pressed ESC
            if self.HasReturn and choice == 27:
                self.Returned = 1
                return 0

            #If user has pressed an arrow key
            if choice == ord('\xe0') and len(self.Pages) > 1:
                choice = getch()
                if ord(choice) == ord('M'): #Right arrow
                    self.PageIndex += 1
                    if self.PageIndex >= len(self.Pages):
                        self.PageIndex = 0
                if ord(choice) == ord('K'): #Left arrow
                    self.PageIndex -= 1
                    if self.PageIndex < 0:
                        self.PageIndex = len(self.Pages)-1

                # Restart the loop with new variables
                continue

            for Temp in self.Items:
                if Temp.IsSeparator: continue
                if chr(choice) == Temp.Key.lower():
                    ChosenItem = Temp
                    break

            print ("")
            print ("")

            #Do an action described in MenuItem, wait for keypress if asked to, return user's choice
            ChosenItem.CallBack()
            if ChosenItem.WaitAfter: waitForKey()
            
            return ChosenItem.ID
开发者ID:mildbyte,项目名称:console-massacre,代码行数:67,代码来源:UI.py


注:本文中的UI.choice方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。