1 Star 0 Fork 0

huanghuagang / OfficeAssistant

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
my_ui.py 7.40 KB
一键复制 编辑 原始数据 按行查看 历史
huanghuagang 提交于 2021-12-24 21:37 . 添加设置菜单
import shutil
import subprocess
import uuid
from PyQt5.QtCore import Qt, QThreadPool
from PyQt5.QtWidgets import QMainWindow, QFileDialog, QListWidgetItem, QMessageBox, QLabel, QLineEdit, QFormLayout, \
QProgressBar
import logic
from read_config import FIELD, PATHS, CONFIG, INVOKE, LINK, APPEARANCE
from ui import Ui_MainWindow
import os
from update import DownloadThread
class MainWindow(QMainWindow):
def closeEvent(self, *args, **kwargs):
CONFIG.save()
self.x()
def edit_text_change_holder(line_edit, section, key):
line_edit.textChanged.connect(lambda x: section.set(key, x))
def err_message(value):
msg = QMessageBox(QMessageBox.Critical, "错误", value)
msg.setStandardButtons(QMessageBox.Yes)
btn = msg.button(QMessageBox.Yes)
btn.setText("知道了")
msg.exec_()
def success_message():
msg = QMessageBox(QMessageBox.Information, "提示", "下手成功")
msg.setStandardButtons(QMessageBox.Yes)
btn = msg.button(QMessageBox.Yes)
btn.setText("知道了")
msg.exec_()
def get_effective_name(path):
suffix = os.path.splitext(path)[1]
name = uuid.uuid4()
while os.path.exists(f"./resource/{name}{suffix}"):
name = uuid.uuid4()
return f"./resource/{name}{suffix}"
class MyUi:
def __init__(self):
# noinspection PyArgumentList
self.main_window = MainWindow()
self.ui = Ui_MainWindow()
self.ui.setupUi(self.main_window)
self.status_bar = self.main_window.statusBar()
self.work = logic.Summary
self.thread_pools = QThreadPool()
self.ui.add_filesbtn.clicked.connect(self.add_files_btn_holder)
self.ui.summary_btn.clicked.connect(self.summary_btn_holder)
self.ui.generate_btn.clicked.connect(self.generate_btn_holder)
self.ui.import_invoke_btn.clicked.connect(self.import_invoke_holder)
self.ui.add_link_btn.clicked.connect(self.add_link_holder)
self.ui.import_link_btn.clicked.connect(self.import_link_holder)
self.ui.start_btn.clicked.connect(self.start_btn_holder)
self.ui.shopping.clicked.connect(self.shopping_btn_holder)
self.ui.setStartScreen.triggered.connect(self.set_start_screen_holder)
self.ui.summary_btn.click()
def add_files(self, files):
for file in files:
item = QListWidgetItem(file)
if (len(self.ui.file_list.findItems(file, Qt.MatchExactly))) > 0:
continue
self.ui.file_list.addItem(item)
def set_start_screen_holder(self):
# noinspection PyArgumentList
path = QFileDialog.getOpenFileName(
self.main_window, "选择启动图像", PATHS["open_image_default"],
"图片(*.jpg;*.jpeg;*.jpe;*.jfif;*.png)", )[0]
if path:
new = get_effective_name(path)
shutil.copyfile(path, new)
APPEARANCE["start_screen"] = new
PATHS["open_image_default"] = os.path.dirname(path)
def add_files_btn_holder(self):
# noinspection PyArgumentList
paths = QFileDialog.getOpenFileNames(
self.main_window, "选择文件", PATHS["openfile_default"], "Excel文件(*.xls;*.xlsx)")[0]
if paths:
self.add_files(paths)
PATHS["openfile_default"] = os.path.dirname(paths[0])
def summary_btn_holder(self):
summary_attrs = [("依据字段", FIELD, "basis"), ("汇总字段", FIELD, "summary")]
self.work = logic.Summary
self.change_attr(summary_attrs)
def shopping_btn_holder(self):
self.work = logic.Shopping
self.change_attr([
("用户名", LINK, "username"),
("密码", LINK, "password"),
("单价字段", FIELD, "unit_price"),
("链接字段", FIELD, "link"),
("数量字段", FIELD, "count"),
])
def generate_btn_holder(self):
self.work = logic.GetInvoke
self.change_attr([
("税率", INVOKE, "tax_rate"),
("版本号", INVOKE, "version"),
("商品字段", FIELD, "product_name"),
("单价字段", FIELD, "unit_price"),
("金额字段", FIELD, "amount_price"),
("单位字段", FIELD, "unit"),
("数量字段", FIELD, "count"),
])
def import_invoke_holder(self):
self.work = logic.UploadInvoke
self.change_attr([
("商品字段", FIELD, "product_name"),
("简名字段", FIELD, "brief_name"),
("编码字段", FIELD, "tax_code"),
])
def add_link_holder(self):
self.work = logic.GetLink
self.change_attr([
("商品字段", FIELD, "product_name"),
("单价字段", FIELD, "unit_price"),
("链接字段", FIELD, "link"),
("数量字段", FIELD, "count"),
])
def import_link_holder(self):
self.work = logic.UploadLink
self.change_attr([
("商品字段", FIELD, "product_name"),
("单价字段", FIELD, "unit_price"),
("链接字段", FIELD, "link"),
])
def add_file(self, path):
if path:
self.ui.file_list.addItem(path)
def start_btn_holder(self):
paths = []
for i in range(self.ui.file_list.count()):
paths.append(self.ui.file_list.item(i).text())
self.ui.file_list.clear()
for path in paths:
work = logic.Work(self.work(path))
work.signals.result.connect(self.add_file)
work.signals.error.connect(err_message)
work.signals.finished.connect(success_message)
self.thread_pools.start(work)
def change_attr(self, widgets):
for i in range(self.ui.attribute_form.rowCount()):
self.ui.attribute_form.removeRow(0)
j = 0
for k in widgets:
text = k[0]
section = k[1]
key = k[2]
label = QLabel(self.ui.formLayoutWidget)
self.ui.attribute_form.setWidget(j, QFormLayout.LabelRole, label)
label.setText(text)
line_edit = QLineEdit(self.ui.formLayoutWidget)
line_edit.setText(section[key])
edit_text_change_holder(line_edit, section, key)
self.ui.attribute_form.setWidget(j, QFormLayout.FieldRole, line_edit)
j += 1
def download(self, url):
message = QMessageBox(QMessageBox.Question, "提示", f"要更新程序吗?")
message.setStandardButtons(QMessageBox.Yes | QMessageBox.Cancel)
btn_y = message.button(QMessageBox.Yes)
btn_c = message.button(QMessageBox.Cancel)
btn_y.setText("是")
btn_c.setText("否")
a = message.exec_()
if a == QMessageBox.Yes:
status_label = QLabel()
status_label.setText("下载进度")
progress_bar = QProgressBar()
progress_bar.setRange(0, 100)
progress_bar.setValue(0)
def set_progressbar_val(value):
progress_bar.setValue(value)
if value == 100:
self.main_window.close()
subprocess.run("setup.exe")
self.status_bar.addPermanentWidget(status_label, stretch=2)
self.status_bar.addPermanentWidget(progress_bar, stretch=10)
self.download_thread = DownloadThread(url)
self.download_thread.download_progress_signal.connect(set_progressbar_val)
self.download_thread.start()
1
https://gitee.com/huanghuagang/office-assistant.git
git@gitee.com:huanghuagang/office-assistant.git
huanghuagang
office-assistant
OfficeAssistant
master

搜索帮助