當前位置: 首頁>>代碼示例>>Python>>正文


Python DirectScrolledList.removeAllItems方法代碼示例

本文整理匯總了Python中direct.gui.DirectGui.DirectScrolledList.removeAllItems方法的典型用法代碼示例。如果您正苦於以下問題:Python DirectScrolledList.removeAllItems方法的具體用法?Python DirectScrolledList.removeAllItems怎麽用?Python DirectScrolledList.removeAllItems使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在direct.gui.DirectGui.DirectScrolledList的用法示例。


在下文中一共展示了DirectScrolledList.removeAllItems方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: Highscore

# 需要導入模塊: from direct.gui.DirectGui import DirectScrolledList [as 別名]
# 或者: from direct.gui.DirectGui.DirectScrolledList import removeAllItems [as 別名]
class Highscore():
    def __init__(self):

        home = os.path.expanduser("~")
        quickJNRDir = os.path.join(home, ".quickShooter")
        if not os.path.exists(quickJNRDir): os.makedirs(quickJNRDir)
        self.highscorefile = os.path.join(quickJNRDir, "highscore.txt")

        self.highscore = []

        if not os.path.exists(self.highscorefile):
            with open(self.highscorefile, "w") as f:
                f.write("""Foxy;4000
Wolf;3500
Coon;3000
Kitty;2020
Ferret;2000
Lynx;1700
Lion;1280
Tiger;800
Birdy;450
Fishy;250""")


        with open(self.highscorefile, "r+") as f:
            data = f.readlines()
            for line in data:
                name = line.split(";")[0]
                pts = line.split(";")[1]
                self.highscore.append([name, pts])


        self.lstHighscore = DirectScrolledList(
            frameSize = (-1, 1, -0.6, 0.6),
            frameColor = (0,0,0,0.5),
            pos = (0, 0, 0),
            numItemsVisible = 10,
            itemMakeFunction = self.__makeListItem,
            itemFrame_frameSize = (-0.9, 0.9, 0.0, -1),
            itemFrame_color = (1, 1, 1, 0),
            itemFrame_pos = (0, 0, 0.5))

        self.btnBack = DirectButton(
            # size of the button
            scale = (0.15, 0.15, 0.15),
            text = "Back",
            # set no relief
            relief = None,
            frameColor = (0,0,0,0),
            # No sink in when press
            pressEffect = False,
            # position on the window
            pos = (0.2, 0, 0.1),
            # the event which is thrown on clickSound
            command = self.btnBack_Click,
            # sounds that should be played
            rolloverSound = None,
            clickSound = None)
        self.btnBack.setTransparency(1)
        self.btnBack.reparentTo(base.a2dBottomLeft)

        self.refreshList()
        self.hide()

    def show(self):
        self.lstHighscore.show()
        self.btnBack.show()

    def hide(self):
        self.lstHighscore.hide()
        self.btnBack.hide()

    def writeHighscore(self):
        self.__sortHigscore()
        with open(self.highscorefile, "w") as f:
            for entry in self.highscore:
                f.write("{0};{1}".format(entry[0], entry[1]))

    def refreshList(self):
        self.__sortHigscore()
        self.lstHighscore.removeAllItems()
        for entry in self.highscore:
            self.lstHighscore.addItem("{0};{1}".format(entry[0], entry[1]))

    def __makeListItem(self, highscoreItem, stuff, morestuff):
        name = highscoreItem.split(";")[0]
        pts = highscoreItem.split(";")[1]
        # left
        l = -0.9
        # right
        r = 0.9
        itemFrame = DirectFrame(
            frameColor=(1, 1, 1, 0.5),
            frameSize=(l, r, -0.1, 0),
            relief=DGG.SUNKEN,
            borderWidth=(0.01, 0.01),
            pos=(0, 0, 0))
        lblName = DirectLabel(
            pos=(l + 0.01, 0, -0.07),
            text=name,
#.........這裏部分代碼省略.........
開發者ID:grimfang,項目名稱:owp_shooter,代碼行數:103,代碼來源:highscore.py

示例2: MenuOptions

# 需要導入模塊: from direct.gui.DirectGui import DirectScrolledList [as 別名]
# 或者: from direct.gui.DirectGui.DirectScrolledList import removeAllItems [as 別名]

#.........這裏部分代碼省略.........

                    "tab", "caps_lock", "shift", "rcontrol", "lcontrol", "ralt",
                    "lalt", "space", "backspace", "enter",

                    "arrow_left", "arrow_up", "arrow_down", "arrow_right",

                    "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l",
                    "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x",
                    "y", "z",

                    "ä", "ö", "ü",

                    ",", ";", ".", ":", "_", "-", "#", "'", "+", "*", "~", "'",
                    "`", "!", "\"", "§", "$", "%", "&", "/", "(", ")", "=", "?",
                    "{", "}", "[", "]", "\\", "^", "°"
                    ]

                def setKey(arg):
                    """
                    This function will set the chosen key for the given action
                    """
                    # ignore all keyboard inputs again
                    for keyboardKey in keyboard:
                        self.ignore(keyboardKey)
                    if arg == 1:
                        # if the dialog was closed with OK
                        # set the settings to the new value
                        self.engine.settings.playerKeys[key][0] = self.selectedKey
                        if len(self.engine.settings.playerKeys[key]) > 1:
                            # just set the run key value if it is possible
                            newKey = self.engine.settings.playerKeys["run"][0] + "-" + self.selectedKey
                            self.engine.settings.playerKeys[key][1] = newKey
                    # refresh the controls list
                    self.controlsList.removeAllItems()
                    self.fillControlsList()
                    # finaly close the dialog
                    self.keySelectDialog.hide()
                    self.keySelectDialog = None

                # this variable will store the selected key for the given action
                self.selectedKey = value[0]
                def setSelectedKey(selkey):
                    """
                    set the pressed key as the selected one and actualise the text
                    on the dialog
                    """
                    self.selectedKey = selkey
                    self.keySelectDialog["text"] = "{0}: {1}".format(key, self.selectedKey)

                # accept all keyboard keys
                for keyboardKey in keyboard:
                    self.accept(
                        keyboardKey,
                        setSelectedKey,
                        [keyboardKey])

                # set up a dialog wich will ask for the new key for the chosen action
                self.keySelectDialog = OkCancelDialog(
                    dialogName = "OkCancelDialog",
                    text = "{0}: {1}".format(key, value[0]),
                    fadeScreen = 1,
                    command = setKey
                    )
                # show the dialog
                self.keySelectDialog.show()
開發者ID:grimfang,項目名稱:rising_reloaded,代碼行數:69,代碼來源:MenuOptions.py


注:本文中的direct.gui.DirectGui.DirectScrolledList.removeAllItems方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。