Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
effect.update(3)
self.assert_canvas_equals(
canvas,
"++------------------------------------++\n" +
"||Item 2 ||\n" +
"||------------------------------------|O\n" +
"||Item 1 ||\n" +
"||Item 2 ||\n" +
"||Item 3 ||\n" +
"|+------------------------------------+|\n" +
"| |\n" +
"| |\n" +
"+--------------------------------------+\n")
# Check Enter works as expected
self.process_keys(scene, [Screen.ctrl("m")])
for effect in scene.effects:
effect.update(4)
self.assert_canvas_equals(
canvas,
"+--------------------------------------+\n" +
"|[Item 2 ]|\n" +
"| O\n" +
"| |\n" +
"| |\n" +
"| |\n" +
"| |\n" +
"| |\n" +
"| |\n" +
"+--------------------------------------+\n")
def test_ctrl(self):
"""
Check that ctrl returns the right values.
"""
# Check standard alphabetical range
for i, char in enumerate(range(ord('@'), ord('Z'))):
self.assertEqual(Screen.ctrl(char), i)
self.assertEqual(Screen.ctrl(chr(char)), i)
self.assertEqual(Screen.ctrl(chr(char).lower()), i)
# Check last few options - which mostly aren't actually returned in
# Linux and so probably only of limited value, but what the heck!
for i, char in enumerate(["[", "\\", "]", "^", "_"]):
self.assertEqual(Screen.ctrl(char), i + 27)
# Check other things return None - pick boundaries for checks.
for char in ["?", "`", "\x7f"]:
self.assertIsNone(Screen.ctrl(char))
Check that ctrl returns the right values.
"""
# Check standard alphabetical range
for i, char in enumerate(range(ord('@'), ord('Z'))):
self.assertEqual(Screen.ctrl(char), i)
self.assertEqual(Screen.ctrl(chr(char)), i)
self.assertEqual(Screen.ctrl(chr(char).lower()), i)
# Check last few options - which mostly aren't actually returned in
# Linux and so probably only of limited value, but what the heck!
for i, char in enumerate(["[", "\\", "]", "^", "_"]):
self.assertEqual(Screen.ctrl(char), i + 27)
# Check other things return None - pick boundaries for checks.
for char in ["?", "`", "\x7f"]:
self.assertIsNone(Screen.ctrl(char))
self.assert_canvas_equals(
canvas,
"+-----|30 Jan 2016|--------------------+\n" +
"|Date:|31/Feb/2017| |\n" +
"|Time:| Mar 2018| O\n" +
"| +-----------+ |\n" +
"| |\n" +
"| |\n" +
"| |\n" +
"| |\n" +
"| |\n" +
"+--------------------------------------+\n")
# Check that a valid date updates the value - wait one second to allow search to reset.
sleep(1)
self.process_keys(scene, ["15", "Jun", Screen.ctrl("m")], separator=Screen.KEY_TAB)
self.assertTrue(form.changed)
for effect in scene.effects:
effect.update(2)
self.assert_canvas_equals(
canvas,
"+--------------------------------------+\n" +
"|Date: 15/Jun/2017 |\n" +
"|Time: 12:00:59 O\n" +
"| |\n" +
"| |\n" +
"| |\n" +
"| |\n" +
"| |\n" +
"| |\n" +
"+--------------------------------------+\n")
self.assertEquals(form.date_widget.value, date(2017, 6, 15))
form.update(1)
self.assert_canvas_equals(
canvas,
"/A Directory Size Last modified\n" +
"|-+ .. \n" +
"|-+ A Directory 9K 1970-01-01\n" +
"|-- A File 9K 1970-01-01\n" +
"|-- A Lnk -> A Tgt 9K 1970-01-01\n" +
"|-- oööÖ.txt 9K 1970-01-01\n" +
" \n" +
" \n" +
" \n" +
" \n")
# Check that enter key handles correctly on files.
self.process_keys(form, [Screen.KEY_DOWN, Screen.KEY_DOWN, Screen.ctrl("m")])
self.assertEqual(form.highlighted, "/A Directory/A File")
self.assertEqual(form.selected, "/A Directory/A File")
form.update(0)
self.assert_canvas_equals(
canvas,
"/ Size Last modified\n" +
"|-+ A Directory 9K 1970-01-01\n" +
"|-- hello.bmp 9K 1970-01-01\n" +
" \n" +
" \n" +
" \n" +
" \n" +
" \n" +
" \n" +
" \n")
# Check that enter key handles correctly on files.
self.process_keys(form, [Screen.KEY_DOWN, Screen.KEY_DOWN, Screen.ctrl("m")])
self.assertEqual(form.highlighted, "/hello.bmp")
self.assertEqual(form.selected, "/hello.bmp")
def process_event(self, event):
if isinstance(event, asciimatics.event.KeyboardEvent):
# key handling for this: Ctrl-C, q/Q to quit, r refresh
if event.key_code in [
ord('q'),
ord('Q'),
asciimatics.screen.Screen.KEY_ESCAPE,
asciimatics.screen.Screen.ctrl("c")
]:
raise asciimatics.exceptions.StopApplication("User quit")
elif event.key_code in [ ord("r"), ord("R") ]:
pass
self.last_frame = 0 # force a refresh
return asciimatics.widgets.Frame.process_event(self, event)
def process_event(self, event):
"""User input for the main map view."""
if isinstance(event, KeyboardEvent):
if event.key_code in [Screen.ctrl("m"), Screen.ctrl("j")]:
self._scene.add_effect(
EnterLocation(
self._screen, self._longitude, self._latitude, self._on_new_location))
elif event.key_code in [ord('q'), ord('Q'), Screen.ctrl("c")]:
raise StopApplication("User quit")
elif event.key_code in [ord('t'), ord('T')]:
self._satellite = not self._satellite
if self._satellite:
self._size = _START_SIZE
elif event.key_code == ord("?"):
self._scene.add_effect(PopUpDialog(self._screen, _HELP, ["OK"]))
elif event.key_code == ord("+") and self._zoom <= 20:
if self._desired_zoom < 20:
self._desired_zoom += 1
elif event.key_code == ord("-") and self._zoom >= 0:
if self._desired_zoom > 0:
def process_event(self, event):
"""Summary
Args:
event (TYPE): Description
Returns:
TYPE: Description
Raises:
StopApplication: Description
"""
# Do the key handling for this Frame.
if isinstance(event, KeyboardEvent):
if event.key_code in [ord('q'), ord('Q'), Screen.ctrl("c")]:
raise StopApplication("User quit")
# Force a refresh for improved responsiveness
self._last_frame = 0
# Now pass on to lower levels for normal handling of the event.
return super(StatusFrame, self).process_event(event)
self._line = max(0, self._line - 1)
self.value = self._options[self._line][1]
elif len(self._options) > 0 and event.key_code == Screen.KEY_DOWN:
# Move down one line in text - use value to trigger on_select.
self._line = min(len(self._options) - 1, self._line + 1)
self.value = self._options[self._line][1]
elif len(self._options) > 0 and event.key_code == Screen.KEY_PAGE_UP:
# Move up one page.
self._line = max(0, self._line - self._h + (1 if self._titles else 0))
self.value = self._options[self._line][1]
elif len(self._options) > 0 and event.key_code == Screen.KEY_PAGE_DOWN:
# Move down one page.
self._line = min(
len(self._options) - 1, self._line + self._h - (1 if self._titles else 0))
self.value = self._options[self._line][1]
elif event.key_code in [Screen.ctrl("m"), Screen.ctrl("j")]:
# Fire select callback.
if self._on_select:
self._on_select()
elif event.key_code > 0:
# Treat any other normal press as a search
now = datetime.now()
if now - self._last_search >= timedelta(seconds=1):
self._search = ""
self._search += chr(event.key_code)
self._last_search = now
# If we find a new match for the search string, update the list selection
new_value = self._find_option(self._search)
if new_value is not None:
self.value = new_value
else: