本文整理汇总了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,
#.........这里部分代码省略.........
示例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()