mirror of
https://github.com/ArchipelagoMW/Archipelago.git
synced 2026-05-04 14:23:29 -07:00
Launcher: migrate type filter to str, Enum
This commit is contained in:
12
Launcher.py
12
Launcher.py
@@ -21,7 +21,7 @@ from shutil import which
|
||||
from typing import Any, TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from worlds.LauncherComponents import Component
|
||||
from worlds.LauncherComponents import Component, Type
|
||||
|
||||
if __name__ == "__main__":
|
||||
import ModuleUpdate
|
||||
@@ -29,7 +29,7 @@ if __name__ == "__main__":
|
||||
ModuleUpdate.update()
|
||||
|
||||
import Utils
|
||||
from Utils import env_cleared_lib_path, init_logging, is_linux, is_macos, is_windows, local_path, Type
|
||||
from Utils import env_cleared_lib_path, init_logging, is_linux, is_macos, is_windows, local_path
|
||||
|
||||
if __name__ == "__main__":
|
||||
init_logging('Launcher')
|
||||
@@ -150,7 +150,7 @@ def run_gui(launch_components: list["Component"], args: Any) -> None:
|
||||
button_layout: ScrollBox = ObjectProperty(None)
|
||||
search_box: MDTextField = ObjectProperty(None)
|
||||
cards: list[LauncherCard]
|
||||
current_filter: Sequence[str | Type] | None
|
||||
current_filter: Sequence["Type"] | None
|
||||
|
||||
def __init__(self, ctx=None, components=None, args=None):
|
||||
self.title = self.base_title + " " + Utils.__version__
|
||||
@@ -164,6 +164,7 @@ def run_gui(launch_components: list["Component"], args: Any) -> None:
|
||||
super().__init__()
|
||||
|
||||
def load_filter(self):
|
||||
from worlds.LauncherComponents import Type
|
||||
self.current_filter = (Type.CLIENT, Type.TOOL, Type.ADJUSTER, Type.MISC)
|
||||
persistent = Utils.persistent_load()
|
||||
if "launcher" in persistent:
|
||||
@@ -214,8 +215,9 @@ def run_gui(launch_components: list["Component"], args: Any) -> None:
|
||||
|
||||
return button_card
|
||||
|
||||
def _refresh_components(self, type_filter: Sequence[str | Type] | None = None) -> None:
|
||||
def _refresh_components(self, type_filter: Sequence["Type"] | None = None) -> None:
|
||||
if not type_filter:
|
||||
from worlds.LauncherComponents import Type
|
||||
type_filter = [Type.CLIENT, Type.ADJUSTER, Type.TOOL, Type.MISC]
|
||||
favorites = "favorites" in type_filter
|
||||
|
||||
@@ -246,6 +248,7 @@ def run_gui(launch_components: list["Component"], args: Any) -> None:
|
||||
if len(name) == 0:
|
||||
self._refresh_components(self.current_filter)
|
||||
return
|
||||
from worlds.LauncherComponents import Type
|
||||
|
||||
sub_matches = [
|
||||
card for card in self.cards
|
||||
@@ -360,6 +363,7 @@ def run_gui(launch_components: list["Component"], args: Any) -> None:
|
||||
super()._stop(*largs)
|
||||
|
||||
def on_stop(self):
|
||||
from worlds.LauncherComponents import Type
|
||||
Utils.persistent_store("launcher", "favorites", self.favorites)
|
||||
Utils.persistent_store("launcher", "filter", ", ".join(filter.name if isinstance(filter, Type) else filter
|
||||
for filter in self.current_filter))
|
||||
|
||||
8
Utils.py
8
Utils.py
@@ -1376,11 +1376,3 @@ def get_all_causes(ex: Exception) -> str:
|
||||
others = "".join(f"\n{' ' * (i + 1)}Which caused: {c}" for i, c in enumerate(reversed(causes[:-1])))
|
||||
return f"{top}{others}"
|
||||
|
||||
|
||||
class Type(Enum):
|
||||
TOOL = auto()
|
||||
MISC = auto()
|
||||
CLIENT = auto()
|
||||
ADJUSTER = auto()
|
||||
FUNC = auto() # do not use anymore
|
||||
HIDDEN = auto()
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#:import Utils Utils
|
||||
#:import Type Utils.Type
|
||||
<LauncherCard>:
|
||||
id: main
|
||||
style: "filled"
|
||||
@@ -80,7 +79,7 @@ MDFloatLayout:
|
||||
MDButton:
|
||||
id: all
|
||||
style: "text"
|
||||
type: (Type.CLIENT, Type.TOOL, Type.ADJUSTER, Type.MISC)
|
||||
type: ("CLIENT", "TOOL", "ADJUSTER", "MISC")
|
||||
on_release: app.filter_clients_by_type(self)
|
||||
|
||||
MDButtonIcon:
|
||||
@@ -90,7 +89,7 @@ MDFloatLayout:
|
||||
MDButton:
|
||||
id: client
|
||||
style: "text"
|
||||
type: (Type.CLIENT, )
|
||||
type: ("CLIENT", )
|
||||
on_release: app.filter_clients_by_type(self)
|
||||
|
||||
MDButtonIcon:
|
||||
@@ -100,7 +99,7 @@ MDFloatLayout:
|
||||
MDButton:
|
||||
id: Tool
|
||||
style: "text"
|
||||
type: (Type.TOOL, )
|
||||
type: ("TOOL", )
|
||||
on_release: app.filter_clients_by_type(self)
|
||||
|
||||
MDButtonIcon:
|
||||
@@ -110,7 +109,7 @@ MDFloatLayout:
|
||||
MDButton:
|
||||
id: adjuster
|
||||
style: "text"
|
||||
type: (Type.ADJUSTER, )
|
||||
type: ("ADJUSTER", )
|
||||
on_release: app.filter_clients_by_type(self)
|
||||
|
||||
MDButtonIcon:
|
||||
@@ -120,7 +119,7 @@ MDFloatLayout:
|
||||
MDButton:
|
||||
id: misc
|
||||
style: "text"
|
||||
type: (Type.MISC, )
|
||||
type: ("MISC", )
|
||||
on_release: app.filter_clients_by_type(self)
|
||||
|
||||
MDButtonIcon:
|
||||
|
||||
@@ -4,10 +4,19 @@ import pathlib
|
||||
import weakref
|
||||
import sys
|
||||
import webbrowser
|
||||
from enum import Enum
|
||||
from typing import Optional, Callable, Iterable, Sequence
|
||||
|
||||
from Utils import local_path, open_filename, is_frozen, is_kivy_running, open_file, user_path, read_apignore, \
|
||||
is_windows, Type
|
||||
is_windows
|
||||
|
||||
|
||||
class Type(str, Enum):
|
||||
TOOL = "TOOL"
|
||||
MISC = "MISC"
|
||||
CLIENT = "CLIENT"
|
||||
ADJUSTER = "ADJUSTER"
|
||||
HIDDEN = "HIDDEN"
|
||||
|
||||
|
||||
class Component:
|
||||
@@ -60,10 +69,6 @@ class Component:
|
||||
self.frozen_name = frozen_name or f'Archipelago{script_name}' if script_name else None
|
||||
self.icon = icon
|
||||
self.cli = cli
|
||||
if component_type == Type.FUNC:
|
||||
from Utils import deprecate
|
||||
deprecate(f"Launcher Component {self.display_name} is using Type.FUNC Type, which is pending removal.")
|
||||
component_type = Type.MISC
|
||||
|
||||
self.type = component_type or (
|
||||
Type.CLIENT if "Client" in display_name else
|
||||
|
||||
Reference in New Issue
Block a user