hytos / DTI_PID / DTI_PID / CopyDrawingDialog.py @ 1ee76b09
이력 | 보기 | 이력해설 | 다운로드 (4.19 KB)
1 |
from PyQt5.QtCore import * |
---|---|
2 |
from PyQt5.QtGui import * |
3 |
from PyQt5.QtWidgets import * |
4 |
import os |
5 |
from AppDocData import AppDocData |
6 |
import CopyDrawing_UI |
7 | |
8 |
class QCopyDrawingDialog(QDialog): |
9 |
def __init__(self, parent, drawing): |
10 |
QDialog.__init__(self, parent)
|
11 | |
12 |
self.selectedProject = None |
13 |
self.ui = CopyDrawing_UI.Ui_CopydrawingDialog()
|
14 |
self.ui.setupUi(self) |
15 |
self.drawing = drawing
|
16 |
self.isAccepted = False |
17 | |
18 |
self.ui.lineEdit_2.setText(os.path.splitext(self.drawing.name)[0]) |
19 | |
20 |
def showDialog(self): |
21 |
self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) |
22 |
self.exec_()
|
23 |
return self.isAccepted |
24 | |
25 |
def accept(self): |
26 |
if not self.validationCheck(): |
27 |
QMessageBox.warning(self, self.tr('Notice'), self.tr('Please check drawing files(png, xml) and name')) |
28 |
return
|
29 |
|
30 |
if self.copy_drawing(): |
31 |
self.isAccepted = True |
32 | |
33 |
QDialog.accept(self)
|
34 | |
35 |
def copy_drawing(self): |
36 |
from shutil import copyfile |
37 |
import uuid |
38 | |
39 |
try:
|
40 |
app_doc_data = AppDocData.instance() |
41 |
project = app_doc_data.getCurrentProject() |
42 | |
43 |
drawing_path = project.getDrawingFilePath() |
44 |
temp_path = project.getTempPath() |
45 | |
46 |
original_drawing = self.ui.lineEdit_2.text() + '.png' |
47 |
origianl_xml = self.ui.lineEdit_2.text() + '.xml' |
48 |
new_drawing = self.ui.lineEdit.text() + '.png' |
49 |
new_xml = self.ui.lineEdit.text() + '.xml' |
50 | |
51 |
original_drawing = os.path.join(drawing_path, original_drawing) |
52 |
origianl_xml = os.path.join(temp_path, origianl_xml) |
53 |
new_drawing = os.path.join(drawing_path, new_drawing) |
54 |
new_xml = os.path.join(temp_path, new_xml) |
55 | |
56 |
if os.path.exists(original_drawing) and os.path.exists(origianl_xml): |
57 |
copyfile(original_drawing, new_drawing) |
58 |
copyfile(origianl_xml, new_xml) |
59 | |
60 |
fw = open(new_xml, 'r', encoding='utf8') |
61 |
xmlCon = fw.read() |
62 |
fw.close() |
63 | |
64 |
uidList = [] |
65 | |
66 |
for index in range(len(xmlCon)): |
67 |
if len(xmlCon) - index < 36: |
68 |
break
|
69 | |
70 |
try:
|
71 |
text = xmlCon[index:index + 36]
|
72 |
uid = uuid.UUID(text) |
73 |
uidList.append(str(uid))
|
74 |
except:
|
75 |
pass
|
76 |
finally:
|
77 |
pass
|
78 | |
79 |
uidList = list(set(uidList)) |
80 |
for uid in uidList: |
81 |
xmlCon = xmlCon.replace(uid, str(uuid.uuid4()))
|
82 | |
83 |
fw = open(new_xml, 'w', encoding='utf8') |
84 |
fw.write(xmlCon) |
85 |
fw.close() |
86 | |
87 |
QMessageBox.about(self, self.tr("Information"), self.tr('Successfully copied.')) |
88 |
return True |
89 |
except Exception as ex: |
90 |
from App import App |
91 |
from AppDocData import MessageType |
92 | |
93 |
message = f"error occurred({repr(ex)}) in {sys.exc_info()[-1].tb_frame.f_code.co_filename}:" \
|
94 |
f"{sys.exc_info()[-1].tb_lineno}"
|
95 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
96 |
|
97 |
return False |
98 | |
99 |
def validationCheck(self): |
100 |
app_doc_data = AppDocData.instance() |
101 |
project = app_doc_data.getCurrentProject() |
102 | |
103 |
drawing_path = project.getDrawingFilePath() |
104 |
temp_path = project.getTempPath() |
105 |
drawing_files = [os.path.splitext(f)[0] for f in os.listdir(drawing_path) if os.path.isfile(os.path.join(drawing_path, f)) and (os.path.splitext(f)[1].upper() == '.PNG')] |
106 |
xml_files = [os.path.splitext(f)[0] for f in os.listdir(temp_path) if os.path.isfile(os.path.join(temp_path, f)) and (os.path.splitext(f)[1].upper() == '.XML')] |
107 | |
108 |
original_drawing = self.ui.lineEdit_2.text()
|
109 |
new_drawing = self.ui.lineEdit.text()
|
110 |
if original_drawing not in drawing_files or original_drawing not in xml_files: |
111 |
return False |
112 |
if new_drawing in drawing_files or new_drawing in xml_files: |
113 |
return False |
114 |
|
115 |
return True |
116 | |
117 |
def reject(self): |
118 |
QDialog.reject(self)
|