Skip to content

Commit

Permalink
Update v1.1.20230108 支持拖拽TXT
Browse files Browse the repository at this point in the history
  • Loading branch information
aoguai committed Jan 8, 2023
1 parent 292e294 commit 5b60597
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
25 changes: 23 additions & 2 deletions GUI.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import sys
import base64
from PyQt5.QtGui import QIcon, QPixmap
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QLineEdit, QPushButton, QGridLayout, QProgressBar, QMessageBox
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QLineEdit, QPushButton, QGridLayout, QProgressBar, \
QMessageBox
from SplitFiles import SplitFiles


class SplitFileGUI(QWidget):
def __init__(self):
super().__init__()
# 支持拖放文件
self.setAcceptDrops(True)
# 调用Drops方法
# Create progress bar
self.progress_bar = QProgressBar(self)

Expand Down Expand Up @@ -38,7 +42,7 @@ def __init__(self):
self.setLayout(layout)

# Set window properties
self.setWindowTitle('奥怪TXT分割v1.0')
self.setWindowTitle('奥怪TXT分割v1.1')

pixmap = QPixmap()
logo_data_bytes = 'AAABAAEAICAAAAEAIACoEAAAFgAAACgAAAAgAAAAQAAAAAEAIAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB8SCQAgEQkAIRAKAAkqAAAkCwwAHw4KAB8OCgAkCwwACSoAACEQCgAgEQkAHxIJAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAfEgkAHxIJAB8SCQAgEQoAHRQIAADsAAAgCwsEIAsLBADsAAAdFAgAIBEKAB8SCQAfEgkAHxIJAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgEAsAIBALACEPDAAfEQoAHhIJAB8RCQAgEAgAIBAIACAQCAAgEAgAIBIJAB8SCQAfEgkAHxIJACQMDAAgEQkWIBEK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ode()
Expand All @@ -48,6 +52,8 @@ def __init__(self):

def split_file(self):
file_name = self.file_name_field.text()
if not file_name[-4:] == '.txt':
QMessageBox.information(self, "警告", "只支持TXT文件")
if len(self.line_count_field.text().strip()) > 0:
line_count = int(self.line_count_field.text())
if line_count <= 0:
Expand All @@ -63,6 +69,21 @@ def split_file(self):
sf = SplitFiles(self, file_name, line_count, part_path)
sf.split_file()

def dragEnterEvent(self, event):
if event.mimeData().hasUrls():
event.accept()
else:
event.ignore()

def dropEvent(self, event):
# Get the file path from the dropped file
file_path = event.mimeData().urls()[0].toLocalFile()
if file_path[-4:] == '.txt':
# Set the file name field to the file path
self.file_name_field.setText(file_path)
else:
QMessageBox.information(self, "警告", "只支持TXT文件")


if __name__ == '__main__':
app = QApplication(sys.argv)
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# SplitFiles

A text splitter that splits a large text file into several smaller text files by line.

一个文本分割器,可以将大文本文件按行分割成若干小文本文件。

## 介绍

这是一个简单的文本分割器,可以将大文本文件**按行**分割成若干小文本文件。
拥有简单的 GUI 界面

Expand All @@ -13,7 +15,7 @@ A text splitter that splits a large text file into several smaller text files by

1. 对中文与特殊符号友好
2. 效率高,速度快

个人测试 13G txt 文件共 1.4亿行 分割为单文本 1700 W 行,耗时不到3分钟

### 展示
Expand Down
3 changes: 0 additions & 3 deletions SplitFiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,10 @@ def get_part_file_name(self, part_num, temp_count):

def write_file(self, part_num, temp_count, *line_content):
"""将按行分割后的内容写入相应的分割文件中"""
# print(temp_count)
part_file_name = self.get_part_file_name(part_num, temp_count)
# print(line_content)
try:
with open(part_file_name, "w", encoding='UTF-8') as part_file:
part_file.writelines(line_content[0])
print(self.windows.progress_bar.value(), self.total_lines)
if self.windows.progress_bar.value() >= self.total_lines:
self.windows.progress_bar.reset() # Reset progress bar
QMessageBox.information(self.windows, "已完成", "文件分割已完成!")
Expand Down

0 comments on commit 5b60597

Please sign in to comment.