Skip to content
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

Launcher: deprecate FUNC Component type #1872

Merged
merged 6 commits into from
Jun 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 6 additions & 6 deletions Launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ class Launcher(App):
container: ContainerLayout
grid: GridLayout

_tools = {c.display_name: c for c in components if c.type == Type.TOOL and isfile(get_exe(c)[-1])}
_clients = {c.display_name: c for c in components if c.type == Type.CLIENT and isfile(get_exe(c)[-1])}
_adjusters = {c.display_name: c for c in components if c.type == Type.ADJUSTER and isfile(get_exe(c)[-1])}
_funcs = {c.display_name: c for c in components if c.type == Type.FUNC}
_tools = {c.display_name: c for c in components if c.type == Type.TOOL}
_clients = {c.display_name: c for c in components if c.type == Type.CLIENT}
_adjusters = {c.display_name: c for c in components if c.type == Type.ADJUSTER}
_miscs = {c.display_name: c for c in components if c.type == Type.MISC}

def __init__(self, ctx=None):
self.title = self.base_title
Expand Down Expand Up @@ -199,7 +199,7 @@ def build_button(component: Component):
button_layout.add_widget(button)

for (tool, client) in itertools.zip_longest(itertools.chain(
self._tools.items(), self._funcs.items(), self._adjusters.items()), self._clients.items()):
self._tools.items(), self._miscs.items(), self._adjusters.items()), self._clients.items()):
# column 1
if tool:
build_button(tool[1])
Expand All @@ -215,7 +215,7 @@ def build_button(component: Component):

@staticmethod
def component_action(button):
if button.component.type == Type.FUNC:
if button.component.func:
button.component.func()
else:
launch(get_exe(button.component), button.component.cli)
Expand Down
8 changes: 4 additions & 4 deletions worlds/LauncherComponents.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
from enum import Enum, auto
from typing import Optional, Callable, List, Iterable

from Utils import local_path, is_windows
from Utils import local_path


class Type(Enum):
TOOL = auto()
FUNC = auto() # not a real component
FUNC = auto() # not a real component, do not use anymore
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be better the other way around? i.e. MISC = auto(); MISC = FUNC ? anyway, this way we can't give a DeprecationWarning. My original idea would've been renaming FUNC -> MISC, and then adding a new FUNC which gets checked and replaecd in Components.__init__ to generate a DeprecationWarning.

CLIENT = auto()
ADJUSTER = auto()
MISC = FUNC


class Component:
Expand All @@ -31,9 +32,8 @@ def __init__(self, display_name: str, script_name: Optional[str] = None, frozen_
self.cli = cli
self.type = component_type or \
None if not display_name else \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while you are at it,

  • i don't think bool(display_name) should ever be False, so we could remove the None if ... and change the type hint for type to not be optional? if we want hide a button, it'd be better to use a special type or an additional flag rather than having display_name = ""

Type.FUNC if func else \
Type.CLIENT if 'Client' in display_name else \
Type.ADJUSTER if 'Adjuster' in display_name else Type.TOOL
Type.ADJUSTER if 'Adjuster' in display_name else Type.MISC
self.func = func
self.file_identifier = file_identifier

Expand Down