Commit 68e1972b authored by dovahkiin's avatar dovahkiin

新增插入多个psd的功能,新增使用颜色代表错误还是通过,

(绿色通过,黄色的是已经发现无法解决的问题,红色是位置问题)
parent eaff4fcb
......@@ -13,6 +13,13 @@
<property name="windowTitle">
<string>切图</string>
</property>
<property name="windowIcon">
<iconset>
<normaloff>pic/cut_pic.ico</normaloff>pic/cut_pic.ico</iconset>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextUnderIcon</enum>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
......@@ -120,11 +127,20 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cbx_auto_1">
<property name="text">
<string>智能
等大</string>
</property>
</widget>
</item>
</layout>
<zorder>cbx_english</zorder>
<zorder>cbx_equal_position</zorder>
<zorder>cbx_show</zorder>
<zorder>cbx_equal_size</zorder>
<zorder>cbx_auto_1</zorder>
</widget>
</item>
</layout>
......
......@@ -9,7 +9,8 @@ from time import sleep
import openpyxl
import psd_tools
from psd_tools import PSDImage
from PyQt5.QtWidgets import QMessageBox
from PyQt5.QtWidgets import QMessageBox, QListWidgetItem
from PyQt5.QtGui import QColor, QBrush
from comm_class import flag_data, lay_item
......@@ -177,7 +178,7 @@ def check_path(path):
else:
return 0
def extractLayerImge(lay_info:lay_item, psd_name:str):
def extractLayerImge(lay_info:lay_item, psd_name:str, lwdtI:QListWidgetItem):
global exc_c
psd = PSDImage.open(psd_name)
for layer in psd.descendants():
......@@ -203,6 +204,7 @@ def extractLayerImge(lay_info:lay_item, psd_name:str):
else:
temp_layer_name = layer_name = lay_info.layer.name
temp_layer_name = layer_name
if layer_name == '.':
layer_name = 'dot'
elif layer_name == '-' or layer_name == '_':
......@@ -224,6 +226,8 @@ def extractLayerImge(lay_info:lay_item, psd_name:str):
# 空格替换为下划线
layer_name = layer_name.replace(' ', '_')
layer_name = layer_name.replace('*', 'x')
layer_name = layer_name.replace('#', 'x')
# layer_name = layer_name.replace('x', 'x')
if pos_type == 2:
layer_name = ".\\" + psd_name[:-4] + '/' + layer_name + '.png'
if pos_type == 1:
......@@ -236,21 +240,32 @@ def extractLayerImge(lay_info:lay_item, psd_name:str):
pos = (x1, y1, x2, y2)
xywh = (lay_info.x , lay_info.y, lay_info.w, lay_info.h)
color = QColor(51, 204, 51)
try:
if lay_info.w != 0 or lay_info.h != 0:
layer_image = psd.composite(viewport = pos, force=True)
# layer_image.show(layer_name)
print("[# layer_image #]:", layer_image, "xywh:", xywh)
# temp_psd_show = psd.compose(True)
# temp_psd_show.show()
if lay_info.show:
layer_image.show()
folder = os.path.exists(psd_name[:-4])
if not folder: #判断是否存在文件夹如果不存在则创建为文件夹
os.makedirs(psd_name[:-4])
layer_image.save(layer_name)
lay_info.layer.visible = False
# {}[0]
except KeyError:
color = QColor(220, 220, 41)
except:
color = QColor(204, 0, 0)
brush = QBrush(color)
lwdtI.setForeground(brush)
if lay_info.x != 0 or lay_info.y != 0:
layer_image = psd.composite(viewport = pos, force=True)
# layer_image.show(layer_name)
print("[# layer_image #]:", layer_image, "xywh:", xywh)
# temp_psd_show = psd.compose(True)
# temp_psd_show.show()
if lay_info.show:
layer_image.show()
folder = os.path.exists(psd_name[:-4])
if not folder: #判断是否存在文件夹如果不存在则创建为文件夹
os.makedirs(psd_name[:-4])
layer_image.save(layer_name)
lay_info.layer.visible = False
# print('翻译结果:', temp_layer_name)
exc_c.exc_write(x1, y1, lay_info.w, lay_info.h, layer_name, temp_layer_name, lay_info.layer.name)
return x1, y1, layer_name, temp_layer_name, lay_info.layer.name
......
......@@ -15,6 +15,10 @@ class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(571, 368)
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap("pic/cut_pic.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
MainWindow.setWindowIcon(icon)
MainWindow.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.verticalLayout_3 = QtWidgets.QVBoxLayout(self.centralwidget)
......@@ -74,10 +78,14 @@ class Ui_MainWindow(object):
self.cbx_show = QtWidgets.QCheckBox(self.widget)
self.cbx_show.setObjectName("cbx_show")
self.verticalLayout.addWidget(self.cbx_show)
self.cbx_auto_1 = QtWidgets.QCheckBox(self.widget)
self.cbx_auto_1.setObjectName("cbx_auto_1")
self.verticalLayout.addWidget(self.cbx_auto_1)
self.cbx_english.raise_()
self.cbx_equal_position.raise_()
self.cbx_show.raise_()
self.cbx_equal_size.raise_()
self.cbx_auto_1.raise_()
self.horizontalLayout.addWidget(self.widget)
self.horizontalLayout_4.addWidget(self.widget_3)
self.stackedWidget.addWidget(self.page)
......@@ -172,6 +180,8 @@ class Ui_MainWindow(object):
self.cbx_english.setText(_translate("MainWindow", "英文"))
self.cbx_equal_position.setText(_translate("MainWindow", "共位"))
self.cbx_show.setText(_translate("MainWindow", "显示"))
self.cbx_auto_1.setText(_translate("MainWindow", "智能\n"
"等大"))
self.lib_info_data.setText(_translate("MainWindow", "你好世界"))
self.menu.setTitle(_translate("MainWindow", "设置"))
self.act_set_order.setText(_translate("MainWindow", "替换规则"))
File added
......@@ -19,7 +19,7 @@ def to_exe():
#pic同上
pic = ""
# pic = "-i pic/COM001.ico "
pic = "-i pic/cut_pic.ico "
ver_info = ''
# with open('version_info.txt', encoding="utf-8") as file_info_obj:
......
......@@ -6,13 +6,16 @@ from ctypes import *
from threading import Thread
import numpy as np
import ctypes
# import numpy.ctypeslib as npct
# import serial
# import serial.tools.list_ports
from PyQt5 import QtWidgets
from PyQt5.QtGui import QIcon
from PyQt5.QtCore import QSize, QTimer, pyqtSignal
from PyQt5.QtWidgets import (QApplication, QListWidgetItem, QMessageBox,
QStatusBar, QStyleFactory, QFileDialog)
QStatusBar, QStyleFactory, QFileDialog,
QApplication)
from comm_class import flag_data, lay_item
from cut_pic import extractLayerImge, get_lay_info
......@@ -55,9 +58,17 @@ class Pyqt5_Cut_psd(QtWidgets.QMainWindow, Ui_Form):
def __init__(self, parent = None) -> None:
super(Pyqt5_Cut_psd, self).__init__()
self.setupUi(self)
self.lay_info_s:list[lay_item]
# self.lay_info_s:(list[lay_item])
self.lay_info_s = {}
icon = QIcon("./pic/cut_pic.ico")
# app = QApplication([])
# app.setWindowIcon(icon)
self.setWindowIcon(icon)
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID("myappid")
# MainWindow.setWindowIcon(icon)
# self.MainWindow.setWindowIcon(icon)
# self.statusbar.showMessage("初始化中")
self.lay_lwdtI = {}
self.cut_pic_t = Thread(target=self.cut_pic_thread)
# ui初始化状态
self.__init()
......@@ -76,53 +87,66 @@ class Pyqt5_Cut_psd(QtWidgets.QMainWindow, Ui_Form):
# 读取文件地址
def __read_file_path(self):
file_path = QFileDialog.getOpenFileName(self, "选择PSD文件", os.getcwd(), 'PSD文件(*.psd)')
file_path,_ = QFileDialog.getOpenFileNames(self, "选择PSD文件", os.getcwd(), 'PSD文件(*.psd)')
if (file_path != ''):
self.let_psd_name.setText(file_path[0])
print(file_path)
self.let_psd_name.setText(str(file_path)[1:-1])
print(str(file_path)[1:-1])
def __analysis_psd(self):
psd_name = self.let_psd_name.text()
if psd_name[-4:] != '.psd':
psd_name += '.psd'
if os.path.exists(psd_name):
self.stackedWidget.setCurrentIndex(1)
self.lwg_confirmed.clear()
psd_data = flag_data()
psd_data.psd_name = psd_name
psd_data.english = self.cbx_english.isChecked()
psd_data.cobit = self.cbx_equal_position.isChecked()
psd_data.show = self.cbx_show.isChecked()
psd_data.equal_size = self.cbx_equal_size.isChecked()
self.lib_info_data.clear()
info_prompt = "<" + psd_name + "|"
if psd_data.equal_size:
info_prompt += "需要等大|"
else:
info_prompt += "无需等大|"
if psd_data.english:
info_prompt += "需要转化成英语|"
else:
info_prompt += "不要转化成英语|"
if psd_data.cobit:
info_prompt += "需要共位|"
else:
info_prompt += "无需共位|"
if psd_data.show:
info_prompt += "需要显示>"
else:
info_prompt += "无需显示>"
self.lib_info_data.setText(info_prompt)
self.lay_info_s = get_lay_info(psd_data)
for lay_info in self.lay_info_s:
self.lwg_confirmed.addItem(str(lay_info))
else :
QMessageBox.critical(self, "错误", '未知的psd文件名\n请检查psd文件名字是否正确', QMessageBox.Yes, QMessageBox.Yes)
self.lwg_confirmed.clear()
self.lay_lwdtI.clear()
for psd_name_i in self.let_psd_name.text().split(","):
psd_name = psd_name_i.replace("'", '').strip()
if psd_name[-4:] != '.psd':
psd_name += '.psd'
if os.path.exists(psd_name):
self.stackedWidget.setCurrentIndex(1)
psd_data = flag_data()
psd_data.psd_name = psd_name
psd_data.english = self.cbx_english.isChecked()
psd_data.cobit = self.cbx_equal_position.isChecked()
psd_data.show = self.cbx_show.isChecked()
psd_data.equal_size = self.cbx_equal_size.isChecked()
self.lib_info_data.clear()
info_prompt = "<" + psd_name + "|"
if psd_data.equal_size:
info_prompt += "需要等大|"
else:
info_prompt += "无需等大|"
if psd_data.english:
info_prompt += "需要转化成英语|"
else:
info_prompt += "不要转化成英语|"
if psd_data.cobit:
info_prompt += "需要共位|"
else:
info_prompt += "无需共位|"
if psd_data.show:
info_prompt += "需要显示>"
else:
info_prompt += "无需显示>"
self.lib_info_data.setText(info_prompt)
self.lay_info_s[psd_name] = get_lay_info(psd_data)
self.lwg_confirmed.addItem(str(psd_name))
# a = b = None
for lay_info in self.lay_info_s[psd_name]:
self.lwg_confirmed.addItem(str(lay_info))
# a = self.lwg_confirmed.item(self.lwg_confirmed.count() - 1)
# if b != None:
# print(a == b)
# b = a
self.lay_lwdtI[lay_info] = self.lwg_confirmed.item(self.lwg_confirmed.count() - 1)
# print(self.lwg_confirmed.item(self.lwg_confirmed.count() - 1), type(self.lwg_confirmed.item(self.lwg_confirmed.count()-1)))
# if psd_name_i != self.let_psd_name.text().split(",")[-1]:
else :
QMessageBox.critical(self, "错误", '未知的psd文件名\n请检查psd文件名字是否正确\n|%s|'%(psd_name), QMessageBox.Yes, QMessageBox.Yes)
print(psd_name, os.path.exists(psd_name))
def __btnb_confirmed(self, btn):
if btn.text() == "Reset":
......@@ -150,29 +174,16 @@ class Pyqt5_Cut_psd(QtWidgets.QMainWindow, Ui_Form):
self.statusbar.clearMessage()
def cut_pic_thread(self):
# try:
# psd_name = self.let_psd_name.text()
# if psd_name[-4:] != '.psd':
# psd_name += '.psd'
# for lay_info in self.lay_info_s:
# if self.flag_stop_cut_pic_t:
# self.flag_stop_cut_pic_t = False
# return
# self.statusbar.showMessage(str(lay_info) + "切图中……")
# extractLayerImge(lay_info, psd_name)
# self.cut_info_ok.emit()
# except:
# self.cut_info_error.emit()
psd_name = self.let_psd_name.text()
if psd_name[-4:] != '.psd':
psd_name += '.psd'
for lay_info in self.lay_info_s:
if self.flag_stop_cut_pic_t:
self.flag_stop_cut_pic_t = False
return
self.statusbar.showMessage(str(lay_info) + "切图中……")
extractLayerImge(lay_info, psd_name)
for psd_name_i in self.let_psd_name.text().split(","):
psd_name = psd_name_i.replace("'","").strip()
if psd_name[-4:] != '.psd':
psd_name += '.psd'
for lay_info in self.lay_info_s[psd_name]:
if self.flag_stop_cut_pic_t:
self.flag_stop_cut_pic_t = False
return
self.statusbar.showMessage(str(psd_name) + "|" +str(lay_info) + "切图中……")
extractLayerImge(lay_info, psd_name, self.lay_lwdtI[lay_info])
self.cut_info_ok.emit()
def connects(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment