Skip to content

Commit

Permalink
<Refactor>[Interface Update]: <IPluginAdapter Update>
Browse files Browse the repository at this point in the history
[Remove a couple of setter;  Then fix the unit tests and the rest of the interfaces]

[#39]
  • Loading branch information
Humberto Sanchez II committed Oct 25, 2022
1 parent 32d5c3b commit eb8738b
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 66 deletions.
25 changes: 3 additions & 22 deletions core/IPluginAdapter.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@

from typing import Union

from abc import ABC
from abc import abstractmethod

from dataclasses import dataclass

from ogl.OglLink import OglLink
from ogl.OglObject import OglObject

from core.types.Types import OglObjectType
from core.types.Types import FrameInformationCallback
from core.types.Types import FrameSizeCallback
from core.types.Types import PluginProject
Expand Down Expand Up @@ -43,11 +39,6 @@ def pyutVersion(self) -> str:
"""
pass

@pyutVersion.setter
@abstractmethod
def pyutVersion(self, newVersion: str):
pass

@property
@abstractmethod
def screenMetrics(self) -> ScreenMetrics:
Expand All @@ -64,16 +55,6 @@ def currentDirectory(self) -> str:
"""
pass

@currentDirectory.setter
@abstractmethod
def currentDirectory(self, theNewValue: str):
"""
TODO: Should plugins be allowed to manipulate the application's current directory
Args:
theNewValue:
"""
pass

@abstractmethod
def getFrameSize(self, callback: FrameSizeCallback):
pass
Expand Down Expand Up @@ -114,9 +95,9 @@ def deselectAllOglObjects(self):
pass

@abstractmethod
def addShape(self, shape: Union[OglObject, OglLink]):
def addShape(self, shape: OglObjectType):
"""
Add an Ogl shape in the currently displayed frame
Add an Ogl shape to the currently displayed frame
Args:
shape:
"""
Expand Down
4 changes: 2 additions & 2 deletions core/PluginInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def askForImportDirectoryName(self) -> ImportDirectoryResponse:
else:
response.directoryName = dirDialog.GetPath()
response.cancelled = False
self._pluginAdapter.currentDirectory = response.directoryName # TODO: Should plugin be doing this?
# self._pluginAdapter.currentDirectory = response.directoryName # TODO: Should plugin be doing this? No

dirDialog.Destroy()

Expand Down Expand Up @@ -261,7 +261,7 @@ def askForExportDirectoryName(self, preferredDefaultPath: str = None) -> ExportD
response.cancelled = True
else:
directory = dirDialog.GetPath()
self._pluginAdapter.currentDirectory = directory # TODO Should a plugin do this
# self._pluginAdapter.currentDirectory = directory # TODO Should a plugin do this; No
dirDialog.Destroy()
response.directoryName = directory

Expand Down
11 changes: 7 additions & 4 deletions core/types/Types.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@

from pyutmodel.PyutLink import PyutLink

from ogl.OglActor import OglActor
from ogl.OglNote import OglNote
from ogl.OglClass import OglClass
from ogl.OglLink import OglLink
from ogl.OglInterface2 import OglInterface2
from ogl.OglNote import OglNote
from ogl.OglText import OglText

from ogl.OglUseCase import OglUseCase
from ogl.OglActor import OglActor

from ogl.sd.OglSDInstance import OglSDInstance
from ogl.sd.OglSDMessage import OglSDMessage

Expand All @@ -36,9 +39,9 @@
OglSDInstances = NewType('OglSDInstances', Dict[int, OglSDInstance])
OglSDMessages = NewType('OglSDMessages', Dict[int, OglSDMessage])

AllOglObjects = Union[OglClasses, OglLinks, OglNotes, OglTexts, OglActors, OglUseCases]
OglObjectType = Union[OglClass, OglLink, OglNote, OglText, OglActor, OglUseCase, OglInterface2]

OglObjects = NewType('OglObjects', List[AllOglObjects])
OglObjects = NewType('OglObjects', List[OglObjectType])
PyutLinks = NewType('PyutLinks', List[PyutLink])

SelectedOglObjectsCallback = Callable[[OglObjects], None] # Todo: Figure out appropriate type for callback
Expand Down
3 changes: 2 additions & 1 deletion plugins/io/IOXml.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ def write(self, oglObjects: OglObjects):
case OglClass() as oglObject:
oglDocument.oglClasses.append(oglObject)
case OglInterface2() as oglObject:
oglDocument.oglLinks.append(oglObject)
# TODO Fix this in oglio
oglDocument.oglLinks.append(oglObject) # type: ignore
case OglLink() as oglObject:
oglDocument.oglLinks.append(oglObject)
case OglNote() as oglObject:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

setup(
name="pyutplugincore",
version="0.5.8",
version="0.5.9",
author='Humberto A. Sanchez II',
author_email='[email protected]',
maintainer='Humberto A. Sanchez II',
Expand Down
7 changes: 2 additions & 5 deletions tests/MockPluginAdapter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

from typing import Union
from typing import cast

from unittest.mock import MagicMock
Expand All @@ -8,13 +7,11 @@

from miniogl.DiagramFrame import DiagramFrame

from ogl.OglLink import OglLink
from ogl.OglObject import OglObject

from core.IPluginAdapter import IPluginAdapter
from core.IPluginAdapter import ScreenMetrics
from core.types.Types import FrameInformationCallback
from core.types.Types import FrameSizeCallback
from core.types.Types import OglObjectType
from core.types.Types import PluginProject
from core.types.Types import SelectedOglObjectsCallback
from tests.scaffoldv2.eventengine.EventEngine import EventEngine
Expand Down Expand Up @@ -91,7 +88,7 @@ def selectAllOglObjects(self):
def deselectAllOglObjects(self):
pass

def addShape(self, shape: Union[OglObject, OglLink]):
def addShape(self, shape: OglObjectType):
pass

def loadProject(self, pluginProject: PluginProject):
Expand Down
29 changes: 17 additions & 12 deletions tests/core/SampleIMediator.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
from typing import Union

from typing import cast

from logging import Logger
from logging import getLogger

from ogl.OglLink import OglLink
from ogl.OglObject import OglObject

from wx import Frame

from miniogl.DiagramFrame import DiagramFrame

from core.IPluginAdapter import IPluginAdapter
from core.IPluginAdapter import ScreenMetrics
from core.types.Types import FrameInformationCallback
from core.types.Types import FrameSizeCallback
from core.types.Types import OglObjectType
from core.types.Types import OglObjects
from core.types.Types import PluginProject
from core.types.Types import SelectedOglObjectsCallback

from tests.scaffoldv2.eventengine.EventEngine import EventEngine


Expand All @@ -30,10 +34,6 @@ def __init__(self):
def currentDirectory(self) -> str:
return self._currentDirectory

@currentDirectory.setter
def currentDirectory(self, newValue: str):
self._currentDirectory = newValue

@property
def umlFrame(self) -> Frame:
return cast(Frame, None)
Expand All @@ -46,10 +46,6 @@ def umlFrame(self, newValue: DiagramFrame):
def pyutVersion(self) -> str:
return self._pyutVersion

@pyutVersion.setter
def pyutVersion(self, newVersion: str):
pass

@property
def screenMetrics(self) -> ScreenMetrics:
return ScreenMetrics(dpiX=72, dpiY=72, screenWidth=250, screenHeight=1440)
Expand All @@ -66,6 +62,15 @@ def eventEngine(self, eventEngine: EventEngine):
def selectedOglObjects(self) -> OglObjects:
return cast(OglObjects, None)

def getFrameSize(self, callback: FrameSizeCallback):
pass

def getFrameInformation(self, callback: FrameInformationCallback):
pass

def getSelectedOglObjects(self, callback: SelectedOglObjectsCallback):
pass

def refreshFrame(self):
pass

Expand All @@ -75,7 +80,7 @@ def selectAllOglObjects(self):
def deselectAllOglObjects(self):
pass

def addShape(self, shape: Union[OglObject, OglLink]):
def addShape(self, shape: OglObjectType):
pass

def loadProject(self, pluginProject: PluginProject):
Expand Down
21 changes: 2 additions & 19 deletions tests/scaffoldv2/PluginAdapterV2.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@

from typing import Union

from logging import Logger
from logging import getLogger

from wx import Yield as wxYield

from ogl.OglLink import OglLink
from ogl.OglObject import OglObject

from core.IPluginAdapter import IPluginAdapter
from core.IPluginAdapter import ScreenMetrics
from core.types.Types import FrameInformationCallback
from core.types.Types import FrameSizeCallback
from core.types.Types import OglObjectType

from core.types.Types import PluginProject
from core.types.Types import SelectedOglObjectsCallback
Expand All @@ -37,10 +33,6 @@ def __init__(self, eventEngine: IEventEngine):
def pyutVersion(self) -> str:
return 'MediatorV2'

@pyutVersion.setter
def pyutVersion(self, newValue: str):
self.logger.warning(f'Unused {newValue}')

@property
def screenMetrics(self) -> ScreenMetrics:
return ScreenMetrics(dpiX=72, dpiY=72, screenWidth=250, screenHeight=1440)
Expand All @@ -52,15 +44,6 @@ def currentDirectory(self) -> str:
"""
return ''

@currentDirectory.setter
def currentDirectory(self, theNewValue: str):
"""
TODO: Should plugins be allowed to manipulate the application's current directory
Args:
theNewValue:
"""
pass

def getFrameSize(self, callback: FrameSizeCallback):
self._eventEngine.sendEvent(EventType.FrameSize, callback=callback)

Expand All @@ -81,7 +64,7 @@ def deselectAllOglObjects(self):
self._eventEngine.sendEvent(EventType.DeSelectAllShapes)
wxYield()

def addShape(self, shape: Union[OglObject, OglLink]):
def addShape(self, shape: OglObjectType):
pass

def loadProject(self, pluginProject: PluginProject):
Expand Down

0 comments on commit eb8738b

Please sign in to comment.