def save_as(self, event): tracing.user_is_interacting() if self.filename: old_filename = self.filename else: old_filename = "Sans nom" filename = self.asksavefile() if filename: if self.writefile(filename): #self.opened=TRUE self.set_filename(filename) self.set_saved(1) try: self.editwin.store_file_breaks() except AttributeError: pass tracing.send_statement( "saved-as", "file", { "https://www.lip6.fr/mocah/invalidURI/extensions/old-filename": os.path.basename(old_filename), "https://www.lip6.fr/mocah/invalidURI/extensions/new-filename": os.path.basename(filename) }) self.editwin.focus_set() self.updaterecentfileslist(filename) return "break"
def new_file(self, event=None): """ Creates a new empty editor and put it into the pyEditorList """ tracing.user_is_interacting() file_editor = PyEditorFrame(self.editor_list) self.editor_list.add(file_editor, self.main_view.editor_widget, text=file_editor.get_file_name()) tracing.send_statement("created", "file")
def enable_disable_tracing(self, event=None): """ Enable/Disable tracing""" tracing.user_is_interacting() tracing_enabled = tracing.switch_tracing_enabled_disabled() if tracing_enabled: msg = "Le suivi a été activé\n" else: msg = "Le suivi a été désactivé\n" self.console.write(msg, tags=('error')) self.icon_widget.switch_icon_tracing(tracing_enabled)
def evaluate_action(self, *args): """ Evaluate the expression in the input console """ expr = self.input_console.get() if not expr: return tracing.send_statement("started", "evaluation", { "https://www.lip6.fr/mocah/invalidURI/extensions/mode": tr(self.mode) }) tracing.user_is_interacting() local_interpreter = False if self.interpreter is None: self.interpreter = InterpreterProxy(self.app.root, self.app.mode, "<<console>>") local_interpreter = True self.app.running_interpreter_proxy = self.interpreter callback_called = False # the call back def callback(ok, report): nonlocal callback_called if callback_called: return else: callback_called = True if ok: self.input_history.record(expr) self.input_console.delete(0, END) self.write_report(ok, report, 'eval') if local_interpreter: self.interpreter.kill() self.interpreter = None self.app.running_interpreter_proxy = None self.app.icon_widget.disable_icon_running() self.app.running_interpreter_callback = None tracing.send_statement_evaluate(report, tr(self.mode), instruction=expr) # non-blocking call self.app.icon_widget.enable_icon_running() self.app.running_interpreter_callback = callback self.interpreter.run_evaluation(expr, callback)
def change_mode(self, event=None): """ Swap the python mode : full python or student """ if self.mode == "student": self.mode = "full" else: self.mode = "student" self.icon_widget.switch_icon_mode(self.mode) self.console.change_mode(tr(self.mode)) self.status_bar.change_mode(tr(self.mode)) if event: tracing.user_is_interacting() tracing.send_statement( "switched", "mode", { "https://www.lip6.fr/mocah/invalidURI/extensions/mode": tr(self.mode) })
def save(self, event): tracing.user_is_interacting() if not self.filename: self.save_as(event) else: if self.writefile(self.filename): tracing.send_statement( "saved", "file", { "https://www.lip6.fr/mocah/invalidURI/extensions/filename": os.path.basename(self.filename) }) self.set_saved(True) try: self.editwin.store_file_breaks() except AttributeError: # may be a PyShell pass self.editwin.focus_set() if not self.filename: return None else: return self.filename
def run_module(self, event=None): """ Run the code : give the file name and code will be run from the source file """ tracing.user_is_interacting() # already running if self.running_interpreter_callback: if self.running_interpreter_proxy and self.running_interpreter_proxy.process.is_alive( ): report = RunReport() report.set_header("\n====== STOP ======\n") report.add_execution_error('error', tr('User interruption'), class_name='UserTerminatedError') report.set_footer("\n==================\n") self.running_interpreter_callback(False, report) self.running_interpreter_callback = None return # not (yet) running if self.editor_list.get_size() == 0: self.main_view.console.no_file_to_run_message() return reply = self.editor_list.get_current_editor().maybesave_run() if (reply != "cancel"): self.editor_list.get_current_editor().send_update_changed_line( force_sending=True) tracing.send_statement( "started", "execution", { "https://www.lip6.fr/mocah/invalidURI/extensions/mode": tr(self.mode) }) tracing.save_execution_start() file_name = self.editor_list.get_current_editor().long_title() self.update_title() self.status_bar.update_save_label(file_name) self.console.run(file_name)
def open(self, event=None): """ Open a file in the text editor """ tracing.user_is_interacting() file_editor = PyEditorFrame(self.editor_list, open=True) if (self.editor_list.focusOn(file_editor.long_title()) == False): if (file_editor.isOpen()): self.editor_list.add(file_editor, self.main_view.editor_widget, text=file_editor.get_file_name()) extensions = { "https://www.lip6.fr/mocah/invalidURI/extensions/filename": file_editor.get_file_name() } with open(file_editor.long_title(), "r") as source: text = source.read() extensions[ "https://www.lip6.fr/mocah/invalidURI/extensions/text"] = text extensions[ "https://www.lip6.fr/mocah/invalidURI/extensions/filelength"] = len( text) tracing.send_statement("opened", "file", extensions) #not clean, io should be handled here and should not require creation of PyEditor widget else: file_editor.destroy()