def check_extensions_changes(self): new_extensions = self.currentData() if self.current_folder_path != "" and not self.current_folder_path.isspace( ): new_files_list = self.get_files_list(new_extensions=new_extensions) new_files_list_sorted = sort_names_like_windows(new_files_list) old_files_list_sorted = sort_names_like_windows( self.current_files_list) if new_files_list_sorted != old_files_list_sorted: if self.is_there_old_files: reload_dialog = ReloadAudioFilesDialog() reload_dialog.execute() if reload_dialog.result == "No": new_extensions = self.current_extensions self.setData(new_extensions) self.current_extensions = new_extensions self.close_list.emit(new_extensions)
def dropEvent(self, event): data = event.mimeData() urls = data.urls() paths_to_add = [] for url in urls: current_path = url.path()[1:] paths_to_add.append(current_path) self.drop_folder_and_files_signal.emit( sort_names_like_windows(paths_to_add))
def get_files_list(self, folder_path): temp_files_names = sort_names_like_windows( names_list=os.listdir(folder_path)) temp_files_names_absolute = get_files_names_absolute_list( temp_files_names, folder_path) result = [] for i in range(len(temp_files_names)): if os.path.isdir(temp_files_names_absolute[i]): continue if os.path.getsize(temp_files_names_absolute[i]) == 0: continue result.append(temp_files_names[i]) return result
def update_files_with_drag_and_drop(self, paths_list): duplicate_flag = False not_duplicate_files_absolute_path_list = [] not_duplicate_files_list = [] duplicate_files_list = [] new_files_absolute_path_list = [] for path in paths_list: if os.path.isfile(path): if os.path.getsize(path) == 0: continue new_files_absolute_path_list.append(path) else: new_files_absolute_path_list.extend( sort_names_like_windows( get_files_names_absolute_list( self.get_files_list(path), path))) for new_file_name in new_files_absolute_path_list: if os.path.basename(new_file_name).lower() in map( str.lower, self.files_names_list): duplicate_flag = True duplicate_files_list.append(os.path.basename(new_file_name)) else: not_duplicate_files_absolute_path_list.append(new_file_name) not_duplicate_files_list.append( os.path.basename(new_file_name)) self.files_names_list.append(os.path.basename(new_file_name)) self.attachment_source_lineEdit.stop_check_path = True self.attachment_source_lineEdit.setText(self.drag_and_dropped_text) self.is_drag_and_drop = True self.folder_path = "" self.files_names_absolute_list.extend( not_duplicate_files_absolute_path_list) self.files_size_list.extend( get_files_size_with_absolute_path_list( not_duplicate_files_absolute_path_list)) self.files_checked_list.extend( [True] * len(not_duplicate_files_absolute_path_list)) self.update_total_size() self.show_files_list() self.attachment_source_lineEdit.stop_check_path = False if duplicate_flag: info_message = "One or more files have the same name with the old files will be " \ "skipped:" for file_name in duplicate_files_list: info_message += "\n" + file_name warning_dialog = WarningDialog( window_title="Duplicate files names", info_message=info_message, parent=self.window()) warning_dialog.execute_wth_no_block()
def get_files_list(self, new_extensions): temp_files_names = sort_names_like_windows( names_list=os.listdir(self.current_folder_path)) temp_files_names_absolute = get_files_names_absolute_list( temp_files_names, self.current_folder_path) result = [] for i in range(len(temp_files_names)): if os.path.isdir(temp_files_names_absolute[i]): continue for j in range(len(new_extensions)): temp_file_extension_start_index = temp_files_names[i].rfind( ".") if temp_file_extension_start_index == -1: continue temp_file_extension = temp_files_names[i][ temp_file_extension_start_index + 1:] if temp_file_extension.lower() == new_extensions[j].lower(): result.append(temp_files_names[i]) break return result
def get_files_list(self, folder_path): temp_files_names = sort_names_like_windows( names_list=os.listdir(folder_path)) temp_files_names_absolute = get_files_names_absolute_list( temp_files_names, folder_path) current_extensions = self.video_extensions_comboBox.currentData() result = [] for i in range(len(temp_files_names)): if os.path.isdir(temp_files_names_absolute[i]): continue if os.path.getsize(temp_files_names_absolute[i]) == 0: continue for j in range(len(current_extensions)): temp_file_extension_start_index = temp_files_names[i].rfind( ".") if temp_file_extension_start_index == -1: continue temp_file_extension = temp_files_names[i][ temp_file_extension_start_index + 1:] if temp_file_extension.lower() == current_extensions[j].lower( ): result.append(temp_files_names[i]) break return result
def update_files_with_drag_and_drop(self, paths_list): duplicate_flag = False not_duplicate_files_absolute_path_list = [] not_duplicate_files_list = [] duplicate_files_list = [] new_files_absolute_path_list = [] current_extensions = self.video_extensions_comboBox.currentData() for path in paths_list: if os.path.isfile(path): if os.path.getsize(path) == 0: continue temp_file_name = os.path.basename(path) for j in range(len(current_extensions)): temp_file_extension_start_index = temp_file_name.rfind(".") if temp_file_extension_start_index == -1: continue temp_file_extension = temp_file_name[ temp_file_extension_start_index + 1:] if temp_file_extension.lower( ) == current_extensions[j].lower(): new_files_absolute_path_list.append(path) break else: if os.path.dirname(path) not in self.folders_paths: self.folders_paths.append(Path(os.path.dirname(path))) new_files_absolute_path_list.extend( sort_names_like_windows( get_files_names_absolute_list( self.get_files_list(path), path))) for new_file_name in new_files_absolute_path_list: if os.path.basename(new_file_name).lower() in map( str.lower, self.files_names_list): duplicate_flag = True duplicate_files_list.append(os.path.basename(new_file_name)) else: not_duplicate_files_absolute_path_list.append(new_file_name) not_duplicate_files_list.append( os.path.basename(new_file_name)) self.files_names_list.append(os.path.basename(new_file_name)) if os.path.dirname(new_file_name) not in self.folders_paths: self.folders_paths.append( Path(os.path.dirname(new_file_name))) self.video_source_lineEdit.stop_check_path = True self.video_source_lineEdit.setText(self.drag_and_dropped_text) self.is_drag_and_drop = True self.folder_path = "" self.files_names_absolute_list_with_dropped_files.extend( not_duplicate_files_absolute_path_list) self.files_names_absolute_list.extend( not_duplicate_files_absolute_path_list) self.files_size_list.extend( get_files_size_with_absolute_path_list( not_duplicate_files_absolute_path_list)) self.files_names_checked_list.extend( [True] * len(not_duplicate_files_absolute_path_list)) self.show_files_list() if len(not_duplicate_files_absolute_path_list) > 0: show_loading_dialog(not_duplicate_files_absolute_path_list) self.video_source_lineEdit.stop_check_path = False if duplicate_flag: info_message = "One or more files have the same name with the old files will be " \ "skipped:" for file_name in duplicate_files_list: info_message += "\n" + file_name warning_dialog = WarningDialog( window_title="Duplicate files names", info_message=info_message, parent=self.window()) warning_dialog.execute_wth_no_block()