def start(self, *args, **kwargs): """Set up the screen. If the screen has already been started, does nothing. May be used as a context manager, in which case :meth:`stop` will automatically be called at the end of the block: with screen.start(): ... You shouldn't override this method in a subclass; instead, override :meth:`_start`. """ if not self._started: self._start(*args, **kwargs) self._started = True return StoppingContext(self)
def start(self): """ Sets up the main loop, hooking into the event loop where necessary. Starts the :attr:`screen` if it hasn't already been started. If you want to control starting and stopping the event loop yourself, you should call this method before starting, and call `stop` once the loop has finished. You may also use this method as a context manager, which will stop the loop automatically at the end of the block: with main_loop.start(): ... Note that some event loop implementations don't handle exceptions specially if you manage the event loop yourself. In particular, the Twisted and asyncio loops won't stop automatically when :exc:`ExitMainLoop` (or anything else) is raised. """ self.screen.start() if self.handle_mouse: self.screen.set_mouse_tracking() if not hasattr(self.screen, 'hook_event_loop'): raise CantUseExternalLoop( "Screen {0!r} doesn't support external event loops") try: signals.connect_signal(self.screen, INPUT_DESCRIPTORS_CHANGED, self._reset_input_descriptors) except NameError: pass # watch our input descriptors self._reset_input_descriptors() self.idle_handle = self.event_loop.enter_idle(self.entering_idle) return StoppingContext(self)