def submit_input_text(self, proc_view=None): if not self.nlp: self.nlp = ModuleSelector() self.nlp.automate.response_callback = self.handle_response self.proc_view = proc_view self.process_text_edit.save_cursor_pos() query = self.process_text_edit.get_text() query_parts = query.split(".") if query == "": return try: for query_part in query_parts: task = self.nlp.prepare(query_part)[0] if task is None: modal.ModalMessageWindow( self.main_window, "Failed to understand what task you wanted to perform. Please check spelling mistakes " + "or simplify your sentence and try again!", "Error", modal.MSG_ERROR, ) return except Exception: traceback.print_exc() self.process_text_edit.restore_cursor_pos() modal.ModalMessageWindow(self.main_window, str(sys.exc_info()[1]), "Oops! Something went wrong!", modal.MSG_ERROR) return self.process_text_edit.set_cursor_pos(0) self.process_text_edit.clear()
def load_taskboard(self, filename=None): filename, absolute_path = self.get_filepath(filename) if not os.path.isfile(absolute_path): modal.ModalMessageWindow( self.main_window, f"The file {filename} cannot be found in this directory, please try something else!", "File cannot be found", modal.MSG_ERROR, ) try: self.model.load(absolute_path) except Exception: modal.ModalMessageWindow(self.design_view.main_window, str(sys.exc_info()[1]), "Ooops! Something went wrong!", modal.MSG_ERROR) return self.design_view.rebuild_from_loaded_model() self.main_window.set_active_view(0)
def record_speech(self): try: self.set_cursor_pos(0) self.clear() self.text_edit.setFocus() audio_interface = pyaudio.PyAudio() transcribed_input = transcribe(audio_interface) self.text_edit.setText(transcribed_input) transcribed_input except Exception: traceback.print_exc() modal.ModalMessageWindow( self.design_view.main_window, str(sys.exc_info()[1]), "Oops! Something went wrong!", modal.MSG_ERROR )
def create_process_block_from_task(self, query, task): model = None view = None if isinstance(task, Send): model = proc_models.SendModel() model.query = query model.recipients = ", ".join(task.to) model.when = str(task.when) model.body = str(task.body) elif isinstance(task, Reminder): model = proc_models.ReminderModel() model.query = query model.recipients = ", ".join(task.to) model.when = str(task.when) model.body = str(task.body) elif isinstance(task, Schedule): model = proc_models.ScheduleModel() model.query = query model.recipients = ", ".join(task.to) model.when = str(task.when) model.body = str(task.body) else: modal.ModalMessageWindow( self.main_window, "Failed to understand what task you wanted to perform. Please check spelling mistakes " + "or simplify your sentence and try again!", "Error", modal.MSG_ERROR, ) return # FIXME(alexander): uses same views for all tasks!!! view = SendEmailView(model) if not self.proc_view: self.proc_view = ProcessView(self.process_editor, view, model) self.proc_view.show() self.process_editor.append_process(self.proc_view, model) self.proc_view = None else: self.proc_view.title.setText(model.name) self.proc_view.layout.replaceWidget(self.proc_view.view, view) self.proc_view.view.close() self.proc_view.view = view self.model.remove_process(self.proc_view.model) self.model.append_process(model) model.id = self.proc_view.model.id self.proc_view.model = model self.update()
def callback(followup, cancel=False): # welcome to callback hell! try: if cancel: self.handle_response(query, task, None) return followup = followup.callback() self.handle_response(query, task, followup) except Exception: if self.main_window.modal: self.main_window.modal.close_window() traceback.print_exc() self.process_text_edit.restore_cursor_pos() modal.ModalMessageWindow( self.main_window, str(sys.exc_info()[1]), "Oops! Something went wrong!", modal.MSG_ERROR )
def rename_contact(self, old_name, new_name): if old_name in SETTINGS["contacts"]: if new_name in SETTINGS["contacts"]: modal.ModalMessageWindow( self.main_window, f"Contact with name {new_name} is already stored in the this contact list.", "Failed to rename contact!", modal.MSG_ERROR, ) return False contact = SETTINGS["contacts"][old_name] del SETTINGS["contacts"][old_name] SETTINGS["contacts"][new_name] = contact if old_name in self.entries: entry = self.entries[old_name] del self.entries[old_name] self.entries[new_name] = entry return True else: print(f"contact `{old_name}` is not in contact list, this is likely a bug!") return False