2022-07-25 22:02:45 +08:00
|
|
|
|
import os.path
|
2022-08-26 17:30:42 +08:00
|
|
|
|
import error
|
2022-07-25 20:32:25 +08:00
|
|
|
|
from ui.mainwindow import Ui_mainWindow
|
|
|
|
|
|
|
|
|
|
|
|
from PyQt6 import QtWidgets
|
2022-08-26 17:30:42 +08:00
|
|
|
|
from PyQt6.QtWidgets import QMainWindow, QFileDialog, QMessageBox, QToolBar
|
|
|
|
|
|
from PyQt6.QtCore import QSettings, QFileInfo, Qt
|
|
|
|
|
|
from PyQt6.QtGui import QAction
|
2022-07-25 20:32:25 +08:00
|
|
|
|
import datetime
|
|
|
|
|
|
from PWFile import ControlFile
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MainWindow(QMainWindow, Ui_mainWindow):
|
2022-08-26 17:30:42 +08:00
|
|
|
|
@staticmethod
|
|
|
|
|
|
def _test_if_file_occupied(file_path):
|
2022-07-25 22:02:45 +08:00
|
|
|
|
if not os.path.exists(file_path):
|
|
|
|
|
|
return False
|
|
|
|
|
|
try:
|
|
|
|
|
|
with open(file_path, "wb") as file:
|
|
|
|
|
|
pass
|
|
|
|
|
|
return False
|
|
|
|
|
|
except PermissionError:
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
2022-07-25 20:32:25 +08:00
|
|
|
|
def open_dialog(self):
|
|
|
|
|
|
z_control_file_paths = QFileDialog.getOpenFileNames(
|
|
|
|
|
|
self,
|
|
|
|
|
|
"打开Excel文件",
|
|
|
|
|
|
filter="Excel 文件(*.xlsx)",
|
|
|
|
|
|
directory=self._setting.value("last_working_directory"),
|
|
|
|
|
|
)[0]
|
|
|
|
|
|
for z_control_file_path in z_control_file_paths:
|
|
|
|
|
|
if z_control_file_path != "":
|
2022-07-27 22:55:44 +08:00
|
|
|
|
cf = ControlFile(
|
|
|
|
|
|
z_control_file_path,
|
|
|
|
|
|
close_cad_document=self.cBCloseCadDoc.isChecked(),
|
|
|
|
|
|
)
|
2022-07-25 22:02:45 +08:00
|
|
|
|
if self._test_if_file_occupied(cf.get_zt_dwg_file_path()):
|
|
|
|
|
|
QMessageBox.warning(
|
|
|
|
|
|
self, "注意", f"{cf.get_zt_dwg_file_path()}被占用,请先关闭。"
|
|
|
|
|
|
)
|
|
|
|
|
|
return
|
2022-08-26 17:30:42 +08:00
|
|
|
|
try:
|
|
|
|
|
|
cf.draw()
|
|
|
|
|
|
except error.DWGFileNotExistError as dwg_not_exist_exception:
|
|
|
|
|
|
QMessageBox.warning(
|
|
|
|
|
|
self,
|
|
|
|
|
|
"错误",
|
|
|
|
|
|
f"DWG文件{dwg_not_exist_exception.not_exist_dwg_file_path}不存在。",
|
|
|
|
|
|
)
|
|
|
|
|
|
continue
|
2022-07-25 20:32:25 +08:00
|
|
|
|
self.statusBar().showMessage(
|
|
|
|
|
|
f"{datetime.datetime.now()} Finished.", 8000
|
|
|
|
|
|
)
|
|
|
|
|
|
file_info = QFileInfo(z_control_file_path)
|
|
|
|
|
|
self._setting.setValue(
|
|
|
|
|
|
"last_working_directory", file_info.absoluteDir().absolutePath()
|
|
|
|
|
|
)
|
2022-08-06 23:08:32 +08:00
|
|
|
|
zfile_name = file_info.baseName()
|
|
|
|
|
|
QMessageBox.information(self, "提示", zfile_name + "断面图已生成。")
|
2022-07-27 22:55:44 +08:00
|
|
|
|
|
2022-07-26 18:22:28 +08:00
|
|
|
|
def _cBCloseCadDocClicked(self):
|
2022-07-27 22:55:44 +08:00
|
|
|
|
self._setting.setValue("close_cad", self.cBCloseCadDoc.isChecked())
|
|
|
|
|
|
|
2022-07-25 20:32:25 +08:00
|
|
|
|
def __init__(self, parent=None):
|
|
|
|
|
|
super().__init__(parent)
|
|
|
|
|
|
self.setupUi(self)
|
|
|
|
|
|
self.pBOpenControlZFile.clicked.connect(self.open_dialog)
|
|
|
|
|
|
self._setting = QSettings("NWEPDI", "Plate", self)
|
2022-07-27 22:55:44 +08:00
|
|
|
|
if not self._setting.value("close_cad"):
|
2022-07-26 18:22:28 +08:00
|
|
|
|
self.cBCloseCadDoc.setChecked(False)
|
|
|
|
|
|
else:
|
2022-07-27 22:55:44 +08:00
|
|
|
|
self.cBCloseCadDoc.setChecked(self._setting.value("close_cad", type=bool))
|
2022-07-26 18:22:28 +08:00
|
|
|
|
self.cBCloseCadDoc.clicked.connect(self._cBCloseCadDocClicked)
|
2022-08-26 17:30:42 +08:00
|
|
|
|
self._toolbar = QToolBar(self)
|
|
|
|
|
|
toolbar = self._toolbar
|
|
|
|
|
|
toolbar.setAllowedAreas(Qt.ToolBarArea.TopToolBarArea)
|
|
|
|
|
|
toolbar.setMovable(False)
|
|
|
|
|
|
about_action = QAction("注意事项", self)
|
|
|
|
|
|
about_action.triggered.connect(
|
|
|
|
|
|
lambda: QMessageBox.information(
|
|
|
|
|
|
self, "注意", "注意检查excel表格是否有电气科权限,wps是否安装了vba。"
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
|
|
|
|
|
toolbar.addAction(about_action)
|
|
|
|
|
|
self.addToolBar(toolbar)
|
2022-07-25 20:32:25 +08:00
|
|
|
|
pass
|