def run_command_string(self, command, end_is_visible = True): "Used for both interactive commands and script files" # Clear undo/redo buffer, we don't want prompts and output in there. self.te.setUndoRedoEnabled(False) if len(self.multiline_command) > 0: # multi-line command can only be ended with a blank line. if len(command) == 0: command = self.multiline_command + "\n" # execute it now else: self.multiline_command = self.multiline_command + "\n" + command command = "" # skip execution until next time # Add carriage return, so output will appear on subsequent line. # (It would be too late if we waited for plainTextEdit # to process the <Return>) self.te.moveCursor(QTextCursor.End) self.append("") # We consumed the key event, so we have to add the newline. if len(command) > 0: self.prompt = self.regular_prompt try: co = code.compile_command(command, filename='<console>') if co is None: # incomplete command self.multiline_command = command self.prompt = self.more_prompt else: exec co in console_context._context() self.multiline_command = "" except: # Exception e: print_exc() self.multiline_command = "" self.place_new_prompt(end_is_visible)
def run_script_file(self, file_name): # print "run_script_file", file_name end_is_visible = self.te.document().lastBlock().isVisible() self.te.moveCursor(QTextCursor.End) self.multiline_command = "" self.prompt = self.regular_prompt self.append_blue("\n[Running script file " + file_name + "]\n") try: execfile(file_name, console_context._context()) except: print_exc() self.recent_files.add_file(file_name) self.place_new_prompt(end_is_visible)