Skip to content

Commit

Permalink
refactor(Ui): 优化 UI 代码格式和结构
Browse files Browse the repository at this point in the history
- 调整代码缩进和格式,提高可读性
- 将长行代码拆分为多行,增加代码清晰度
- 统一使用 PySide6 替代 PyQt6
- 用 Slot 替代 pyqtSignal
- 删除未使用的导入
- 添加一些缺失的逗号
jerryliang122 committed Jan 8, 2025
1 parent 66a963a commit 1caa54a
Showing 8 changed files with 1,728 additions and 167 deletions.
259 changes: 210 additions & 49 deletions Ui/Ui_untitled.py

Large diffs are not rendered by default.

1,381 changes: 1,381 additions & 0 deletions Ui/untitled_ui.py

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions controllers/bill_calculate.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import sys
import os
from PyQt6.QtGui import QStandardItemModel, QStandardItem
from PyQt6.QtCore import QThread, pyqtSignal
from PyQt6.QtWidgets import (
from PySide6.QtGui import QStandardItemModel, QStandardItem
from PySide6.QtCore import QThread, Slot
from PySide6.QtWidgets import (
QListView,
QAbstractItemView,
QMainWindow,
@@ -13,38 +13,38 @@
import logging
import re

class BillCalculate():

class BillCalculate:
def __init__(self, main_window):
self.main_window = main_window
self.main_window.bill_output.clicked.connect(self.calculate_bill)
self.main_window.bill_clean.clicked.connect(self.clean)

#计算方式
def calculate(self,bill_number,separator,exclude_number):
#根据英文,分割bill_number
# 计算方式
def calculate(self, bill_number, separator, exclude_number):
# 根据英文,分割bill_number
bill_number_list = bill_number.split(separator)
new_bill_number_list = []
for i in bill_number_list:
#使用正则表达式
# 使用正则表达式
if not re.search(exclude_number, i):
new_bill_number_list.append(i)
return new_bill_number_list


def calculate_bill(self):
# 获取输入框中的值
bill_number = self.main_window.bill_number.toPlainText()
# 获取输入框分隔符
separator = self.main_window.bill_split.text()
# 输入需要剔除的编号
exclude_number = self.main_window.bill_splitout.toPlainText()
#计算
bill_number_list = self.calculate(bill_number,separator,exclude_number)
#显示到qplaintextedit
# 计算
bill_number_list = self.calculate(bill_number, separator, exclude_number)
# 显示到qplaintextedit
self.main_window.bill_out.setPlainText(str(bill_number_list))
self.main_window.bill_out2.setPlainText(str(len(bill_number_list)))

def clean(self):
self.main_window.bill_out.clear()
self.main_window.bill_out2.clear()
self.main_window.bill_number.clear()
self.main_window.bill_number.clear()
12 changes: 6 additions & 6 deletions controllers/inquiry.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import sys
import os
from PyQt6.QtGui import QStandardItemModel, QStandardItem
from PyQt6.QtCore import QThread, pyqtSignal
from PyQt6.QtWidgets import (
from PySide6.QtGui import QStandardItemModel, QStandardItem
from PySide6.QtCore import QThread, Slot
from PySide6.QtWidgets import (
QListView,
QAbstractItemView,
QMainWindow,
@@ -15,7 +15,6 @@
import logging
from utils import inquiry_smtp
from utils import port
from Ui.Ui_untitled import Ui_Form

logger = logging.getLogger("my_logger")

@@ -104,8 +103,8 @@ def delete_agent_by_port_and_name(port, name):


class AIRecognitionThread(QThread):
auto_identification_ai_finished_signal = pyqtSignal(str) # 用于传递识别结果的信号
auto_identification_ai_error_signal = pyqtSignal(str)
auto_identification_ai_finished_signal = Slot(str) # 用于传递识别结果的信号
auto_identification_ai_error_signal = Slot(str)

def __init__(self, data):
super().__init__()
@@ -143,6 +142,7 @@ def __init__(self, main_window):
self.main_window.auto_identification.clicked.connect(
self.auto_identification_ai
)

# 自动生成航线菜单栏中的内容
def get_line(self):
self.main_window.hangxian.clear()
24 changes: 12 additions & 12 deletions controllers/nomination_list_send.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import sys
import os
from PyQt6.QtGui import QStandardItemModel, QStandardItem
from PyQt6.QtCore import QThread, pyqtSignal
from PyQt6.QtWidgets import (
from PySide6.QtGui import QStandardItemModel, QStandardItem
from PySide6.QtCore import QThread, Slot
from PySide6.QtWidgets import (
QListView,
QAbstractItemView,
QMainWindow,
@@ -15,7 +15,6 @@
import logging
from utils import nomination_list_smtp
from utils import port
from Ui.Ui_untitled import Ui_Form

logger = logging.getLogger("my_logger")

@@ -118,8 +117,6 @@ def __init__(self, main_window):
self.main_window.nom_agent_delete.clicked.connect(self.delete_agent)
self.main_window.nom_file_list_update.clicked.connect(self.nomination_list_file)
self.main_window.nom_email_send.clicked.connect(self.send_email)



# 自动生成航线菜单栏中的内容
def get_line(self):
@@ -146,11 +143,11 @@ def get_port(self):
self.main_window.nom_port.clear()
self.main_window.nom_port.addItems(port)
return port

# 获取文件列表 并显示在nom_file_list
def nomination_list_file(self):
# 获取文件列表
file_list = os.listdir(os.path.join('conf','nomination_list'))
file_list = os.listdir(os.path.join("conf", "nomination_list"))
# 创建表格模型并填充数据
model = QStandardItemModel()
for file in file_list:
@@ -177,6 +174,7 @@ def get_proxy(self):
)

# 代理信息写入数据库

def write_proxy(self):
# 读取选择的港口信息
port = self.main_window.nom_port.currentText()
@@ -234,7 +232,7 @@ def delete_agent(self):
# 弹出提示信息
QMessageBox.about(self.main_window, "提示", "出现崩溃")
logger.error(e)

# 发送邮件
def send_email(self):
try:
@@ -246,8 +244,10 @@ def send_email(self):
port = self.main_window.nom_port.currentText()
# 获取从nom_file_list 中的文件名称
file_name = self.main_window.nom_file_list.selectedIndexes()
#拼接文件路径
file_path = os.path.join(os.getcwd(), 'conf','nomination_list', file_name[0].data())
# 拼接文件路径
file_path = os.path.join(
os.getcwd(), "conf", "nomination_list", file_name[0].data()
)
proxy_infos = read_email(selected_indexes[0].data(), port)
# 发送邮件
report = nomination_list_smtp.send_mail(proxy_infos, subject, file_path)
@@ -258,4 +258,4 @@ def send_email(self):
QMessageBox.about(self.main_window, "提示", "发送成功")
except Exception as e:
QMessageBox.about(self.main_window, "提示", "出现崩溃")
logger.error(e)
logger.error(e)
179 changes: 99 additions & 80 deletions controllers/warehouse_price.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import sys
import os
from PyQt6.QtGui import QStandardItemModel, QStandardItem
from PyQt6.QtCore import QThread, pyqtSignal
from PyQt6.QtWidgets import (
from PySide6.QtGui import QStandardItemModel, QStandardItem
from PySide6.QtCore import QThread, Slot
from PySide6.QtWidgets import (
QListView,
QAbstractItemView,
QMainWindow,
@@ -12,15 +12,14 @@
from utils import email_sql
import logging
import yaml
import utils.warehouse.web as web
import utils.warehouse.web as web
import utils.warehouse.cfs_wg as cfs_wg


class WebDataThread(QThread):
'''
'''
finished = pyqtSignal(dict) # 信号,用于在线程完成后发送结果
""" """

finished = Slot(dict) # 信号,用于在线程完成后发送结果

def __init__(self, cargo_data, cargo_stander):
super().__init__()
@@ -29,76 +28,79 @@ def __init__(self, cargo_data, cargo_stander):

def run(self):
# 根据仓库名称选择不同的网页抓取方式
if self.cargo_data['warehouse_name'] == '外港仓库':
if self.cargo_data["warehouse_name"] == "外港仓库":
cargo_data_web = web.web_grasp(False, self.cargo_data["cfs_number"])
web_data = cargo_data_web.get_data()
else:
cargo_data_web = web.web_grasp(True, self.cargo_data["cfs_number"])
web_data = cargo_data_web.get_data()

# 如果没有找到单号,则弹出提示框
if cargo_data_web is None:
QMessageBox.information(self.main_window, "提示", "没有找到此单号,请检查单号是否正确")
QMessageBox.information(
self.main_window, "提示", "没有找到此单号,请检查单号是否正确"
)
return

# 如果仓库标准没有设置,则弹出提示框
if all(v is not None and v != '' for v in self.cargo_stander.values()) == False:
if all(v is not None and v != "" for v in self.cargo_stander.values()) == False:
QMessageBox.information(self.main_window, "提示", "请先设置仓库标准")
return

# 获取折扣信息
discount = {
'where_cfs_discount': self.cargo_data["where_cfs_discount"],
'cfs_discount': self.cargo_data["cfs_discount"],
'cfs_discount_price': self.cargo_data["cfs_discount_price"]
"where_cfs_discount": self.cargo_data["where_cfs_discount"],
"cfs_discount": self.cargo_data["cfs_discount"],
"cfs_discount_price": self.cargo_data["cfs_discount_price"],
}

# 根据仓库名称选择不同的计算方式
if self.cargo_data["warehouse_name"] == "外港仓库":
cargo_calculate = cfs_wg.calculate_cfs_wg(web_data, self.cargo_stander, discount)
cargo_calculate = cfs_wg.calculate_cfs_wg(
web_data, self.cargo_stander, discount
)
cargo_data_calculate = cargo_calculate.main()

self.finished.emit(cargo_data_calculate) # 发送结果信号

self.finished.emit(cargo_data_calculate) # 发送结果信号


class warehouse_price():
class warehouse_price:
def __init__(self, main_window):
self.main_window = main_window
self.check_config_folder()
self.main_window.wright_yaml.clicked.connect(self.write_warehouse_stander)
self.main_window.clean_cfs_charge.clicked.connect(self.clear_field)
self.main_window.pushButton_4.clicked.connect(self.read_warehouse_stander)
self.main_window.use_cfs_numebr_calculate.clicked.connect(self.calculate_warehouse_price_no)


self.main_window.use_cfs_numebr_calculate.clicked.connect(
self.calculate_warehouse_price_no
)

#检查config文件夹中是否有warehouse,没有则创建。
# 检查config文件夹中是否有warehouse,没有则创建。
def check_config_folder(self):
if not os.path.exists("conf/warehouse"):
os.mkdir("conf/warehouse")
#当按下写入键后,写入文件到config/warehouse

# 当按下写入键后,写入文件到config/warehouse
def write_warehouse_stander(self):
stander_name = self.main_window.cfs_name.text()
BL_charge = self.main_window.cfs_bl_charge.text()
#外港上下车费
# 外港上下车费
cfs_yg_pkgs_charge = self.main_window.cfs_yg_pkgs_charge.text()
cfs_yg_weight_charge = self.main_window.cfs_yg_weight_charge.text()
cfs_yg_cmb_charge = self.main_window.cfs_yg_cmb_charge.text()
cfs_yg_mini_charge = self.main_window.cfs_yg_mini_charge.text()
#洋山收费标准
# 洋山收费标准
cfs_ys_pkgs_charge = self.main_window.cfs_ys_pkgs_charge.text()
cfs_ys_weight_charge = self.main_window.cfs_ys_weight_charge.text()
cfs_ys_cbm_charge = self.main_window.cfs_ys_cbm_charge.text()
cfs_ys_mini_charge = self.main_window.cfs_ys_mini_charge.text()
#厢式车
# 厢式车
cfs_van_charge = self.main_window.cfs_van_charge.text()
#超大费
# 超大费
cfs_ows_charge = self.main_window.cfs_ows_charge.text()
#保险费
# 保险费
cfs_Insurance_charge = self.main_window.cfs_Insurance_charge.text()
#配置成字典
# 配置成字典
cfs_stander = {
"BL_charge": BL_charge,
"cfs_yg_pkgs_charge": cfs_yg_pkgs_charge,
@@ -113,23 +115,32 @@ def write_warehouse_stander(self):
"cfs_ows_charge": cfs_ows_charge,
"cfs_Insurance_charge": cfs_Insurance_charge,
}
#检查warehouse文件夹中是否已经由对应的名称
# 检查warehouse文件夹中是否已经由对应的名称
if os.path.exists(f"conf/warehouse/{stander_name}.yaml"):
#弹出框询问是否覆盖
if QMessageBox.question(
self.main_window,
"提示",
"文件已存在,是否覆盖?",
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No,
) == QMessageBox.StandardButton.Yes:
with open(f"conf/warehouse/{stander_name}.yaml", "w", encoding="utf-8") as f:
yaml.dump(cfs_stander, f, allow_unicode=True, default_flow_style=False)
# 弹出框询问是否覆盖
if (
QMessageBox.question(
self.main_window,
"提示",
"文件已存在,是否覆盖?",
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No,
)
== QMessageBox.StandardButton.Yes
):
with open(
f"conf/warehouse/{stander_name}.yaml", "w", encoding="utf-8"
) as f:
yaml.dump(
cfs_stander, f, allow_unicode=True, default_flow_style=False
)
else:
#写入文件
with open(f"conf/warehouse/{stander_name}.yaml", "w", encoding="utf-8") as f:
# 写入文件
with open(
f"conf/warehouse/{stander_name}.yaml", "w", encoding="utf-8"
) as f:
yaml.dump(cfs_stander, f, allow_unicode=True, default_flow_style=False)

#清除字段
# 清除字段
def clear_field(self):
self.main_window.cfs_name.clear()
self.main_window.cfs_bl_charge.clear()
@@ -144,11 +155,10 @@ def clear_field(self):
self.main_window.cfs_van_charge.clear()
self.main_window.cfs_ows_charge.clear()
self.main_window.cfs_Insurance_charge.clear()
#弹框
# 弹框
QMessageBox.information(self.main_window, "提示", "清除成功")


#读取conf/warehouse 文件并呈现在QlistView中对象名为stander_list
# 读取conf/warehouse 文件并呈现在QlistView中对象名为stander_list
def read_warehouse_stander(self):
# 创建表格模型并填充数据
model = QStandardItemModel()
@@ -159,34 +169,42 @@ def read_warehouse_stander(self):
item = QStandardItem(file.replace(".yaml", ""))
model.appendRow([item])
self.main_window.stander_list.setModel(model)
self.main_window.stander_list.selectionModel().currentRowChanged.connect(self.read_and_show_warehouse_stander)
self.main_window.stander_list.selectionModel().currentRowChanged.connect(
self.read_and_show_warehouse_stander
)

#读取conf/warehouse 并写入标准的登记配置
# 读取conf/warehouse 并写入标准的登记配置
def read_and_show_warehouse_stander(self, current):
stander_name = self.main_window.stander_list.model().itemFromIndex(current)
stander_name = self.main_window.stander_list.model().itemFromIndex(current)
stander_name = stander_name.text()
with open(f"conf/warehouse/{stander_name}.yaml", "r", encoding="utf-8") as f:
cfs_stander = yaml.load(f, Loader=yaml.FullLoader)
self.main_window.cfs_name.setText(stander_name)
self.main_window.cfs_bl_charge.setText(cfs_stander['BL_charge'])
self.main_window.cfs_yg_pkgs_charge.setText(cfs_stander['cfs_yg_pkgs_charge'])
self.main_window.cfs_yg_weight_charge.setText(cfs_stander['cfs_yg_weight_charge'])
self.main_window.cfs_yg_cmb_charge.setText(cfs_stander['cfs_yg_cmb_charge'])
self.main_window.cfs_yg_mini_charge.setText(cfs_stander['cfs_yg_mini_charge'])
self.main_window.cfs_ys_pkgs_charge.setText(cfs_stander['cfs_ys_pkgs_charge'])
self.main_window.cfs_ys_weight_charge.setText(cfs_stander['cfs_ys_weight_charge'])
self.main_window.cfs_ys_cbm_charge.setText(cfs_stander['cfs_ys_cbm_charge'])
self.main_window.cfs_ys_mini_charge.setText(cfs_stander['cfs_ys_mini_charge'])
self.main_window.cfs_van_charge.setText(cfs_stander['cfs_van_charge'])
self.main_window.cfs_ows_charge.setText(cfs_stander['cfs_ows_charge'])
self.main_window.cfs_Insurance_charge.setText(cfs_stander['cfs_Insurance_charge'])

#计算仓库费用, 使用进仓费编号计算
self.main_window.cfs_bl_charge.setText(cfs_stander["BL_charge"])
self.main_window.cfs_yg_pkgs_charge.setText(cfs_stander["cfs_yg_pkgs_charge"])
self.main_window.cfs_yg_weight_charge.setText(
cfs_stander["cfs_yg_weight_charge"]
)
self.main_window.cfs_yg_cmb_charge.setText(cfs_stander["cfs_yg_cmb_charge"])
self.main_window.cfs_yg_mini_charge.setText(cfs_stander["cfs_yg_mini_charge"])
self.main_window.cfs_ys_pkgs_charge.setText(cfs_stander["cfs_ys_pkgs_charge"])
self.main_window.cfs_ys_weight_charge.setText(
cfs_stander["cfs_ys_weight_charge"]
)
self.main_window.cfs_ys_cbm_charge.setText(cfs_stander["cfs_ys_cbm_charge"])
self.main_window.cfs_ys_mini_charge.setText(cfs_stander["cfs_ys_mini_charge"])
self.main_window.cfs_van_charge.setText(cfs_stander["cfs_van_charge"])
self.main_window.cfs_ows_charge.setText(cfs_stander["cfs_ows_charge"])
self.main_window.cfs_Insurance_charge.setText(
cfs_stander["cfs_Insurance_charge"]
)

# 计算仓库费用, 使用进仓费编号计算
def calculate_warehouse_price_no(self):
# 定义一个字典cargo_data,用于存储货物信息
cargo_data = {
"warehouse_name":self.main_window.chose_cfs_name.currentText(), # 仓库名称
"warehouse_in_out":self.main_window.cfs_inout_chose.currentText(), # 仓库进出
"warehouse_name": self.main_window.chose_cfs_name.currentText(), # 仓库名称
"warehouse_in_out": self.main_window.cfs_inout_chose.currentText(), # 仓库进出
"cfs_pallets": self.main_window.cfs_pallets.isChecked(), # 是否有托盘
"cfs_night_in": self.main_window.cfs_night_in.isChecked(), # 是否夜间进仓
"cfs_van": self.main_window.cfs_van.isChecked(), # 是否有货车
@@ -202,18 +220,18 @@ def calculate_warehouse_price_no(self):
# 定义一个字典cargo_stander,用于存储货物标准信息
cargo_stander = {
"cfs_name": self.main_window.cfs_name.text(), # 货物名称
"cfs_bl_charge" : self.main_window.cfs_bl_charge.text(), # 货物BL费用
"cfs_yg_pkgs_charge" : self.main_window.cfs_yg_pkgs_charge.text(), # 货物运费(件数)
"cfs_yg_weight_charge" : self.main_window.cfs_yg_weight_charge.text(), # 货物运费(重量)
"cfs_yg_cmb_charge" : self.main_window.cfs_yg_cmb_charge.text(), # 货物运费(体积)
"cfs_yg_mini_charge" : self.main_window.cfs_yg_mini_charge.text(), # 货物运费(最小费用)
"cfs_ys_pkgs_charge" : self.main_window.cfs_ys_pkgs_charge.text(), # 货物运输费用(件数)
"cfs_ys_weight_charge" : self.main_window.cfs_ys_weight_charge.text(), # 货物运输费用(重量)
"cfs_ys_cbm_charge" : self.main_window.cfs_ys_cbm_charge.text(), # 货物运输费用(体积)
"cfs_bl_charge": self.main_window.cfs_bl_charge.text(), # 货物BL费用
"cfs_yg_pkgs_charge": self.main_window.cfs_yg_pkgs_charge.text(), # 货物运费(件数)
"cfs_yg_weight_charge": self.main_window.cfs_yg_weight_charge.text(), # 货物运费(重量)
"cfs_yg_cmb_charge": self.main_window.cfs_yg_cmb_charge.text(), # 货物运费(体积)
"cfs_yg_mini_charge": self.main_window.cfs_yg_mini_charge.text(), # 货物运费(最小费用)
"cfs_ys_pkgs_charge": self.main_window.cfs_ys_pkgs_charge.text(), # 货物运输费用(件数)
"cfs_ys_weight_charge": self.main_window.cfs_ys_weight_charge.text(), # 货物运输费用(重量)
"cfs_ys_cbm_charge": self.main_window.cfs_ys_cbm_charge.text(), # 货物运输费用(体积)
"cfs_ys_mini_charge": self.main_window.cfs_ys_mini_charge.text(), # 货物运输费用(最小费用)
"cfs_van_charge" : self.main_window.cfs_van_charge.text(), # 货物货车费用
"cfs_ows_charge" : self.main_window.cfs_ows_charge.text(), # 货物其他费用
"cfs_Insurance_charge" : self.main_window.cfs_Insurance_charge.text(), # 货物保险费用
"cfs_van_charge": self.main_window.cfs_van_charge.text(), # 货物货车费用
"cfs_ows_charge": self.main_window.cfs_ows_charge.text(), # 货物其他费用
"cfs_Insurance_charge": self.main_window.cfs_Insurance_charge.text(), # 货物保险费用
}
# 创建一个WebDataThread线程,用于处理货物信息
thread = WebDataThread(cargo_data, cargo_stander)
@@ -224,6 +242,7 @@ def calculate_warehouse_price_no(self):

return
# 定义一个函数update_ui_with_result,用于更新UI界面

def update_ui_with_result(self, result):
# 将计算结果输出到UI界面的cfs_price_output文本框中
self.main_window.cfs_price_output.setText(str(result))
self.main_window.cfs_price_output.setText(str(result))
10 changes: 6 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
@@ -8,8 +8,8 @@
# 没有的话新建一个conf文件夹,并执行
os.mkdir("conf")
config.config.main()
from PyQt6.QtWidgets import QApplication, QMainWindow
from Ui.Ui_untitled import Ui_Form
from PySide6.QtWidgets import QApplication, QMainWindow
from Ui.untitled_ui import Ui_Form
import sys
from controllers import work_inquiry
from controllers import warehouse_price
@@ -37,7 +37,8 @@ def __init__(self):
super().__init__()
self.setupUi(self)
# 在这里设置样式
self.setStyleSheet("""
self.setStyleSheet(
"""
QMainWindow {
background-color: #f0f0f0;
}
@@ -53,7 +54,8 @@ def __init__(self):
QLabel {
color: #333;
}
""")
"""
)
# 创建一个处理询价的实例
self.combo_box_handler = work_inquiry(self)
# 创建一个处理仓库费用计算的实例
4 changes: 1 addition & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
greenlet==3.0.3
PyQt6==6.7.0
PyQt6-Qt6==6.7.0
PyQt6-sip==13.6.0
pyside6==6.8.1.1
PyYAML==6.0.1
SQLAlchemy==2.0.30
typing_extensions==4.11.0

0 comments on commit 1caa54a

Please sign in to comment.