AutoDealPics.py 27 KB

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