Skip to content

Commit

Permalink
Cleaned up core.
Browse files Browse the repository at this point in the history
  • Loading branch information
freakboy3742 committed Jul 4, 2020
1 parent a75af36 commit b32e8bd
Show file tree
Hide file tree
Showing 39 changed files with 144 additions and 487 deletions.
1 change: 1 addition & 0 deletions src/core/tests/sources/test_list_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ def test_init_with_flat_list_of_objects(self):
class MyObject:
def __init__(self, info):
self.info = info

def __str__(self):
return "string value %s" % self.info

Expand Down
2 changes: 1 addition & 1 deletion src/core/tests/style/test_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

from toga.colors import rgb
from toga.fonts import Font
from toga.style.pack import Pack, CENTER, COLUMN, HIDDEN, LEFT, RIGHT, ROW, RTL
from toga.style.applicator import TogaApplicator
from toga.style.pack import CENTER, COLUMN, HIDDEN, LEFT, RIGHT, ROW, RTL, Pack


class TestNode(Node):
Expand Down
2 changes: 1 addition & 1 deletion src/core/tests/test_app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from unittest.mock import patch, MagicMock
from unittest.mock import MagicMock, patch

import toga
import toga_dummy
Expand Down
5 changes: 3 additions & 2 deletions src/core/tests/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import toga
import toga_dummy
from toga_dummy.utils import TestCase
from toga.command import cmd_sort_key
from toga_dummy.utils import TestCase


class TestCommand(TestCase):
Expand All @@ -26,7 +26,8 @@ def test_group_init_with_order(self):
self.assertEqual(grp.order, 2)

def test_group_lt(self):
grp1, grp2 = toga.Group('A'), toga.Group('B')
toga.Group('A'),
toga.Group('B')
self.assertTrue(toga.Group('A', 1) < toga.Group('A', 2))
self.assertTrue(toga.Group('A') < toga.Group('B'))

Expand Down
3 changes: 1 addition & 2 deletions src/core/tests/test_font.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import toga
from toga.fonts import SANS_SERIF, ITALIC, SMALL_CAPS, BOLD

import toga_dummy
from toga.fonts import BOLD, ITALIC, SANS_SERIF, SMALL_CAPS
from toga_dummy.utils import TestCase


Expand Down
1 change: 0 additions & 1 deletion src/core/tests/test_image.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import toga

import toga_dummy
from toga_dummy.utils import TestCase

Expand Down
4 changes: 2 additions & 2 deletions src/core/tests/test_window.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from unittest.mock import patch, MagicMock
from unittest.mock import MagicMock, patch

import toga
import toga_dummy
from toga.command import CommandSet
Expand All @@ -11,7 +12,6 @@ def setUp(self):
self.window = toga.Window(factory=toga_dummy.factory)

def test_widget_created(self):
id = self.window.id
self.assertIsNotNone(self.window.id)
app = toga.App('test_name', 'id.app', factory=toga_dummy.factory)
new_app = toga.App('error_name', 'id.error', factory=toga_dummy.factory)
Expand Down
2 changes: 1 addition & 1 deletion src/core/tests/widgets/test_base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import toga
from toga.style import Pack
import toga_dummy
from toga.style import Pack
from toga_dummy.utils import TestCase


Expand Down
2 changes: 1 addition & 1 deletion src/core/tests/widgets/test_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_widget_created(self):

@patch('toga.widgets.base.get_platform_factory')
def test_box_with_without_factory(self, mock_function):
btn = toga.Box()
toga.Box()
mock_function.assert_called_once_with(None)

def test_children_added(self):
Expand Down
7 changes: 3 additions & 4 deletions src/core/tests/widgets/test_canvas.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from math import pi, cos, sin
from math import cos, pi, sin

import toga
from toga.colors import REBECCAPURPLE, BLANCHEDALMOND, CRIMSON, rgb
from toga.fonts import SANS_SERIF, SERIF

import toga_dummy
from toga.colors import BLANCHEDALMOND, CRIMSON, REBECCAPURPLE, rgb
from toga.fonts import SANS_SERIF, SERIF
from toga.widgets.canvas import FillRule
from toga_dummy.utils import TestCase

Expand Down
3 changes: 2 additions & 1 deletion src/core/tests/widgets/test_datepicker.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import datetime

import toga
import toga_dummy
from toga_dummy.utils import TestCase
import datetime


class DatePickerTests(TestCase):
Expand Down
1 change: 0 additions & 1 deletion src/core/tests/widgets/test_label.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import toga
import toga_dummy
from toga import constants
from toga_dummy.utils import TestCase


Expand Down
1 change: 0 additions & 1 deletion src/core/tests/widgets/test_progressbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import toga_dummy
from toga_dummy.utils import TestCase


# ### ProgressBar truth table
#
# | max | running | Behavior |
Expand Down
2 changes: 1 addition & 1 deletion src/core/tests/widgets/test_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_set_items(self):
self.assertEqual(self.selection._items, new_items)

def test_get_selected_item_invokes_impl_method(self):
value = self.selection.value
self.selection.value
self.assertValueGet(self.selection, 'selected_item')

def test_set_selected_item_invokes_impl_methods(self):
Expand Down
2 changes: 1 addition & 1 deletion src/core/tests/widgets/test_slider.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_parameter_are_all_set_correctly(self):
self.assertEqual(self.slider.enabled, self.enabled)

def test_get_value_invokes_impl_method(self):
slider_value = self.slider.value
self.slider.value
self.assertValueGet(self.slider, 'value')

