def terminal_spawn(self, directory=None): terminal = GuakeTerminal(self.guake) terminal.grab_focus() terminal.connect( "key-press-event", lambda x, y: self.guake.accel_group.activate(x, y) if self.guake.accel_group else False, ) if not isinstance(directory, str): directory = os.environ["HOME"] try: if self.guake.settings.general.get_boolean("open-tab-cwd"): # Do last focused terminal still alive? active_terminal = self.get_current_terminal() if not active_terminal: # If not alive, can we get any focused terminal? active_terminal = self.get_focused_terminal() directory = os.path.expanduser("~") if active_terminal: # If found, we will use its directory as new terminal's directory directory = active_terminal.get_current_directory() except BaseException: pass log.info("Spawning new terminal at %s", directory) terminal.spawn_sync_pid(directory) return terminal