当前位置: 首页>>代码示例>>Python>>正文


Python Display.refresh方法代码示例

本文整理汇总了Python中display.Display.refresh方法的典型用法代码示例。如果您正苦于以下问题:Python Display.refresh方法的具体用法?Python Display.refresh怎么用?Python Display.refresh使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在display.Display的用法示例。


在下文中一共展示了Display.refresh方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from display import Display [as 别名]
# 或者: from display.Display import refresh [as 别名]
def main(args):
    # Initialize main transport
    transport = get_transport(args.transport, args.path)

    # Initialize hardware (screen, buttons)
    but = Buttons(hw=args.shield, stdin=not args.shield, pygame=not args.shield)
    buff = DisplayBuffer(DISPLAY_WIDTH, DISPLAY_HEIGHT)
    display = Display(buff, spi=args.shield, virtual=not args.shield)
    display.init()

    # Initialize layout driver
    layout = Layout(buff)

    # Startup state machine and switch it to default state
    machine = StateMachine(args.keyfile, layout)

    display.refresh()

    # Main cycle
    while True:
        # Set True if device does something
        # False = device will sleep for a moment
        is_active = False

        try:
            # Read button states
            button = but.read()
        except KeyboardInterrupt:
            # User requested to close the app
            break

        if button is not None:
            print "Button", button
            is_active = True

            resp = machine.press_button(button)
            if resp is not None:
                print "Sending", resp
                transport.write(resp)

        # Handle main connection
        msg = transport.read()
        if msg is not None:
            print "Received", msg.__class__.__name__  # , msg
            resp = machine.process_message(msg)
            if resp is not None:
                print "Sending", resp.__class__.__name__, resp
                transport.write(resp)
                is_active = True

        # Display scrolling
        is_active |= layout.update()

        if layout.need_refresh:
            # Update display
            display.refresh()

        if not is_active:
            # Nothing to do, sleep for a moment
            time.sleep(0.1)

    # Close transports
    transport.close()
开发者ID:slush0,项目名称:trezor-signer,代码行数:65,代码来源:__init__.py

示例2: main

# 需要导入模块: from display import Display [as 别名]
# 或者: from display.Display import refresh [as 别名]
def main(args):
    # Initialize debuglink transport
    if args.debuglink:
        print "Starting debug connection on '%s'" % args.debuglink_path
        print "Debug connection is for unit tests only. NEVER use debug connection with real wallet!"
        debug_transport = get_transport(args.debuglink_transport, args.debuglink_path)
    else:
        debug_transport = get_transport('fake', None)

    # Initialize main transport
    transport = get_transport(args.transport, args.path)

    # Load persisted data. Create new wallet if file doesn't exist
    print "Loading wallet..."
    wallet = Wallet(args.wallet)
    print wallet.struct

    # Initialize hardware (screen, buttons)
    but = Buttons(hw=args.shield, stdin=not args.shield, pygame=not args.shield)
    buff = DisplayBuffer(DISPLAY_WIDTH, DISPLAY_HEIGHT)
    display = Display(buff, spi=args.shield, virtual=not args.shield)
    display.init()

    # Initialize layout driver
    layout = Layout(buff)

    # Startup state machine and switch it to default state
    machine = StateMachine(wallet, layout)

    #tx1 = proto.TxOutput(address='1BRMLAB7nryYgFGrG8x9SYaokb8r2ZwAsX', amount=112000000)
    #tx2 = proto.TxOutput(address='1MarekMKDKRb6PEeHeVuiCGayk9avyBGBB', amount=12340123400)
    #layout.show_transactions([tx1, tx2 ], False)

    display.refresh()

    # Main cycle
    while True:
	#d=datetime.now()
	#layout.show_message([d.strftime("%d %B %Y %H:%M:%S")],question=False)
        # Set True if device does something
        # False = device will sleep for a moment
        is_active = False

        try:
            # Read button states
            button = but.read()
        except KeyboardInterrupt:
            # User requested to close the app
            break

        # Handle debug link connection
        msg = debug_transport.read()
        if msg is not None:
            print "Received debuglink", msg.__class__.__name__, msg
            if isinstance(msg, proto.DebugLinkDecision):
                # Press the button
                button = msg.yes_no
            else:
                resp = machine.process_message(msg)
                if resp is not None:
                    print "Sending debuglink", resp.__class__.__name__, resp
                    debug_transport.write(resp)
                    is_active = True

            '''
            elif isinstance(msg, proto.DebugLinkGetState):
                # Report device state
                resp = machine.get_state(msg)
                print "Sending debuglink", resp.__class__.__name__, resp
                debug_transport.write(resp)
            else:
                raise Exception("Got unexpected object %s" % msg.__class__.__name__)
            '''

        if button is not None:
            print "Button", button
            is_active = True

            resp = machine.press_button(button)
            if resp is not None:
                print "Sending", resp
                transport.write(resp)

        '''
        if button == True:
            layout.show_transactions([tx1, tx2 ], False)
            layout.show_question_dummy()

        if button == False:
            layout.show_logo(logo)
        '''

        # Handle main connection
        msg = transport.read()
        if msg is not None:
            print "Received", msg.__class__.__name__, msg
            resp = machine.process_message(msg)
            if resp is not None:
                print "Sending", resp.__class__.__name__, resp
                transport.write(resp)
#.........这里部分代码省略.........
开发者ID:jackjack-jj,项目名称:trezor-emu-jj,代码行数:103,代码来源:__init__.py

示例3: main

# 需要导入模块: from display import Display [as 别名]
# 或者: from display.Display import refresh [as 别名]
def main(args):
    monkeypatch_google_protobuf_text_format()

    # Initialize debuglink transport
    if args.debuglink:
        print "Starting debug connection on '%s'" % args.debuglink_path
        print "Debug connection is for unit tests only. NEVER use debug connection with real wallet!"
        debug_transport = get_transport(args.debuglink_transport, args.debuglink_path)
    else:
        debug_transport = get_transport('fake', None)

    # Initialize main transport
    transport = get_transport(args.transport, args.path)

    # Load persisted data. Create new wallet if file doesn't exist
    print "Loading wallet..."
    storage = Storage(args.wallet, bootloader_mode=args.bootloader_mode)
    # storage.struct.settings.label = 'Slushova penezenka'
    print storage.struct

    # Initialize hardware (screen, buttons)
    but = Buttons(hw=args.shield, stdin=not args.shield, pygame=not args.shield)
    buff = DisplayBuffer(DISPLAY_WIDTH, DISPLAY_HEIGHT)
    display = Display(buff, spi=args.shield, virtual=not args.shield)
    display.init()

    # Initialize layout driver
    layout = Layout(buff, display)

    # Process exponential backoff if there was unsuccesfull PIN attempts
    if storage.get_pin_delay():
        delay = storage.get_pin_delay()
        print "Waiting %s seconds until boot up" % delay
        layout.show_pin_backoff_progress(delay)

    # Startup state machine and switch it to default state
    machine = StateMachine(storage, layout)

    display.refresh()

    # Main cycle
    while True:
        try:
            # Read button states
            button = but.read()
        except KeyboardInterrupt:
            # User requested to close the app
            break

        # Set is_active=True if device does something
        # False = device will sleep for a moment to prevent CPU load
        # Set button=None to use event only for rendering
        # and hide it against state machine
        (is_active, button) = layout.update(button)

        # Handle debug link connection
        msg = debug_transport.read()
        if msg is not None:
            print "Received debuglink", msg.__class__.__name__, msg
            if isinstance(msg, proto.DebugLinkDecision):
                # Press the button
                button = msg.yes_no
            else:
                resp = machine.process_debug_message(msg)
                if resp is not None:
                    print "Sending debuglink", resp.__class__.__name__, resp
                    debug_transport.write(resp)
                    is_active = True

        if button is not None:
            print "Button", button
            is_active = True

            resp = machine.press_button(button)
            if resp is not None:
                print "Sending", resp
                transport.write(resp)

        # Handle main connection
        msg = transport.read()
        if msg is not None:
            print "Received", msg.__class__.__name__, msg
            resp = machine.process_message(msg)
            if resp is not None:
                print "Sending", resp.__class__.__name__, resp
                transport.write(resp)
                is_active = True

        if not is_active:
            # Nothing to do, sleep for a moment
            time.sleep(0.05)

    # Close transports
    transport.close()
    debug_transport.close()
开发者ID:adballar,项目名称:trezor-emu,代码行数:97,代码来源:__init__.py

示例4: Game

# 需要导入模块: from display import Display [as 别名]
# 或者: from display.Display import refresh [as 别名]

#.........这里部分代码省略.........
		alien_height = 0

		aliens = []

		for x in range(0, self.aliens_width):
			for y in range(0, self.aliens_height):

				objAlien = Alien1
				if y == 0:
					objAlien = Alien2

				alien = objAlien(
						logger=self.logger,
						display=self.display,
						game=self,
						x=start_x + x * (alien_width + self.aliens_margin),
						y=start_y + y * (alien_height + self.aliens_margin),
						line=y
					)

				alien_width = alien.width
				alien_height = alien.height

				aliens.append(alien)

		return aliens

	def win(self):
		self.display.clear()
		self.display.write(
					pos=self.display.get_center(you_win),
					sprite=you_win
				)
		self.display.refresh()
		time.sleep(5)

	def game_over(self):
		self.display.clear()
		self.display.write(
			pos=self.display.get_center(game_over),
			sprite=game_over
		)
		self.display.refresh()
		time.sleep(5)		

	def start(self):
		err = None
		lastfire = time.time() - 5
		way = True

		try:
			self.logger.debug("Start game")
			run = True
			while run:
				time.sleep(1.0/self.frame_rate)
				self.display.clear()

				# GAME OVER
				if self.ship.life <= 0:
					self.game_over()
					break

				# Choose way right or left
				nb_mob = 0
				ori_way = way
				for index, alien in enumerate(self.aliens):
开发者ID:william-p,项目名称:pyCursesInvaders,代码行数:70,代码来源:game.py

示例5: start

# 需要导入模块: from display import Display [as 别名]
# 或者: from display.Display import refresh [as 别名]
	def start(self):
		score = 0
		lives = 3
		level = 1
		framerate = 25
		shields = 4
		alien_tick = 15
		gameover = False

		display = Display()
		gun = Gun(maxx=display.width, maxy=display.height)
		aliens = self.make_aliens(42, display.width, alien_tick)

		while True:
			self.status(display, lives, score, level)

			for alien in aliens:
				alien.move()
				display.putstring(alien.last[0], alien.last[1], "     ")
				display.putstring(alien.current[0], alien.current[1], alien.alien)

			display.putstring(gun.guny, gun.gunx, gun.gun)
			
			for index, alien in enumerate(aliens):
				hit = gun.hit(alien.current[0], alien.current[1])
				if hit:
					display.putstring(alien.current[0], alien.current[1], " BOOM ")
					score += 1
					del(aliens[index])
					break
				
				if alien.current[0] == display.height - 2:
					if lives > 0:
						lives -= 1
						aliens = self.make_aliens(42, display.width, alien_tick)
						display.erase()
					else:
						gameover = True
						display.putstring(10, 30, "Game Over!!!")
					break

			if aliens == []:
				display.putstring(10, 30, "YOU WIN!!!!")
				
			if gun.firing:
				gun.fire()
				display.putstring(gun.bullety, gun.bulletx, gun.bullet)
		
			display.refresh()
			time.sleep(1.0 / framerate)
			
			if gameover:
				display.close()
				break

			if gun.firing:
				display.putstring(gun.bullety, gun.bulletx, " ")

			if hit:
				display.putstring(alien.current[0], alien.current[1], "      ")
				
			if aliens == []:
				display.putstring(10, 30, "            ")
				level += 1
				alien_tick -= 1
				aliens = self.make_aliens(42, display.width, alien_tick)

			display.refresh()
	
			i = display.getch()
			if i == ord("a"):
				gun.left()
			elif i == ord("d"):
				gun.right()
			elif i == ord("s"):
				gun.start()
			elif i == ord("q"):
				display.close()
				break
开发者ID:belambic,项目名称:invaders,代码行数:81,代码来源:game.py

示例6: Level

# 需要导入模块: from display import Display [as 别名]
# 或者: from display.Display import refresh [as 别名]
import sys
import pygame

from display import Display
from level import Level

level = Level(0)
display = Display()

display = Display()
display.load_data()
display.first_display()
while 1:
  for event in pygame.event.get():
    if event.type == pygame.QUIT:
      sys.exit()
    for bloc in level.get_blocs():
      display.display_bloc(bloc)      
    display.refresh()

开发者ID:arvatarox,项目名称:AutoMario,代码行数:21,代码来源:mario.py


注:本文中的display.Display.refresh方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。