Skip to content

Commit

Permalink
v9.5.2
Browse files Browse the repository at this point in the history
1、筛选条件增加不包含
2、修复批量新增、填充
3、增加状态栏
  • Loading branch information
cgkings committed Dec 23, 2024
1 parent 97802c4 commit ddfd0b6
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 75 deletions.
142 changes: 75 additions & 67 deletions NFO.Editor.Qt5.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def on_rating_key_release(self, widget, event):
key_text = event.text()

# 打印调试信息,帮助排查问题
print(f"当前文本: {current_text}, 输入字符: {key_text}")
# print(f"当前文本: {current_text}, 输入字符: {key_text}")

# 如果输入的是数字
if key_text.isdigit():
Expand Down Expand Up @@ -381,7 +381,7 @@ def load_files_in_folder(self):
# 更新状态栏信息
total_folders = len(set(os.path.dirname(f) for f in self.nfo_files))
status_msg = f"目录: {self.folder_path} (共加载 {total_folders} 个文件夹)"
self.statusBar().showMessage(status_msg)
self.status_bar.showMessage(status_msg) # 使用 self.status_bar

except Exception as e:
QMessageBox.critical(self, "错误", f"加载文件失败: {str(e)}")
Expand Down Expand Up @@ -516,7 +516,7 @@ def load_target_files(self, target_path):
folder_count -= 1 # 不计算返回上级目录项

status_text = f"目标目录: {target_path} (共{folder_count}个文件夹)"
self.statusBar().showMessage(status_text)
self.status_bar.showMessage(status_text) # 使用 self.status_bar

except Exception as e:
QMessageBox.critical(self, "错误", f"加载目标目录失败: {str(e)}")
Expand Down Expand Up @@ -995,6 +995,7 @@ def apply_filter(self):
return

# 遍历 NFO 文件
matches = []
for nfo_file in self.nfo_files:
try:
tree = ET.parse(nfo_file)
Expand Down Expand Up @@ -1046,26 +1047,14 @@ def apply_filter(self):
except ValueError:
continue
else:
match = filter_text.lower() in value.lower()
if condition == "包含":
match = filter_text.lower() in value.lower()
elif condition == "不包含":
match = filter_text.lower() not in value.lower()

# 如果匹配,添加到树中
# 如果匹配,添加到匹配列表
if match:
relative_path = os.path.relpath(nfo_file, self.folder_path)
parts = relative_path.split(os.sep)

if len(parts) > 1:
first_level = (
os.sep.join(parts[:-2]) if len(parts) > 2 else ""
)
second_level = parts[-2]
nfo_name = parts[-1]
else:
first_level = ""
second_level = ""
nfo_name = parts[-1]

item = QTreeWidgetItem([first_level, second_level, nfo_name])
self.file_tree.addTopLevelItem(item)
matches.append(nfo_file)

except ET.ParseError:
print(f"解析文件失败: {nfo_file}")
Expand All @@ -1074,12 +1063,29 @@ def apply_filter(self):
print(f"处理文件出错 {nfo_file}: {str(e)}")
continue

# 添加匹配的文件到树中
for nfo_file in matches:
relative_path = os.path.relpath(nfo_file, self.folder_path)
parts = relative_path.split(os.sep)

if len(parts) > 1:
first_level = os.sep.join(parts[:-2]) if len(parts) > 2 else ""
second_level = parts[-2]
nfo_name = parts[-1]
else:
first_level = ""
second_level = ""
nfo_name = parts[-1]

item = QTreeWidgetItem([first_level, second_level, nfo_name])
self.file_tree.addTopLevelItem(item)

# 更新状态栏信息
matched_count = self.file_tree.topLevelItemCount()
matched_count = len(matches)
total_count = len(self.nfo_files)
self.statusBar().showMessage(
self.status_bar.showMessage(
f"筛选结果: 匹配 {matched_count} / 总计 {total_count}"
)
) # 使用 self.status_bar

except Exception as e:
QMessageBox.critical(self, "错误", f"筛选过程出错: {str(e)}")
Expand Down Expand Up @@ -1316,46 +1322,46 @@ def open_batch_rename_tool(self):
except Exception as e:
QMessageBox.critical(self, "错误", f"启动重命名工具时出错: {str(e)}")

def on_file_select(self):
"""文件选择回调"""
selected_items = self.file_tree.selectedItems()
if not selected_items:
return

# 检查是否有未保存的更改
if self.current_file_path and self.has_unsaved_changes():
reply = QMessageBox.question(
self,
"保存更改",
"当前有未保存的更改,是否保存?",
QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel,
)

if reply == QMessageBox.Cancel:
return
elif reply == QMessageBox.Yes:
self.save_changes()

# 处理新选中的文件
item = selected_items[0]
values = [item.text(i) for i in range(3)]

if values[2]: # 如果有NFO文件名
self.current_file_path = (
os.path.join(self.folder_path, values[0], values[1], values[2])
if values[1]
else os.path.join(self.folder_path, values[0], values[2])
)

if not os.path.exists(self.current_file_path):
self.file_tree.takeTopLevelItem(
self.file_tree.indexOfTopLevelItem(item)
)
return

