Skip to content

Commit

Permalink
chore: format
Browse files Browse the repository at this point in the history
* 删除大量换行, 增加多参数换行, 提高可读性
* 使用 f-string 代替格式化字符串
* 清理冗余正则表达式
  • Loading branch information
sqzw-x committed Oct 22, 2024
1 parent 7c9d183 commit 5de2804
Show file tree
Hide file tree
Showing 72 changed files with 1,277 additions and 2,867 deletions.
108 changes: 108 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = false
max_line_length = 170
tab_width = 4
ij_continuation_indent_size = 8
ij_formatter_off_tag = @formatter:off
ij_formatter_on_tag = @formatter:on
ij_formatter_tags_enabled = true
ij_smart_tabs = false
ij_visual_guides =
ij_wrap_on_typing = false

[.editorconfig]
ij_editorconfig_align_group_field_declarations = false
ij_editorconfig_space_after_colon = false
ij_editorconfig_space_after_comma = true
ij_editorconfig_space_before_colon = false
ij_editorconfig_space_before_comma = false
ij_editorconfig_spaces_around_assignment_operators = true


[{*.bash,*.sh,*.zsh}]
indent_size = 2
tab_width = 2
ij_shell_binary_ops_start_line = false
ij_shell_keep_column_alignment_padding = false
ij_shell_minify_program = false
ij_shell_redirect_followed_by_space = false
ij_shell_switch_cases_indented = false
ij_shell_use_unix_line_separator = true


[{*.py,*.pyc,*.pyw}]
ij_python_align_collections_and_comprehensions = true
ij_python_align_multiline_imports = true
ij_python_align_multiline_parameters = true
ij_python_align_multiline_parameters_in_calls = true
ij_python_blank_line_at_file_end = true
ij_python_blank_lines_after_imports = 1
ij_python_blank_lines_after_local_imports = 0
ij_python_blank_lines_around_class = 1
ij_python_blank_lines_around_method = 1
ij_python_blank_lines_around_top_level_classes_functions = 2
ij_python_blank_lines_before_first_method = 0
ij_python_call_parameters_new_line_after_left_paren = false
ij_python_call_parameters_right_paren_on_new_line = false
ij_python_call_parameters_wrap = on_every_item
ij_python_dict_alignment = 0
ij_python_dict_new_line_after_left_brace = false
ij_python_dict_new_line_before_right_brace = true
ij_python_dict_wrapping = 5
ij_python_from_import_new_line_after_left_parenthesis = false
ij_python_from_import_new_line_before_right_parenthesis = false
ij_python_from_import_parentheses_force_if_multiline = false
ij_python_from_import_trailing_comma_if_multiline = false
ij_python_from_import_wrapping = 1
ij_python_hang_closing_brackets = false
ij_python_keep_blank_lines_in_code = 1
ij_python_keep_blank_lines_in_declarations = 1
ij_python_keep_indents_on_empty_lines = false
ij_python_keep_line_breaks = true
ij_python_method_parameters_new_line_after_left_paren = false
ij_python_method_parameters_right_paren_on_new_line = false
ij_python_method_parameters_wrap = on_every_item
ij_python_new_line_after_colon = false
ij_python_new_line_after_colon_multi_clause = true
ij_python_optimize_imports_always_split_from_imports = false
ij_python_optimize_imports_case_insensitive_order = false
ij_python_optimize_imports_join_from_imports_with_same_source = true
ij_python_optimize_imports_sort_by_type_first = true
ij_python_optimize_imports_sort_imports = true
ij_python_optimize_imports_sort_names_in_from_imports = true
ij_python_space_after_comma = true
ij_python_space_after_number_sign = true
ij_python_space_after_py_colon = true
ij_python_space_before_backslash = true
ij_python_space_before_comma = false
ij_python_space_before_for_semicolon = false
ij_python_space_before_lbracket = false
ij_python_space_before_method_call_parentheses = false
ij_python_space_before_method_parentheses = false
ij_python_space_before_number_sign = true
ij_python_space_before_py_colon = false
ij_python_space_within_empty_method_call_parentheses = false
ij_python_space_within_empty_method_parentheses = false
ij_python_spaces_around_additive_operators = true
ij_python_spaces_around_assignment_operators = true
ij_python_spaces_around_bitwise_operators = true
ij_python_spaces_around_eq_in_keyword_argument = false
ij_python_spaces_around_eq_in_named_parameter = false
ij_python_spaces_around_equality_operators = true
ij_python_spaces_around_multiplicative_operators = true
ij_python_spaces_around_power_operator = true
ij_python_spaces_around_relational_operators = true
ij_python_spaces_around_shift_operators = true
ij_python_spaces_within_braces = false
ij_python_spaces_within_brackets = false
ij_python_spaces_within_method_call_parentheses = false
ij_python_spaces_within_method_parentheses = false
ij_python_use_continuation_indent_for_arguments = false
ij_python_use_continuation_indent_for_collection_and_comprehensions = false
ij_python_use_continuation_indent_for_parameters = true
ij_python_wrap_long_lines = false

