Пример #1
0
    def __init__(self, pyutNote=None, w: int = 0, h: int = 0):
        """

        Args:
            pyutNote:   A PyutNote Object
            w:          Default width override
            h:          Default height override
        """

        # Init pyutObject (coming from OglObject)
        if pyutNote is None:
            pyutObject = PyutNote()
        else:
            pyutObject = pyutNote

        width: int = w
        height: int = h
        prefs: PyutPreferences = PyutPreferences()
        if width == 0:
            width = prefs.noteDimensions.width
        if height == 0:
            height = prefs.noteDimensions.height

        super().__init__(pyutObject, width, height)

        self.logger: Logger = getLogger(__name__)
        self.SetBrush(Brush(Colour(255, 255, 230)))
Пример #2
0
    def testNoneNoteContent(self):
        pyutNote: PyutNote = PyutNote(theNoteText=cast(str, None))

        expectedContent: str = PyutPreferences().noteText
        actualContent: str = pyutNote.content

        self.assertEqual(expectedContent, actualContent,
                         'Did not use preferences note content')
Пример #3
0
    def testOurNoteContent(self):

        pyutNote: PyutNote = PyutNote(theNoteText='Humberto the Pythonista')

        expectedContent: str = 'Humberto the Pythonista'
        actualContent: str = pyutNote.content

        self.assertEqual(expectedContent, actualContent,
                         'Did not use our note content')
Пример #4
0
    def testDefaultNoteContent(self):

        pyutNote: PyutNote = PyutNote()

        expectedContent: str = PyutPreferences().noteText
        actualContent: str = pyutNote.content

        self.assertEqual(expectedContent, actualContent,
                         'Did not use preferences note content')
Пример #5
0
    def _getOglNotes(self, xmlOglNotes, dicoOglObjects, dicoLink, dicoFather,
                     umlFrame):
        """
        Parse the XML elements given and build data layer for PyUT notes.
        If file is version 1.0, the dictionary given will contain, for key,
        the name of the OGL object. Otherwise, it will be the ID
        (multi-same-name support from version 1.1). Everything is fixed
        later.

        @param Element[] xmlOglNotes : XML 'GraphicNote' elements
        @param {id / srcName, OglObject} dicoOglObjects : OGL objects loaded
        @param {id / srcName, OglLink} dicoLink : OGL links loaded
        @param {id / srcName, id / srcName} dicoFather: Inheritance
        @param UmlFrame umlFrame : Where to draw
        @since 2.0
        @author Philippe Waelti <*****@*****.**>
        """
        oldData = 0

        for xmlOglNote in xmlOglNotes:
            pyutNote = PyutNote()

            # Building OGL Note
            height = int(xmlOglNote.getAttribute('height'))
            width = int(xmlOglNote.getAttribute('width'))
            oglNote = OglNote(pyutNote, width, height)

            xmlNote = xmlOglNote.getElementsByTagName('Note')[0]

            # Backward compatibility (pyut v1.0). If id not present,
            # auto set by the instantiation of object
            if xmlNote.hasAttribute('id'):
                pyutNote.setId(int(xmlNote.getAttribute('id')))
            else:
                oldData = 1

            # adding name for this class
            pyutNote.setName(xmlNote.getAttribute('name').encode("charmap"))

            # adding fathers
            self._getFathers(xmlNote.getElementsByTagName("Father"),
                             dicoFather, pyutNote.getId())

            # Update dicos
            dicoLink[pyutNote.getId()] = self._getLinks(xmlNote)
            dicoOglObjects[pyutNote.getId()] = oglNote

            # Update UML Frame
            x = int(xmlOglNote.getAttribute('x'))
            y = int(xmlOglNote.getAttribute('y'))
            umlFrame.addShape(oglNote, x, y)

        return oldData
Пример #6
0
    def createNewNote(self, x, y):
        """
        Add a new note at (x, y).

        @return PyutNote : the newly created PyutNote
        """
        pyutNote: PyutNote = PyutNote("")
        oglNote: OglNote = OglNote(pyutNote)

        self.addShape(oglNote, x, y)
        self.Refresh()
        return pyutNote
Пример #7
0
    def createNewNote(self, x: int, y: int):
        """
        Add a new note at (x, y).

        Args:
            x:
            y:

        Returns:    the newly created PyutNote
        """
        pyutNote: PyutNote = PyutNote()
        oglNote: OglNote = OglNote(pyutNote)

        self.addShape(oglNote, x, y)
        self.Refresh()
        return pyutNote