self.load_nfo_fields()
if self.show_images_checkbox.isChecked():
self.display_image()
# def on_file_select(self):
# """文件选择回调"""
# selected_items = self.file_tree.selectedItems()
# if not selected_items:
# return

# # 检查是否有未保存的更改
# if self.current_file_path and self.has_unsaved_changes():
# reply = QMessageBox.question(
# self,
# "保存更改",
# "当前有未保存的更改,是否保存?",
# QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel,
# )

# if reply == QMessageBox.Cancel:
# return
# elif reply == QMessageBox.Yes:
# self.save_changes()

# # 处理新选中的文件
# item = selected_items[0]
# values = [item.text(i) for i in range(3)]

# if values[2]: # 如果有NFO文件名
# self.current_file_path = (
# os.path.join(self.folder_path, values[0], values[1], values[2])
# if values[1]
# else os.path.join(self.folder_path, values[0], values[2])
# )

# if not os.path.exists(self.current_file_path):
# self.file_tree.takeTopLevelItem(
# self.file_tree.indexOfTopLevelItem(item)
# )
# return

# self.load_nfo_fields()
# if self.show_images_checkbox.isChecked():
# self.display_image()

def on_file_double_click(self, item, column):
"""双击文件列表项处理"""
Expand Down Expand Up @@ -1527,9 +1533,11 @@ def dropEvent(self, event):


def main():
# 设置高DPI支持
QApplication.setAttribute(Qt.ApplicationAttribute.AA_EnableHighDpiScaling, True)
QApplication.setAttribute(Qt.ApplicationAttribute.AA_UseHighDpiPixmaps, True)
# 在创建 QApplication 之前设置高DPI属性
if hasattr(Qt, "AA_EnableHighDpiScaling"):
QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
if hasattr(Qt, "AA_UseHighDpiPixmaps"):
QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps)

app = QApplication(sys.argv)
app.setStyle("Fusion")
Expand Down
14 changes: 9 additions & 5 deletions NFO_Editor_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,13 @@ def __init__(self):
self.screen_dpi = self.screen().logicalDotsPerInch()
self.scale_factor = self.screen_dpi / 96.0

self.setWindowTitle("大锤 NFO Editor Qt v9.5.1")
self.setWindowTitle("大锤 NFO Editor Qt v9.5.2")
self.resize(1280, 800)

# 初始化状态栏
self.status_bar = self.statusBar()
self.status_bar.showMessage("就绪") # 设置默认状态信息

try:
icon_path = os.path.join(
os.path.dirname(os.path.abspath(__file__)), "chuizi.ico"
Expand Down Expand Up @@ -311,7 +315,6 @@ def create_sorting_panel(self):

self.condition_combo = QComboBox()
self.condition_combo.setFixedWidth(int(65 * self.scale_factor))
self.condition_combo.addItem("包含")
grid.addWidget(self.condition_combo, 0, len(sort_options) + 2)

self.filter_entry = QLineEdit()
Expand All @@ -320,19 +323,20 @@ def create_sorting_panel(self):

def on_field_changed(index):
self.condition_combo.clear()
# 清空输入框
self.filter_entry.clear()
if self.field_combo.currentText() == "评分":
self.condition_combo.addItems(["大于", "小于"])
else:
self.condition_combo.addItems(["包含"])
self.condition_combo.addItems(["包含", "不包含"])

self.field_combo.currentIndexChanged.connect(on_field_changed)
# 条件变化时只清空输入框,用一个简单的 lambda 函数就搞定了
self.condition_combo.currentIndexChanged.connect(
lambda x: self.filter_entry.clear()
)

# Initialize default conditions
on_field_changed(0)

filter_button = QPushButton("筛选")
filter_button.setFixedSize(
int(45 * self.scale_factor), int(30 * self.scale_factor)
Expand Down
2 changes: 1 addition & 1 deletion cg_crop.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ class EmbyPosterCrop(QDialog):
def __init__(self, parent=None, nfo_base_name=None):
super().__init__(parent)
self.nfo_base_name = nfo_base_name
self.setWindowTitle("大锤 EMBY海报裁剪工具 v9.5.1")
self.setWindowTitle("大锤 EMBY海报裁剪工具 v9.5.2")
self.setMinimumSize(1200, 640)

# 设置窗口图标
Expand Down
2 changes: 1 addition & 1 deletion cg_dedupe.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def __init__(self, initial_directory=None):
self.add_directory(initial_directory)

def init_ui(self):
self.setWindowTitle("大锤 NFO查重工具 v9.5.1")
self.setWindowTitle("大锤 NFO查重工具 v9.5.2")
self.setGeometry(100, 100, 800, 600)
self.setMinimumSize(600, 400)

Expand Down
2 changes: 1 addition & 1 deletion cg_rename.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def __init__(self, parent=None):

def init_ui(self):
"""Initialize the UI"""
self.setWindowTitle("大锤 批量改名工具 v9.5.1")
self.setWindowTitle("大锤 批量改名工具 v9.5.2")
self.setMinimumSize(900, 800)

# 设置窗口样式
Expand Down

0 comments on commit ddfd0b6

Please sign in to comment.