10 changes: 5 additions & 5 deletions resources/c_number/__get_c_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def get_c_number():
)

while i:
url = ('https://www.sehuatang.org/forum-103-%s.html' % i)
url = (f'https://www.sehuatang.org/forum-103-{i}.html')
# 获取当前页面信息
try:
res = requests.get(url, headers=headers)
Expand All @@ -119,9 +119,9 @@ def get_c_number():
html = etree.HTML(res.text.replace('encoding="utf-8"', ''))
if i == 1:
page_total = html.xpath('//a[@class="last"]/text()')[0][-3:]
print('当前共 %s 页数据!' % page_total)
print('当前共 {} 页数据!'.format(page_total))
print('\n' + '**' * 20)
print('开始下载第 %s 页数据...\n页面地址:%s' % (i, url))
print(f'开始下载第 {i} 页数据...\n页面地址:{url}')
# 获取当前页面帖子列表
try:
post_info = html.xpath('//tbody[contains(@id, "normal")]/tr/th/a[2]')
Expand All @@ -131,7 +131,7 @@ def get_c_number():
save_log(error_info)
else:
post_number = len(post_info)
print('帖子数量:%s' % post_number)
print(f'帖子数量:{post_number}')
j = 0
for each in post_info:
j += 1
Expand Down Expand Up @@ -183,7 +183,7 @@ def get_c_number():
print(j)
print(post_title)
print(number + ' : ' + title)
print('\n当前第 %s 页数据...\n页面地址:%s' % (i, url))
print(f'\n当前第 {i} 页数据...\n页面地址:{url}')
print('**' * 20)
with open(json_filename, 'w', encoding='utf-8') as f:
json.dump(
Expand Down
32 changes: 12 additions & 20 deletions src/controllers/cut_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,10 @@ def __init__(self, parent=None):
self.Ui.pushButton_select_cutrange.setGeometry(QRect(420, 0, 379, 539))
self.Ui.pushButton_select_cutrange.setCursor(QCursor(Qt.OpenHandCursor))
self.Ui.pushButton_select_cutrange.setAcceptDrops(True)
self.Ui.pushButton_select_cutrange.setStyleSheet(
u"background-color: rgba(200, 200, 200, 80);\n"
"font-size:13px;\n" "font-weight:normal;"
"color: rgba(0, 0, 0, 255);\n"
"border:2px solid rgba(0, 55, 255, 255);\n")
self.Ui.pushButton_select_cutrange.setStyleSheet(u"background-color: rgba(200, 200, 200, 80);\n"
"font-size:13px;\n" "font-weight:normal;"
"color: rgba(0, 0, 0, 255);\n"
"border:2px solid rgba(0, 55, 255, 255);\n")
self.set_style()
self.Ui.horizontalSlider_left.valueChanged.connect(self.change_postion_left)
self.Ui.horizontalSlider_right.valueChanged.connect(self.change_postion_right)
Expand All @@ -80,8 +79,7 @@ def __init__(self, parent=None):

def set_style(self):
# 控件美化 裁剪弹窗
self.Ui.widget.setStyleSheet(
'''
self.Ui.widget.setStyleSheet('''
* {
font-family: Consolas, 'PingFang SC', 'Microsoft YaHei UI', 'Noto Color Emoji', 'Segoe UI Emoji';
}
Expand Down Expand Up @@ -121,8 +119,7 @@ def set_style(self):
border-width:14px;
font-weight:bold;
}
'''
)
''')

def change_postion_left(self):
# abc: 0-10000
Expand All @@ -146,8 +143,7 @@ def change_postion_right(self):

# 打开图片选择框
def open_image(self):
img_path, img_type = QFileDialog. \
getOpenFileName(None, "打开图片", "", "*.jpg *.png;;All Files(*)", options=self.parent().options)
img_path, img_type = QFileDialog.getOpenFileName(None, "打开图片", "", "*.jpg *.png;;All Files(*)", options=self.parent().options)
if img_path:
self.showimage(img_path)

Expand Down Expand Up @@ -212,8 +208,8 @@ def showimage(self, img_path='', json_data={}):
if '.nfo' in each:
temp_path = os.path.join(img_folder, each)
break
json_data, movie_number, folder_old_path, file_name, file_ex, \
sub_list, file_show_name, file_show_path = models.core.file.get_file_info(temp_path, copy_sub=False)
json_data, movie_number, folder_old_path, file_name, file_ex, sub_list, file_show_name, file_show_path = models.core.file.get_file_info(temp_path,
copy_sub=False)

self.setWindowTitle(json_data.get('number') + ' 封面图片裁剪') # 设置窗口标题

Expand All @@ -226,9 +222,7 @@ def showimage(self, img_path='', json_data={}):
poster_path = os.path.join(img_folder, 'poster.jpg')
if pic_name == 0: # 文件名-poster.jpg
if '-' in img_name:
poster_path = img_path.replace('-fanart', '').replace('-thumb', '').replace('-poster',
'').replace(
img_ex, '') + '-poster.jpg'
poster_path = img_path.replace('-fanart', '').replace('-thumb', '').replace('-poster', '').replace(img_ex, '') + '-poster.jpg'
thumb_path = poster_path.replace('poster.', 'thumb.')
fanart_path = poster_path.replace('poster.', 'fanart.')
self.cut_thumb_path = thumb_path # 裁剪后的thumb路径
Expand Down Expand Up @@ -273,8 +267,7 @@ def showimage(self, img_path='', json_data={}):
self.rect_h = int(self.rect_w * self.rect_h_w_ratio) # 计算裁剪框的高度
self.rect_x = 0 # 裁剪框左上角的x值
self.rect_y = int((self.pic_new_h - self.rect_h) / 2) # 裁剪框左上角的y值(默认垂直居中)
self.Ui.pushButton_select_cutrange.setGeometry(
QRect(self.rect_x, self.rect_y, self.rect_w, self.rect_h)) # 显示裁剪框
self.Ui.pushButton_select_cutrange.setGeometry(QRect(self.rect_x, self.rect_y, self.rect_w, self.rect_h)) # 显示裁剪框
self.getRealPos() # 显示裁剪框实际位置

# 计算在原图的裁剪位置
Expand Down Expand Up @@ -333,8 +326,7 @@ def getRealPos(self):
self.c_y = int(self.c_y)

# 显示实际裁剪位置
self.Ui.label_cut_postion.setText(
'%s, %s, %s, %s' % (str(self.c_x), str(self.c_y), str(self.c_x2), str(self.c_y2)))
self.Ui.label_cut_postion.setText('%s, %s, %s, %s' % (str(self.c_x), str(self.c_y), str(self.c_x2), str(self.c_y2)))

# self.show_traceback_log('选择位置: %s, %s, %s, %s' % (str(self.c_x), str(self.c_y), str(self.c_x2), str(self.c_y2)))
# 显示实际裁剪尺寸
Expand Down
18 changes: 7 additions & 11 deletions src/controllers/main_window/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,11 @@ def Init_Singal(self):

def n(a): ... # mousePressEvent 的返回值必须是 None, 用这个包装一下

