main_control.py 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. import os
  2. from UI.auto_deal_pics_ui.auto_main import Ui_Form as generate_goods_no_detail_pic_Ui_Form
  3. #
  4. from module.view_control.generate_goods_no_detail_pic.data import DataModeGenerateDetail
  5. from module.view_control.auto_deal_pics.base_deal import BaseDealImage
  6. from module.view_control.auto_deal_pics.run_main import RunMain
  7. from module.view_control.auto_deal_pics.upload_pic import UploadPic
  8. from module.view_control.auto_deal_pics.queren_control import QueRen
  9. # 手动移动图片等操作
  10. from module.view_control.manual_image_matching.m_image_matching_cotrol import MainMatchingWindow
  11. # 每个详情的模板
  12. from module.view_control.auto_deal_pics.detail_temp import TempItem
  13. from module.base_mode.load_plugins import LoadAllPlugins
  14. from import_qt_mode import *
  15. from functools import partial
  16. from threading import Lock
  17. from module.view_control.MineQWidget import MineQWidget, DialogShow
  18. from module.base_mode.base import *
  19. import threading
  20. import settings
  21. # 抠图与详情生成
  22. class AutoDealPics(MineQWidget):
  23. progress_sign = Signal(dict)
  24. text_show = Signal(str)
  25. progress_show_sign = Signal(bool)
  26. progress_end_sign = Signal()
  27. send_dialog_sign = Signal()
  28. change_state_sign = Signal(int)
  29. run_end_sign = Signal(dict)
  30. def __init__(self, windows=None, top_windows=None):
  31. super().__init__()
  32. self.windows = windows
  33. self.top_windows = top_windows
  34. self.ui = generate_goods_no_detail_pic_Ui_Form()
  35. self.ui.setupUi(self)
  36. self.setWindowFlags(self.windowFlags() & ~Qt.WindowStaysOnTopHint)
  37. self.run_main = RunMain(windows=self)
  38. self.run_main.run_end_sign.connect(self.deal_run_end_sign)
  39. self.run_main.show_dialog_sign.connect(self.show_dialog)
  40. self.run_main.show_progress_detail_sign.connect(self.show_progress_detail)
  41. # 程序执行信号
  42. self.run_end_sign.connect(self.deal_run_end_sign)
  43. # 改变状态
  44. self.change_state_sign.connect(self.set_state)
  45. self.setWindowTitle("详情生成(new)")
  46. # 线程锁
  47. self.lock = Lock()
  48. self.image_dir = ""
  49. # 0禁用 1进行中 2已结束 99等待结束
  50. self.state = 2
  51. self.data_mode_generate_detail = DataModeGenerateDetail()
  52. self.init_cutout()
  53. self.init_detail()
  54. self.init_schedule()
  55. self.set_state(0)
  56. self.show()
  57. # 延时检查是否存在匹配图片
  58. QTimer.singleShot(1000, self.check_and_matching_pics)
  59. # 添加进度页面
  60. def init_schedule(self, *args):
  61. self.ui.back.clicked.connect(self.back)
  62. self.ui.stop.clicked.connect(self.to_stop)
  63. self.ui.progressBar.hide()
  64. def back(self, *args):
  65. self.set_state(0)
  66. def to_stop(self, *args):
  67. self.state = 99
  68. # 自动检查匹配图片
  69. def check_and_matching_pics(self, *args, **kwargs):
  70. func = partial(self.run_matching)
  71. self.do_thread_run(func=func, call_back=self.run_matching_call, time_out=30)
  72. # 运行自动匹配
  73. def run_matching(self, *args):
  74. image_dir = "{}/data".format(os.getcwd())
  75. check_path(image_dir)
  76. baseDealImage = BaseDealImage(image_dir=image_dir)
  77. result = baseDealImage.dealMoveImage(image_dir=image_dir, callback_func=None)
  78. # return {'code': 0, 'msg': '处理完成', 'target_path': output_path, 'data': {}}
  79. return result
  80. # 自动匹配的回调函数
  81. def run_matching_call(self, return_data):
  82. print(return_data)
  83. code = return_data["code"]
  84. if code == 0:
  85. output_path = return_data["target_path"]
  86. self.image_dir = "{}/{}".format(os.getcwd(), output_path)
  87. self.show_img_dir()
  88. def show_progress_detail(self, text):
  89. self.ui.textBrowser_4.append(text)
  90. # todo ===========主方法入口===========
  91. def deal_run_end_sign(self, config_data: dict):
  92. if config_data["sign_text"] == "开始抠图":
  93. # 先做整体校验
  94. func = partial(self.run_main.check_before_cutout, config_data=config_data)
  95. self.do_thread_run(func=func, call_back=self.run_main.check_for_cutout_image_first_call_back, time_out=30,
  96. is_show_mask=False)
  97. print(config_data)
  98. if config_data["sign_text"] == "已结束抠图处理":
  99. if config_data["detail_is_enable"]:
  100. # 先做整体校验
  101. # temp_name=self.last_temp, temp_name_list=self.temp_list
  102. func = partial(self.run_main.check_before_detail, config_data=config_data)
  103. self.do_thread_run(func=func,
  104. call_back=self.run_main.check_for_detail_first_call_back,
  105. time_out=30,
  106. is_show_mask=False)
  107. else:
  108. self.set_state(state_value=2)
  109. if config_data["sign_text"] == "已结束详情处理":
  110. if config_data["upload_is_enable"]:
  111. to_deal_dir = "{}/软件-详情图生成".format(config_data["image_dir"])
  112. print("to_deal_dir", to_deal_dir)
  113. if os.path.exists(to_deal_dir):
  114. self.upload_pic = UploadPic(windows=self, to_deal_dir=to_deal_dir, config_data=config_data)
  115. self.upload_pic.run_end_sign.connect(self.deal_run_end_sign)
  116. self.upload_pic.show_progress_detail_sign.connect(self.show_progress_detail)
  117. self.upload_pic.run()
  118. # threading.Thread(target=self.upload_pic.run_by_thread, args=()).start()
  119. else:
  120. self.set_state(state_value=2)
  121. else:
  122. self.set_state(state_value=2)
  123. if config_data["sign_text"] == "结束":
  124. self.set_state(state_value=2)
  125. def change_temp_mode(self, *args, **kwargs):
  126. if self.ui.check_use_excel.isChecked():
  127. self.ui.temp_list_get.hide()
  128. else:
  129. self.ui.temp_list_get.show()
  130. # 重新载入模块
  131. def reload_temp_mode(self, *args, **kwargs):
  132. a = QMessageBox.question(
  133. self, "确认", "是否重启加载模板", QMessageBox.Yes | QMessageBox.No
  134. )
  135. if a != QMessageBox.Yes:
  136. return
  137. # 检查资源包
  138. if settings.env == "prod":
  139. if self.top_windows:
  140. self.top_windows.check_resources_download()
  141. settings.PLUGINS_DICT = LoadAllPlugins(windows=None).load()
  142. # 重新载入模板
  143. self.load_temp_list()
  144. # 获取页面配置
  145. def get_config(self, *args):
  146. if not settings.IsLogin:
  147. QMessageBox.question(
  148. self, "确认", "请先登录", QMessageBox.Yes | QMessageBox.No
  149. )
  150. return
  151. logo_name = self.ui.logo_select_ui.currentText()
  152. if logo_name == "请选择":
  153. QMessageBox.question(
  154. self, "确认", "请先选择logo模板", QMessageBox.Yes | QMessageBox.No
  155. )
  156. return
  157. if self.ui.cutout_exquisite.isChecked() and not bool(settings.IsExquisiteMode):
  158. QMessageBox.question(
  159. self, "确认", "暂无 精细化抠图权限", QMessageBox.Yes | QMessageBox.No
  160. )
  161. return
  162. if "失败" in self.image_dir:
  163. self.WaringMessage("文件夹路径不能含有 失败 字样")
  164. return
  165. image_dir = self.ui.path_name.text()
  166. image_order = self.ui.line_image_pos.text()
  167. is_check_number = self.ui.check_image_total.isChecked()
  168. resize_image_view = self.ui.need_resize.text()
  169. logo_name = self.ui.logo_select_ui.currentText()
  170. settings.MATCHING_LAST_LOGO_TEMP = logo_name
  171. logo_path = self.logo_path_dict[logo_name]
  172. cutout_mode = '1'
  173. if self.ui.cutout_exquisite.isChecked():
  174. cutout_mode = '2'
  175. configData = {
  176. 'imageorder': image_order,
  177. 'resize_image_view': resize_image_view,
  178. 'is_check_number': str(is_check_number),
  179. 'cutout_mode': str(cutout_mode),
  180. 'matching_mode_last': settings.MATCHING_MODE_LAST,
  181. "matching_last_temp": self.last_temp,
  182. "matching_last_logo_temp": logo_name,
  183. }
  184. settings.cutimage_dict['imageorder'] = image_order
  185. settings.cutimage_dict['resize_image_view'] = resize_image_view
  186. settings.cutimage_dict['is_check_number'] = str(is_check_number)
  187. settings.cutimage_dict['cutout_mode'] = str(cutout_mode)
  188. settings.set_config(data_dict=configData, section='cutimage')
  189. config_data = {}
  190. config_data["image_dir"] = image_dir
  191. config_data["image_order"] = image_order
  192. config_data["is_check_number"] = is_check_number
  193. config_data["resize_image_view"] = resize_image_view
  194. config_data["cutout_mode"] = cutout_mode
  195. config_data["logo_path"] = logo_path
  196. config_data["special_goods_art_no_folder_line"] = ""
  197. # =======================================
  198. settings.GOODS_DETAIL_IS_USE_EXCEL = self.is_use_excel
  199. settings.GOODS_DETAIL_EXCEL_PATH = self.excel_path
  200. settings.GOODS_DETAIL_LAST_IMAGE_PATH = self.image_dir
  201. settings.GOODS_DETAIL_IS_CHECK_COLOR_IS_ALL = self.is_check_color_is_all
  202. settings.GOODS_DETAIL_IS_PASS = self.is_check_is_pass
  203. settings.GOODS_DETAIL_LAST_TEMP = self.last_temp
  204. data_dict = {
  205. "is_use_excel": "是" if self.is_use_excel else "否",
  206. "excel_path": self.excel_path if self.excel_path else "",
  207. "last_image_path": self.image_dir if self.image_dir else "",
  208. "is_check_color_is_all": "是" if self.is_check_color_is_all else "否",
  209. "last_temp": self.last_temp,
  210. "goods_detail_temp_mode_last": settings.GOODS_DETAIL_TEMP_MODE_LAST,
  211. }
  212. settings.set_config(data_dict=data_dict, section="goods_detail")
  213. # 红蜻蜓/惠利玛,且为非表格数据必须需要登录处理
  214. assigned_page = self.ui.assigned_page.text()
  215. if assigned_page:
  216. assigned_page_dict = self.check_assigned_page(assigned_page)
  217. if not assigned_page_dict:
  218. self.WaringMessage("指定模板填写格式不合规")
  219. else:
  220. assigned_page_dict = {}
  221. config_data["is_use_excel"] = self.is_use_excel
  222. config_data["excel_path"] = self.excel_path
  223. config_data["is_check_color_is_all"] = self.is_check_color_is_all
  224. config_data["assigned_page_dict"] = assigned_page_dict
  225. config_data["temp_class"] = self.temp_class
  226. config_data["temp_name"] = self.last_temp
  227. config_data["temp_name_list"] = self.temp_list
  228. config_data["target_error_folder"] = self.target_error_folder
  229. print("=============config_data=============")
  230. print(
  231. config_data
  232. )
  233. return config_data
  234. # 抠图相关处理
  235. def init_cutout(self):
  236. # 指定单独处理的颜色文件夹
  237. self.special_goods_art_no_folder = []
  238. self.show_img_dir()
  239. self.ui.select_path.mousePressEvent = self.change_img_dir
  240. self.ui.line_image_pos.setText(settings.cutimage_dict['imageorder'])
  241. self.ui.need_resize.setText(settings.cutimage_dict['resize_image_view'])
  242. self.ui.check_image_total.setChecked(bool(settings.cutimage_dict['is_check_number']))
  243. if settings.DEFAULT_CUTOUT_MODE == '普通抠图':
  244. self.ui.cutout_nomal.setChecked(True)
  245. elif settings.DEFAULT_CUTOUT_MODE == ' 精细化抠图':
  246. self.ui.cutout_exquisite.setChecked(True)
  247. if not bool(settings.IsExquisiteMode):
  248. self.ui.cutout_exquisite.setEnabled(False)
  249. self.progress_sign.connect(self.show_progress)
  250. self.ui.run.clicked.connect(self.run) # 抠图与主图加工
  251. self.set_logo_selected()
  252. # 手动匹配图片
  253. self.ui.manual_matching_pic.mousePressEvent = self.manual_matching_pic_mousePressEvent
  254. def init_detail(self):
  255. # 使用使用表格数据
  256. self.is_use_excel = settings.GOODS_DETAIL_IS_USE_EXCEL
  257. self.excel_path = settings.GOODS_DETAIL_EXCEL_PATH
  258. # 目标文件夹
  259. self.image_dir = settings.GOODS_DETAIL_LAST_IMAGE_PATH
  260. # 对应的错误文件夹目录
  261. if self.image_dir and os.path.exists(self.image_dir):
  262. self.target_error_folder = "{}/软件-生成详情错误".format(self.image_dir)
  263. else:
  264. self.target_error_folder = ""
  265. # 检查颜色是否齐全
  266. self.is_check_color_is_all = settings.GOODS_DETAIL_IS_CHECK_COLOR_IS_ALL
  267. # 已生成主图的自动过滤
  268. self.is_check_is_pass = settings.GOODS_DETAIL_IS_PASS
  269. # 上次使用的详情模板
  270. self.last_temp = settings.GOODS_DETAIL_LAST_TEMP
  271. # 重新载入模块
  272. self.ui.reload_func.mousePressEvent = self.reload_temp_mode
  273. # 手工整理数据
  274. self.ui.manual_matching_pic.mousePressEvent = self.manual_matching_pic
  275. # -------初始化页面--------
  276. if self.is_use_excel:
  277. self.ui.check_use_excel.setChecked(True)
  278. else:
  279. self.ui.check_use_excel.setChecked(False)
  280. if self.excel_path:
  281. self.ui.excel_path_show.setText(self.excel_path)
  282. if self.image_dir:
  283. self.ui.path_name.setText(self.image_dir)
  284. if self.is_check_color_is_all:
  285. self.ui.check_image_total_2.setChecked(True)
  286. else:
  287. self.ui.check_image_total_2.setChecked(False)
  288. # 是否开启使用外部数据
  289. self.ui.check_use_excel.toggled.connect(self.check_box_change)
  290. self.ui.check_image_total_2.toggled.connect(self.check_box_change)
  291. self.check_box_change()
  292. self.ui.select_path.mousePressEvent = self.change_img_dir
  293. self.ui.select_excel.mousePressEvent = self.select_excel_path
  294. # ====================================
  295. self.progress_sign.connect(self.show_progress)
  296. # 复制Excel模板
  297. self.ui.get_excel_temp.mousePressEvent = self.copy_excel
  298. self.change_temp_mode()
  299. # 加载模板
  300. QTimer.singleShot(1000, self.load_temp_list)
  301. def manual_matching_pic_mousePressEvent(self, event):
  302. if not self.image_dir:
  303. a = QMessageBox.question(
  304. self,
  305. "确认",
  306. "请先选择目标文件夹",
  307. QMessageBox.Yes,
  308. )
  309. return
  310. self.manual = MainMatchingWindow(root_path=self.image_dir)
  311. # 手工整理数据
  312. def manual_matching_pic(self, *args, **kwargs):
  313. if not self.image_dir:
  314. a = QMessageBox.question(
  315. self,
  316. "确认",
  317. "请先选择目标文件夹",
  318. QMessageBox.Yes,
  319. )
  320. return
  321. self.manual = MainMatchingWindow(root_path=self.image_dir)
  322. def load_temp_list(self):
  323. # 注册模板类
  324. self.temp_class = {}
  325. self.temp_list = []
  326. plugins_company_name = "企业名称"
  327. if settings.PROJECT == "红蜻蜓":
  328. self.temp_class = {}
  329. plugins_company_name = "红蜻蜓"
  330. elif settings.PROJECT == "惠利玛":
  331. if "惠利玛" in settings.Company:
  332. self.temp_class = {}
  333. plugins_company_name = "惠利玛"
  334. if "小苏" in settings.Company:
  335. self.temp_class = {}
  336. plugins_company_name = "小苏"
  337. # 通过动态进行加载获取
  338. if settings.PLUGINS_DICT:
  339. print("554 settings.PLUGINS_DICT")
  340. for _key, _value in settings.PLUGINS_DICT["detail_template"].items():
  341. print(_key, _value)
  342. try:
  343. if "全部" in settings.PLUGINS_DICT["detail_template"]:
  344. for i, v in settings.PLUGINS_DICT["detail_template"]["全部"].items():
  345. self.temp_class[i] = v
  346. if plugins_company_name in settings.PLUGINS_DICT["detail_template"]:
  347. for i, v in settings.PLUGINS_DICT["detail_template"][plugins_company_name].items():
  348. self.temp_class[i] = v
  349. except BaseException as e:
  350. print("209 通过动态进行加载详情获取error", e)
  351. pass
  352. # 模板名称列表
  353. self.temp_list = [x for x in self.temp_class]
  354. print("570 temp_list", self.temp_list)
  355. # 删除已渲染的模板
  356. for i in self.ui.show_temp_list.findChildren(TempItem):
  357. i.deleteLater()
  358. # 模板列表
  359. x, y = 10, 10
  360. self.ui.show_temp_list.setMinimumSize(self.ui.widget_10.width(), 100)
  361. self.ui.show_temp_list.resize(self.ui.widget_10.width(), 100)
  362. temp_high = 100
  363. for temp_name in self.temp_list:
  364. _class = self.temp_class[temp_name]
  365. _d = _class.get_temp_pic_info(_class.root)
  366. temp_image_path = _d["temp_pic_path"]
  367. # print("224 temp_image_path",temp_image_path)
  368. # temp_item = TempItem(self.ui.scrollArea, temp_name, temp_image_path)
  369. # temp_item.select_sign.connect(self.change_temp_select)
  370. # self.ui.horizontalLayout_18.insertWidget(
  371. # self.ui.horizontalLayout_18.count() - 1, temp_item
  372. # )
  373. temp_item = TempItem(self.ui.show_temp_list, temp_name, temp_image_path)
  374. temp_high = temp_item.height()
  375. temp_item.select_sign.connect(self.change_temp_select)
  376. temp_item.move(x, y)
  377. x += temp_item.width()
  378. x += 10
  379. if x > self.ui.show_temp_list.width() - temp_item.width():
  380. y += temp_item.height()
  381. y += 10
  382. x = 10
  383. y += 100
  384. y += temp_high
  385. print(y)
  386. self.ui.scrollAreaWidgetContents_3.setMinimumSize(x, self.height() + y)
  387. self.ui.show_temp_list.setMinimumSize(x, y)
  388. self.ui.show_temp_list.resize(x, y)
  389. print(self.ui.show_temp_list.height())
  390. # 设置默认值
  391. if self.last_temp not in self.temp_list:
  392. if self.temp_list:
  393. self.last_temp = self.temp_list[0]
  394. # 设置值
  395. for temp_item in self.ui.show_temp_list.findChildren(TempItem):
  396. temp_item.select()
  397. break
  398. def change_temp_select(self, _id):
  399. self.last_temp = _id
  400. print("已设置模板的值为:{}".format(self.last_temp))
  401. for temp_item in self.ui.show_temp_list.findChildren(TempItem):
  402. if temp_item.id != _id:
  403. temp_item.cancel_select()
  404. def copy_excel(self, *args, **kwargs):
  405. excel_path = r"{}\resources\init\goods_excel_temp.xlsx".format(os.getcwd())
  406. if not os.path.exists(excel_path):
  407. return
  408. self.check_path(r"{}\temp".format(os.getcwd()))
  409. self.check_path(r"{}\temp\excel_temp".format(os.getcwd()))
  410. new_excel_path = r"{}\temp\excel_temp\goods_excel_temp.xlsx".format(os.getcwd())
  411. if not os.path.exists(new_excel_path):
  412. shutil.copy(excel_path, new_excel_path)
  413. # 打开文件夹
  414. os.startfile(r"{}\temp\excel_temp".format(os.getcwd()))
  415. def check_box_change(self, *args):
  416. if self.ui.check_use_excel.isChecked():
  417. self.is_use_excel = True
  418. self.ui.widget.show()
  419. self.ui.temp_list_get.hide()
  420. else:
  421. self.is_use_excel = False
  422. self.ui.widget.hide()
  423. self.ui.temp_list_get.show()
  424. if self.ui.check_image_total_2.isChecked():
  425. self.is_check_color_is_all = True
  426. else:
  427. self.is_check_color_is_all = False
  428. # 设置选择logo模板
  429. def set_logo_selected(self):
  430. logo_root_path = ""
  431. if settings.PROJECT == "红蜻蜓":
  432. logo_root_path = r"{}\resources\LOGO\HQT".format(os.getcwd())
  433. elif settings.PROJECT == "惠利玛":
  434. if "小苏" in settings.Company:
  435. logo_root_path = r"{}\resources\LOGO\xiaosushuoxie".format(os.getcwd())
  436. if "惠利玛" in settings.Company:
  437. logo_root_path = r"{}\resources\LOGO\HLM".format(os.getcwd())
  438. self.logo_path_dict = {"请选择": "", "无logo": ""}
  439. if logo_root_path:
  440. if os.path.exists(logo_root_path):
  441. image_list = get_images(logo_root_path)
  442. for image_data in image_list:
  443. self.logo_path_dict[image_data["file_name"]] = image_data["file_path"]
  444. self.ui.logo_select_ui.addItems([x for x in self.logo_path_dict])
  445. self.ui.logo_select_ui.setCurrentText("请选择")
  446. if settings.MATCHING_LAST_LOGO_TEMP:
  447. if settings.MATCHING_LAST_LOGO_TEMP in [x for x in self.logo_path_dict]:
  448. self.ui.logo_select_ui.setCurrentText(settings.MATCHING_LAST_LOGO_TEMP)
  449. def select_excel_path(self, *args, **kwargs):
  450. folder = QFileDialog.getOpenFileName(self, "选取excel", "./")[0]
  451. if "xlsx" in folder:
  452. # if len(folder) > 20:
  453. # text = folder[-20:]
  454. # else:
  455. # text = folder
  456. self.ui.excel_path_show.setText(folder)
  457. self.excel_path = folder
  458. print("folder", folder)
  459. def change_img_dir(self, *args):
  460. folder = QFileDialog.getExistingDirectory(self, "选取文件夹", settings.GOODS_DETAIL_LAST_IMAGE_PATH)
  461. if folder:
  462. # todo 增加检测是否有正常文件文件夹
  463. folder = check_goods_folder(folder)
  464. if folder is None:
  465. QMessageBox.question(self, "确认", "您已选的文件夹下不存在任何有效数据", QMessageBox.Yes, )
  466. return
  467. else:
  468. self.image_dir = folder
  469. self.target_error_folder = "{}/软件-生成详情错误".format(self.image_dir)
  470. self.show_img_dir()
  471. def change_img_dir_by_text(self, folder):
  472. self.image_dir = folder
  473. self.target_error_folder = "{}/软件-生成详情错误".format(self.image_dir)
  474. self.show_img_dir()
  475. def show_img_dir(self):
  476. self.ui.path_name.setText(self.image_dir)
  477. def set_state(self, state_value: int):
  478. # 0禁用 1进行中 2已结束
  479. if state_value not in [0, 1, 2, 99]:
  480. return
  481. self.state = state_value
  482. if self.state == 0:
  483. self.ui.stackedWidget.setCurrentIndex(0)
  484. if self.state == 1:
  485. self.ui.stackedWidget.setCurrentIndex(1)
  486. self.ui.progressBar.setValue(0)
  487. self.ui.textBrowser_4.clear()
  488. self.ui.back.hide()
  489. self.ui.stop.show()
  490. if self.state == 2:
  491. self.ui.back.show()
  492. self.ui.stop.hide()
  493. pass
  494. def check_path(self, _path):
  495. if not os.path.exists(_path):
  496. os.mkdir(_path)
  497. return True
  498. def show_progress(self, *args, **kwargs):
  499. pass
  500. # todo 主程序处理
  501. def run(self):
  502. config_data = self.get_config()
  503. if not config_data:
  504. return
  505. self.queren = QueRen(self)
  506. ret = self.queren.exec()
  507. if ret == QDialog.Accepted:
  508. print("对话框以接受状态关闭")
  509. for key, value in self.queren.get_config().items():
  510. config_data[key] = value
  511. config_data["sign_text"] = "开始抠图"
  512. for key, value in config_data.items():
  513. print("key:{}, value:{}".format(key, value))
  514. self.set_state(state_value=1)
  515. self.run_end_sign.emit(config_data)
  516. # 解析指定模板页面数据
  517. def check_assigned_page(self, text: str):
  518. try:
  519. # temp_dict 示例{“4”:“xiaosushuoxie-4”}
  520. temp_dict = {}
  521. for i in self.temp_list:
  522. temp_dict[i[-1]] = i
  523. text = text.replace(" ", "")
  524. text = text.replace(",", ",")
  525. text = text.replace(":", ":")
  526. text = text.replace(";", ",")
  527. assigned_page_list = text.split(",")
  528. assigned_page_dict = {}
  529. for i in assigned_page_list:
  530. if not i:
  531. continue
  532. _k, _v = i.split(":")
  533. _k = temp_dict[_k]
  534. if _k not in assigned_page_dict:
  535. assigned_page_dict[_k] = []
  536. if _v not in assigned_page_dict[_k]:
  537. assigned_page_dict[_k].append(_v)
  538. # assigned_page_dict 数据结构,一个模板中存在多个页面数值。
  539. return assigned_page_dict
  540. except:
  541. return {}
  542. # 弹出对话框
  543. def show_dialog(self, data):
  544. windows = data["windows"]
  545. windows.dialog_result = ""
  546. my_dialog = DialogShow(self, text=data["text"],
  547. button_1=data["button_1"] if "button_1" in data else None,
  548. button_2=data["button_2"] if "button_2" in data else None,
  549. button_3=data["button_3"] if "button_3" in data else None, )
  550. ret = my_dialog.exec()
  551. print("641 my_dialog.flag_name", my_dialog.flag_name)
  552. # 根据用户的选择发出相应的信号
  553. windows.dialog_result_signal.emit(my_dialog.flag_name)