Skip to content

Commit

Permalink
[basics] Resolve merging conflicts.
Browse files Browse the repository at this point in the history
  • Loading branch information
MuhammadMuradG committed Nov 10, 2023
2 parents a9e4e9a + 73c8fc0 commit e8dd20f
Show file tree
Hide file tree
Showing 48 changed files with 274 additions and 133 deletions.
8 changes: 5 additions & 3 deletions android/src/toga_android/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,12 @@ def create(self):
self._listener = TogaApp(self)
# Call user code to populate the main window
self.interface._startup()
self._create_app_commands()

def create_menus(self):
self.native.invalidateOptionsMenu() # Triggers onPrepareOptionsMenu

def _create_app_commands(self):
self.interface.commands.add(
# About should be the last item in the menu, in a section on its own.
Command(
Expand All @@ -187,9 +192,6 @@ def create(self):
),
)

def create_menus(self):
self.native.invalidateOptionsMenu() # Triggers onPrepareOptionsMenu

def main_loop(self):
# In order to support user asyncio code, start the Python/Android cooperative event loop.
self.loop.run_forever_cooperatively()
Expand Down
4 changes: 0 additions & 4 deletions android/src/toga_android/widgets/progressbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from android import R
from android.view import View
from android.widget import ProgressBar as A_ProgressBar
from travertino.size import at_least

from .base import Widget

Expand Down Expand Up @@ -94,9 +93,6 @@ def rehint(self):
View.MeasureSpec.UNSPECIFIED,
View.MeasureSpec.UNSPECIFIED,
)
self.interface.intrinsic.width = self.scale_out(
at_least(self.native.getMeasuredWidth()), ROUND_UP
)
self.interface.intrinsic.height = self.scale_out(
self.native.getMeasuredHeight(), ROUND_UP
)
4 changes: 0 additions & 4 deletions android/src/toga_android/widgets/selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from android.view import View
from android.widget import AdapterView, ArrayAdapter, Spinner
from java import dynamic_proxy
from travertino.size import at_least

from .base import Widget

Expand Down Expand Up @@ -86,9 +85,6 @@ def clear(self):

def rehint(self):
self.native.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED)
self.interface.intrinsic.width = self.scale_out(
at_least(self.native.getMeasuredWidth()), ROUND_UP
)
self.interface.intrinsic.height = self.scale_out(
self.native.getMeasuredHeight(), ROUND_UP
)
4 changes: 0 additions & 4 deletions android/src/toga_android/widgets/slider.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from android.view import View
from android.widget import SeekBar
from java import dynamic_proxy
from travertino.size import at_least

import toga

Expand Down Expand Up @@ -69,9 +68,6 @@ def _load_tick_drawable(self):

def rehint(self):
self.native.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED)
self.interface.intrinsic.width = self.scale_out(
at_least(self.native.getMeasuredWidth()), ROUND_UP
)
self.interface.intrinsic.height = self.scale_out(
self.native.getMeasuredHeight(), ROUND_UP
)
5 changes: 2 additions & 3 deletions android/tests_backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@


class AppProbe(BaseProbe):
supports_key = False

def __init__(self, app):
super().__init__(app)
self.native = self.app._impl.native
Expand Down Expand Up @@ -88,9 +90,6 @@ def activate_menu_close_all_windows(self):
def activate_menu_minimize(self):
xfail("This backend doesn't have a window management menu")

def keystroke(self, combination):
xfail("This backend doesn't use keyboard shortcuts")