self.Ui.label_download_actor_zip.mousePressEvent = lambda e: n(webbrowser.open(
'https://github.com/moyy996/AVDC/releases/tag/%E5%A4%B4%E5%83%8F%E5%8C%85-2'))
self.Ui.label_download_sub_zip.mousePressEvent = lambda e: n(webbrowser.open(
'https://www.dropbox.com/sh/vkbxawm6mwmwswr/AADqZiF8aUHmK6qIc7JSlURIa'))
self.Ui.label_download_mark_zip.mousePressEvent = lambda e: n(webbrowser.open(
'https://www.dropbox.com/sh/vkbxawm6mwmwswr/AADqZiF8aUHmK6qIc7JSlURIa'))
self.Ui.label_download_actor_zip.mousePressEvent = lambda e: n(webbrowser.open('https://github.com/moyy996/AVDC/releases/tag/%E5%A4%B4%E5%83%8F%E5%8C%85-2'))
self.Ui.label_download_sub_zip.mousePressEvent = lambda e: n(webbrowser.open('https://www.dropbox.com/sh/vkbxawm6mwmwswr/AADqZiF8aUHmK6qIc7JSlURIa'))
self.Ui.label_download_mark_zip.mousePressEvent = lambda e: n(webbrowser.open('https://www.dropbox.com/sh/vkbxawm6mwmwswr/AADqZiF8aUHmK6qIc7JSlURIa'))
self.Ui.label_get_cookie_url.mousePressEvent = lambda e: n(webbrowser.open('https://tieba.baidu.com/p/5492736764'))
self.Ui.label_download_actor_db.mousePressEvent = lambda e: n(webbrowser.open(
'https://github.com/sqzw-x/mdcx/releases/tag/actor_info_database'))
self.Ui.label_download_actor_db.mousePressEvent = lambda e: n(webbrowser.open('https://github.com/sqzw-x/mdcx/releases/tag/actor_info_database'))
# endregion

# region 控件更新
Expand Down Expand Up @@ -267,8 +263,7 @@ def n(a): ... # mousePressEvent 的返回值必须是 None, 用这个包装一
self.pushButton_move_mp4.connect(self.Ui.pushButton_move_mp4.setText)
self.pushButton_find_missing_number.connect(self.Ui.pushButton_find_missing_number.setText)
self.label_result.connect(self.Ui.label_result.setText)
self.label_show_version.connect(self.Ui.label_show_version.setText)
# endregion
self.label_show_version.connect(self.Ui.label_show_version.setText) # endregion


def Init_QSystemTrayIcon(self):
Expand All @@ -289,7 +284,8 @@ def Init_QSystemTrayIcon(self):
tray_menu.addAction(quit_action)
self.tray_icon.setContextMenu(tray_menu)
self.tray_icon.show()
# self.tray_icon.showMessage(f"MDCx {self.localversion}", u'已启动!欢迎使用!', QIcon(self.icon_ico), 3000) # icon的值 0没有图标 1是提示 2是警告 3是错误
# self.tray_icon.showMessage(f"MDCx {self.localversion}", u'已启动!欢迎使用!', QIcon(self.icon_ico), 3000)
# icon的值 0没有图标 1是提示 2是警告 3是错误


def init_QTreeWidget(self):
Expand Down
61 changes: 28 additions & 33 deletions src/controllers/main_window/load_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1057,10 +1057,29 @@ def load_config(self):
self.timer_scrape.stop()
self.statement = int(config.statement) # 间歇刮削间隔时间

self.Ui.checkBox_show_web_log.setChecked(config.show_web_log == 'on') # 显示字段刮削过程
self.Ui.checkBox_show_from_log.setChecked(config.show_from_log == 'on') # 显示字段来源信息
self.Ui.checkBox_show_data_log.setChecked(config.show_data_log == 'on') # 显示字段内容信息
if config.save_log == 'off': # 保存日志
self.Ui.radioButton_log_off.setChecked(True)
else:
self.Ui.radioButton_log_on.setChecked(True)
if config.update_check == 'off': # 检查更新
self.Ui.radioButton_update_off.setChecked(True)
else:
self.Ui.radioButton_update_on.setChecked(True)

self.Ui.lineEdit_local_library_path.setText(convert_path(config.local_library)) # 本地资源库
self.Ui.lineEdit_actors_name.setText(str(config.actors_name)) # 演员名
self.Ui.lineEdit_netdisk_path.setText(convert_path(config.netdisk_path)) # 网盘目录
self.Ui.lineEdit_localdisk_path.setText(convert_path(config.localdisk_path)) # 本地磁盘目录
self.Ui.checkBox_hide_window_title.setChecked(config.window_title == 'hide') # 窗口标题栏
# endregion

# region switch_on
switch_on = config.switch_on
if read_version < 20230404:
switch_on += 'ipv4_only,'
# region switch_on
self.Ui.checkBox_auto_start.setChecked('auto_start' in switch_on)
self.Ui.checkBox_auto_exit.setChecked('auto_exit' in switch_on)
self.Ui.checkBox_rest_scrape.setChecked('rest_scrape' in switch_on)
Expand Down Expand Up @@ -1100,8 +1119,7 @@ def load_config(self):
except:
self.Init_QSystemTrayIcon()
if not mdcx_config:
self.tray_icon.showMessage(f"MDCx {self.localversion}", u'配置写入失败!所在目录没有读写权限!',
QIcon(resources.icon_ico), 3000)
self.tray_icon.showMessage(f"MDCx {self.localversion}", u'配置写入失败!所在目录没有读写权限!', QIcon(resources.icon_ico), 3000)
if 'passthrough' in switch_on:
self.Ui.checkBox_highdpi_passthrough.setChecked(True)
if not os.path.isfile('highdpi_passthrough'):
Expand All @@ -1126,9 +1144,7 @@ def load_config(self):
except:
self.Init_QSystemTrayIcon()
if not mdcx_config:
self.tray_icon.showMessage(f"MDCx {self.localversion}",
u'配置写入失败!所在目录没有读写权限!',
QIcon(resources.icon_ico), 3000)
self.tray_icon.showMessage(f"MDCx {self.localversion}", u'配置写入失败!所在目录没有读写权限!', QIcon(resources.icon_ico), 3000)

# TODO macOS上运行pyinstaller打包的程序,这个处理方式有问题
try:
Expand All @@ -1152,26 +1168,6 @@ def load_config(self):
except Exception as e:
signal.show_traceback_log(f'hide_dock_flag_file: {os.path.realpath(hide_dock_flag_file)}')
signal.show_traceback_log(traceback.format_exc())
# endregion

self.Ui.checkBox_show_web_log.setChecked(config.show_web_log == 'on') # 显示字段刮削过程
self.Ui.checkBox_show_from_log.setChecked(config.show_from_log == 'on') # 显示字段来源信息
self.Ui.checkBox_show_data_log.setChecked(config.show_data_log == 'on') # 显示字段内容信息
if config.save_log == 'off': # 保存日志
self.Ui.radioButton_log_off.setChecked(True)
else:
self.Ui.radioButton_log_on.setChecked(True)
if config.update_check == 'off': # 检查更新
self.Ui.radioButton_update_off.setChecked(True)
else:
self.Ui.radioButton_update_on.setChecked(True)

self.Ui.lineEdit_local_library_path.setText(convert_path(config.local_library)) # 本地资源库
self.Ui.lineEdit_actors_name.setText(str(config.actors_name)) # 演员名
self.Ui.lineEdit_netdisk_path.setText(convert_path(config.netdisk_path)) # 网盘目录
self.Ui.lineEdit_localdisk_path.setText(convert_path(config.localdisk_path)) # 本地磁盘目录
self.Ui.checkBox_hide_window_title.setChecked(config.window_title == 'hide') # 窗口标题栏
# endregion
# endregion

self.Ui.checkBox_create_link.setChecked(config.auto_link)
Expand All @@ -1186,13 +1182,12 @@ def load_config(self):
scrape_like_text += " · 软连接开"
elif config.soft_link == 2:
scrape_like_text += " · 硬连接开"
signal.show_log_text(
f' 🛠 当前配置:{config.path} 加载完成!\n '
f'📂 程序目录:{get_main_path()} \n '
f'📂 刮削目录:{get_movie_path_setting()[0]} \n '
f'💠 刮削模式:{Flags.main_mode_text} · {scrape_like_text} \n '
f'🖥️ 系统信息:{platform.platform()} \n '
f'🐰 软件版本:{self.localversion} \n')
signal.show_log_text(f' 🛠 当前配置:{config.path} 加载完成!\n '
f'📂 程序目录:{get_main_path()} \n '
f'📂 刮削目录:{get_movie_path_setting()[0]} \n '
f'💠 刮削模式:{Flags.main_mode_text} · {scrape_like_text} \n '
f'🖥️ 系统信息:{platform.platform()} \n '
f'🐰 软件版本:{self.localversion} \n')
except:
signal.show_traceback_log(traceback.format_exc())
try:
Expand Down
Loading

0 comments on commit 5de2804

Please sign in to comment.