def checkInput(self): allValid = True invalidField = None for field in self.editFields: text = field.text() validator = field.validator() # dueDate may be empty if text == "" and field == self.dueDateEdit: continue result = validator.validate(text, 0) if (result[0] == QValidator.State.Invalid or result[0] == QValidator.State.Intermediate): allValid = False invalidField = field break if not allValid: view.showNotification(self, "Text of field {} is"\ " invalid".format(invalidField.objectName())) return False if self.dueDateEdit.text() != "": try: datetime.datetime.fromisoformat(self.dueDateEdit.text()) except ValueError as err: view.showNotification(self, "DueDate: {}".format(str(err))) return False return True
def openDocRef(self, index): """ Opens an additional document specified by `index` or copies the path to clipboard. The behavior is determined by the column, in which the double clicked element resides. For elements in the first column it is tried to open them with the default application of the platform. For elements in the second column the content is copied to the clipboard. """ filePath = index.model().getFilePath(index) if index.column() == 0: if not os.path.exists(filePath): showNotification(self, "File does not exist locally. Cannot"\ " be opened") return if filePath is not None: system = platform.system() if system == "Darwin": # this my dear friend is macOS subprocess.call(["open", filePath]) elif system == "Windows": # ... well, MS Windows os.startfile(filePath) else: # good old linux derivatives subprocess.call(["xdg-open", filePath]) else: # copy path to clipboard and notify the user about it pyperclip.copy(index.model().data(index)) showNotification(self, "Copied path to clipboard.")
def createProject(self): name = self.nameEdit.text() extSchema = "" #extSchemaUriEdit() if not model.createProject(name, extSchema): view.showNotification(self, "Project could not be created.") else: self.done(0)
def showDoubleClickHint(self, index): """ Shows a notification, informing about the double click behavior. """ filePath = index.model().getFilePath(index) if index.column() == 0: if os.path.exists(filePath): showNotification(self, "Double click to open document.") elif index.column() == 1: showNotification(self, "Double click to copy path.")
def createTopic(self): if not self.checkInput(): return if not util.isAuthorSet(): view.openAuthorsDialog(None) creationAuthor = util.getAuthor() dueDate = None if self.dueDateEdit.text() != "": dueDate = datetime.datetime.fromisoformat(self.dueDateEdit.text()) labels = [] if self.lblEdit.text() != "": labels = [ label.strip() for label in self.lblEdit.text().split(',') ] idx = self.idxEdit.text() newTopic = { "title": self.titleEdit.text(), "author": creationAuthor, "type": self.typeEdit.text(), "status": self.statusEdit.text(), "referenceLinks": [], # referenceLinks "description": self.descEdit.text(), "priority": self.prioEdit.text(), "index": int(idx) if idx != "" else -1, "labels": labels, "dueDate": dueDate, "assignee": self.assigneeEdit.text(), "stage": self.stageEdit.text() } if not model.addTopic(newTopic): logger.error("Could not add topic {}".format(newTopic)) view.showNotification(self, "Addition of the topic was unsuccessful.") else: logger.info("New topic added!") self.done(0)