Пример #8
0
    def _getOglNotes(self, xmlOglNotes, dicoOglObjects, dicoLink, dicoFather,
                     umlFrame):
        """
        Parse the XML elements given and build data layer for PyUT notes.
        If file is version 1.0, the dictionary given will contain, for key,
        the name of the OGL object. Otherwise, it will be the ID
        (multi-same-name support from version 1.1). Everything is fixed
        later.

        @param Element[] xmlOglNotes : XML 'GraphicNote' elements

        @param {id / srcName, OglObject} dicoOglObjects : OGL objects loaded

        @param {id / srcName, OglLink} dicoLink : OGL links loaded

        @param {id / srcName, id / srcName} dicoFather: Inheritance

        @param UmlFrame umlFrame : Where to draw
        """
        for xmlOglNote in xmlOglNotes:
            pyutNote = PyutNote()

            # Building OGL Note
            height = float(xmlOglNote.getAttribute('height'))
            width = float(xmlOglNote.getAttribute('width'))
            oglNote = OglNote(pyutNote, width, height)

            xmlNote = xmlOglNote.getElementsByTagName('Note')[0]

            pyutNote.setId(int(xmlNote.getAttribute('id')))

            # adding note content for this class
            name = xmlNote.getAttribute('name')
            name = name.replace("\\\\\\\\", "\n")
            pyutNote.content = name

            # adding associated filename ([email protected])
            pyutNote.setFilename(xmlNote.getAttribute('filename'))

            # Update dicos
            dicoOglObjects[pyutNote.getId()] = oglNote

            # Update UML Frame
            x = float(xmlOglNote.getAttribute('x'))
            y = float(xmlOglNote.getAttribute('y'))
            umlFrame.addShape(oglNote, x, y)
Пример #9
0
    def getOglNotes(self, xmlOglNotes: NodeList) -> OglNotes:
        """
        Parse the XML elements given and build data layer for PyUt notes.

        Args:
            xmlOglNotes:        XML 'GraphicNote' elements

        Returns:
            The returned dictionary uses a generated ID for the key
        """
        oglNotes: OglNotes = cast(OglNotes, {})
        for xmlOglNote in xmlOglNotes:

            pyutNote: PyutNote = PyutNote()

            # Building OGL Note
            height: float = float(
                xmlOglNote.getAttribute(PyutXmlConstants.ATTR_HEIGHT))
            width: float = float(
                xmlOglNote.getAttribute(PyutXmlConstants.ATTR_WIDTH))
            oglNote = OglNote(pyutNote, width, height)

            xmlNote: Element = xmlOglNote.getElementsByTagName(
                PyutXmlConstants.ELEMENT_MODEL_NOTE)[0]

            pyutNote.setId(int(xmlNote.getAttribute(PyutXmlConstants.ATTR_ID)))

            content: str = xmlNote.getAttribute(PyutXmlConstants.ATTR_NAME)
            content = content.replace("\\\\\\\\", "\n")

            pyutNote.content = content

            pyutNote.setFilename(
                xmlNote.getAttribute(PyutXmlConstants.ATTR_FILENAME))

            # Adding properties necessary to place shape on a diagram frame
            x: float = float(xmlOglNote.getAttribute(PyutXmlConstants.ATTR_X))
            y: float = float(xmlOglNote.getAttribute(PyutXmlConstants.ATTR_Y))

            oglNote.SetPosition(x, y)
            # Update the dictionary
            oglNotes[pyutNote.getId()] = oglNote

        return oglNotes
Пример #10
0
    def __init__(self, pyutNote=None, w=100, h=50):
        """
        Constructor.

        @param pyutNote : a PyutNote object
        @param  w : Width of the shape
        @param  h : Height of the shape
        @since 1.0
        @author Philippe Waelti<*****@*****.**>
        """
        # Init pyutObject (coming from OglObject)
        if pyutNote is None:
            pyutObject = PyutNote()
        else:
            pyutObject = pyutNote
        super().__init__(pyutObject, w, h)

        self.logger: Logger = getLogger(__name__)
        self.SetBrush(Brush(Colour(255, 255, 230)))
    def testSerialize(self):

        pyutNote: PyutNote = PyutNote(theNoteText='Some note text')
        pyutNote.fileName = '/Users/hasii/code/PyutNote.java'
        pyutNote.name = 'UnitTestNote'

        mockFrame: Mock = Mock(spec=UmlClassDiagramsFrame)

        mockFrame.GetXOffset.return_value = 0
        mockFrame.GetYOffset.return_value = 0
        mockFrame.GetCurrentZoom.return_value = 1.0

        mockDiagram: Mock = Mock(spec=Diagram)
        mockDiagram.GetPanel.return_value = mockFrame

        oglNote: OglNote = OglNote(pyutNote=pyutNote, w=100, h=100)

        oglNote._diagram = mockDiagram  # Normally should not do this; only in unit tess
        oglNote.SetPosition(1024, 1024)
        oglNote.SetSize(width=100, height=100)
        oglNote._id = 3  # too match deserialized file

        oglLinkedObjectCommand: DeleteOglLinkedObjectCommand = DeleteOglLinkedObjectCommand(
            shape=oglNote)

        serializedShape: str = oglLinkedObjectCommand.serialize()
        self.logger.debug(f'{serializedShape=}')

        import re
        fixedSerializedShape = re.sub('shapeId=[0-9]*', 'shapeId=3',
                                      serializedShape)
        self.logger.debug(f'{fixedSerializedShape=}')
        self.assertIsNotNone(fixedSerializedShape, 'Something must come back')

        self.maxDiff = None

        self.assertEqual(self._serializedCommand, fixedSerializedShape,
                         'Oops, something changed')