本文整理汇总了Python中asciimatics.screen.Screen.wrapper方法的典型用法代码示例。如果您正苦于以下问题:Python Screen.wrapper方法的具体用法?Python Screen.wrapper怎么用?Python Screen.wrapper使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类asciimatics.screen.Screen
的用法示例。
在下文中一共展示了Screen.wrapper方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_key_input
# 需要导入模块: from asciimatics.screen import Screen [as 别名]
# 或者: from asciimatics.screen.Screen import wrapper [as 别名]
def test_key_input(self):
"""
Check that keyboard input works.
"""
def internal_checks(screen):
# Inject a letter and check it is picked up
self._inject_key(screen, ord("a"))
ch = screen.get_event()
self.assertEqual(ch.key_code, ord("a"))
self.assertIsNone(screen.get_event())
# Inject a letter and check it is picked up
self._inject_key(screen, Screen.KEY_BACK_TAB)
ch = screen.get_event()
self.assertEqual(ch.key_code, Screen.KEY_BACK_TAB)
self.assertIsNone(screen.get_event())
# Check that get_key also works.
self._inject_key(screen, ord("b"))
ch = screen.get_key()
self.assertEqual(ch, ord("b"))
self.assertIsNone(screen.get_key())
# Check that unicode input also works
self._inject_key(screen, ord(u"├"))
ch = screen.get_event()
self.assertEqual(ch.key_code, ord(u"├"))
self.assertIsNone(screen.get_event())
Screen.wrapper(internal_checks, height=15, unicode_aware=True)
示例2: test_palette
# 需要导入模块: from asciimatics.screen import Screen [as 别名]
# 或者: from asciimatics.screen.Screen import wrapper [as 别名]
def test_palette(self):
"""
Check that we have a valid colour palette.
"""
def internal_checks(screen):
# Check basic length
self.assertGreater(screen.colours, 0)
self.assertEqual(len(screen.palette), 256 * 3)
# Should always have fundamental console colours
for i, c in enumerate((0, 0, 0)):
self.assertEqual(screen.palette[i], c)
for i, c in enumerate((128, 0, 0)):
self.assertEqual(screen.palette[i+3], c)
for i, c in enumerate((0, 128, 0)):
self.assertEqual(screen.palette[i+6], c)
for i, c in enumerate((128, 128, 0)):
self.assertEqual(screen.palette[i+9], c)
for i, c in enumerate((0, 0, 128)):
self.assertEqual(screen.palette[i+12], c)
for i, c in enumerate((128, 0, 128)):
self.assertEqual(screen.palette[i+15], c)
for i, c in enumerate((0, 128, 128)):
self.assertEqual(screen.palette[i+18], c)
for i, c in enumerate((192, 192, 192)):
self.assertEqual(screen.palette[i+21], c)
Screen.wrapper(internal_checks, height=15)
示例3: test_play
# 需要导入模块: from asciimatics.screen import Screen [as 别名]
# 或者: from asciimatics.screen.Screen import wrapper [as 别名]
def test_play(self):
"""
Check that we can play a basic Effect in a Scene.
"""
def internal_checks(screen):
# Since the Screen draws things, there's not too much we can do
# to genuinely verify this without verifying all Scene and Effect
# function too. Just play a dummy Effect for now.
test_effect = MockEffect()
screen.play([Scene([test_effect], 0)])
self.assertTrue(test_effect.stop_called)
self.assertTrue(test_effect.reset_called)
# Now check that the desired duration is used.
test_effect = MockEffect(count=6)
screen.play([Scene([test_effect], 15)])
self.assertFalse(test_effect.stop_called)
self.assertTrue(test_effect.reset_called)
# Now check that delete_count works.
test_effect = MockEffect(count=6)
test_effect2 = MockEffect(delete_count=3)
scene = Scene([test_effect, test_effect2], 15)
self.assertEqual(len(scene.effects), 2)
screen.play([scene])
self.assertEqual(len(scene.effects), 1)
self.assertEqual(scene.effects[0], test_effect)
Screen.wrapper(internal_checks, height=15)
示例4: test_last_pos
# 需要导入模块: from asciimatics.screen import Screen [as 别名]
# 或者: from asciimatics.screen.Screen import wrapper [as 别名]
def test_last_pos(self):
"""
Check that screen drawing is efficient and unaffected by draw.
"""
def internal_checks(screen):
# Should start with no known location.
screen.reset()
self.assertEqual(screen._cur_x, None)
self.assertEqual(screen._cur_y, None)
# Drawing should not affect latest update. This was previously
# bugged - hence this test case!
screen.move(0, 0)
screen.draw(10, 10)
self.assertEqual(screen._cur_x, None)
self.assertEqual(screen._cur_y, None)
# Printing should not affect latest update.
screen.print_at("Hi", 12, 12)
self.assertEqual(screen._cur_x, None)
self.assertEqual(screen._cur_y, None)
# Refresh should update the last drawn character.
screen.refresh()
self.assertEqual(screen._cur_x, 14)
self.assertEqual(screen._cur_y, 12)
Screen.wrapper(
internal_checks,
height=15,
unicode_aware=False)
示例5: test_polygons
# 需要导入模块: from asciimatics.screen import Screen [as 别名]
# 或者: from asciimatics.screen.Screen import wrapper [as 别名]
def test_polygons(self):
"""
Check that filled polygons work as expected.
"""
def internal_checks(screen):
screen.fill_polygon([[(0, 0), (10, 0), (0, 10), (10, 10)]])
screen.fill_polygon([[(20, 0), (30, 0), (30, 10), (25, 5), (20, 10)]])
screen.fill_polygon([[(40, 0), (45, 5), (50, 0), (50, 10), (40, 10)]])
screen.fill_polygon([[(60, 0), (70, 0), (70, 10), (60, 10)],
[(63, 2), (67, 2), (67, 8), (63, 8)]])
self.maxDiff = None
self.assert_canvas_equals(
screen,
"Y########7 ########## . . ########## \n" +
" Y######7 ########## #. .# ########## \n" +
" Y####7 ########## ##. .## ### ### \n" +
" Y##7 ########## ###. .### ### ### \n" +
" Y7 ########## ####..#### ### ### \n" +
" .. ####7Y#### ########## ### ### \n" +
" .##. ###7 Y### ########## ### ### \n" +
" .####. ##7 Y## ########## ### ### \n" +
" .######. #7 Y# ########## ########## \n" +
".########. 7 Y ########## ########## \n")
Screen.wrapper(
check_screen_and_canvas,
height=10,
unicode_aware=False,
arguments=[internal_checks])
示例6: test_limits
# 需要导入模块: from asciimatics.screen import Screen [as 别名]
# 或者: from asciimatics.screen.Screen import wrapper [as 别名]
def test_limits(self):
"""
Check that get_from and print_at limit checking works.
"""
def internal_checks(screen):
# Check we have some canvas dimensions
self.assertEqual(screen.dimensions[1], screen.width)
self.assertEqual(screen.dimensions[0], screen.height)
# Basic limit checking
self.assertIsNone(screen.get_from(-1, -1))
self.assertIsNone(screen.get_from(screen.width, screen.height))
# Printing off-screen should not fail, but do nothing.
screen.print_at("hello", 0, -1)
screen.print_at("hello", 0, screen.height)
# Printing across screen edge should crop.
screen.print_at("12345", -1, 0)
char, fg, _, bg = screen.get_from(0, 0)
self.assertEqual(char, ord("2"))
self.assertEqual(fg, Screen.COLOUR_WHITE)
self.assertEqual(bg, Screen.COLOUR_BLACK)
Screen.wrapper(
check_screen_and_canvas, height=15, arguments=[internal_checks])
示例7: test_text_effects
# 需要导入模块: from asciimatics.screen import Screen [as 别名]
# 或者: from asciimatics.screen.Screen import wrapper [as 别名]
def test_text_effects(self):
"""
Check effects can be played.
"""
# Skip for non-Windows if the terminal definition is incomplete.
# This typically means we're running inside a non-standard termina;.
# For example, thi happens when embedded in PyCharm.
if sys.platform != "win32":
curses.initscr()
if curses.tigetstr("ri") is None:
self.skipTest("No valid terminal definition")
# A lot of effects are just about the visual output working when played
# so check that playing a load of text effects doesn't crash.
#
# It's really not a great test, but it's important to show Effects are
# dynamically compatible with Screen.play().
def internal_checks(screen):
screen.play([
Scene([
MockEffect(count=5),
Print(screen, FigletText("hello"), 2),
Cycle(screen, FigletText("world"), 6),
BannerText(screen, FigletText("world"), 10, 3),
Mirage(screen, FigletText("huh?"), 14, 2)], 0)])
Screen.wrapper(internal_checks, height=25)
示例8: test_origin
# 需要导入模块: from asciimatics.screen import Screen [as 别名]
# 或者: from asciimatics.screen.Screen import wrapper [as 别名]
def test_origin(self):
"""
Check that Canvas origin is correct.
"""
def internal_checks(screen):
canvas = Canvas(screen, 5, 5, 1, 2)
self.assertEqual(canvas.origin, (1, 2))
Screen.wrapper(internal_checks, height=15)
示例9: test_title
# 需要导入模块: from asciimatics.screen import Screen [as 别名]
# 或者: from asciimatics.screen.Screen import wrapper [as 别名]
def test_title(self):
"""
Check that we can change the screen title.
"""
def internal_checks(screen):
# It's not possible to read values back, so just check code doesn't
# crash.
screen.set_title("Asciimatics test")
Screen.wrapper(internal_checks, height=15)
示例10: test_centre
# 需要导入模块: from asciimatics.screen import Screen [as 别名]
# 或者: from asciimatics.screen.Screen import wrapper [as 别名]
def test_centre(self):
"""
Check that centre works as expected.
"""
def internal_checks(screen):
screen.centre("1234", 0)
char, fg, _, bg = screen.get_from((screen.width - 4) // 2, 0)
self.assertEqual(char, ord("1"))
self.assertEqual(fg, Screen.COLOUR_WHITE)
self.assertEqual(bg, Screen.COLOUR_BLACK)
Screen.wrapper(internal_checks, height=15)
示例11: test_draw
# 需要导入模块: from asciimatics.screen import Screen [as 别名]
# 或者: from asciimatics.screen.Screen import wrapper [as 别名]
def test_draw(self):
"""
Check that line drawing works as expected.
"""
def internal_checks(screen):
# Draw thick and thin lines
for line_type in (True, False):
# Draw in opposite directions
for start in range(0, 11, 10):
screen.print_at(str(start), 11, 2)
# Horizontal line
screen.move(start, 0)
screen.draw(10 - start, 0, thin=line_type)
res = screen.get_from(1, 0)
self.assertEqual(res[0], ord("^" if line_type else "#"))
# Check clearing works too
screen.draw(start, 0, char=" ", thin=line_type)
res = screen.get_from(1, 0)
self.assertEqual(res[0], ord(" "))
# Vertical line
screen.move(0, start)
screen.draw(0, 10 - start, thin=line_type)
res = screen.get_from(0, 1)
self.assertEqual(res[0], ord("|" if line_type else "#"))
# Check clearing works too
screen.draw(0, start, char=" ", thin=line_type)
res = screen.get_from(0, 1)
self.assertEqual(res[0], ord(" "))
# Diagonal line
screen.move(0, start)
screen.draw(10, 10 - start, thin=line_type)
res = screen.get_from(1, 9 if start else 1)
if line_type:
self.assertEqual(res[0], ord("'" if start else "\\"))
else:
self.assertEqual(res[0], ord("7" if start else "Y"))
# Check clearing works too
screen.move(0, start)
screen.draw(10, 10 - start, char=" ", thin=line_type)
res = screen.get_from(1, 9 if start else 1)
self.assertEqual(res[0], ord(" "))
Screen.wrapper(
check_screen_and_canvas,
height=15,
unicode_aware=False,
arguments=[internal_checks])
示例12: test_next_scene
# 需要导入模块: from asciimatics.screen import Screen [as 别名]
# 或者: from asciimatics.screen.Screen import wrapper [as 别名]
def test_next_scene(self):
"""
Check that we can play multiple Scenes.
"""
def internal_checks(screen):
# First check that we can move between screens.
test_effect1 = MockEffect(stop=False)
test_effect2 = MockEffect(count=5)
screen.play([
Scene([test_effect1], 5),
Scene([test_effect2], 0)])
self.assertTrue(test_effect1.update_called)
self.assertTrue(test_effect2.update_called)
# Now check that we can start at the second scene.
test_effect1 = MockEffect(stop=False)
scene1 = Scene([test_effect1], 5, name="1")
test_effect2 = MockEffect(count=3)
scene2 = Scene([test_effect2], 0, name="2")
screen.play([scene1, scene2], start_scene=scene2)
self.assertFalse(test_effect1.update_called)
self.assertTrue(test_effect2.update_called)
# Now check that we can move to named scenes.
test_effect1 = MockEffect(stop=False, next_scene="B")
test_effect2 = MockEffect(count=5)
screen.play([
Scene([test_effect1], 15, name="A"),
Scene([test_effect2], 0, name="B")])
self.assertTrue(test_effect1.update_called)
self.assertTrue(test_effect2.update_called)
# Now check that bad names cause an exception.
with self.assertRaises(RuntimeError):
test_effect1 = MockEffect(stop=False, next_scene="C")
test_effect2 = MockEffect(count=5)
screen.play([
Scene([test_effect1], 15, name="A"),
Scene([test_effect2], 0, name="B")])
self.assertTrue(test_effect1.update_called)
self.assertFalse(test_effect2.update_called)
# Now check that play stops at the end when repeat=False
test_effect1 = MockEffect(stop=False)
scene1 = Scene([test_effect1], 5, name="1")
screen.play([scene1], repeat=False)
self.assertTrue(test_effect1.update_called)
Screen.wrapper(internal_checks, height=15)
示例13: test_refresh
# 需要导入模块: from asciimatics.screen import Screen [as 别名]
# 或者: from asciimatics.screen.Screen import wrapper [as 别名]
def test_refresh(self):
"""
Check that refresh works.
"""
def internal_checks(screen):
# Not much we can do here as refresh will draw to a screen we can't
# query. Check that we don't hit an Exception on refresh().
screen.print_at("Hello world!",
0, 0,
colour=Screen.COLOUR_CYAN,
attr=Screen.A_BOLD,
bg=Screen.COLOUR_BLUE)
screen.refresh()
Screen.wrapper(
check_screen_and_canvas, height=15, arguments=[internal_checks])
示例14: display
# 需要导入模块: from asciimatics.screen import Screen [as 别名]
# 或者: from asciimatics.screen.Screen import wrapper [as 别名]
def display(self):
while True:
try:
# save the console so if the program encounters
# a problem/exception we may be able to restore the console
self._save_window()
Screen.wrapper(self._start_app,
catch_interrupt=False,
arguments=[self.last_scene])
break
except ResizeScreenError as e:
self.last_scene = e.scene
except Exception as e:
print('Unhandled exception: ' + str(e))
self._restore_window()
raise e
示例15: test_unhandled_events
# 需要导入模块: from asciimatics.screen import Screen [as 别名]
# 或者: from asciimatics.screen.Screen import wrapper [as 别名]
def test_unhandled_events(self):
"""
Check that default handling of events works as documented.
"""
def internal_checks(screen):
# Check for exit
for char in ("X", "x", "Q", "q"):
with self.assertRaises(StopApplication):
event = KeyboardEvent(ord(char))
screen._unhandled_event_default(event)
for char in (" ", "\n"):
with self.assertRaises(NextScene):
event = KeyboardEvent(ord(char))
screen._unhandled_event_default(event)
Screen.wrapper(internal_checks, height=15)