本文整理匯總了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()