parent
e4754a3193
commit
3f1560402a
20
PWFile.py
20
PWFile.py
|
|
@ -1,6 +1,8 @@
|
|||
import os.path
|
||||
from collections import OrderedDict
|
||||
import re
|
||||
|
||||
import attrs
|
||||
import pandas as pd
|
||||
from attrs import define
|
||||
from tkinter.messagebox import NO
|
||||
|
|
@ -509,6 +511,7 @@ class ContinuousPlate:
|
|||
|
||||
@define
|
||||
class ControlFile:
|
||||
_z_excel_file_path: bool = attrs.field(init=True, kw_only=False)
|
||||
_z_file_path: str = ""
|
||||
_dwg_file_path: str = ""
|
||||
_from_tower_name: str = ""
|
||||
|
|
@ -519,8 +522,11 @@ class ControlFile:
|
|||
_s_file_path: str = ""
|
||||
_dir_prefix: str = ""
|
||||
_z_file_name: str = ""
|
||||
|
||||
def __init__(self, z_excel_file_path):
|
||||
_close_cad_document: bool = attrs.field(init=True, kw_only=False, default=True)
|
||||
# def __init__(self, z_excel_file_path):
|
||||
def __attrs_post_init__(self):
|
||||
# self._close_cad_document=close_cad_document
|
||||
z_excel_file_path = self._z_excel_file_path
|
||||
excel_pf = pd.read_excel(z_excel_file_path)
|
||||
pf_dict = excel_pf.to_dict("records")[0]
|
||||
z_excel_path = os.path.split(z_excel_file_path)
|
||||
|
|
@ -537,6 +543,9 @@ class ControlFile:
|
|||
self._dwg_file_path = os.path.join(dir_prefix, pf_dict["DWG文件"])
|
||||
self._s_file_path = os.path.join(dir_prefix, pf_dict["S文件"])
|
||||
|
||||
def get_zt_dwg_file_path(self): # 获得生成的dwg文件名路径
|
||||
return os.path.join(self._dir_prefix, "ZT" + self._z_file_name + ".dwg")
|
||||
|
||||
def draw(self):
|
||||
continousePlate = ContinuousPlate(
|
||||
self._dwg_file_path,
|
||||
|
|
@ -555,7 +564,6 @@ class ControlFile:
|
|||
)
|
||||
string_impact_plate.draw()
|
||||
cad = continousePlate.cad
|
||||
cad.doc.SaveAs(
|
||||
os.path.join(self._dir_prefix, "ZT" + self._z_file_name + ".dwg")
|
||||
)
|
||||
cad.doc.Close(False)
|
||||
cad.doc.SaveAs(self.get_zt_dwg_file_path())
|
||||
if self._close_cad_document:
|
||||
cad.doc.Close(False)
|
||||
|
|
|
|||
19
gui.py
19
gui.py
|
|
@ -1,3 +1,5 @@
|
|||
import os.path
|
||||
|
||||
from ui.mainwindow import Ui_mainWindow
|
||||
|
||||
from PyQt6 import QtWidgets
|
||||
|
|
@ -8,6 +10,16 @@ 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,
|
||||
|
|
@ -17,7 +29,12 @@ class MainWindow(QMainWindow, Ui_mainWindow):
|
|||
)[0]
|
||||
for z_control_file_path in z_control_file_paths:
|
||||
if z_control_file_path != "":
|
||||
cf = ControlFile(z_control_file_path)
|
||||
cf = ControlFile(z_control_file_path,close_cad_document=False)
|
||||
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
|
||||
|
|
|
|||
Loading…
Reference in New Issue