本文整理汇总了Python中memory.Memory.scan方法的典型用法代码示例。如果您正苦于以下问题:Python Memory.scan方法的具体用法?Python Memory.scan怎么用?Python Memory.scan使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类memory.Memory
的用法示例。
在下文中一共展示了Memory.scan方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MemoryDisplay
# 需要导入模块: from memory import Memory [as 别名]
# 或者: from memory.Memory import scan [as 别名]
class MemoryDisplay(threading.Thread):
"Displays timer and memory images. Handles barcode input (barcode scanner is a HID)."
# taken from http://learn.adafruit.com/pi-video-output-using-pygame/pygame-drawing-functions
def __init__(self, ledstrip, noReturn=False):
"Ininitializes a new pygame screen using the framebuffer"
threading.Thread.__init__(self)
if DEBUG:
logging.info("DEBUG MODE")
self.screen = pygame.display.set_mode((640, 480))
else:
# Based on "Python GUI in Linux frame buffer"
# http://www.karoltomala.com/blog/?p=679
dispNo = os.getenv("DISPLAY")
if dispNo:
logging.info("I'm running under X display = %s" % dispNo)
# Check which frame buffer drivers are available
# Start with fbcon since directfb hangs with composite output
drivers = ["fbcon", "directfb", "svgalib"]
found = False
for driver in drivers:
# Make sure that SDL_VIDEODRIVER is set
if not os.getenv("SDL_VIDEODRIVER"):
os.putenv("SDL_VIDEODRIVER", driver)
try:
pygame.display.init()
except pygame.error:
logging.warning("Driver: %s failed." % driver)
continue
found = True
break
if not found:
logging.critical("No suitable video driver found! Are you root?")
raise Exception("No suitable video driver found! Are you root?")
size = (pygame.display.Info().current_w, pygame.display.Info().current_h)
logging.info("Framebuffer size: %d x %d" % (size[0], size[1]))
self.screen = pygame.display.set_mode(size, pygame.FULLSCREEN)
self.clock = pygame.time.Clock()
self.playTime = 0
self.noReturn = noReturn
self.runGame = True
self.inGame = False
self.lastAction = datetime.now() - timedelta(seconds=30)
self.validGame = True
self.lastHighscore = []
self.barcode = ""
self.lastImg = None
self.white = (255, 255, 255)
self.black = (0, 0, 0)
self.red = (255, 0, 0)
self.green = (0, 255, 0)
self.ledstrip = ledstrip
self.memory = Memory(self)
# preload images
gameImgs = ["byhickerspace.png", "qrcode.png"]
self.preloadedImgs = {}
for imgPath in gameImgs:
self.preloadedImgs[imgPath] = pygame.image.load(imgPath).convert()
for imgPath in self.memory.images:
img = pygame.image.load(imgPath).convert()
self.preloadedImgs[imgPath] = self.scalePercentage(img, 1)
# Clear the screen to start
self.screen.fill((0, 0, 0))
# Initialise font support
pygame.font.init()
# hide mouse pointer
pygame.mouse.set_visible(False)
# Render the screen
pygame.display.update()
self.endGame()
def __del__(self):
"Destructor to make sure pygame shuts down, etc."
def scalePercentage(self, surface, perc):
screenRect = self.screen.get_rect()
surface = pygame.transform.scale(surface, (int(perc*screenRect.width),
int(perc*screenRect.height)))
return surface
def showImg(self, img, firstMove):
"Takes image path and displays the image."
if not self.inGame: return
self.screen.fill((0, 0, 0))
self.screen.blit(self.preloadedImgs[img], (0, 25))
if firstMove:
self.lastImg = img
else:
#.........这里部分代码省略.........