本文整理汇总了Python中view.View.render方法的典型用法代码示例。如果您正苦于以下问题:Python View.render方法的具体用法?Python View.render怎么用?Python View.render使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类view.View
的用法示例。
在下文中一共展示了View.render方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: index
# 需要导入模块: from view import View [as 别名]
# 或者: from view.View import render [as 别名]
def index(method, get, post, headers):
messages = message_manager.all()
status = '200 OK'
view = View('main.html')
body = view.render(messages=messages)
if method == 'POST':
status = '303 See Other'
body = b''
headers.append(('Location', '/'))
message_name = get_first_element(post, 'name', '')
message_message = get_first_element(post, 'message', '')
message = Message(message_name, message_message)
message_manager.save(message)
return status, body
示例2: Game
# 需要导入模块: from view import View [as 别名]
# 或者: from view.View import render [as 别名]
class Game() :
def __init__(self, windowLabel = "My game", tileSize = 32) :
# Initialize PyGame
pygame.init()
# Set up FPS clock
self.fps = 30
self.fpsClock = pygame.time.Clock()
# Setup a view
self.view = View(windowLabel, tileSize, (16,16))
self.tileSize = tileSize
def setMap(self, map) :
self.map = map
def setHero(self, hero) :
self.hero = hero
self.hero.walkabilityChecker = self.map.getWalkability
self.hero.getObject = self.map.getObject
def mainLoop(self) :
# Handle events
self.eventHandler()
# Handle keys
self.keysHandler()
# Update character
self.hero.update()
# Center the view on hero
self.view.setCenter((self.hero.x, self.hero.y))
# Render elements
self.view.render(self.map, self.hero)
# Update screen
pygame.display.update()
self.fpsClock.tick(self.fps)
def eventHandler(self) :
for event in pygame.event.get():
if (event.type == pygame.QUIT) :
pygame.quit()
sys.exit()
def keysHandler(self) :
keyPressed = pygame.key.get_pressed()
moveDirection = ""
if (keyPressed[pygame.K_UP]) : moveDirection = "back"
if (keyPressed[pygame.K_DOWN]) : moveDirection = "front"
if (keyPressed[pygame.K_LEFT]) : moveDirection = "left"
if (keyPressed[pygame.K_RIGHT]) : moveDirection = "right"
if (moveDirection != "") :
self.hero.look(moveDirection)
self.hero.move(moveDirection)
if (keyPressed[pygame.K_e]) :
self.hero.actionKeyHandler();