mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-25 00:33:37 +05:00
refactor: start at index 1 in moonraker setup dialog if multi instance
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
@@ -52,7 +52,7 @@ def select_instances_to_remove(
|
||||
) -> Union[List[Klipper], None]:
|
||||
start_index = 1
|
||||
options = [str(i + start_index) for i in range(len(instances))]
|
||||
options.extend(["a", "A", "b", "B"])
|
||||
options.extend(["a", "b"])
|
||||
instance_map = {options[i]: instances[i] for i in range(len(instances))}
|
||||
|
||||
print_instance_overview(
|
||||
@@ -64,9 +64,9 @@ def select_instances_to_remove(
|
||||
selection = get_selection_input("Select Klipper instance to remove", options)
|
||||
|
||||
instances_to_remove = []
|
||||
if selection == "b".lower():
|
||||
if selection == "b":
|
||||
return None
|
||||
elif selection == "a".lower():
|
||||
elif selection == "a":
|
||||
instances_to_remove.extend(instances)
|
||||
else:
|
||||
instances_to_remove.append(instance_map[selection])
|
||||
|
||||
@@ -48,7 +48,7 @@ def print_moonraker_overview(
|
||||
for i, k in enumerate(instance_map):
|
||||
mr_name = instance_map.get(k)
|
||||
m = f"<-> {mr_name}" if mr_name != "" else ""
|
||||
line = f"{COLOR_CYAN}{f'{i})' if show_index else '●'} {k} {m} {RESET_FORMAT}"
|
||||
line = f"{COLOR_CYAN}{f'{i+1})' if show_index else '●'} {k} {m} {RESET_FORMAT}"
|
||||
dialog += f"║ {line:<63}║\n"
|
||||
|
||||
warn_l1 = f"{COLOR_YELLOW}PLEASE NOTE: {RESET_FORMAT}"
|
||||
|
||||
@@ -60,7 +60,7 @@ def select_instances_to_remove(
|
||||
) -> Union[List[Moonraker], None]:
|
||||
start_index = 1
|
||||
options = [str(i + start_index) for i in range(len(instances))]
|
||||
options.extend(["a", "A", "b", "B"])
|
||||
options.extend(["a", "b"])
|
||||
instance_map = {options[i]: instances[i] for i in range(len(instances))}
|
||||
|
||||
print_instance_overview(
|
||||
@@ -72,9 +72,9 @@ def select_instances_to_remove(
|
||||
selection = get_selection_input("Select Moonraker instance to remove", options)
|
||||
|
||||
instances_to_remove = []
|
||||
if selection == "b".lower():
|
||||
if selection == "b":
|
||||
return None
|
||||
elif selection == "a".lower():
|
||||
elif selection == "a":
|
||||
instances_to_remove.extend(instances)
|
||||
else:
|
||||
instances_to_remove.append(instance_map[selection])
|
||||
|
||||
@@ -6,8 +6,11 @@
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
# ======================================================================= #
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import subprocess
|
||||
from typing import List
|
||||
|
||||
from components.klipper.klipper import Klipper
|
||||
from components.moonraker import (
|
||||
@@ -57,36 +60,36 @@ def install_moonraker() -> None:
|
||||
if not check_moonraker_install_requirements():
|
||||
return
|
||||
|
||||
kl_im = InstanceManager(Klipper)
|
||||
klipper_instances = kl_im.instances
|
||||
klipper_list: List[Klipper] = InstanceManager(Klipper).instances
|
||||
mr_im = InstanceManager(Moonraker)
|
||||
moonraker_instances = mr_im.instances
|
||||
moonraker_list: List[Moonraker] = mr_im.instances
|
||||
|
||||
selected_klipper_instance = 0
|
||||
if len(klipper_instances) > 1:
|
||||
instance_names = []
|
||||
selected_option: str | Klipper
|
||||
|
||||
if len(klipper_list) == 0:
|
||||
instance_names.append(klipper_list[0].suffix)
|
||||
else:
|
||||
print_moonraker_overview(
|
||||
klipper_instances,
|
||||
moonraker_instances,
|
||||
klipper_list,
|
||||
moonraker_list,
|
||||
show_index=True,
|
||||
show_select_all=True,
|
||||
)
|
||||
options = [str(i) for i in range(len(klipper_instances))]
|
||||
options.extend(["a", "A", "b", "B"])
|
||||
options = {str(i + 1): k for i, k in enumerate(klipper_list)}
|
||||
additional_options = {"a": None, "b": None}
|
||||
options = {**options, **additional_options}
|
||||
question = "Select Klipper instance to setup Moonraker for"
|
||||
selected_klipper_instance = get_selection_input(question, options).lower()
|
||||
selected_option = get_selection_input(question, options)
|
||||
|
||||
instance_names = []
|
||||
if selected_klipper_instance == "b":
|
||||
Logger.print_status(EXIT_MOONRAKER_SETUP)
|
||||
return
|
||||
if selected_option == "b":
|
||||
Logger.print_status(EXIT_MOONRAKER_SETUP)
|
||||
return
|
||||
|
||||
elif selected_klipper_instance == "a":
|
||||
for instance in klipper_instances:
|
||||
instance_names.append(instance.suffix)
|
||||
|
||||
else:
|
||||
index = int(selected_klipper_instance)
|
||||
instance_names.append(klipper_instances[index].suffix)
|
||||
if selected_option == "a":
|
||||
instance_names.extend([k.suffix for k in klipper_list])
|
||||
else:
|
||||
instance_names.append(options.get(selected_option).suffix)
|
||||
|
||||
create_example_cfg = get_confirm("Create example moonraker.conf?")
|
||||
|
||||
@@ -95,9 +98,7 @@ def install_moonraker() -> None:
|
||||
setup_moonraker_prerequesites()
|
||||
install_moonraker_polkit()
|
||||
|
||||
used_ports_map = {
|
||||
instance.suffix: instance.port for instance in moonraker_instances
|
||||
}
|
||||
used_ports_map = {m.suffix: m.port for m in moonraker_list}
|
||||
for name in instance_names:
|
||||
current_instance = Moonraker(suffix=name)
|
||||
|
||||
|
||||
@@ -157,7 +157,7 @@ def get_printer_selection(
|
||||
instances: List[BaseInstance], is_install: bool
|
||||
) -> Union[List[BaseInstance], None]:
|
||||
options = [str(i) for i in range(len(instances))]
|
||||
options.extend(["a", "A", "b", "B"])
|
||||
options.extend(["a", "b"])
|
||||
|
||||
if is_install:
|
||||
q = "Select the printer to install the theme for"
|
||||
@@ -166,9 +166,9 @@ def get_printer_selection(
|
||||
selection = get_selection_input(q, options)
|
||||
|
||||
install_for = []
|
||||
if selection == "b".lower():
|
||||
if selection == "b":
|
||||
return None
|
||||
elif selection == "a".lower():
|
||||
elif selection == "a":
|
||||
install_for.extend(instances)
|
||||
else:
|
||||
instance = instances[int(selection)]
|
||||
|
||||
@@ -62,7 +62,7 @@ class ObicoExtension(BaseExtension):
|
||||
obico_instances: List[MoonrakerObico] = obico_im.instances
|
||||
if obico_instances:
|
||||
self._print_is_already_installed()
|
||||
options = ["l", "L", "r", "R", "b", "B"]
|
||||
options = ["l", "r", "b"]
|
||||
action = get_selection_input("Perform action", option_list=options)
|
||||
if action.lower() == "b":
|
||||
Logger.print_info("Exiting Obico for Klipper installation ...")
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
from typing import List, Union
|
||||
from typing import Dict, List, Union
|
||||
|
||||
from utils import INVALID_CHOICE
|
||||
from utils.constants import COLOR_CYAN, RESET_FORMAT
|
||||
@@ -120,7 +120,7 @@ def get_string_input(
|
||||
Logger.print_error(INVALID_CHOICE)
|
||||
|
||||
|
||||
def get_selection_input(question: str, option_list: List, default=None) -> str:
|
||||
def get_selection_input(question: str, option_list: List | Dict, default=None) -> str:
|
||||
"""
|
||||
Helper method to get a selection from a list of options from the user
|
||||
:param question: The question to display
|
||||
@@ -129,10 +129,16 @@ def get_selection_input(question: str, option_list: List, default=None) -> str:
|
||||
:return: The option that was selected by the user
|
||||
"""
|
||||
while True:
|
||||
_input = input(format_question(question, default)).strip()
|
||||
_input = input(format_question(question, default)).strip().lower()
|
||||
|
||||
if _input in option_list:
|
||||
return _input
|
||||
if isinstance(option_list, list):
|
||||
if _input in option_list:
|
||||
return _input
|
||||
elif isinstance(option_list, dict):
|
||||
if _input in option_list.keys():
|
||||
return _input
|
||||
else:
|
||||
raise ValueError("Invalid option_list type")
|
||||
|
||||
Logger.print_error(INVALID_CHOICE)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user