Skip to content

Commit

Permalink
process
Browse files Browse the repository at this point in the history
  • Loading branch information
invoker111 committed Jan 21, 2021
1 parent ab7b0cd commit 0f09da6
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 75 deletions.
7 changes: 5 additions & 2 deletions assets/button.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions assets/button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
border: 1px solid black;
color: black;
border-radius: 3px;
padding: 5px 10px;
padding: 3px 10px;
&:hover{
background: #dcdcdc;
background: #ddf9ff;
}
&:disabled{
color: gray;
border-color: gray;
}
}
28 changes: 20 additions & 8 deletions assets/container.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 21 additions & 12 deletions assets/container.scss
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,30 @@
}
}
}
>.footer{
>.choose{
>.running{
border-top: 1px solid black;
background: white;
padding: 8px 4px;
QProgressBar{
border: none;
background: rgb(54, 54, 54);
border-radius: 5px;
text-align: center;
color: rgb(229, 229, 229);
height: 15px;

}
>.remove{
background: gray;
&[available=t]{
background: #ff3d3d;
&:chunk {
background-color: rgb(0, 118, 239);
border-radius: 4px;
}
}
>.do{
background: gray;
&[available=t]{
background: #0073ff;
&:disabled{
background: rgb(127, 127, 127);
}
}
QLabel{
color: black;
font-weight: bold;
margin-left: 5px;
}
}
}
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
PyQt5==5.12.2
pyinstaller==4.2
PyQt5==5.12.2
3 changes: 2 additions & 1 deletion src/components/body_file_row.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ def update_regx(self, input_, output_, backup, time_stamp):
self.back_up_dir = sub('[/\\\\]$', '', self.dir_name) + time_stamp
self.output_name = parse_path(self.dir_name if not backup else self.back_up_dir, sub(input_, output_, self.base_name))
if backup:
self.output_label.setText(sub('([/\\\\])([^/\\\\]+)([/\\\\])([^/\\\\]+)$', '\\1<a style="color: blue">\\2</a>\\3<a style="color: red">\\4</a>', self.output_name))
self.output_label.setText(sub('([/\\\\])([^/\\\\]+)([/\\\\])([^/\\\\]+)$',
'\\1<a style="color: blue">\\2</a>\\3<a style="color: red">\\4</a>', self.output_name))
else:
self.output_label.setText(sub('([/\\\\])([^/\\\\]+)$', '\\1<a style="color: red">\\2</a>', self.output_name))
self.file_exist = False
Expand Down
118 changes: 88 additions & 30 deletions src/components/running.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,93 @@
from PyQt5.Qt import *

from src.components.button import Button
from src.utils import set_css


class Running(QDialog):
def __init__(self, type_='success', title='', text=''):
super().__init__()
self.setObjectName("dialog")
self.setFixedWidth(300)
self.setWindowIcon(QIcon('assets/icon.png'))
self.setWindowTitle(title)

self.icon_label = QLabel(self)
self.icon_label.setPixmap(QPixmap(f'assets/{type_}.png').scaled(50, 50, Qt.KeepAspectRatio))
self.icon_label.setProperty("class", "icon")
self.text_label = QLabel(text, self)
self.text_label.setWordWrap(True)
self.text_label.setProperty("class", "text")

self.ok_button = Button("知道了", self)
self.ok_button.clicked.connect(self.close)

layout1 = QHBoxLayout()
layout1.addWidget(self.icon_label, 1)
layout1.addWidget(self.text_label, 4)

layout = QVBoxLayout()
layout.addLayout(layout1)
layout.addWidget(self.ok_button)


class Runner(QThread):
cursor = pyqtSignal(int)
finish_args = pyqtSignal(str, str, str)
abort = pyqtSignal()

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.lis = []
self.backup = False
self.aborted = False

self.abort.connect(self.set_abort)

def set_args(self, lis, backup):
self.lis = lis
self.backup = backup

def set_abort(self):
self.aborted = True

def run(self):
self.aborted = False
# 检查重复
lis = []
for i in self.lis:
if i.file_exist:
self.finish_args.emit('warn', "文件已存在", f"文件(夹)<b>{i.output_name}</b>已经存在,无法执行!")
return
if i.output_name in lis:
for file in lis:
file.set_same_name_warn(i.output_name)
self.finish_args.emit('warn', "文件名重复", f"文件名<b>{i.output_name}</b>存在重复,无法执行!")
return
lis.append(i.output_name)
# 执行
cursor = 0
for i in self.lis:
if self.aborted:
return
error = i.do_rename(self.backup)
if error:
self.finish_args.emit('error', "重命名失败", f"文件<b>{i.input_name}</b>重命名失败!Error:{error}")
return
cursor += 1
self.cursor.emit(cursor)
self.finish_args.emit('success', "重命名成功", f"所有<b>{len(self.lis)}</b>个文件重命名成功!")


class Running(QFrame):
def __init__(self, parent):
super().__init__(parent)

self.runner = Runner(self)
self.progress = QProgressBar(self)
self.progress.setEnabled(False)
self.percentage_label = QLabel("0/0", self)
self.abort_btn = Button("中断", self)
self.abort_btn.setEnabled(False)

self.runner.cursor.connect(self.change_cursor)
self.runner.finished.connect(self.set_finished)

layout = QHBoxLayout()
layout.addWidget(self.progress)
layout.addWidget(self.percentage_label)
layout.addWidget(self.abort_btn)
self.setLayout(layout)
set_css(self, 'assets/dialog.css')
self.exec()

def run(self, lis, backup):
lis = [x for x in range(15)]
self.progress.setMaximum(len(lis))
self.progress.setEnabled(True)
self.progress.setValue(0)
self.percentage_label.setText(f"0/{len(lis)}")

self.runner.set_args(lis, backup)
self.runner.start()
self.abort_btn.setEnabled(True)

def change_cursor(self, cursor):
self.progress.setValue(cursor)
self.percentage_label.setText(f"{cursor}/{self.progress.maximum()}")

def set_finished(self):
self.progress.setValue(0)
self.progress.setEnabled(False)
self.percentage_label.setText("0/0")
self.abort_btn.setEnabled(False)
40 changes: 22 additions & 18 deletions src/views/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from src.components.body_file_row import FileRow
from src.components.dialog import Dialog
from src.components.running import Running
from src.utils import set_css
from src.views.about import About

Expand All @@ -21,13 +22,15 @@ def __init__(self):
self.files_widget_list = []
self.all_chosen = False
self.can_run = False
self.is_running = False
self.back_up = False

from src.views.menu import Menu
self.menubar = Menu(self)
self.frame_head = QFrame(self)
self.frame_body = QFrame(self)
self.dialog_about = About(self)
self.running = Running(self)
self.body_table = QTableWidget(0, 4, self.frame_body)

self.input_regx = QLineEdit(self.frame_head)
Expand Down Expand Up @@ -65,15 +68,20 @@ def set_layout(self):
layout.addLayout(menu_layout)
layout.addWidget(self.frame_head)
layout.addWidget(self.frame_body)
layout.addWidget(self.running)
self.setLayout(layout)

def connect(self):
self.input_regx.textChanged.connect(self.apply_regx)
self.out_regx.textChanged.connect(self.apply_regx)
self.running.runner.finished.connect(self.do_finish)
self.running.runner.finish_args.connect(lambda *args: Dialog(*args))
self.running.abort_btn.clicked.connect(lambda: self.running.runner.abort.emit())

def set_class(self):
self.frame_head.setProperty("class", "head")
self.frame_body.setProperty("class", "body")
self.running.setProperty("class", "running")

self.input_regx.setProperty("class", "input")
self.out_regx.setProperty("class", "output")
Expand Down Expand Up @@ -173,22 +181,18 @@ def choose_changed(self):
self.can_run = can_run

def do_operate(self):
if self.is_running:
return
candidate = [x for x in self.files_widget_list if x.chosen]
# 检查重复
lis = []
for i in candidate:
if i.file_exist:
Dialog('warn', "文件已存在", f"文件(夹){i.output_name}已经存在,无法执行!")
return
if i.output_name in lis:
for file in candidate:
file.set_same_name_warn(i.output_name)
Dialog('warn', "文件名重复", f"文件名{i.output_name}存在重复,无法执行!")
return
lis.append(i.output_name)
for i in candidate:
error = i.do_rename(self.back_up)
if error:
Dialog('error', "重命名失败", f"以下文件{i.input_name}重命名失败!Error:{error}")
return
Dialog('success', "重命名成功", f"重命名成功!")
self.is_running = True
self.running.run(candidate, self.back_up)

def do_finish(self):
self.is_running = False

def closeEvent(self, e):
e.accept()
if self.is_running:
self.running.runner.abort.emit()
else:
super().close()

0 comments on commit 0f09da6

Please sign in to comment.