eric7/Graphics/UMLDialog.py

branch
eric7
changeset 8356
68ec9c3d4de5
parent 8348
f4775ae8f441
child 8358
144a6b854f70
equal deleted inserted replaced
8355:8a7677a63c8d 8356:68ec9c3d4de5
12 12
13 from PyQt6.QtCore import pyqtSlot, Qt, QFileInfo, QCoreApplication 13 from PyQt6.QtCore import pyqtSlot, Qt, QFileInfo, QCoreApplication
14 from PyQt6.QtGui import QAction 14 from PyQt6.QtGui import QAction
15 from PyQt6.QtWidgets import QToolBar, QGraphicsScene 15 from PyQt6.QtWidgets import QToolBar, QGraphicsScene
16 16
17 from E5Gui import E5MessageBox, E5FileDialog 17 from E5Gui import EricMessageBox, EricFileDialog
18 from E5Gui.E5MainWindow import E5MainWindow 18 from E5Gui.EricMainWindow import EricMainWindow
19 19
20 import UI.Config 20 import UI.Config
21 import UI.PixmapCache 21 import UI.PixmapCache
22 22
23 23
30 IMPORTS_DIAGRAM = 2 30 IMPORTS_DIAGRAM = 2
31 APPLICATION_DIAGRAM = 3 31 APPLICATION_DIAGRAM = 3
32 NO_DIAGRAM = 255 32 NO_DIAGRAM = 255
33 33
34 34
35 class UMLDialog(E5MainWindow): 35 class UMLDialog(EricMainWindow):
36 """ 36 """
37 Class implementing a dialog showing UML like diagrams. 37 Class implementing a dialog showing UML like diagrams.
38 """ 38 """
39 FileVersions = ("1.0", ) 39 FileVersions = ("1.0", )
40 JsonFileVersions = ("1.0", ) 40 JsonFileVersions = ("1.0", )
236 236
237 @param filename name of the file to write to 237 @param filename name of the file to write to
238 @type str 238 @type str
239 """ 239 """
240 if not filename: 240 if not filename:
241 fname, selectedFilter = E5FileDialog.getSaveFileNameAndFilter( 241 fname, selectedFilter = EricFileDialog.getSaveFileNameAndFilter(
242 self, 242 self,
243 self.tr("Save Diagram"), 243 self.tr("Save Diagram"),
244 "", 244 "",
245 self.tr("Eric Graphics File (*.egj);;" 245 self.tr("Eric Graphics File (*.egj);;"
246 "Eric Text Graphics File (*.e5g);;" 246 "Eric Text Graphics File (*.e5g);;"
247 "All Files (*)"), 247 "All Files (*)"),
248 "", 248 "",
249 E5FileDialog.DontConfirmOverwrite) 249 EricFileDialog.DontConfirmOverwrite)
250 if not fname: 250 if not fname:
251 return 251 return
252 ext = QFileInfo(fname).suffix() 252 ext = QFileInfo(fname).suffix()
253 if not ext: 253 if not ext:
254 ex = selectedFilter.split("(*")[1].split(")")[0] 254 ex = selectedFilter.split("(*")[1].split(")")[0]
255 if ex: 255 if ex:
256 fname += ex 256 fname += ex
257 if QFileInfo(fname).exists(): 257 if QFileInfo(fname).exists():
258 res = E5MessageBox.yesNo( 258 res = EricMessageBox.yesNo(
259 self, 259 self,
260 self.tr("Save Diagram"), 260 self.tr("Save Diagram"),
261 self.tr("<p>The file <b>{0}</b> already exists." 261 self.tr("<p>The file <b>{0}</b> already exists."
262 " Overwrite it?</p>").format(fname), 262 " Overwrite it?</p>").format(fname),
263 icon=E5MessageBox.Warning) 263 icon=EricMessageBox.Warning)
264 if not res: 264 if not res:
265 return 265 return
266 filename = fname 266 filename = fname
267 267
268 res = self.__writeJsonGraphicsFile(filename) 268 res = self.__writeJsonGraphicsFile(filename)
280 @type str 280 @type str
281 @return flag indicating success 281 @return flag indicating success
282 @rtype bool 282 @rtype bool
283 """ 283 """
284 if not filename: 284 if not filename:
285 filename = E5FileDialog.getOpenFileName( 285 filename = EricFileDialog.getOpenFileName(
286 self, 286 self,
287 self.tr("Load Diagram"), 287 self.tr("Load Diagram"),
288 "", 288 "",
289 self.tr("Eric Graphics File (*.egj);;" 289 self.tr("Eric Graphics File (*.egj);;"
290 "Eric Text Graphics File (*.e5g);;" 290 "Eric Text Graphics File (*.e5g);;"
317 """ 317 """
318 try: 318 try:
319 with open(filename, "r", encoding="utf-8") as f: 319 with open(filename, "r", encoding="utf-8") as f:
320 data = f.read() 320 data = f.read()
321 except OSError as err: 321 except OSError as err:
322 E5MessageBox.critical( 322 EricMessageBox.critical(
323 self, 323 self,
324 self.tr("Load Diagram"), 324 self.tr("Load Diagram"),
325 self.tr( 325 self.tr(
326 """<p>The file <b>{0}</b> could not be read.</p>""" 326 """<p>The file <b>{0}</b> could not be read.</p>"""
327 """<p>Reason: {1}</p>""").format(filename, str(err))) 327 """<p>Reason: {1}</p>""").format(filename, str(err)))
427 ## try: 427 ## try:
428 ## with open(filename, "w", encoding="utf-8") as f: 428 ## with open(filename, "w", encoding="utf-8") as f:
429 ## f.write("\n".join(lines)) 429 ## f.write("\n".join(lines))
430 ## return True 430 ## return True
431 ## except OSError as err: 431 ## except OSError as err:
432 ## E5MessageBox.critical( 432 ## EricMessageBox.critical(
433 ## self, 433 ## self,
434 ## self.tr("Save Diagram"), 434 ## self.tr("Save Diagram"),
435 ## self.tr( 435 ## self.tr(
436 ## """<p>The file <b>{0}</b> could not be saved.</p>""" 436 ## """<p>The file <b>{0}</b> could not be saved.</p>"""
437 ## """<p>Reason: {1}</p>""").format(filename, str(err))) 437 ## """<p>Reason: {1}</p>""").format(filename, str(err)))
452 if linenum < 0 else 452 if linenum < 0 else
453 self.tr("""<p>The file <b>{0}</b> does not contain""" 453 self.tr("""<p>The file <b>{0}</b> does not contain"""
454 """ valid data.</p><p>Invalid line: {1}</p>""" 454 """ valid data.</p><p>Invalid line: {1}</p>"""
455 ).format(filename, linenum + 1) 455 ).format(filename, linenum + 1)
456 ) 456 )
457 E5MessageBox.critical(self, self.tr("Load Diagram"), msg) 457 EricMessageBox.critical(self, self.tr("Load Diagram"), msg)
458 458
459 ####################################################################### 459 #######################################################################
460 ## Methods to read and write eric graphics files of the JSON based 460 ## Methods to read and write eric graphics files of the JSON based
461 ## file format. 461 ## file format.
462 ####################################################################### 462 #######################################################################
485 jsonString = json.dumps(data, indent=2) 485 jsonString = json.dumps(data, indent=2)
486 with open(filename, "w") as f: 486 with open(filename, "w") as f:
487 f.write(jsonString) 487 f.write(jsonString)
488 return True 488 return True
489 except (TypeError, OSError) as err: 489 except (TypeError, OSError) as err:
490 E5MessageBox.critical( 490 EricMessageBox.critical(
491 self, 491 self,
492 self.tr("Save Diagram"), 492 self.tr("Save Diagram"),
493 self.tr( 493 self.tr(
494 """<p>The file <b>{0}</b> could not be saved.</p>""" 494 """<p>The file <b>{0}</b> could not be saved.</p>"""
495 """<p>Reason: {1}</p>""").format(filename, str(err)) 495 """<p>Reason: {1}</p>""").format(filename, str(err))
509 try: 509 try:
510 with open(filename, "r") as f: 510 with open(filename, "r") as f:
511 jsonString = f.read() 511 jsonString = f.read()
512 data = json.loads(jsonString) 512 data = json.loads(jsonString)
513 except (OSError, json.JSONDecodeError) as err: 513 except (OSError, json.JSONDecodeError) as err:
514 E5MessageBox.critical( 514 EricMessageBox.critical(
515 None, 515 None,
516 self.tr("Load Diagram"), 516 self.tr("Load Diagram"),
517 self.tr( 517 self.tr(
518 """<p>The file <b>{0}</b> could not be read.</p>""" 518 """<p>The file <b>{0}</b> could not be read.</p>"""
519 """<p>Reason: {1}</p>""").format(filename, str(err)) 519 """<p>Reason: {1}</p>""").format(filename, str(err))
542 542
543 # step 4: extract builder data if available 543 # step 4: extract builder data if available
544 ok, msg = self.builder.fromDict(version, data["builder"]) 544 ok, msg = self.builder.fromDict(version, data["builder"])
545 if not ok: 545 if not ok:
546 if msg: 546 if msg:
547 res = E5MessageBox.warning( 547 res = EricMessageBox.warning(
548 self, 548 self,
549 self.tr("Load Diagram"), 549 self.tr("Load Diagram"),
550 msg, 550 msg,
551 E5MessageBox.Abort | E5MessageBox.Ignore, 551 EricMessageBox.Abort | EricMessageBox.Ignore,
552 E5MessageBox.Abort) 552 EricMessageBox.Abort)
553 if res == E5MessageBox.Abort: 553 if res == EricMessageBox.Abort:
554 return False 554 return False
555 else: 555 else:
556 self.umlView.setLayoutActionsEnabled(False) 556 self.umlView.setLayoutActionsEnabled(False)
557 else: 557 else:
558 self.__showInvalidDataMessage(filename) 558 self.__showInvalidDataMessage(filename)

eric ide

mercurial