From eb8738bd19c918179cb4bb7954b4ff220687747e Mon Sep 17 00:00:00 2001 From: Humberto Sanchez II Date: Tue, 25 Oct 2022 15:12:00 -0500 Subject: [PATCH] [Interface Update]: [Remove a couple of setter; Then fix the unit tests and the rest of the interfaces] [https://github.com/hasii2011/pyutplugincore/issues/39] --- core/IPluginAdapter.py | 25 +++---------------------- core/PluginInterface.py | 4 ++-- core/types/Types.py | 11 +++++++---- plugins/io/IOXml.py | 3 ++- setup.py | 2 +- tests/MockPluginAdapter.py | 7 ++----- tests/core/SampleIMediator.py | 29 +++++++++++++++++------------ tests/scaffoldv2/PluginAdapterV2.py | 21 ++------------------- 8 files changed, 36 insertions(+), 66 deletions(-) diff --git a/core/IPluginAdapter.py b/core/IPluginAdapter.py index 4e2c068..7adae60 100644 --- a/core/IPluginAdapter.py +++ b/core/IPluginAdapter.py @@ -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 @@ -43,11 +39,6 @@ def pyutVersion(self) -> str: """ pass - @pyutVersion.setter - @abstractmethod - def pyutVersion(self, newVersion: str): - pass - @property @abstractmethod def screenMetrics(self) -> ScreenMetrics: @@ -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 @@ -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: """ diff --git a/core/PluginInterface.py b/core/PluginInterface.py index 6661293..e69b24b 100644 --- a/core/PluginInterface.py +++ b/core/PluginInterface.py @@ -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() @@ -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 diff --git a/core/types/Types.py b/core/types/Types.py index 35fc89f..73ed00e 100644 --- a/core/types/Types.py +++ b/core/types/Types.py @@ -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 @@ -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 diff --git a/plugins/io/IOXml.py b/plugins/io/IOXml.py index d1def47..72fb3ef 100644 --- a/plugins/io/IOXml.py +++ b/plugins/io/IOXml.py @@ -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: diff --git a/setup.py b/setup.py index 01ab6af..086eefe 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ setup( name="pyutplugincore", - version="0.5.8", + version="0.5.9", author='Humberto A. Sanchez II', author_email='humberto.a.sanchez.ii@gmail.com', maintainer='Humberto A. Sanchez II', diff --git a/tests/MockPluginAdapter.py b/tests/MockPluginAdapter.py index 560959b..a492040 100644 --- a/tests/MockPluginAdapter.py +++ b/tests/MockPluginAdapter.py @@ -1,5 +1,4 @@ -from typing import Union from typing import cast from unittest.mock import MagicMock @@ -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 @@ -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): diff --git a/tests/core/SampleIMediator.py b/tests/core/SampleIMediator.py index 71baf76..6f81226 100644 --- a/tests/core/SampleIMediator.py +++ b/tests/core/SampleIMediator.py @@ -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 @@ -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) @@ -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) @@ -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 @@ -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): diff --git a/tests/scaffoldv2/PluginAdapterV2.py b/tests/scaffoldv2/PluginAdapterV2.py index 3e13505..0d111e4 100644 --- a/tests/scaffoldv2/PluginAdapterV2.py +++ b/tests/scaffoldv2/PluginAdapterV2.py @@ -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 @@ -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) @@ -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) @@ -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):