diff -r 2f4b8212a151 -r 1436fd09d1e1 eric6/Graphics/UMLDialog.py --- a/eric6/Graphics/UMLDialog.py Sat May 01 15:08:38 2021 +0200 +++ b/eric6/Graphics/UMLDialog.py Sat May 01 16:01:43 2021 +0200 @@ -7,6 +7,8 @@ Module implementing a dialog showing UML like diagrams. """ +import enum + from PyQt5.QtCore import pyqtSlot, Qt, QFileInfo from PyQt5.QtWidgets import QAction, QToolBar, QGraphicsScene @@ -17,32 +19,41 @@ import UI.PixmapCache +class UMLDialogType(enum.Enum): + """ + Class defining the UML dialog types. + """ + CLASS_DIAGRAM = 0 + PACKAGE_DIAGRAM = 1 + IMPORTS_DIAGRAM = 2 + APPLICATION_DIAGRAM = 3 + NO_DIAGRAM = 255 + + class UMLDialog(E5MainWindow): """ Class implementing a dialog showing UML like diagrams. """ - # convert to Enum - NoDiagram = 255 - ClassDiagram = 0 - PackageDiagram = 1 - ImportsDiagram = 2 - ApplicationDiagram = 3 - - FileVersions = ["1.0"] + FileVersions = ("1.0") def __init__(self, diagramType, project, path="", parent=None, initBuilder=True, **kwargs): """ Constructor - @param diagramType type of the diagram (one of ApplicationDiagram, - ClassDiagram, ImportsDiagram, NoDiagram, PackageDiagram) - @param project reference to the project object (Project) - @param path file or directory path to build the diagram from (string) - @param parent parent widget of the dialog (QWidget) + @param diagramType type of the diagram + @type UMLDialogType + @param project reference to the project object + @type Project + @param path file or directory path to build the diagram from + @type str + @param parent parent widget of the dialog + @type QWidget @param initBuilder flag indicating to initialize the diagram - builder (boolean) + builder + @type bool @keyparam kwargs diagram specific data + @type dict """ super().__init__(parent) self.setObjectName("UMLDialog") @@ -50,10 +61,10 @@ self.__project = project self.__diagramType = diagramType self.__diagramTypeString = { - UMLDialog.ClassDiagram: "Class Diagram", - UMLDialog.PackageDiagram: "Package Diagram", - UMLDialog.ImportsDiagram: "Imports Diagram", - UMLDialog.ApplicationDiagram: "Application Diagram", + UMLDialogType.CLASS_DIAGRAM: "Class Diagram", + UMLDialogType.PACKAGE_DIAGRAM: "Package Diagram", + UMLDialogType.IMPORTS_DIAGRAM: "Imports Diagram", + UMLDialogType.APPLICATION_DIAGRAM: "Application Diagram", }.get(diagramType, "Illegal Diagram Type") from .UMLGraphicsView import UMLGraphicsView @@ -163,34 +174,27 @@ Private method to instantiate a diagram builder object. @param diagramType type of the diagram - (one of ApplicationDiagram, ClassDiagram, ImportsDiagram, - PackageDiagram) - @param path file or directory path to build the diagram from (string) + @type UMLDialogType + @param path file or directory path to build the diagram from + @type str @keyparam kwargs diagram specific data + @type dict @return reference to the instantiated diagram builder - @exception ValueError raised to indicate an illegal diagram type + @rtype UMLDiagramBuilder """ - if diagramType not in ( - UMLDialog.ClassDiagram, UMLDialog.PackageDiagram, - UMLDialog.ImportsDiagram, UMLDialog.ApplicationDiagram, - UMLDialog.NoDiagram - ): - raise ValueError(self.tr( - "Illegal diagram type '{0}' given.").format(diagramType)) - - if diagramType == UMLDialog.ClassDiagram: + if diagramType == UMLDialogType.CLASS_DIAGRAM: from .UMLClassDiagramBuilder import UMLClassDiagramBuilder return UMLClassDiagramBuilder( self, self.umlView, self.__project, path, **kwargs) - elif diagramType == UMLDialog.PackageDiagram: + elif diagramType == UMLDialogType.PACKAGE_DIAGRAM: from .PackageDiagramBuilder import PackageDiagramBuilder return PackageDiagramBuilder( self, self.umlView, self.__project, path, **kwargs) - elif diagramType == UMLDialog.ImportsDiagram: + elif diagramType == UMLDialogType.IMPORTS_DIAGRAM: from .ImportsDiagramBuilder import ImportsDiagramBuilder return ImportsDiagramBuilder( self, self.umlView, self.__project, path, **kwargs) - elif diagramType == UMLDialog.ApplicationDiagram: + elif diagramType == UMLDialogType.APPLICATION_DIAGRAM: from .ApplicationDiagramBuilder import ApplicationDiagramBuilder return ApplicationDiagramBuilder( self, self.umlView, self.__project, **kwargs) @@ -240,7 +244,7 @@ lines = [ "version: 1.0", "diagram_type: {0} ({1})".format( - self.__diagramType, self.__diagramTypeString), + self.__diagramType.value, self.__diagramTypeString), "scene_size: {0};{1}".format(self.scene.width(), self.scene.height()), ] @@ -318,7 +322,7 @@ return False try: diagramType, diagramTypeString = value.strip().split(None, 1) - self.__diagramType = int(self.__diagramType) + self.__diagramType = UMLDialogType(int(self.__diagramType)) self.__diagramTypeString = diagramTypeString[1:-1] # remove opening an closing bracket except ValueError: