本文整理汇总了Python中screen.Screen.clear方法的典型用法代码示例。如果您正苦于以下问题:Python Screen.clear方法的具体用法?Python Screen.clear怎么用?Python Screen.clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类screen.Screen
的用法示例。
在下文中一共展示了Screen.clear方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ScreenTest
# 需要导入模块: from screen import Screen [as 别名]
# 或者: from screen.Screen import clear [as 别名]
class ScreenTest(unittest.TestCase):
SCREEN_W = 64
SCREEN_H = 32
def setUp(self):
self.screen = Screen(self.SCREEN_W, self.SCREEN_H)
def tearDown(self):
pass
def testShouldHaveCorrectSize(self):
self.assertEqual(self.screen.width, self.SCREEN_W)
self.assertEqual(self.screen.height, self.SCREEN_H)
def testShouldChangeCorrectPixel(self):
self.screen.setPixel(1, 1, True)
pixel1 = self.screen.getPixel(1, 1)
self.assertTrue(pixel1)
self.screen.setPixel(1, 1, False)
pixel2 = self.screen.getPixel(1, 1)
self.assertFalse(pixel2)
def testShouldBeClearedAfterInit(self):
self.assertTrue(self.screen.screen == [0] * len(self.screen.screen))
def testShouldFullyClearScreen(self):
self.screen.setPixel(1, 1, True)
self.screen.clear()
self.assertTrue(self.screen.screen == [0] * len(self.screen.screen))
示例2: clear
# 需要导入模块: from screen import Screen [as 别名]
# 或者: from screen.Screen import clear [as 别名]
def clear(self, color, i=None):
""" Clear the subscreen at index i.
"""
if i != None:
pygame.draw.rect(self.screen, color, self.rect(i))
else:
Screen.clear(self, color)
示例3: add_screen
# 需要导入模块: from screen import Screen [as 别名]
# 或者: from screen.Screen import clear [as 别名]
def add_screen(self, ref):
""" Add Screen """
if ref not in self.screens:
screen = Screen(self, ref)
screen.clear()
self.screens[ref] = screen
return self.screens[ref]
示例4: Screen
# 需要导入模块: from screen import Screen [as 别名]
# 或者: from screen.Screen import clear [as 别名]
from framerate import Framerate
from screen import Screen
from gameController import GameController
width = 20#60
height = 20#35
screen = Screen(width,height)
gameController = GameController(screen)
framerate = Framerate()
while True:
screen.clear()
gameController.update()
framerate.render()
screen.render()
示例5: GtkUI
# 需要导入模块: from screen import Screen [as 别名]
# 或者: from screen.Screen import clear [as 别名]
class GtkUI(object):
"""Gtk+ UI class."""
def __init__(self):
"""Initialize the UI instance."""
self._redraw_arg = None
self._foreground = -1
self._background = -1
self._font_size = 13
self._font_name = 'Monospace'
self._screen = None
self._attrs = None
self._busy = False
self._mouse_enabled = False
self._insert_cursor = False
self._blink = False
self._blink_timer_id = None
self._resize_timer_id = None
self._pressed = None
self._invalid = None
self._pending = [0, 0, 0]
self._reset_cache()
def start(self, bridge):
"""Start the UI event loop."""
bridge.attach(80, 24, True)
drawing_area = Gtk.DrawingArea()
drawing_area.connect('draw', self._gtk_draw)
window = Gtk.Window()
window.add(drawing_area)
window.set_events(window.get_events() |
Gdk.EventMask.BUTTON_PRESS_MASK |
Gdk.EventMask.BUTTON_RELEASE_MASK |
Gdk.EventMask.POINTER_MOTION_MASK |
Gdk.EventMask.SCROLL_MASK)
window.connect('configure-event', self._gtk_configure)
window.connect('delete-event', self._gtk_quit)
window.connect('key-press-event', self._gtk_key)
window.connect('button-press-event', self._gtk_button_press)
window.connect('button-release-event', self._gtk_button_release)
window.connect('motion-notify-event', self._gtk_motion_notify)
window.connect('scroll-event', self._gtk_scroll)
window.show_all()
im_context = Gtk.IMContextSimple()
im_context.connect('commit', self._gtk_input)
self._pango_context = drawing_area.create_pango_context()
self._drawing_area = drawing_area
self._window = window
self._im_context = im_context
self._bridge = bridge
Gtk.main()
def quit(self):
"""Exit the UI event loop."""
GObject.idle_add(Gtk.main_quit)
def schedule_screen_update(self, apply_updates):
"""Schedule screen updates to run in the UI event loop."""
def wrapper():
apply_updates()
self._flush()
self._start_blinking()
self._screen_invalid()
GObject.idle_add(wrapper)
def _screen_invalid(self):
self._drawing_area.queue_draw()
def _nvim_resize(self, columns, rows):
da = self._drawing_area
# create FontDescription object for the selected font/size
font_str = '{0} {1}'.format(self._font_name, self._font_size)
self._font, pixels, normal_width, bold_width = _parse_font(font_str)
# calculate the letter_spacing required to make bold have the same
# width as normal
self._bold_spacing = normal_width - bold_width
cell_pixel_width, cell_pixel_height = pixels
# calculate the total pixel width/height of the drawing area
pixel_width = cell_pixel_width * columns
pixel_height = cell_pixel_height * rows
gdkwin = da.get_window()
content = cairo.CONTENT_COLOR
self._cairo_surface = gdkwin.create_similar_surface(content,
pixel_width,
pixel_height)
self._cairo_context = cairo.Context(self._cairo_surface)
self._pango_layout = PangoCairo.create_layout(self._cairo_context)
self._pango_layout.set_alignment(Pango.Alignment.LEFT)
self._pango_layout.set_font_description(self._font)
self._pixel_width, self._pixel_height = pixel_width, pixel_height
self._cell_pixel_width = cell_pixel_width
self._cell_pixel_height = cell_pixel_height
self._screen = Screen(columns, rows)
self._window.resize(pixel_width, pixel_height)
def _nvim_clear(self):
self._clear_region(self._screen.top, self._screen.bot + 1,
self._screen.left, self._screen.right + 1)
self._screen.clear()
#.........这里部分代码省略.........
示例6: __init__
# 需要导入模块: from screen import Screen [as 别名]
# 或者: from screen.Screen import clear [as 别名]
class GameOfLife:
"""
An instance of the game of life.
"""
SAVE_FILENAME = "saved_game.gol"
RECORD_FILENAME = "recorded_game.gol"
REPLAY_FILENAME = "replay_game.gol"
def __init__(self, stdscr):
self.mode = Mode.NORMAL
self.screen = Screen(stdscr)
self.board = Board()
self.start()
@property
def mode(self):
return self._mode.get_code()
@mode.setter
def mode(self, value):
if value == Mode.INSERT:
self._mode = InsertMode()
elif value == Mode.NORMAL:
self._mode = NormalMode()
elif value == Mode.PAN:
self._mode = PanMode()
elif value == Mode.RECORD:
self._mode = RecordMode()
elif value == Mode.REPLAY:
self._mode = ReplayMode()
def start(self):
"""
Starts the Game of Life
"""
self.refresh_screen()
continue_execution = True
while continue_execution:
input_key = self.screen.get_input_key()
continue_execution = self.dispatch_user_command(input_key)
def dispatch_user_command(self, input_key):
"""
Takes a user input and decides what to do about it
"""
# Dispatch command to the current mode
self._mode.dispatch_user_command(self, input_key)
# Common commands for all Modes
if input_key == Command.QUIT:
return False
elif input_key == Command.INSERT_MODE:
self.mode = Mode.INSERT
elif input_key == Command.NORMAL_MODE:
self.mode = Mode.NORMAL
elif input_key == Command.PAN_MODE:
self.mode = Mode.PAN
elif input_key == Command.RECORD_MODE:
self.mode = Mode.RECORD
elif input_key == Command.REPLAY_MODE:
self.mode = Mode.REPLAY
elif input_key == Command.INSERT_CELL:
self.add_cell(self.screen.cursor_position)
elif input_key == Command.DELETE_CELL:
self.remove_cell(self.screen.cursor_position)
elif input_key == Command.SAVE_BOARD:
self.save()
elif input_key == Command.LOAD_BOARD:
self.load()
return True
def add_cell(self, position):
self.board.add_cell(position)
self.screen.add_cell(position)
def remove_cell(self, position):
self.board.remove_cell(position)
self.screen.remove_cell(position)
def refresh_screen(self):
self.screen.save_cursor()
self.screen.clear()
for point in self.board.cells:
self.screen.add_cell(point)
self.screen.restore_cursor()
def step(self):
self.board.step()
self.refresh_screen()
def replay_step(self):
if not hasattr(self, "replay_fhandle"):
self.replay_fhandle = open(self.REPLAY_FILENAME)
try:
serialized_board_state = self.replay_fhandle.readline()
self.board.load_serialized_board(serialized_board_state)
self.refresh_screen()
except:
return
def save(self):
#.........这里部分代码省略.........