def unhandled(self, key):
"""Input not handled by any other widgets.
@key - string representing key that was pressed.
Most key presses inside sshchan should be handled by this function.
Buttons don't need handling here, they respond to Enter, Space or
mouse clicks.
"""
# Refresh screen dimensions in case terminal is resized.
self.loop.dimensions = self.loop.screen.get_cols_rows()
# Calculate width and margins of Padding based on terminal size.
self.width = self.loop.dimensions[0] // 2
self.margin = int((self.loop.dimensions[0] - self.width) * 0.60)
if key in ("Q", "q"):
self.quit_prompt()
elif key == "tab":
# Switch focus from body to top bar and vice versa.
if self.loop.baseWidget.focus_position == "header":
self.loop.baseWidget.focus_position = "body"
else:
self.loop.baseWidget.focus_position = "header"
elif key in ("H", "h"):
# Disable MOTD flag.
self.motd_flag = False
if not self.help_flag:
self.loop.Widget = self.show_help()
elif key in ("B", "b"):
if not self.list_visible and self.motd_flag:
# If board list isn't currently being displayed, let's show it.
self.list_visible = True
self.loop.frameBody.extend(self.list_boards())
elif self.list_visible and self.motd_flag:
# Board list was being displayed, get rid of it.
for i in range(self.boards_count):
self.loop.frameBody.pop()
self.list_visible = False
elif key == "esc":
# If not on the main screen, ESC goes back, otherwise try to quit.
if not self.motd_flag:
self.button_press(None, "back")
else:
self.quit_prompt()
# Urwid expects the handler function to return True after it's done.
return True
评论列表
文章目录