Skip to content

Commit

Permalink
<Enhancement>[Dynamic Configuration]: <The conversation to new is com…
Browse files Browse the repository at this point in the history
…plete>

[
* The property names no match the method names
* A few more tests for rationality
* Update to include serializers
]

[#115]
  • Loading branch information
hasii2011 committed Oct 22, 2024
1 parent eb58f57 commit 6b2b168
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/miniogl/DiagramFrame.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ def OnPaint(self, event: PaintEvent):
#
# Paint events don't seem to be generated when Pyut is built for deployment; So code duplicated in .Redraw()
#
if self._prefs.backgroundGridEnabled is True:
if self._prefs.backGroundGridEnabled is True:
self._drawGrid(memDC=mem, width=w, height=h, startX=x, startY=y)
self.Redraw(mem)

Expand Down
2 changes: 1 addition & 1 deletion src/ogl/OglAssociation.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

class OglAssociation(OglLink):

clsDiamondSize: int = OglPreferences().associationDiamondSize
clsDiamondSize: int = OglPreferences().diamondSize
"""
Graphical link representation of an association, (simple line, no arrow).
To get a new link, use the `OglLinkFactory` and specify
Expand Down
2 changes: 1 addition & 1 deletion src/ogl/OglClass.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def __init__(self, pyutClass: PyutClass | None, w: int = 0, h: int = 0):
oglTextColor: MiniOglColorEnum = self._oglPreferences.classTextColor
self._textColor: Colour = Colour(MiniOglColorEnum.toWxColor(oglTextColor))

oglBackgroundColor: MiniOglColorEnum = self._oglPreferences.classBackgroundColor
oglBackgroundColor: MiniOglColorEnum = self._oglPreferences.classBackGroundColor
backgroundColor: Colour = Colour(MiniOglColorEnum.toWxColor(oglBackgroundColor))

self.brush = Brush(backgroundColor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from tests.DynamicConfiguration import ValueDescriptions

MODULE_NAME: str = 'ogl'
PREFERENCES_FILE_NAME: str = f'{MODULE_NAME}V2.ini'
PREFERENCES_FILE_NAME: str = f'{MODULE_NAME}.ini'

DEFAULT_CLASS_BACKGROUND_COLOR: str = MiniOglColorEnum.MINT_CREAM.value
DEFAULT_CLASS_TEXT_COLOR: str = MiniOglColorEnum.BLACK.value
Expand All @@ -38,9 +38,9 @@
KeyName('textFontSize'): ValueDescription(defaultValue='14', deserializer=SecureConversions.secureInteger),
KeyName('displayConstructor'): ValueDescription(defaultValue='True', deserializer=SecureConversions.secureBoolean),
KeyName('displayDunderMethods'): ValueDescription(defaultValue='True', deserializer=SecureConversions.secureBoolean),
KeyName('classDimensions'): ValueDescription(defaultValue=OglDimensions(150, 75).__str__()),
KeyName('classBackGroundColor'): ValueDescription(defaultValue=DEFAULT_CLASS_BACKGROUND_COLOR, enumUseValue=True),
KeyName('classTextColor'): ValueDescription(defaultValue=DEFAULT_CLASS_TEXT_COLOR, enumUseValue=True),
KeyName('classDimensions'): ValueDescription(defaultValue=str(OglDimensions(150, 75)), deserializer=OglDimensions.deSerialize),
KeyName('classBackGroundColor'): ValueDescription(defaultValue=DEFAULT_CLASS_BACKGROUND_COLOR, enumUseValue=True, deserializer=MiniOglColorEnum),
KeyName('classTextColor'): ValueDescription(defaultValue=DEFAULT_CLASS_TEXT_COLOR, enumUseValue=True, deserializer=MiniOglColorEnum),
}
)
diagramProperties: ValueDescriptions = ValueDescriptions(
Expand Down Expand Up @@ -68,7 +68,7 @@
)
sequenceDiagramPreferences: ValueDescriptions = ValueDescriptions(
{
KeyName('instanceYPosition'): ValueDescription(defaultValue='50'),
KeyName('instanceYPosition'): ValueDescription(defaultValue='50', deserializer=SecureConversions.secureInteger),
KeyName('instanceDimensions'): ValueDescription(defaultValue=str(OglDimensions(100, 400)), deserializer=OglDimensions.deSerialize)
}
)
Expand All @@ -81,7 +81,7 @@
debugPreferences: ValueDescriptions = ValueDescriptions(
{
KeyName('debugDiagramFrame'): ValueDescription(defaultValue='False', deserializer=SecureConversions.secureBoolean),
KeyName('debugBasicShape'): ValueDescription(defaultValue='False', deserializer=SecureConversions.secureBoolean),
KeyName('debugBasicShape'): ValueDescription(defaultValue='False', deserializer=SecureConversions.secureBoolean),
}
)

Expand All @@ -97,7 +97,7 @@
)


class OglPreferencesV2(DynamicConfiguration, metaclass=SingletonV3):
class OglPreferences(DynamicConfiguration, metaclass=SingletonV3):

def __init__(self):
self._logger: Logger = getLogger(__name__)
Expand Down
4 changes: 2 additions & 2 deletions src/ogl/ui/DiagramPreferencesPage.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def _setControlValues(self):
"""
self._resetSnapToGridControl()

self._enableBackgroundGrid.SetValue(self._preferences.backgroundGridEnabled)
self._enableBackgroundGrid.SetValue(self._preferences.backGroundGridEnabled)
self._snapToGrid.SetValue(self._preferences.snapToGrid)
self._centerDiagramView.SetValue(self._preferences.centerDiagram)
self._showParameters.SetValue(self._preferences.showParameters)
Expand Down Expand Up @@ -228,7 +228,7 @@ def _resetSnapToGridControl(self):
Make the UI consistent when the background grid is used or not
If no background grid there is nothing to snap to
"""
if self._preferences.backgroundGridEnabled is True:
if self._preferences.backGroundGridEnabled is True:
self._snapToGrid.Enabled = True
else:
self._snapToGrid.SetValue(False)
Expand Down
3 changes: 1 addition & 2 deletions src/ogl/ui/valuecontrols/AssociationAttributesControl.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def _layoutControls(self, parentPanel: SizedPanel):

def _setControlValues(self):
self._textFontSize.SetValue(str(self._preferences.associationTextFontSize))
self._diamondSize.SetValue(str(self._preferences.associationDiamondSize))
self._diamondSize.SetValue(str(self._preferences.diamondSize))

def _onTextFontSizedChanged(self, event: CommandEvent):
newFontSize: str = event.GetString()
Expand All @@ -65,4 +65,3 @@ def _onTextFontSizedChanged(self, event: CommandEvent):
def _onDiamondSizeChanged(self, event: CommandEvent):
newDiamondSize: str = event.GetString()
self._preferences.associationDiamondSize = int(newDiamondSize)

6 changes: 3 additions & 3 deletions src/ogl/ui/valuecontrols/ClassAttributesControl.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def _layoutNameControl(self, parentPanel):
nameSizedPanel.SetSizerProps(proportion=1, expand=False)

StaticText(nameSizedPanel, ID_ANY, 'Default Class Name:')
self._className = TextCtrl(nameSizedPanel, value=self._preferences.className, size=(160, -1))
self._className = TextCtrl(nameSizedPanel, value=self._preferences.defaultClassName, size=(160, -1))
self._className.SetSizerProps(proportion=1, expand=False)

def _layoutClassBackgroundControl(self, parentPanel: SizedPanel):
Expand Down Expand Up @@ -124,7 +124,7 @@ def _setControlValues(self):
self._classDimensions.dimensions = self._preferences.classDimensions

oglColors: List[str] = self._classBackgroundColor.GetItems()
bgColorSelIdx: int = oglColors.index(self._preferences.classBackgroundColor.value)
bgColorSelIdx: int = oglColors.index(self._preferences.classBackGroundColor.value)
self._classBackgroundColor.SetSelection(bgColorSelIdx)

txtColorSelIdx: int = oglColors.index(self._preferences.classTextColor.value)
Expand Down Expand Up @@ -162,4 +162,4 @@ def _onDisplayDunderMethodsChanged(self, event: CommandEvent):
def _onDisplayConstructorChanged(self, event: CommandEvent):

newValue: bool = event.IsChecked()
self._preferences.displayConstructor = newValue
self._preferences.displayConstructor = newValue
12 changes: 6 additions & 6 deletions src/ogl/ui/valuecontrols/DefaultNamesControl.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ def __init__(self, parent: Window):
#
p: OglPreferences = self._preferences
self._nameData: List[NameData] = [
NameData(label='Interface Name: ', callback=self._onInterfaceNameChanged, initialValue=p.interfaceName),
NameData(label='Use Case Name: ', callback=self._onUseCaseNameChanged, initialValue=p.useCaseName),
NameData(label='Actor Name: ', callback=self._onActorNameChanged, initialValue=p.actorName),
NameData(label='Method Name: ', callback=self._onMethodNameChanged, initialValue=p.methodName),
NameData(label='Field Name: ', callback=self._onFieldNameChanged, initialValue=p.fieldName),
NameData(label='Parameter Name: ', callback=self._onParameterNameChanged, initialValue=p.parameterName),
NameData(label='Interface Name: ', callback=self._onInterfaceNameChanged, initialValue=p.defaultNameInterface),
NameData(label='Use Case Name: ', callback=self._onUseCaseNameChanged, initialValue=p.defaultNameUsecase),
NameData(label='Actor Name: ', callback=self._onActorNameChanged, initialValue=p.defaultNameActor),
NameData(label='Method Name: ', callback=self._onMethodNameChanged, initialValue=p.defaultNameMethod),
NameData(label='Field Name: ', callback=self._onFieldNameChanged, initialValue=p.defaultNameField),
NameData(label='Parameter Name: ', callback=self._onParameterNameChanged, initialValue=p.defaultNameParameter),
]
for nd in self._nameData:
nameData: NameData = cast(NameData, nd)
Expand Down
24 changes: 12 additions & 12 deletions tests/ogl/preferences/TestOglPreferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

from ogl.OglDimensions import OglDimensions

from ogl.preferences.OglPreferencesV2 import MODULE_NAME
from ogl.preferences.OglPreferencesV2 import OglPreferencesV2
from ogl.preferences.OglPreferencesV2 import PREFERENCES_FILE_NAME
from ogl.preferences.OglPreferences import MODULE_NAME
from ogl.preferences.OglPreferences import OglPreferences
from ogl.preferences.OglPreferences import PREFERENCES_FILE_NAME


class TestOglPreferencesV2(UnitTestBase):
Expand Down Expand Up @@ -56,7 +56,7 @@ def tearDown(self):

def testDefaultInstantiation(self):

oglPreferencesV2: OglPreferencesV2 = OglPreferencesV2()
oglPreferencesV2: OglPreferences = OglPreferences()

self.assertIsNotNone(oglPreferencesV2, 'We should get an object')
self.assertEqual(14, oglPreferencesV2.textFontSize)
Expand All @@ -68,39 +68,39 @@ def testDefaultInstantiation(self):

self.assertTrue(isinstance(gridLineColor, MiniOglColorEnum), 'Wrong type returned')

instanceDimensions: OglDimensions = oglPreferencesV2.instanceDimensions
self.assertTrue(isinstance(instanceDimensions, OglDimensions), 'Wrong type returned')
classDimensions: OglDimensions = oglPreferencesV2.classDimensions
self.assertTrue(isinstance(classDimensions, OglDimensions), 'Wrong type returned')

def testGetTextFontFamily(self):

oglPreferencesV2: OglPreferencesV2 = OglPreferencesV2()
oglPreferencesV2: OglPreferences = OglPreferences()

self.assertIsNotNone(oglPreferencesV2.textFontFamily, 'Something should be there')

def testSetTextFontFamily(self):

oglPreferencesV2: OglPreferencesV2 = OglPreferencesV2()
oglPreferencesV2: OglPreferences = OglPreferences()

oglPreferencesV2.textFontFamily = 'Script'

self.logger.info(oglPreferencesV2.textFontFamily)

def testStringGet(self):

prefsV2: OglPreferencesV2 = OglPreferencesV2()
prefsV2: OglPreferences = OglPreferences()

noteText: str = prefsV2.noteText
self.assertTrue(len(noteText) > 0, 'Should not be empty')

def testStringSet(self):

prefsV2: OglPreferencesV2 = OglPreferencesV2()
prefsV2: OglPreferences = OglPreferences()

prefsV2.noteText = 'I changed it'
self.assertEqual(prefsV2.noteText, 'I changed it', 'Hmm, why did it not change')

def testOglDimensionsGet(self):
prefsV2: OglPreferencesV2 = OglPreferencesV2()
prefsV2: OglPreferences = OglPreferences()

actualDimensions: OglDimensions = prefsV2.noteDimensions
self.assertIsNotNone(actualDimensions, 'I should get some value')
Expand All @@ -111,7 +111,7 @@ def testOglDimensionsGet(self):

def testOglDimensionsSet(self):

prefsV2: OglPreferencesV2 = OglPreferencesV2()
prefsV2: OglPreferences = OglPreferences()
expected: OglDimensions = OglDimensions(1000, 1000)
prefsV2.noteDimensions = expected

Expand Down

0 comments on commit 6b2b168

Please sign in to comment.