예제 #1
0
    def file_save_as(self):
        name = QtWidgets.QFileDialog.getSaveFileName(self, '', '', '')
        path_split = str(name).split('/')
        length = len(path_split)
        file_name = path_split[length - 1]
        if not notepad_function.allow_save(file_name):
            choice = QtWidgets.QMessageBox.question(
                self, "Oops!!", "Could not support the file format",
                QtWidgets.QMessageBox.Cancel)

            if choice == QtWidgets.QMessageBox.Cancel:
                pass
        else:
            try:
                file = open(str(name[0]), 'w')
                text = self.textEdit.toPlainText()
                file.write(text)
                file.close()
                self.currentPath = name[0]
                file_name = str(name[0]).split('/')
                length = len(file_name)
                self.titleName = file_name[length - 1]
                self.setWindowTitle(self.titleName)
            except FileNotFoundError:
                pass
예제 #2
0
    def file_save(self):
        if (os.path.exists(self.currentPath)):
            self.apply_settings()
            file = open(str(self.currentPath), 'w')
            text = self.textEdit.toPlainText()
            file.write(text)
            file.close()
        else:
            name = QtWidgets.QFileDialog.getSaveFileName(self, 'Save File')
            path_split = str(name).split('/')
            length = len(path_split)
            file_name = path_split[length - 1]
            if notepad_function.allow_save(file_name) == False:
                choice = QtWidgets.QMessageBox.question(
                    self, "Oops!!", "Could not support the file format",
                    QtWidgets.QMessageBox.Cancel)

                if choice == QtWidgets.QMessageBox.Cancel:
                    pass
            else:
                try:
                    file = open(str(name[0]), 'w')
                    text = self.textEdit.toPlainText()
                    file.write(text)
                    file.close()
                    self.currentPath = name[0]

                    settings = QtCore.QSettings("MyCompany", "MyApp")
                    if self.currentPath != "" and self.currentPath != None:
                        if self.currentPath not in self.file_opened:
                            self.file_opened.append(self.currentPath)
                            settings.setValue('file_opened', self.file_opened)
                        index = self.file_opened.index(self.currentPath)
                        try:
                            self.colors_opened[index] = self.textEdit.font()
                            settings.setValue('colors_opened',
                                              self.colors_opened)
                        except IndexError:
                            self.colors_opened.append(self.textEdit.font())
                            settings.setValue('colo_property',
                                              self.colors_opened)
                    print("in save")
                    print(self.file_opened)
                    print(self.colors_opened)
                    file_name = str(name[0]).split('/')
                    length = len(file_name)
                    self.titleName = file_name[length - 1]
                    self.setWindowTitle(self.titleName)
                    if self.currentPath not in self.dict:
                        self.dict[self.currentPath] = self.titleName
                        self.listWidget.addItem(self.titleName)
                except FileNotFoundError:
                    pass