123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230 |
- # coding:utf8
- '''
- @Project :Scan
- @File :ScanInput.py
- @Author :Leslie
- @Date :2023/5/6 9:03
- '''
- import datetime
- import os
- from PyQt5.QtCore import *
- import time
- from PyQt5.QtCore import QCoreApplication, QThread, pyqtSignal, QDate
- from PyQt5.QtGui import QIcon
- from PyQt5.QtWidgets import QApplication, QWidget, QFileDialog, QPlainTextEdit, QMessageBox
- import CRC8
- from ScanUtils import Config
- from ScanUtils.Config import Configuration
- from ScanUtils.Dialogadd import Dialogadd
- from ScanUtils.ui.Scan import Ui_Form
- from VersionSet import VersionSet
- softwareIconPath = r'./pic/scan.png'
- folderName = 'material'
- # softwareIconPath = r'./pic/scan.png'
- from PyQt5.QtCore import *
- from PyQt5.QtGui import *
- from PyQt5.QtWidgets import *
- # class WorkThread(QThread):
- # sinOut = pyqtSignal(str)
- # def run(self):
- # while True:
- # time.sleep(5)
- # self.sinOut.emit("1111run")
- class ScanInput(QWidget):
- def __init__(self, versionCode,productDate, parent=None, closeToDlg=None):
- super(ScanInput, self).__init__(parent)
- self.ui = Ui_Form()
- self.ui.setupUi(self)
- self.setWindowTitle("物料扫码")
- self.setWindowIcon(QIcon(softwareIconPath))
- self.ui.versionCode.setText(versionCode)
- self.ui.Deliverydate.setText(productDate)
- self.QComboBoxnit()
- self.ui.save.clicked.connect(self.actSaveTriggered)
- self.ui.open.clicked.connect(self.actOpenTriggered)
- self.ui.materialType.currentTextChanged.connect(self.materialTypeChanged)
- # 创建保存.txt的文件夹
- self.mkdirFile()
- # 线程传参
- self.autoSave = AutoSaveThread(self)
- self.autoSave.start()
- # 下拉框属性
- def getParamDict(self):
- paramDict = Config.Configuration().getConfiguration()
- return paramDict
- # 下拉框初始化
- def QComboBoxnit(self):
- paramDict = self.getParamDict()
- for item in paramDict:
- self.ui.materialType.addItem(item)
- # 打开文件
- def actOpenTriggered(self):
- curPath = QCoreApplication.applicationDirPath()
- QMessageBox.information(self, '提示', '请选择以版本代码+发料日期为名的.txt文件')
- # 调用打开文件对话框打开一个文件
- QFileName = QFileDialog.getOpenFileName(self, "选取文件", curPath,
- "文本文件(*.txt)")
- if QFileName[0]:
- fileName = QFileName[0].split("/")[-1].split(".")[0].split("_")
- versionCode = fileName[0]
- deliveryDate = fileName[1]
- self.ui.Deliverydate.setText(deliveryDate)
- self.ui.versionCode.setText(versionCode)
- f = open(QFileName[0], 'r')
- with f:
- data = f.read()
- self.ui.plainTextEdit.setPlainText(data)
- # 文件保存
- def actSaveTriggered(self):
- desktopPath = Configuration().get_desktop()
- # print(VersionSet.getCurrentParam())
- versionCode = self.ui.versionCode.text()
- Deliverydate = self.ui.Deliverydate.text()
- filenameStr = versionCode + "_" + Deliverydate + ".txt"
- filePathName = desktopPath + '\\' + folderName + '\\' + filenameStr
- aFileName = QFileDialog.getSaveFileName(self, "另存为", filePathName, "文本文档(*.txt)")
- text = self.ui.plainTextEdit.toPlainText()
- if str(aFileName[0]) == "":
- QMessageBox.warning(self, "提示", "没有保存数据,请重新保存。")
- saveFlag = 0
- return aFileName, saveFlag
- else:
- saveFlag = 1
- try:
- with open(aFileName[0], 'w') as f:
- f.write(text)
- except Exception as e:
- QMessageBox.information(self, "提示", str(e), )
- QMessageBox.information(self, "提示", "数据文件保存成功!", QMessageBox.Ok)
- return aFileName, saveFlag
- # 物料类别选择
- def materialTypeChanged(self, materialType):
- print(materialType)
- if not materialType == '无':
- str = "= = = = = = = = = = = = " + materialType + " = = = = = = = = = = = = ="
- self.ui.plainTextEdit.insertPlainText(str + "\n")
- self.ui.plainTextEdit.insertPlainText("\n")
- # 创建保存文件的文件夹
- def mkdirFile(self):
- desktopPath = Configuration().get_desktop()
- folderNamePath = desktopPath + '\\' + folderName
- if not os.path.exists(folderNamePath):
- os.mkdir(folderNamePath)
- else:
- return True
- # 添加物料类别的界面 目前没用
- def openDialog(self):
- dialog = Dialogadd(self)
- # 连接【子窗口内置消息和主窗口的槽函数】
- # dialog.datetime.dateChanged.connect(self.slot_inner)
- # 连接【子窗口自定义消息和主窗口槽函数】
- dialog.dialogSignel.connect(self.slot_emit)
- dialog.show()
- # 自动保存 线程任务
- class AutoSaveThread(QThread):
- # 初始化传参
- def __init__(self, inputDiog,parent=None):
- super(AutoSaveThread, self).__init__(parent)
- self.inputDiog = inputDiog
- self.versionCode = inputDiog.ui.versionCode.text()
- self.deliveryDate = inputDiog.ui.Deliverydate.text()
- def run(self):
- self.loop_monitor()
- def time_printer(self):
- # 定时
- if self.inputDiog.ui.plainTextEdit.toPlainText():
- desktopPath = Configuration().get_desktop()
- versionCode = self.versionCode
- deliveryDate = self.Deliverydate
- filenameStr = versionCode+"_"+deliveryDate + ".txt"
- filePathName = desktopPath + '\\' + folderName + '\\' + filenameStr
- txt = self.inputDiog.ui.plainTextEdit.toPlainText()
- file = open(filePathName, 'w')
- file.write(txt)
- file.close()
- self.loop_monitor()
- else:
- self.loop_monitor()
- def loop_monitor(self):
- time.sleep(20)
- self.time_printer()
- if __name__ == '__main__':
- import sys
- app = QApplication(sys.argv)
- ui = ScanInput()
- ui.show()
- sys.exit(app.exec_())
|