263 icon=E5MessageBox.Warning) |
263 icon=E5MessageBox.Warning) |
264 if not res: |
264 if not res: |
265 return |
265 return |
266 filename = fname |
266 filename = fname |
267 |
267 |
268 res = ( |
268 res = self.__writeJsonGraphicsFile(filename) |
269 self.__writeLineBasedGraphicsFile(filename) |
|
270 if filename.endswith(".e5g") else |
|
271 # JSON format is the default |
|
272 self.__writeJsonGraphicsFile(filename) |
|
273 ) |
|
274 |
269 |
275 if res: |
270 if res: |
276 # save the file name only in case of success |
271 # save the file name only in case of success |
277 self.__fileName = filename |
272 self.__fileName = filename |
278 |
273 |
279 # TODO: eric7: delete the current one |
274 # Note: remove loading of eric6 line based diagram format after 22.6 |
280 def load(self, filename=""): |
275 def load(self, filename=""): |
281 """ |
276 """ |
282 Public method to load a diagram from a file. |
277 Public method to load a diagram from a file. |
283 |
278 |
284 @param filename name of the file to be loaded |
279 @param filename name of the file to be loaded |
404 self.setWindowTitle(self.__getDiagramTitel(self.__diagramType)) |
399 self.setWindowTitle(self.__getDiagramTitel(self.__diagramType)) |
405 self.__fileName = filename |
400 self.__fileName = filename |
406 |
401 |
407 return True |
402 return True |
408 |
403 |
409 def __writeLineBasedGraphicsFile(self, filename): |
404 ## def __writeLineBasedGraphicsFile(self, filename): |
410 """ |
405 ## """ |
411 Private method to write an eric graphics file using the old line |
406 ## Private method to write an eric graphics file using the old line |
412 based file format. |
407 ## based file format. |
413 |
408 ## |
414 @param filename name of the file to write to |
409 ## @param filename name of the file to write to |
415 @type str |
410 ## @type str |
416 @return flag indicating a successful write |
411 ## @return flag indicating a successful write |
417 @rtype bool |
412 ## @rtype bool |
418 """ |
413 ## """ |
419 lines = [ |
414 ## lines = [ |
420 "version: 1.0", |
415 ## "version: 1.0", |
421 "diagram_type: {0} ({1})".format( |
416 ## "diagram_type: {0} ({1})".format( |
422 self.__diagramType.value, |
417 ## self.__diagramType.value, |
423 self.__getDiagramTitel(self.__diagramType)), |
418 ## self.__getDiagramTitel(self.__diagramType)), |
424 "scene_size: {0};{1}".format(self.scene.width(), |
419 ## "scene_size: {0};{1}".format(self.scene.width(), |
425 self.scene.height()), |
420 ## self.scene.height()), |
426 ] |
421 ## ] |
427 persistenceData = self.builder.getPersistenceData() |
422 ## persistenceData = self.builder.getPersistenceData() |
428 if persistenceData: |
423 ## if persistenceData: |
429 lines.append("builder_data: {0}".format(persistenceData)) |
424 ## lines.append("builder_data: {0}".format(persistenceData)) |
430 lines.extend(self.umlView.getPersistenceData()) |
425 ## lines.extend(self.umlView.getPersistenceData()) |
431 |
426 ## |
432 try: |
427 ## try: |
433 with open(filename, "w", encoding="utf-8") as f: |
428 ## with open(filename, "w", encoding="utf-8") as f: |
434 f.write("\n".join(lines)) |
429 ## f.write("\n".join(lines)) |
435 return True |
430 ## return True |
436 except OSError as err: |
431 ## except OSError as err: |
437 E5MessageBox.critical( |
432 ## E5MessageBox.critical( |
438 self, |
433 ## self, |
439 self.tr("Save Diagram"), |
434 ## self.tr("Save Diagram"), |
440 self.tr( |
435 ## self.tr( |
441 """<p>The file <b>{0}</b> could not be saved.</p>""" |
436 ## """<p>The file <b>{0}</b> could not be saved.</p>""" |
442 """<p>Reason: {1}</p>""").format(filename, str(err))) |
437 ## """<p>Reason: {1}</p>""").format(filename, str(err))) |
443 return False |
438 ## return False |
444 |
439 ## |
445 def __showInvalidDataMessage(self, filename, linenum=-1): |
440 def __showInvalidDataMessage(self, filename, linenum=-1): |
446 """ |
441 """ |
447 Private slot to show a message dialog indicating an invalid data file. |
442 Private slot to show a message dialog indicating an invalid data file. |
448 |
443 |
449 @param filename name of the file containing the invalid data |
444 @param filename name of the file containing the invalid data |