Exemplo n.º 1
0
    def ensureUniqueFilename(self, name, appendFormat="(%s)"):
        assert('%s' in appendFormat)

        info = QFileInfo(name)
        if not info.exists():
            return name

        # QDir
        dir_ = info.absoluteDir()
        # QString
        fileName = info.fileName()

        idx = 1
        while info.exists():
            file_ = fileName
            index = file_.rfind('.')
            appendString = appendFormat % idx
            if index == -1:
                file_ += appendString
            else:
                file_ = file_[:index] + appendString + file_[index:]
            info.setFile(dir_, file_)
            idx += 1

        return info.absoluteFilePath()
Exemplo n.º 2
0
 def save_file(self):
     if self.validate():
         self.clear_file_error()
         filepath = str(self.file_path_tview.text())
         fileinfo = QFileInfo(filepath)
         filename = str(int(time.time())) + "_" + fileinfo.fileName()
         keyboard_name = "Unknown"
         with open(filepath, encoding="utf-8") as search:
             for line in search:
                 line = line.rstrip()  # remove '\n' at end of line
                 if "NAME" in line:
                     name_line = line
                     name_list = name_line.split('=', 1)
                     if len(name_list) > 0:
                         keyboard_name = name_list[1]
         if keyboard_name == "Unknown":
             self.show_file_error("SCIM table name header not found")
         elif DatabaseManager.check_keyboard_exist(keyboard_name):
             self.show_file_error("Keyboard already exists")
         else:
             shutil.copyfile(filepath, self.table_path + "\\" + filename)
             DatabaseManager.add_keyboard(keyboard_name, self.table_path + "\\" + filename)
             self.file_path_tview.setText("")
             self.update_table()
Exemplo n.º 3
0
 def save_file(self):
     if self.validate():
         self.clear_file_error()
         filepath = str(self.file_path_tview.text())
         fileinfo = QFileInfo(filepath)
         filename = str(int(time.time())) + "_" + fileinfo.fileName()
         keyboard_name = "Unknown"
         with open(filepath, encoding="utf-8") as search:
             for line in search:
                 line = line.rstrip()  # remove '\n' at end of line
                 if "NAME" in line:
                     name_line = line
                     name_list = name_line.split('=', 1)
                     if len(name_list) > 0:
                         keyboard_name = name_list[1]
         if keyboard_name == "Unknown":
             self.show_file_error("SCIM table name header not found")
         elif DatabaseManager.check_keyboard_exist(keyboard_name):
             self.show_file_error("Keyboard already exists")
         else:
             shutil.copyfile(filepath, self.table_path + "\\" + filename)
             DatabaseManager.add_keyboard(keyboard_name, filename)
             self.file_path_tview.setText("")
             self.update_table()