本文整理汇总了Python中state.State.open方法的典型用法代码示例。如果您正苦于以下问题:Python State.open方法的具体用法?Python State.open怎么用?Python State.open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类state.State
的用法示例。
在下文中一共展示了State.open方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MainWindow
# 需要导入模块: from state import State [as 别名]
# 或者: from state.State import open [as 别名]
#.........这里部分代码省略.........
raise urwid.ExitMainLoop
self.keypress(self.size, key)
self.size = self.ui.get_cols_rows()
self.main_loop = urwid.MainLoop(
self.context,
screen=self.ui,
handle_mouse=False,
unhandled_input=input_handler
)
# Disable bold on bright fonts
self.main_loop.screen.set_terminal_properties(bright_is_bold=False)
try:
self.main_loop.run()
except KeyboardInterrupt:
self.quit()
def print_content(self, text):
"""Print given text as content."""
# Accept strings, convert them to urwid.Text instances
if not isinstance(text, (urwid.Text, urwid.Pile)):
text = urwid.Text(text)
self.content.append(text)
def parse_input(self):
"""Parse input data."""
text = self.footer.get_edit_text()
# Remove input after submitting
self.footer.set_edit_text("")
# input: description
# -------------------------------------------------------------
# exit, quit, q: exit the application
# help: show help page
# license: show license page
# listboards: list all available boards
# open: open specific thread by index (shown on the screen)
# thread: open specific thread
# board: trigger either "board <code>" or "board <code> <page>"
# archive: trigger "archive <code>"
# empty: show initial status message
# else: invalid command
if text in ("exit", "quit", "q"):
self.quit()
elif text == "help":
_content = self.state.help()
elif text == "license":
_content = self.state.license()
elif text == "listboards":
_content = self.state.listboards()
elif text.startswith("open"):
_content = self.state.open(text)
elif text.startswith("thread"):
_content = self.state.thread(text)
elif text.startswith("board"):
_content = self.state.board(text)
elif text.startswith("archive"): # archive <board>
_content = self.state.archive(text)
elif text.strip() == "":
_content = self.state.empty()
else:
_content = self.state.invalid(text)
if _content['content']: # Only update if content given
del self.content[:] # Remove previous content
self.print_content(_content['content'])
self.divider.set_text(_content['status'])
def keypress(self, size, key):
"""Handle user input."""
urwid.emit_signal(self, "keypress", size, key)
# Focus management
if key == "up" or key == "down":
self.context.set_focus("body")
else:
self.context.set_focus("footer")
# New dimension on resize
if key == "window resize":
self.size = self.ui.get_cols_rows()
elif key == "enter":
# Parse input data
self.parse_input()
elif key in ("ctrl d", "ctrl c"):
# Quit by key combination
self.quit()
def quit(self):
"""Quit the application."""
urwid.emit_signal(self, "quit")
self.mark_quit = True
sys.exit(0)