Commit 8d26d7e9 authored by dovahkiin's avatar dovahkiin

出版,可选切图方式,可选psd路径。

parent 78ea3aae
/vscode/
*.spec
/build/
/dist/
/__pycache__/
image coordinate size.xlsx
Thumbs.db
from typing import Dict, List, Tuple
from psd_tools.api.layers import PixelLayer, TypeLayer
# 标志位类
class flag_data:
psd_name = ''
english = False
cobit = False
show = False
equal_size = True
def __str__(self) -> str:
return "psd名:{}, english:{}, cobit:{}, show:{}, equal_size:{}".format(self.psd_name, self.english, self.cobit, self.show, self.equal_size)
class lay_item:
layer:Tuple[PixelLayer, TypeLayer]
layer_name:str
# psd_name:str
x = y = w = h = 0
english = False
show = False
def __str__(self) -> str:
return"<图层名:{} ,x:{} ,y:{} ,w:{} ,h:{} >".format(self.layer_name, self.x, self.y, self.w, self.h)
def new_str(self)->str:
return"<layer_name:{}, x:{} ,y:{} ,w:{} ,h:{}, english:{}, show:{}|\n layer:{}>".format(self.layer_name, self.x, self.y, self.w, self.h, self.english, self.show, self.layer)
# if __name__ == '__main__':
# a = lay_item()
# a.layer = ''
# a.layer_name = "123"
# a.x = 32
# a.y = 64
# a.w = 128
# a.h = 256
# print(a)
# b = "aaa{}".format(True)
# print(b)
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>571</width>
<height>368</height>
</rect>
</property>
<property name="windowTitle">
<string>切图</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QStackedWidget" name="stackedWidget">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="page">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QWidget" name="widget_3" native="true">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QWidget" name="widget_2" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="lab_pic_name">
<property name="text">
<string>PSD名字:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="let_psd_name">
<property name="clearButtonEnabled">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btn_select_file">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>20</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>23</width>
<height>23</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>23</width>
<height>23</height>
</size>
</property>
<property name="text">
<string></string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btn_analysis">
<property name="text">
<string>解析</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QWidget" name="widget" native="true">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QCheckBox" name="cbx_equal_size">
<property name="text">
<string>等大</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="autoRepeat">
<bool>false</bool>
</property>
<property name="autoExclusive">
<bool>false</bool>
</property>
<property name="tristate">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cbx_english">
<property name="text">
<string>英文</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cbx_equal_position">
<property name="text">
<string>共位</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cbx_show">
<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>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="page_2">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QScrollArea" name="scrollArea">
<property name="minimumSize">
<size>
<width>0</width>
<height>115</height>
</size>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>533</width>
<height>256</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<property name="leftMargin">
<number>2</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>3</number>
</property>
<property name="bottomMargin">
<number>12</number>
</property>
<item>
<widget class="QListWidget" name="lwg_confirmed">
<property name="font">
<font>
<family>方正姚体</family>
<pointsize>12</pointsize>
</font>
</property>
<property name="cursor" stdset="0">
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAsNeeded</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="viewMode">
<enum>QListView::ListMode</enum>
</property>
<property name="currentRow">
<number>-1</number>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="lib_info_data">
<property name="minimumSize">
<size>
<width>0</width>
<height>20</height>
</size>
</property>
<property name="font">
<font>
<family>方正姚体</family>
<pointsize>9</pointsize>
</font>
</property>
<property name="cursor">
<cursorShape>BlankCursor</cursorShape>
</property>
<property name="text">
<string>你好世界</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="btnb_confirmed">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok|QDialogButtonBox::Reset</set>
</property>
<property name="centerButtons">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="page_3">
<widget class="QDialogButtonBox" name="buttonBox_2">
<property name="geometry">
<rect>
<x>10</x>
<y>150</y>
<width>341</width>
<height>32</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</widget>
</widget>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>571</width>
<height>23</height>
</rect>
</property>
<widget class="QMenu" name="menu">
<property name="title">
<string>设置</string>
</property>
<addaction name="act_set_order"/>
</widget>
<addaction name="menu"/>
</widget>
<widget class="QStatusBar" name="statusbar"/>
<action name="act_set_order">
<property name="text">
<string>替换规则</string>
</property>
</action>
</widget>
<tabstops>
<tabstop>let_psd_name</tabstop>
<tabstop>btn_analysis</tabstop>
<tabstop>cbx_equal_size</tabstop>
<tabstop>cbx_english</tabstop>
<tabstop>cbx_equal_position</tabstop>
<tabstop>cbx_show</tabstop>
<tabstop>scrollArea</tabstop>
<tabstop>lwg_confirmed</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>
This diff is collapsed.
import json
import os
import re
import urllib.parse
import urllib.request
from random import uniform
from time import sleep
import openpyxl
import psd_tools
from psd_tools import PSDImage
excel_file_name = 'image coordinate size.xlsx' # EXCEL名称
image_name_colum = 'A'
x_coord_column = 'B'
y_coord_column = 'C'
width_column = 'D'
height_column = 'E'
translation_column = 'F'
Original_column = 'G'
need_en = ''
need_cobit = ''
# 起始行
start_line_number = 2
def crawler_translation(content):
url='http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule'
head={}
#隐藏爬虫信息
head['User-Agent']='Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:67.0) Gecko/20100101 Firefox/67.0'
#编辑表单
data={}
data['i']=content
data['from']='AUTO'
data['to']='AUTO'
data['smartresult']='dict'
data['client']='fanyideskweb'
data['salt']='15590456742344'
data['sign']='238073a9cc158731f9feea2f63589c3f'
data['ts']='1559045674234'
data['bv']='e2a78ed30c66e16a857c5b6486a1d326'
data['doctype']='json'
data['version']='2.1'
data['keyfrom']='fanyi.web'
data['action']='FY_BY_CLICKBUTTION'
#确认新表单
data=urllib.parse.urlencode(data).encode('utf-8')
#传入url和data
req=urllib.request.Request(url,data,head)
#获得响应
response=urllib.request.urlopen(url,data)
html=response.read().decode('utf-8')
'''
print(html)
target=json.loads(html)
print(target)
print(target['translateResult'])
print(target['translateResult'][0][0])
print(target['translateResult'][0][0]['tgt'])
'''
target=json.loads(html)
#获取结果
# print('翻译结果:%s'%(target['translateResult'][0][0]['tgt']))
return target['translateResult'][0][0]['tgt']
def extractLayerImge(layer:psd_tools.api.layers.TypeLayer):
# layer.is_group()
# layer_image = psd.compose(False)
layer.visible = True
# layer_image = layer.composite()
temp_layer_name = ''
if bool(re.search('[a-z, A-Z,.,-,_]', layer.name)):
temp_layer_name = layer_name = layer.name
else:
sleep(uniform(0.5, 3.6))
if (need_en == 'Y' or need_en == 'y'):
layer_name = temp_layer_name = crawler_translation(layer.name)
else:
temp_layer_name = layer_name = layer.name
if layer_name == '.':
layer_name = 'dot'
elif layer_name == '-' or layer_name == '_':
layer_name = 'line'
layer_name = layer_name.replace("/", "_")
layer_name = layer_name.replace("\\", "_")
layer_name = layer_name.replace(".", "_")
layer_name = layer_name.replace(":", "_")
layer_name = layer_name.replace("?", "!")
layer_name = layer_name.replace("*", "#")
layer_name = layer_name.replace('"', "'")
layer_name = layer_name.replace('<', "_")
layer_name = layer_name.replace('>', "_")
layer_name = layer_name.replace('|', "&")
layer_name = psd_name[:-4] + '/' + psd_name[:-4] + '_' + layer_name + '.png'
# 空格替换为下划线
layer_name = layer_name.replace(' ', '_')
# layer_name = psd_name[:-4] + '_' + layer_name + '.png'
# layer_image = psd.composite(viewport=(5,5,10,10),force=True)
# layer_image = psd.composite(force=True)
x1 = x2 = y1 = y2 = 0
if need_cobit == 'Y' or need_cobit == 'y':
x1 = max_x
y1 = max_y
x2 = max_x + max_w
y2 = max_y + max_h
else:
difference_x = (max_w - layer.width)//2
difference_y = (max_h - layer.height)//2
x1 = layer.left-difference_x
y1 = layer.top-difference_y
x2 = x1 + max_w
y2 = y1 + max_h
pos = (x1, y1, x2, y2)
xywh = (x1, y1, x2-x1, y2-y1)
layer_image = psd.composite(viewport = pos, force=True)
# layer_image.show(layer_name)
print("[# layer_image #]:", layer_image, "xywh:", xywh)
# print('\n\n\nlayer_name' + layer_name + '\n\n\n')
layer_image.save(layer_name, quality=95, subsampling=0)
layer.visible = False
# print('翻译结果:', temp_layer_name)
return x1, y1, layer_name, temp_layer_name, layer.name
# layer.is_group()
if __name__ == '__main__':
wb = openpyxl.load_workbook(excel_file_name) # 创建excel对象
sheet = wb.sheetnames # 获取工作表名称
sheet1 = wb[sheet[0]] # 获取sheet1工作表对象
while(True):
x_coord_index = x_coord_column + str(start_line_number)
y_coord_index = y_coord_column + str(start_line_number)
width_index = width_column + str(start_line_number)
height_index = height_column + str(start_line_number)
image_name_index = image_name_colum + str(start_line_number)
translation_index = translation_column + str(start_line_number)
Original_index = Original_column + str(start_line_number)
if sheet1[image_name_index].value != None:
sheet1[x_coord_index] = None
sheet1[y_coord_index] = None
sheet1[width_index] = None
sheet1[height_index] = None
sheet1[image_name_index] = None
sheet1[translation_index] = None
sheet1[Original_index] = None
start_line_number += 1
else:
while True:
try:
wb.save('image coordinate size.xlsx')
break
except PermissionError:
print("please close the Excel file")
sleep(3)
break
start_line_number = 2
while(True):
psd_name = input('please input psd name(input \\q out):\n')
if psd_name == '\\q':
break
if psd_name[-4:] != '.psd':
psd_name = psd_name + '.psd'
while(True):
need_en = input('need english?(Y/N)')
if need_en == 'y' or need_en == 'n' or need_en == 'Y' or need_en == 'N':
break
else:
print('please Reenter')
while(True):
need_cobit = input('need cobit?(Y/N)')
if need_cobit == 'y' or need_cobit == 'n' or need_cobit == 'Y' or need_cobit == 'N':
break
else:
print('please Reenter')
try:
psd = PSDImage.open(psd_name)
except FileNotFoundError:
print('file "%s" does not exist Please re-enter' % (psd_name[:-4]))
continue
max_w = max_h = 0
max_x = max_y= -1
layer_list = []
for layer in psd.descendants():
if layer.is_group():
# print(layer)
continue
if layer.is_visible() == True:
layer_list.append(layer)
# 关闭所有图层并寻找最大宽高
if max_w < layer.width:
max_w = layer.width
if max_h < layer.height:
max_h = layer.height
if max_x > layer.left or max_x == -1:
max_x = layer.left
if max_y > layer.top or max_y == -1:
max_y = layer.top
# layer.visible = False
print("*"*20)
for layer in layer_list:
print(layer)
print("H"*20)
print("max_w: %d, max_h: %d" % (max_w, max_h))
print("*"*20)
while(True):
confirm_data = input('Please confirm(Y/N)')
if confirm_data == 'y' or confirm_data == 'Y' or confirm_data == 'n' or confirm_data == 'N':
break
else:
print('please Reenter')
if confirm_data == 'n' or confirm_data == 'N':
continue
# 偶数处理
if max_w % 2:
max_w += 1
if max_h % 2:
max_h += 1
folder = os.path.exists(psd_name[:-4])
if not folder: #判断是否存在文件夹如果不存在则创建为文件夹
os.makedirs(psd_name[:-4])
for layer in layer_list:
print('descendants ', layer)
x_coord, y_coord, image_name, translation, Original = extractLayerImge(layer)
# 处理单元格索引
x_coord_index = x_coord_column + str(start_line_number)
y_coord_index = y_coord_column + str(start_line_number)
width_index = width_column + str(start_line_number)
height_index = height_column + str(start_line_number)
image_name_index = image_name_colum + str(start_line_number)
translation_index = translation_column + str(start_line_number)
Original_index = Original_column + str(start_line_number)
sheet1[x_coord_index] = x_coord
sheet1[y_coord_index] = y_coord
sheet1[width_index] = max_w
sheet1[height_index] = max_h
sheet1[image_name_index] = image_name
sheet1[translation_index] = translation
sheet1[Original_index] = Original
start_line_number += 1
wb.save('image coordinate size.xlsx')
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'cti_pic_ui.ui'
#
# Created by: PyQt5 UI code generator 5.15.4
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(571, 368)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.verticalLayout_3 = QtWidgets.QVBoxLayout(self.centralwidget)
self.verticalLayout_3.setObjectName("verticalLayout_3")
self.stackedWidget = QtWidgets.QStackedWidget(self.centralwidget)
self.stackedWidget.setObjectName("stackedWidget")
self.page = QtWidgets.QWidget()
self.page.setObjectName("page")
self.horizontalLayout_4 = QtWidgets.QHBoxLayout(self.page)
self.horizontalLayout_4.setObjectName("horizontalLayout_4")
self.widget_3 = QtWidgets.QWidget(self.page)
self.widget_3.setObjectName("widget_3")
self.horizontalLayout = QtWidgets.QHBoxLayout(self.widget_3)
self.horizontalLayout.setObjectName("horizontalLayout")
self.widget_2 = QtWidgets.QWidget(self.widget_3)
self.widget_2.setObjectName("widget_2")
self.horizontalLayout_3 = QtWidgets.QHBoxLayout(self.widget_2)
self.horizontalLayout_3.setObjectName("horizontalLayout_3")
self.lab_pic_name = QtWidgets.QLabel(self.widget_2)
self.lab_pic_name.setObjectName("lab_pic_name")
self.horizontalLayout_3.addWidget(self.lab_pic_name)
self.let_psd_name = QtWidgets.QLineEdit(self.widget_2)
self.let_psd_name.setClearButtonEnabled(True)
self.let_psd_name.setObjectName("let_psd_name")
self.horizontalLayout_3.addWidget(self.let_psd_name)
self.btn_select_file = QtWidgets.QPushButton(self.widget_2)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(20)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.btn_select_file.sizePolicy().hasHeightForWidth())
self.btn_select_file.setSizePolicy(sizePolicy)
self.btn_select_file.setMinimumSize(QtCore.QSize(23, 23))
self.btn_select_file.setMaximumSize(QtCore.QSize(23, 23))
self.btn_select_file.setObjectName("btn_select_file")
self.horizontalLayout_3.addWidget(self.btn_select_file)
self.btn_analysis = QtWidgets.QPushButton(self.widget_2)
self.btn_analysis.setObjectName("btn_analysis")
self.horizontalLayout_3.addWidget(self.btn_analysis)
self.horizontalLayout.addWidget(self.widget_2)
self.widget = QtWidgets.QWidget(self.widget_3)
self.widget.setObjectName("widget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.widget)
self.verticalLayout.setObjectName("verticalLayout")
self.cbx_equal_size = QtWidgets.QCheckBox(self.widget)
self.cbx_equal_size.setChecked(True)
self.cbx_equal_size.setAutoRepeat(False)
self.cbx_equal_size.setAutoExclusive(False)
self.cbx_equal_size.setTristate(False)
self.cbx_equal_size.setObjectName("cbx_equal_size")
self.verticalLayout.addWidget(self.cbx_equal_size)
self.cbx_english = QtWidgets.QCheckBox(self.widget)
self.cbx_english.setObjectName("cbx_english")
self.verticalLayout.addWidget(self.cbx_english)
self.cbx_equal_position = QtWidgets.QCheckBox(self.widget)
self.cbx_equal_position.setObjectName("cbx_equal_position")
self.verticalLayout.addWidget(self.cbx_equal_position)
self.cbx_show = QtWidgets.QCheckBox(self.widget)
self.cbx_show.setObjectName("cbx_show")
self.verticalLayout.addWidget(self.cbx_show)
self.cbx_english.raise_()
self.cbx_equal_position.raise_()
self.cbx_show.raise_()
self.cbx_equal_size.raise_()
self.horizontalLayout.addWidget(self.widget)
self.horizontalLayout_4.addWidget(self.widget_3)
self.stackedWidget.addWidget(self.page)
self.page_2 = QtWidgets.QWidget()
self.page_2.setObjectName("page_2")
self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.page_2)
self.verticalLayout_2.setObjectName("verticalLayout_2")
self.scrollArea = QtWidgets.QScrollArea(self.page_2)
self.scrollArea.setMinimumSize(QtCore.QSize(0, 115))
self.scrollArea.setWidgetResizable(True)
self.scrollArea.setObjectName("scrollArea")
self.scrollAreaWidgetContents = QtWidgets.QWidget()
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 533, 256))
self.scrollAreaWidgetContents.setMinimumSize(QtCore.QSize(0, 0))
self.scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents")
self.verticalLayout_4 = QtWidgets.QVBoxLayout(self.scrollAreaWidgetContents)
self.verticalLayout_4.setContentsMargins(2, 2, 3, 12)
self.verticalLayout_4.setObjectName("verticalLayout_4")
self.lwg_confirmed = QtWidgets.QListWidget(self.scrollAreaWidgetContents)
font = QtGui.QFont()
font.setFamily("方正姚体")
font.setPointSize(12)
self.lwg_confirmed.setFont(font)
self.lwg_confirmed.viewport().setProperty("cursor", QtGui.QCursor(QtCore.Qt.PointingHandCursor))
self.lwg_confirmed.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
self.lwg_confirmed.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.lwg_confirmed.setViewMode(QtWidgets.QListView.ListMode)
self.lwg_confirmed.setObjectName("lwg_confirmed")
self.verticalLayout_4.addWidget(self.lwg_confirmed)
self.lib_info_data = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.lib_info_data.setMinimumSize(QtCore.QSize(0, 20))
font = QtGui.QFont()
font.setFamily("方正姚体")
font.setPointSize(9)
self.lib_info_data.setFont(font)
self.lib_info_data.setCursor(QtGui.QCursor(QtCore.Qt.BlankCursor))
self.lib_info_data.setAlignment(QtCore.Qt.AlignCenter)
self.lib_info_data.setObjectName("lib_info_data")
self.verticalLayout_4.addWidget(self.lib_info_data)
self.scrollArea.setWidget(self.scrollAreaWidgetContents)
self.verticalLayout_2.addWidget(self.scrollArea)
self.btnb_confirmed = QtWidgets.QDialogButtonBox(self.page_2)
self.btnb_confirmed.setOrientation(QtCore.Qt.Horizontal)
self.btnb_confirmed.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok|QtWidgets.QDialogButtonBox.Reset)
self.btnb_confirmed.setCenterButtons(True)
self.btnb_confirmed.setObjectName("btnb_confirmed")
self.verticalLayout_2.addWidget(self.btnb_confirmed)
self.stackedWidget.addWidget(self.page_2)
self.page_3 = QtWidgets.QWidget()
self.page_3.setObjectName("page_3")
self.buttonBox_2 = QtWidgets.QDialogButtonBox(self.page_3)
self.buttonBox_2.setGeometry(QtCore.QRect(10, 150, 341, 32))
self.buttonBox_2.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox_2.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok)
self.buttonBox_2.setObjectName("buttonBox_2")
self.stackedWidget.addWidget(self.page_3)
self.verticalLayout_3.addWidget(self.stackedWidget)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 571, 23))
self.menubar.setObjectName("menubar")
self.menu = QtWidgets.QMenu(self.menubar)
self.menu.setObjectName("menu")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.act_set_order = QtWidgets.QAction(MainWindow)
self.act_set_order.setObjectName("act_set_order")
self.menu.addAction(self.act_set_order)
self.menubar.addAction(self.menu.menuAction())
self.retranslateUi(MainWindow)
self.stackedWidget.setCurrentIndex(0)
self.lwg_confirmed.setCurrentRow(-1)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
MainWindow.setTabOrder(self.let_psd_name, self.btn_analysis)
MainWindow.setTabOrder(self.btn_analysis, self.cbx_equal_size)
MainWindow.setTabOrder(self.cbx_equal_size, self.cbx_english)
MainWindow.setTabOrder(self.cbx_english, self.cbx_equal_position)
MainWindow.setTabOrder(self.cbx_equal_position, self.cbx_show)
MainWindow.setTabOrder(self.cbx_show, self.scrollArea)
MainWindow.setTabOrder(self.scrollArea, self.lwg_confirmed)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "切图"))
self.lab_pic_name.setText(_translate("MainWindow", "PSD名字:"))
self.btn_select_file.setText(_translate("MainWindow", "…"))
self.btn_analysis.setText(_translate("MainWindow", "解析"))
self.cbx_equal_size.setText(_translate("MainWindow", "等大"))
self.cbx_english.setText(_translate("MainWindow", "英文"))
self.cbx_equal_position.setText(_translate("MainWindow", "共位"))
self.cbx_show.setText(_translate("MainWindow", "显示"))
self.lib_info_data.setText(_translate("MainWindow", "你好世界"))
self.menu.setTitle(_translate("MainWindow", "设置"))
self.act_set_order.setText(_translate("MainWindow", "替换规则"))
import os
import time
def to_exe():
# 改这两个
# 主要的py,py入口
main_py = "agasdfa.py"
# 其他导入的py文件
# secondary = [
# "comm_class.py",
# "cut_pic.py",
# "outputUI.py",
# ]
# 希望cmd黑窗口看见就注销下面-w这句话
can_see_cmd = " "
can_see_cmd = "-w "
#pic同上
pic = ""
# pic = "-i pic/COM001.ico "
ver_info = ''
# with open('version_info.txt', encoding="utf-8") as file_info_obj:
# ver_info = file_info_obj.read()
# print("现在的版本为:", ver_info)
# ver_info = input("请输入新的版本号(输入\\q取消):\n\t")
# if ver_info == '\\q':
# return
# print("新的版本为:", ver_info)
print('->>del '+main_py[:-2] + 'spec')
os.system('del '+main_py[:-2] + 'spec')
# secondary_pys = "-p "
# for i in range(len(secondary)):
# secondary_pys += secondary[i]
# if i != len(secondary)-1:
# secondary_pys += ";"
# secondary_pys += " "
secondary_pys = ""
main_py = "-F "+main_py+" "
print("->>pyinstaller " + pic +main_py+secondary_pys+can_see_cmd)
os.system("pyinstaller " + pic +main_py+secondary_pys+can_see_cmd)
# 记录版本
# with open('version_info.txt', 'w') as file_info_obj:
# file_info_obj.write(ver_info)
# # ver_info = file_info_obj.read();
# # 获取名字信息
# strname = ''
# if os.path.isfile('name'):
# with open('name', 'r', encoding='UTF-8') as file_name_obj:
# strname = file_name_obj.read()
# else:
# strname = os.environ['USERNAME']
# # 在版本日志中记录版本
# with open('version_info_log.txt', 'a') as file_log_obj:
# str_time = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
# file_log_obj.write(str_time + '\t' + strname + '\tpyserial_demo_V' + ver_info + '\n')
# os.rename('dist\\pyserial_demo.exe', 'dist\\pyserial_demo_V'+ver_info+'.exe')
print("#OK!#\n#成功!#")
if __name__ == '__main__':
to_exe()
from translate import Translator
def translate_text(text):
translator = Translator(from_lang='chinese', to_lang='english')
translation = translator.translate(text)
return translation
# 要翻译的中文文本
chinese_text = "右走条"
# 进行翻译
english_text = translate_text(chinese_text)
# 打印翻译结果
print(english_text)
# import resource
import os
import sys
import time
from ctypes import *
from threading import Thread
import numpy as np
# import numpy.ctypeslib as npct
# import serial
# import serial.tools.list_ports
from PyQt5 import QtWidgets
from PyQt5.QtCore import QSize, QTimer, pyqtSignal
from PyQt5.QtWidgets import (QApplication, QListWidgetItem, QMessageBox,
QStatusBar, QStyleFactory, QFileDialog)
from comm_class import flag_data, lay_item
from cut_pic import extractLayerImge, get_lay_info
from outputUI import Ui_MainWindow as Ui_Form
fozu = r"""
##################################################################
# _ooOoo_ #
# o8888888o #
# 88" . "88 #
# (| -|- |) #
# O\ = /O #
# ____/`---'\____ #
# .' \\| |# `. #
# / \\||| : |||# \ #
# / _||||| -:- |||||- \ #
# | | \\\ - #/ | | #
# | \_| ''\---/'' | | #
# \ .-\__ `-` ___/-. / #
# ___`. .' /--.--\ `. . ___ #
# ."" '< `.___\_<|>_/___.' >'"". #
# | | : `- \`.;`\ _ /`;.`/ - ` : | | #
# \ \ `-. \_ __\ /__ _/ .-` / / #
# ========`-.____`-.___\_____/___.-`____.-'======== #
# `=---=' #
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #
# 佛祖保佑 永无BUG 永不修改 #
##################################################################
"""
print(fozu)
class Pyqt5_Cut_psd(QtWidgets.QMainWindow, Ui_Form):
# 定义信号
cut_info_signal = pyqtSignal(int, str)
cut_info_ok = pyqtSignal()
cut_info_error = pyqtSignal()
flag_stop_cut_pic_t = False
def __init__(self, parent = None) -> None:
super(Pyqt5_Cut_psd, self).__init__()
self.setupUi(self)
self.lay_info_s:list[lay_item]
# self.statusbar.showMessage("初始化中")
self.cut_pic_t = Thread(target=self.cut_pic_thread)
# ui初始化状态
self.__init()
# 设置链接
self.connects()
def __init(self):
self.stackedWidget.setCurrentIndex(0)
self.let_psd_name.clear()
def __add_item(self, layer_data:lay_item):
temp_item = QListWidgetItem()
temp_item.setSizeHint(QSize(self.lwg_confirmed.widght(), 16))
temp_item.setText(str(layer_data))
self.lwg_confirmed.addItem(temp_item)
# 读取文件地址
def __read_file_path(self):
file_path = QFileDialog.getOpenFileName(self, "选择PSD文件", os.getcwd(), '表格文件(*.psd)')
if (file_path != ''):
self.let_psd_name.setText(file_path[0])
print(file_path)
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)
def __btnb_confirmed(self, btn):
if btn.text() == "Reset":
self.__analysis_psd()
self.flag_stop_cut_pic_t = True
elif btn.text() == "OK":
self.cut_pic_t.start()
del self.cut_pic_t
self.cut_pic_t = Thread(target=self.cut_pic_thread)
pass
elif btn.text() == "Cancel":
self.statusbar.clearMessage()
self.stackedWidget.setCurrentIndex(0)
self.flag_stop_cut_pic_t = True
pass
def cut_pic_ok(self):
QMessageBox.information(self, "成功", '图片已经切成功放入对应文件夹中,\n坐标位于《image coordinate size.xlsx》文件中。', QMessageBox.Yes, QMessageBox.Yes)
self.statusbar.clearMessage()
def cut_pic_error(self):
QMessageBox.critical(self, "错误", '未知的错误,已暂停', QMessageBox.Yes, QMessageBox.Yes)
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)
self.cut_info_ok.emit()
def connects(self):
self.btn_analysis.clicked.connect(self.__analysis_psd)
self.btnb_confirmed.clicked.connect(self.__btnb_confirmed)
self.cut_info_ok.connect(self.cut_pic_ok)
self.cut_info_error.connect(self.cut_pic_error)
self.btn_select_file.clicked.connect(self.__read_file_path)
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
myshow = Pyqt5_Cut_psd()
myshow.show()
sys.exit(app.exec_())
import os
def ui_to_py():
import time as t
# 设置目标文件的名称
py_name = "outputUI.py"
# 设置要转换文件的名称
ui_name = "cti_pic_ui.ui"
prc_name = 'prc\\resources.prc'
prc_py_name = 'resource.py'
url = __file__[:-11]
# print(url[:2])
# os.system(url[:2])
# print("cd "+url)
os.system("cd "+url)
# pyside2-rcc prc\resources.prc -o resource.py
# 合成命令字符串
cmd = "pyuic5 -o "+py_name+" "+ui_name
# cmd_prc = "pyside2-rcc " + prc_name + " -o " + prc_py_name
# 执行pyserial_demo.py文件
# cmd2 = "python -u d:\\Users\\Administrator\\Desktop\\Work\\Project\\Pyserial-Demo-master\\pyserial_demo.py"
# 输出要执行的命令
print("->>" + cmd)
# 执行命令
os.system(cmd)
# print("->>" + cmd_prc)
# os.system(cmd_prc)
print("#转换完成!#")
# os.system(cmd2)
if __name__ == '__main__':
ui_to_py()
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