def test_set_value_invokes_impl_method(self):
Expand Down
2 changes: 1 addition & 1 deletion src/core/tests/widgets/test_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ def test_setting_is_on_invokes_impl_method(self):
self.assertValueSet(self.switch, 'is_on', False)

def test_getting_is_on_invokes_impl_method(self):
value = self.switch.is_on
self.switch.is_on
self.assertValueGet(self.switch, 'is_on')
2 changes: 1 addition & 1 deletion src/core/tests/widgets/test_textinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_set_value_with_None(self):
self.assertValueSet(self.text_input, 'value', '')

def test_getting_value_invokes_impl_method(self):
value = self.text_input.value
self.text_input.value
self.assertValueGet(self.text_input, 'value')

def test_setting_value_invokes_impl_method(self):
Expand Down
3 changes: 2 additions & 1 deletion src/core/tests/widgets/test_timepicker.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import datetime

import toga
import toga_dummy
from toga_dummy.utils import TestCase
import datetime


class TimePickerTests(TestCase):
Expand Down
11 changes: 7 additions & 4 deletions src/core/tests/widgets/test_tree.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import toga
import toga_dummy
from toga.sources import TreeSource
from toga_dummy.utils import TestCase
from toga.sources import TreeSource, Source


class TreeTests(TestCase):
def setUp(self):
Expand All @@ -10,9 +11,11 @@ def setUp(self):
self.headings = ['Heading {}'.format(x) for x in range(3)]

self.data = None
self.tree = toga.Tree(headings=self.headings,
data=self.data,
factory=toga_dummy.factory)
self.tree = toga.Tree(
headings=self.headings,
data=self.data,
factory=toga_dummy.factory
)

def test_widget_created(self):
self.assertEqual(self.tree._impl.interface, self.tree)
Expand Down
16 changes: 6 additions & 10 deletions src/core/toga/__init__.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
from .app import App, DocumentApp, MainWindow
from .command import Command, CommandSet, Group, GROUP_BREAK, SECTION_BREAK
from .documents import Document
from .keys import Key

# Resources
from .colors import hsl, hsla, rgb, rgba
from .command import GROUP_BREAK, SECTION_BREAK, Command, CommandSet, Group
from .documents import Document
from .fonts import Font
from .icons import Icon
from .images import Image

from .keys import Key
from .widgets.activityindicator import ActivityIndicator
# Widgets
from .widgets.base import Widget

from .widgets.activityindicator import ActivityIndicator
from .widgets.box import Box
from .widgets.button import Button
from .widgets.canvas import Canvas
from .widgets.datepicker import DatePicker
from .widgets.detailedlist import DetailedList
from .widgets.divider import Divider
from .widgets.imageview import ImageView
from .widgets.datepicker import DatePicker
from .widgets.timepicker import TimePicker
from .widgets.label import Label
from .widgets.multilinetextinput import MultilineTextInput
from .widgets.numberinput import NumberInput
Expand All @@ -34,11 +30,11 @@
from .widgets.switch import Switch
from .widgets.table import Table
from .widgets.textinput import TextInput
from .widgets.timepicker import TimePicker
from .widgets.tree import Tree
from .widgets.webview import WebView
from .window import Window


__all__ = [
# Applications
'App', 'DocumentApp', 'MainWindow',
Expand Down
11 changes: 6 additions & 5 deletions src/core/toga/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
from builtins import id as identifier
from email.message import Message

from toga.command import CommandSet
from toga.handlers import wrapped_handler
from toga.icons import Icon
from toga.platform import get_platform_factory
from toga.window import Window

try:
from importlib import metadata as importlib_metadata
except ImportError:
# Backwards compatibility - imporlib.metadata was added in Python 3.8
import importlib_metadata

from toga.command import CommandSet
from toga.handlers import wrapped_handler
from toga.icons import Icon
from toga.platform import get_platform_factory
from toga.window import Window


class MainWindow(Window):
Expand Down
2 changes: 1 addition & 1 deletion src/core/toga/colors.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Use the Travertino color definitions as-is
from travertino.colors import *
from travertino.colors import * # noqa: F401,F403
23 changes: 15 additions & 8 deletions src/core/toga/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,21 @@ def __eq__(self, other):
class Command:
"""
Args:
action: a function to invoke when the command is activated.
label: a name for the command.
shortcut: (optional) a key combination that can be used to invoke the command.
tooltip: (optional) a short description for what the command will do.
icon: (optional) a path to an icon resource to decorate the command.
group: (optional) a Group object describing a collection of similar commands. If no group is specified, a default "Command" group will be used.
section: (optional) an integer providing a sub-grouping. If no section is specified, the command will be allocated to section 0 within the group.
order: (optional) an integer indicating where a command falls within a section. If a Command doesn't have an order, it will be sorted alphabetically by label within its section.
action: a function to invoke when the command is activated.
label: a name for the command.
shortcut: (optional) a key combination that can be used to invoke the
command.
tooltip: (optional) a short description for what the command will do.
icon: (optional) a path to an icon resource to decorate the command.
group: (optional) a Group object describing a collection of similar
commands. If no group is specified, a default "Command" group will
be used.
section: (optional) an integer providing a sub-grouping. If no section
is specified, the command will be allocated to section 0 within the
group.
order: (optional) an integer indicating where a command falls within a
section. If a Command doesn't have an order, it will be sorted
alphabetically by label within its section.
"""
def __init__(self, action, label,
shortcut=None, tooltip=None, icon=None,
Expand Down
2 changes: 1 addition & 1 deletion src/core/toga/constants/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from travertino.constants import *
from travertino.constants import * # noqa: F401,F403
Loading

0 comments on commit b32e8bd

Please sign in to comment.