Skip to content

Experiments with typing support #1239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions pyface/action/api.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# (C) Copyright 2005-2023 Enthought, Inc., Austin, TX
# All rights reserved.
#
# This software is provided without warranty under the terms of the BSD
# license included in LICENSE.txt and may be redistributed only under
# the conditions described in the aforementioned license. The license
# is also available online at http://www.enthought.com/licenses/BSD.txt
#
# Thanks for using Enthought open source!

from typing import Type

from .i_menu_bar_manager import IMenuBarManager
from .i_menu_manager import IMenuManager
from .i_status_bar_manager import IStatusBarManager
from .i_tool_bar_manager import IToolBarManager


# we know these are importable and implement the interfaces
MenuBarManager: Type[IMenuBarManager]
MenuManager: Type[IMenuManager]
StatusBarManager: Type[IStatusBarManager]
ToolBarManager: Type[IToolBarManager]
4 changes: 2 additions & 2 deletions pyface/i_image_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from collections.abc import Sequence

from traits.api import HasTraits, List, Str
from traits.api import Directory, HasTraits, List, Str

from pyface.i_image import IImage
from pyface.resource.resource_path import resource_module, resource_path
Expand All @@ -34,7 +34,7 @@ class IImageResource(IImage):

#: A list of directories, classes or instances that will be used to search
#: for the image (see the resource manager for more details).
search_path = List()
search_path = List(Directory())

@classmethod
def image_size(cls, image):
Expand Down
4 changes: 2 additions & 2 deletions pyface/resource/resource_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
except ImportError:
from importlib_resources import files

from traits.api import HasTraits, Instance, List
from traits.api import Directory, HasTraits, Instance, List
from traits.util.resource import get_path

from pyface.resource.resource_factory import ResourceFactory
Expand All @@ -48,7 +48,7 @@ class ResourceManager(HasTraits):

# A list of additional search paths. These paths are fallbacks, and hence
# have lower priority than the paths provided by resource objects.
extra_paths = List()
extra_paths = List(Directory)

# The resource factory is responsible for actually creating resources.
# This is used so that (for example) different GUI toolkits can create
Expand Down
96 changes: 96 additions & 0 deletions pyface/ui_traits.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# (C) Copyright 2005-2023 Enthought, Inc., Austin, TX
# All rights reserved.
#
# This software is provided without warranty under the terms of the BSD
# license included in LICENSE.txt and may be redistributed only under
# the conditions described in the aforementioned license. The license
# is also available online at http://www.enthought.com/licenses/BSD.txt
#
# Thanks for using Enthought open source!

from collections.abc import Sequence
from typing import Any, Callable, Dict, Optional, Union

from traits.api import ABCHasStrictTraits, Enum, Range
from traits.trait_type import _TraitType

from pyface.util.font_parser import simple_parser
from .color import Color
from .font import Font
from .i_image import IImage


class Image(_TraitType[Union[IImage, str], Optional[IImage]]):

def __init__(self, value: Union[IImage, str, None] = None, **metadata) -> None:
...


class PyfaceColor(_TraitType[Union[Color, str, Sequence], Color]):

def __init__(
self,
value: Union[Color, str, Sequence, None] = None,
**metadata,
) -> None:
...


class PyfaceFont(_TraitType[Union[Font, str], Font]):

def __init__(
self,
value: Union[Font, str, None] = None,
parser: Callable[[str], Dict[str, Any]] = simple_parser,
**metadata,
) -> None:
...


class BaseMB(ABCHasStrictTraits):
...


class Margin(BaseMB):

# The amount of padding/margin at the top:
top = Range(-32, 32, 0)

# The amount of padding/margin at the bottom:
bottom = Range(-32, 32, 0)

# The amount of padding/margin on the left:
left = Range(-32, 32, 0)

# The amount of padding/margin on the right:
right = Range(-32, 32, 0)


class HasMargin(_TraitType[Union[int, tuple, Margin], Margin]):
...


class Border(BaseMB):

# The amount of border at the top:
top = Range(0, 32, 0)

# The amount of border at the bottom:
bottom = Range(0, 32, 0)

# The amount of border on the left:
left = Range(0, 32, 0)

# The amount of border on the right:
right = Range(0, 32, 0)


class HasBorder(_TraitType[Union[int, tuple, Border], Border]):
...

Position = Enum("left", "right", "above", "below")

Alignment = Enum("default", "left", "center", "right")

Orientation = Enum("vertical", "horizontal")