From 32f0b66eb28311fbe3eac58a09095420e060ffa1 Mon Sep 17 00:00:00 2001 From: obulat Date: Sun, 1 Sep 2019 07:38:05 +0300 Subject: [PATCH] Replace `enabled` property on implementation level with `set_enabled`, adjust tests Signed-off-by: obulat --- src/core/tests/test_command.py | 8 ++++---- src/core/toga/command.py | 2 +- src/dummy/toga_dummy/command.py | 5 ++++- src/winforms/toga_winforms/command.py | 7 +------ src/winforms/toga_winforms/window.py | 1 - 5 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/core/tests/test_command.py b/src/core/tests/test_command.py index f932b468f6..affb7a7d92 100644 --- a/src/core/tests/test_command.py +++ b/src/core/tests/test_command.py @@ -1,12 +1,12 @@ import unittest -from unittest.mock import Mock import toga import toga_dummy +from toga_dummy.utils import TestCase from toga.command import cmd_sort_key -class TestCommand(unittest.TestCase): +class TestCommand(TestCase): def test_group_init_no_order(self): grp = toga.Group('label') self.assertEqual(grp.label, 'label') @@ -97,9 +97,9 @@ def test_command_enabler(self): ) cmd.bind(toga_dummy.factory) cmd.enabled = False - self.assertFalse(cmd._impl.enabled) + self.assertActionPerformedWith(cmd, 'set enabled', value=False) cmd.enabled = True - self.assertTrue(cmd._impl.enabled) + self.assertActionPerformedWith(cmd, 'set enabled', value=True) def test_cmd_sort_key(self): grp = toga.Group('Test group', order=10) diff --git a/src/core/toga/command.py b/src/core/toga/command.py index d660a4e1be..fe1f51ae39 100644 --- a/src/core/toga/command.py +++ b/src/core/toga/command.py @@ -74,7 +74,7 @@ def enabled(self): def enabled(self, value): self._enabled = value if self._impl is not None: - self._impl.enabled = value + self._impl.set_enabled(value) GROUP_BREAK = object() diff --git a/src/dummy/toga_dummy/command.py b/src/dummy/toga_dummy/command.py index 3001abed56..2021332fa0 100644 --- a/src/dummy/toga_dummy/command.py +++ b/src/dummy/toga_dummy/command.py @@ -4,4 +4,7 @@ class Command(LoggedObject): def __init__(self, interface): super().__init__() - self.interface = interface + self.interface = interface + + def set_enabled(self, value): + self._action('set enabled', value=value) diff --git a/src/winforms/toga_winforms/command.py b/src/winforms/toga_winforms/command.py index 9da39b0029..cf989aa48f 100644 --- a/src/winforms/toga_winforms/command.py +++ b/src/winforms/toga_winforms/command.py @@ -14,12 +14,7 @@ def __init__(self, interface): else: self.interface.icon = None - @property - def enabled(self): - return self.interface.enabled - - @enabled.setter - def enabled(self, value): + def set_enabled(self, value): if self.native: for widget in self.native: widget.Enabled = self.interface.enabled diff --git a/src/winforms/toga_winforms/window.py b/src/winforms/toga_winforms/window.py index 31db9462e9..c32c989b8d 100644 --- a/src/winforms/toga_winforms/window.py +++ b/src/winforms/toga_winforms/window.py @@ -44,7 +44,6 @@ def create_toolbar(self): item = WinForms.ToolStripSeparator() else: cmd_impl = cmd.bind(self.interface.factory) - print("Cmd impl is ", cmd_impl) if cmd.icon is not None: native_icon = cmd.icon.bind(self.interface.factory).native item = WinForms.ToolStripMenuItem(cmd.label, native_icon.ToBitmap())