本文整理汇总了Python中Menu.Menu.selectItem方法的典型用法代码示例。如果您正苦于以下问题:Python Menu.selectItem方法的具体用法?Python Menu.selectItem怎么用?Python Menu.selectItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Menu.Menu
的用法示例。
在下文中一共展示了Menu.selectItem方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ItemChooser
# 需要导入模块: from Menu import Menu [as 别名]
# 或者: from Menu.Menu import selectItem [as 别名]
class ItemChooser(BackgroundLayer, KeyListener):
"""Item menu layer."""
def __init__(self, engine, items, selected = None, prompt = ""):
self.prompt = prompt
self.engine = engine
self.accepted = False
self.selectedItem = None
self.time = 0.0
self.menu = Menu(self.engine, choices = [(c, self._callbackForItem(c)) for c in items], onClose = self.close, onCancel = self.cancel)
if selected and selected in items:
self.menu.selectItem(items.index(selected))
self.engine.loadSvgDrawing(self, "background", "editor.svg")
def _callbackForItem(self, item):
def cb():
self.chooseItem(item)
return cb
def chooseItem(self, item):
self.selectedItem = item
accepted = True
self.engine.view.popLayer(self.menu)
self.engine.view.popLayer(self)
def cancel(self):
self.accepted = True
self.engine.view.popLayer(self)
def close(self):
self.accepted = True
self.engine.view.popLayer(self)
def shown(self):
self.engine.view.pushLayer(self.menu)
def getSelectedItem(self):
return self.selectedItem
def run(self, ticks):
self.time += ticks / 50.0
def render(self, visibility, topMost):
v = (1 - visibility) ** 2
# render the background
t = self.time / 100
w, h, = self.engine.view.geometry[2:4]
r = .5
self.background.transform.reset()
self.background.transform.translate(v * 2 * w + w / 2 + math.sin(t / 2) * w / 2 * r, h / 2 + math.cos(t) * h / 2 * r)
self.background.transform.rotate(-t)
self.background.transform.scale(math.sin(t / 8) + 2, math.sin(t / 8) + 2)
self.background.draw()
self.engine.view.setOrthogonalProjection(normalize = True)
font = self.engine.data.font
try:
glEnable(GL_BLEND)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
glEnable(GL_COLOR_MATERIAL)
Theme.setBaseColor(1 - v)
wrapText(font, (.1, .05 - v), self.prompt)
finally:
self.engine.view.resetProjection()