def enter_background(self):
xfail(
"This is possible (https://stackoverflow.com/a/7071289), but there's no "
Expand Down
1 change: 0 additions & 1 deletion changes/2103.docs.rst

This file was deleted.

1 change: 1 addition & 0 deletions changes/2194.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The web backend no longer generates a duplicate titlebar.
1 change: 1 addition & 0 deletions changes/2195.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
An issue with the display of the About dialog on the web backend was corrected.
1 change: 1 addition & 0 deletions changes/2198.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A wider range of command shortcut keys are now supported on WinForms.
1 change: 1 addition & 0 deletions changes/2198.removal.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The use of Caps Lock as a keyboard modifier for commands was removed.
1 change: 1 addition & 0 deletions changes/2199.doc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Documentation for ``toga.Key`` was added.
1 change: 1 addition & 0 deletions changes/2200.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Most widgets with flexible sizes now default to a minimum size of 100 CSS pixels. An explicit size will still override this value.
1 change: 1 addition & 0 deletions changes/2201.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Minor fix: removed a repeated word in the docs for App Paths
1 change: 1 addition & 0 deletions changes/2204.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Some inconsistencies in widget support documentation were corrected.
1 change: 1 addition & 0 deletions changes/2215.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
On Android the creation of the app commands has been moved to the method _create_app_commands()
1 change: 1 addition & 0 deletions changes/2216.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add more tests for sliders with empty ranges
4 changes: 0 additions & 4 deletions cocoa/src/toga_cocoa/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from toga import Key
from toga_cocoa.libs import (
NSEventModifierFlagCapsLock,
NSEventModifierFlagCommand,
NSEventModifierFlagControl,
NSEventModifierFlagOption,
Expand Down Expand Up @@ -151,8 +150,6 @@ def toga_key(event):
modifiers.add(Key.MOD_2)
if event.modifierFlags & NSEventModifierFlagControl:
modifiers.add(Key.MOD_3)
if event.modifierFlags & NSEventModifierFlagCapsLock:
modifiers.add(Key.CAPSLOCK)

return {"key": key, "modifiers": modifiers}

Expand Down Expand Up @@ -213,7 +210,6 @@ def toga_key(event):

COCOA_MODIFIERS = {
Key.SHIFT: NSEventModifierFlagShift,
Key.CAPSLOCK: NSEventModifierFlagCapsLock,
Key.MOD_1: NSEventModifierFlagCommand,
Key.MOD_2: NSEventModifierFlagOption,
Key.MOD_3: NSEventModifierFlagControl,
Expand Down
3 changes: 3 additions & 0 deletions cocoa/tests_backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@


class AppProbe(BaseProbe):
supports_key = True
supports_key_mod3 = True

def __init__(self, app):
super().__init__()
self.app = app
Expand Down
3 changes: 2 additions & 1 deletion core/src/toga/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from toga.handlers import wrapped_handler
from toga.icons import Icon
from toga.keys import Key
from toga.platform import get_platform_factory

if TYPE_CHECKING:
Expand Down Expand Up @@ -163,7 +164,7 @@ def __init__(
action: ActionHandler | None,
text: str,
*,
shortcut: str | None = None,
shortcut: str | Key | None = None,
tooltip: str | None = None,
icon: str | Icon | None = None,
group: Group = Group.COMMANDS,
Expand Down
44 changes: 24 additions & 20 deletions core/src/toga/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@


class Key(Enum):
"""An enumeration providing a symbolic representation for the characters on
a keyboard."""

A = "a"
B = "b"
C = "c"
Expand Down Expand Up @@ -92,25 +95,25 @@ class Key(Enum):
MOD_2 = "<mod 2>" # OPT on macOS, ALT on Linux/Windows
MOD_3 = "<mod 3>" # CTRL on macOS, Flag on Windows, Tux on Linux

F1 = "<F1>"
F2 = "<F2>"
F3 = "<F3>"
F4 = "<F4>"
F5 = "<F5>"
F6 = "<F6>"
F7 = "<F7>"
F8 = "<F8>"
F9 = "<F9>"
F10 = "<F10>"
F11 = "<F11>"
F12 = "<F12>"
F13 = "<F13>"
F14 = "<F14>"
F15 = "<F15>"
F16 = "<F16>"
F17 = "<F17>"
F18 = "<F18>"
F19 = "<F19>"
F1 = "<f1>"
F2 = "<f2>"
F3 = "<f3>"
F4 = "<f4>"
F5 = "<f5>"
F6 = "<f6>"
F7 = "<f7>"
F8 = "<f8>"
F9 = "<f9>"
F10 = "<f10>"
F11 = "<f11>"
F12 = "<f12>"
F13 = "<f13>"
F14 = "<f14>"
F15 = "<f15>"
F16 = "<f16>"
F17 = "<f17>"
F18 = "<f18>"
F19 = "<f19>"

EJECT = "<eject>"

Expand Down Expand Up @@ -144,7 +147,8 @@ class Key(Enum):
NUMPAD_MULTIPLY = "numpad:*"
NUMPAD_PLUS = "numpad:+"

def is_printable(self):
def is_printable(self) -> bool:
"""Does pressing the key result in a printable character?"""
return not (self.value.startswith("<") and self.value.endswith(">"))

def __add__(self, other):
Expand Down
3 changes: 0 additions & 3 deletions core/src/toga/widgets/scrollcontainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@


class ScrollContainer(Widget):
_MIN_WIDTH = 0
_MIN_HEIGHT = 0

def __init__(
self,
id=None,
Expand Down
66 changes: 54 additions & 12 deletions core/tests/widgets/test_slider.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,36 +229,44 @@ def test_range(slider, on_change, min, max, value):


@pytest.mark.parametrize(
"new_min, new_max",
"new_min, new_value, new_max",
[
[-5, 10], # less than old min
[5, 10], # more than old min, less than max
[15, 15], # more than max
[-5, 5, 10], # less than old min
[5, 5, 10], # more than old min
[6, 6, 10], # more than old min and value
[15, 15, 15], # more than old min, value and max
],
)
def test_min_clipping(slider, new_min, new_max):
def test_min_clipping(slider, new_min, new_value, new_max):
slider.tick_count = None
slider.min = 0
slider.value = 5
slider.max = 10

slider.min = new_min
assert slider.min == new_min
assert slider.value == new_value
assert slider.max == new_max


@pytest.mark.parametrize(
"new_max, new_min",
"new_min, new_value, new_max",
[
[15, 0], # less than old max
[5, 0], # less than old max, more than min
[-5, -5], # less than min
[0, 5, 15], # more than old max
[0, 5, 5], # less than old max
[0, 4, 4], # less than old max and value
[-5, -5, -5], # less than old max, value and min
],
)
def test_max_clipping(slider, new_max, new_min):
def test_max_clipping(slider, new_min, new_value, new_max):
slider.tick_count = None
slider.min = 0
slider.value = 5
slider.max = 10

slider.max = new_max
assert slider.min == new_min
assert slider.value == new_value
assert slider.max == new_max


Expand Down Expand Up @@ -429,14 +437,31 @@ def test_int_impl_continuous():
assert impl.int_value == int_value
assert impl.get_value() == value

# Check a range that doesn't start at zero.
# Range that doesn't start at zero
impl.set_min(-0.4)
assert impl.get_min() == pytest.approx(-0.4)
impl.set_max(0.6)
assert impl.get_max() == pytest.approx(0.6)
impl.set_value(0.5)
assert impl.get_value() == 0.5
assert impl.int_value == 9000
assert impl.int_max == 10000

# Empty range
impl.set_min(0)
impl.set_max(0)
impl.set_value(0)
assert impl.get_value() == 0
assert impl.int_value == 0
assert impl.int_max == 10000

# Empty range that doesn't start at zero
impl.set_min(1)
impl.set_max(1)
impl.set_value(1)
assert impl.get_value() == 1
assert impl.int_value == 0
assert impl.int_max == 10000


def test_int_impl_discrete():
Expand Down Expand Up @@ -467,14 +492,31 @@ def test_int_impl_discrete():
assert impl.get_value() == value
assert impl.int_value == int_value

# Check a range that doesn't start at zero.
# Range that doesn't start at zero
impl.set_min(-0.4)
assert impl.get_min() == pytest.approx(-0.4)
impl.set_max(0.6)
assert impl.get_max() == pytest.approx(0.6)
impl.set_value(0.5)
assert impl.get_value() == 0.5
assert impl.int_value == 7
assert impl.int_max == 8

# Empty range
impl.set_min(0)
impl.set_max(0)
impl.set_value(0)
assert impl.get_value() == 0
assert impl.int_value == 0
assert impl.int_max == 8

# Empty range that doesn't start at zero
impl.set_min(1)
impl.set_max(1)
impl.set_value(1)
assert impl.get_value() == 1
assert impl.int_value == 0
assert impl.int_max == 8


@pytest.mark.parametrize(
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/api/documentapp.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The top-level representation of an application that manages documents.
.. csv-filter:: Availability (:ref:`Key <api-status-key>`)
:header-rows: 1
:file: ../data/widgets_by_platform.csv
:included_cols: 4,5,6,7,8,9
:included_cols: 4,5,6,7,8,9,10
:exclude: {0: '(?!(DocumentApp|Component))'}


Expand Down
2 changes: 2 additions & 0 deletions docs/reference/api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ Other
Component Description
============================================== ========================================================================
:doc:`Constants </reference/api/constants>` Symbolic constants used by various APIs.
:doc:`Keys </reference/api/keys>` Symbolic representation of keys used for keyboard shortcuts.
============================================== ========================================================================

.. toctree::
Expand All @@ -109,3 +110,4 @@ Other
resources/index
widgets/index
constants
keys
Loading

0 comments on commit e8dd20f

Please sign in to comment.