def __init__(self, ui: UserInterface.UserInterface, locals=None, properties=None): super().__init__(ui.create_column_widget()) self.prompt = ">>> " self.continuation_prompt = "... " self.__cursor_position = None self.__text_edit_widget = ui.create_text_edit_widget(properties) self.__text_edit_widget.set_text_color("white") self.__text_edit_widget.set_text_background_color("black") self.__text_edit_widget.set_text_font( Panel.Panel.get_monospace_text_font()) self.__text_edit_widget.set_line_height_proportional( Panel.Panel.get_monospace_proportional_line_height()) self.__text_edit_widget.word_wrap_mode = "anywhere" self.__text_edit_widget.on_cursor_position_changed = self.__cursor_position_changed self.__text_edit_widget.on_selection_changed = self.__selection_changed self.__text_edit_widget.on_return_pressed = self.__return_pressed self.__text_edit_widget.on_key_pressed = self.__key_pressed self.__text_edit_widget.on_insert_mime_data = self.__insert_mime_data class StdoutCatcher: def __init__(self, text_edit_widget): self.__text_edit_widget = text_edit_widget def write(self, stuff): if self.__text_edit_widget: self.__text_edit_widget.append_text(str(stuff).rstrip()) def flush(self): pass stdout = StdoutCatcher(self.__text_edit_widget) locals = locals if locals is not None else dict() locals.update({ '__name__': None, '__console__': None, '__doc__': None, '_stdout': stdout }) self.__state_controller = ConsoleWidgetStateController(locals) self.__text_edit_widget.append_text(self.prompt) self.__text_edit_widget.move_cursor_position("end") self.__last_position = copy.deepcopy(self.__cursor_position) self.content_widget.add(self.__text_edit_widget)
def __init__( self, ui: UserInterface.UserInterface, locals: typing.Optional[typing.Dict[str, typing.Any]] = None, properties: typing.Optional[Persistence.PersistentDictType] = None ) -> None: content_widget = ui.create_column_widget() super().__init__(content_widget) self.prompt = ">>> " self.continuation_prompt = "... " self.__cursor_position: typing.Optional[ UserInterface.CursorPosition] = None self.__text_edit_widget = ui.create_text_edit_widget(properties) self.__text_edit_widget.set_text_color("white") self.__text_edit_widget.set_text_background_color("black") self.__text_edit_widget.set_text_font( Panel.Panel.get_monospace_text_font()) self.__text_edit_widget.set_line_height_proportional( Panel.Panel.get_monospace_proportional_line_height()) self.__text_edit_widget.word_wrap_mode = "anywhere" self.__text_edit_widget.on_cursor_position_changed = self.__cursor_position_changed self.__text_edit_widget.on_return_pressed = self.__return_pressed self.__text_edit_widget.on_key_pressed = self.__key_pressed self.__text_edit_widget.on_insert_mime_data = self.__insert_mime_data class StdoutCatcher: def __init__( self, text_edit_widget: UserInterface.TextEditWidget) -> None: self.__text_edit_widget = text_edit_widget def write(self, stuff: str) -> int: if self.__text_edit_widget: stripped_stuff = str(stuff).rstrip() self.__text_edit_widget.append_text(stripped_stuff) return len(stripped_stuff) return 0 def flush(self) -> None: pass stdout = StdoutCatcher(self.__text_edit_widget) locals = locals if locals is not None else dict() locals.update({ '__name__': None, '__console__': None, '__doc__': None, '_stdout': stdout }) self.__state_controller = ConsoleWidgetStateController(locals) self.__text_edit_widget.append_text(self.prompt) self.__text_edit_widget.move_cursor_position("end") self.__last_cursor_position: typing.Optional[ UserInterface.CursorPosition] = copy.deepcopy( self.__cursor_position) content_widget.add(self.__text_edit_widget)