66 lines
2.4 KiB
Python
66 lines
2.4 KiB
Python
import os.path
|
|
|
|
from ui.mainwindow import Ui_mainWindow
|
|
|
|
from PyQt6 import QtWidgets
|
|
from PyQt6.QtWidgets import QMainWindow, QFileDialog, QMessageBox, QStatusBar
|
|
from PyQt6.QtCore import QSettings, QFileInfo
|
|
import datetime
|
|
from PWFile import ControlFile
|
|
|
|
|
|
class MainWindow(QMainWindow, Ui_mainWindow):
|
|
def _test_if_file_occupied(self, file_path):
|
|
if not os.path.exists(file_path):
|
|
return False
|
|
try:
|
|
with open(file_path, "wb") as file:
|
|
pass
|
|
return False
|
|
except PermissionError:
|
|
return True
|
|
|
|
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 != "":
|
|
cf = ControlFile(
|
|
z_control_file_path,
|
|
close_cad_document=self.cBCloseCadDoc.isChecked(),
|
|
)
|
|
if self._test_if_file_occupied(cf.get_zt_dwg_file_path()):
|
|
QMessageBox.warning(
|
|
self, "注意", f"{cf.get_zt_dwg_file_path()}被占用,请先关闭。"
|
|
)
|
|
return
|
|
cf.draw()
|
|
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()
|
|
)
|
|
zfile_name = file_info.baseName()
|
|
QMessageBox.information(self, "提示", zfile_name + "断面图已生成。")
|
|
|
|
def _cBCloseCadDocClicked(self):
|
|
self._setting.setValue("close_cad", self.cBCloseCadDoc.isChecked())
|
|
|
|
def __init__(self, parent=None):
|
|
super().__init__(parent)
|
|
self.setupUi(self)
|
|
self.pBOpenControlZFile.clicked.connect(self.open_dialog)
|
|
self._setting = QSettings("NWEPDI", "Plate", self)
|
|
if not self._setting.value("close_cad"):
|
|
self.cBCloseCadDoc.setChecked(False)
|
|
else:
|
|
self.cBCloseCadDoc.setChecked(self._setting.value("close_cad", type=bool))
|
|
self.cBCloseCadDoc.clicked.connect(self._cBCloseCadDocClicked)
|
|
pass
|