1.添加注意事项。

2.判断dwg文件是否存在。
3.添加了error。
This commit is contained in:
n3040 2022-08-26 17:30:42 +08:00
parent 64973f9df5
commit ce1ff065d1
3 changed files with 41 additions and 10 deletions

View File

@ -11,7 +11,7 @@ import numpy as np
from time import sleep from time import sleep
from attrs import define from attrs import define
from typing import List from typing import List
import error
@define @define
class SEntry: class SEntry:
@ -633,23 +633,25 @@ class ControlFile:
return os.path.join(self._dir_prefix, "ZT" + self._z_file_name + ".dwg") return os.path.join(self._dir_prefix, "ZT" + self._z_file_name + ".dwg")
def draw(self): def draw(self):
continousePlate = ContinuousPlate( if not os.path.exists(self._dwg_file_path):
raise error.DWGFileNotExistError(self._dwg_file_path)
continuous_plate = ContinuousPlate(
self._dwg_file_path, self._dwg_file_path,
self._s_file_path, self._s_file_path,
self._from_tower_name, self._from_tower_name,
self._end_tower_name, self._end_tower_name,
) )
continousePlate.draw() continuous_plate.draw()
string_impact_plate = StringImpactPlate( string_impact_plate = StringImpactPlate(
self._dwg_file_path, self._dwg_file_path,
self._s_file_path, self._s_file_path,
self._from_tower_name, self._from_tower_name,
self._excel_continuous_path, self._excel_continuous_path,
self._excel_string_weight_path, self._excel_string_weight_path,
continousePlate.cad, continuous_plate.cad,
) )
string_impact_plate.draw() string_impact_plate.draw()
cad = continousePlate.cad cad = continuous_plate.cad
cad.doc.SaveAs(self.get_zt_dwg_file_path()) cad.doc.SaveAs(self.get_zt_dwg_file_path())
# # 画完后再打开 # # 画完后再打开
# cad = None # cad = None

7
error.py Normal file
View File

@ -0,0 +1,7 @@
import attrs
@attrs.define
class DWGFileNotExistError(Exception):
not_exist_dwg_file_path: str
pass

32
gui.py
View File

@ -1,16 +1,18 @@
import os.path import os.path
import error
from ui.mainwindow import Ui_mainWindow from ui.mainwindow import Ui_mainWindow
from PyQt6 import QtWidgets from PyQt6 import QtWidgets
from PyQt6.QtWidgets import QMainWindow, QFileDialog, QMessageBox, QStatusBar from PyQt6.QtWidgets import QMainWindow, QFileDialog, QMessageBox, QToolBar
from PyQt6.QtCore import QSettings, QFileInfo from PyQt6.QtCore import QSettings, QFileInfo, Qt
from PyQt6.QtGui import QAction
import datetime import datetime
from PWFile import ControlFile from PWFile import ControlFile
class MainWindow(QMainWindow, Ui_mainWindow): class MainWindow(QMainWindow, Ui_mainWindow):
def _test_if_file_occupied(self, file_path): @staticmethod
def _test_if_file_occupied(file_path):
if not os.path.exists(file_path): if not os.path.exists(file_path):
return False return False
try: try:
@ -38,7 +40,15 @@ class MainWindow(QMainWindow, Ui_mainWindow):
self, "注意", f"{cf.get_zt_dwg_file_path()}被占用,请先关闭。" self, "注意", f"{cf.get_zt_dwg_file_path()}被占用,请先关闭。"
) )
return return
cf.draw() 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
self.statusBar().showMessage( self.statusBar().showMessage(
f"{datetime.datetime.now()} Finished.", 8000 f"{datetime.datetime.now()} Finished.", 8000
) )
@ -62,4 +72,16 @@ class MainWindow(QMainWindow, Ui_mainWindow):
else: else:
self.cBCloseCadDoc.setChecked(self._setting.value("close_cad", type=bool)) self.cBCloseCadDoc.setChecked(self._setting.value("close_cad", type=bool))
self.cBCloseCadDoc.clicked.connect(self._cBCloseCadDocClicked) self.cBCloseCadDoc.clicked.connect(self._cBCloseCadDocClicked)
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)
pass pass