Skip to content

Commit 60a336b

Browse files
committed
fix(engineonly): utiliser un entrypoint temporaire sans écrire dans la config ARK
1 parent b1d639b commit 60a336b

1 file changed

Lines changed: 123 additions & 29 deletions

File tree

OnlyMod/EngineOnlyMod/gui.py

Lines changed: 123 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ def __init__(
224224
self.theme = theme
225225
self.selected_engine_id = None
226226
self.selected_file = None
227+
self.entrypoint_file = None
228+
self._entrypoint_relpath = None
227229

228230
# État du venv
229231
self.venv_path: Optional[str] = None
@@ -247,6 +249,8 @@ def __init__(
247249

248250
# Initialisation du gestionnaire de venv
249251
self._init_venv_manager()
252+
self._load_entrypoint_from_workspace()
253+
self._apply_entrypoint_marker()
250254

251255
# Centre la fenêtre sur l'écran
252256
self._center_window()
@@ -325,20 +329,6 @@ def _setup_ui(self):
325329
project_layout.setHorizontalSpacing(8)
326330
project_layout.setVerticalSpacing(8)
327331

328-
file_label = QLabel("File:")
329-
file_label.setMinimumWidth(72)
330-
self.file_path_edit = QLineEdit()
331-
self.file_path_edit.setPlaceholderText("Select a Python file to compile...")
332-
self.file_path_edit.setMinimumHeight(30)
333-
browse_btn = QPushButton("Browse")
334-
browse_btn.setObjectName("secondary_button")
335-
browse_btn.setMinimumHeight(30)
336-
browse_btn.setMinimumWidth(84)
337-
browse_btn.clicked.connect(self._browse_file)
338-
project_layout.addWidget(file_label, 0, 0)
339-
project_layout.addWidget(self.file_path_edit, 0, 1)
340-
project_layout.addWidget(browse_btn, 0, 2)
341-
342332
workspace_label = QLabel("Workspace:")
343333
workspace_label.setMinimumWidth(72)
344334
self.workspace_edit = QLineEdit()
@@ -351,9 +341,27 @@ def _setup_ui(self):
351341
workspace_browse_btn.setMinimumHeight(30)
352342
workspace_browse_btn.setMinimumWidth(84)
353343
workspace_browse_btn.clicked.connect(self._browse_workspace)
354-
project_layout.addWidget(workspace_label, 1, 0)
355-
project_layout.addWidget(self.workspace_edit, 1, 1)
356-
project_layout.addWidget(workspace_browse_btn, 1, 2)
344+
project_layout.addWidget(workspace_label, 0, 0)
345+
project_layout.addWidget(self.workspace_edit, 0, 1)
346+
project_layout.addWidget(workspace_browse_btn, 0, 2)
347+
348+
file_label = QLabel("File:")
349+
file_label.setMinimumWidth(72)
350+
self.file_path_edit = QLineEdit()
351+
self.file_path_edit.setPlaceholderText("Select a Python file (entrypoint)...")
352+
self.file_path_edit.setMinimumHeight(30)
353+
browse_file_btn = QPushButton("Browse")
354+
browse_file_btn.setObjectName("secondary_button")
355+
browse_file_btn.setMinimumHeight(30)
356+
browse_file_btn.setMinimumWidth(84)
357+
browse_file_btn.clicked.connect(self._browse_file)
358+
project_layout.addWidget(file_label, 1, 0)
359+
project_layout.addWidget(self.file_path_edit, 1, 1)
360+
project_layout.addWidget(browse_file_btn, 1, 2)
361+
362+
self.entrypoint_info_label = QLabel("Entrypoint: not set")
363+
self.entrypoint_info_label.setObjectName("subtle_label")
364+
project_layout.addWidget(self.entrypoint_info_label, 2, 0, 1, 3)
357365
left_layout.addWidget(project_group)
358366

359367
venv_group = QGroupBox("Virtual Environment")
@@ -893,18 +901,96 @@ def _check_compatibility(self):
893901
except Exception as e:
894902
self._log(f"Error checking compatibility: {e}")
895903

896-
def _browse_file(self):
897-
"""Ouvre une boîte de dialogue pour sélectionner un fichier."""
904+
def _load_entrypoint_from_workspace(self) -> None:
905+
"""Load entrypoint from ARK_Main_Config.yml for current workspace."""
906+
self._entrypoint_relpath = None
907+
self.entrypoint_file = None
908+
ws = (self.workspace_edit.text() or "").strip()
909+
if not ws:
910+
return
911+
try:
912+
from Core.ArkConfigManager import get_entrypoint, load_ark_config
913+
914+
cfg = load_ark_config(ws)
915+
rel = get_entrypoint(cfg)
916+
if rel:
917+
abs_path = os.path.join(ws, rel)
918+
if os.path.isfile(abs_path):
919+
self._entrypoint_relpath = rel
920+
self.entrypoint_file = abs_path
921+
except Exception:
922+
return
923+
924+
def _apply_entrypoint_marker(self) -> None:
925+
"""Refresh entrypoint labels and file preview."""
926+
if self.selected_file:
927+
try:
928+
ws = self.workspace_edit.text().strip() or self.workspace_dir or ""
929+
rel = (
930+
os.path.relpath(self.selected_file, ws).replace("\\", "/")
931+
if ws
932+
else self.selected_file
933+
)
934+
except Exception:
935+
rel = self.selected_file
936+
self.entrypoint_info_label.setText(f"Entrypoint (this build only): {rel}")
937+
if self._is_valid(self.file_path_edit):
938+
self.file_path_edit.setText(self.selected_file)
939+
return
940+
941+
rel = self._entrypoint_relpath
942+
if rel:
943+
self.entrypoint_info_label.setText(f"Entrypoint (config): {rel}")
944+
if self._is_valid(self.file_path_edit):
945+
self.file_path_edit.setText(self.entrypoint_file or rel)
946+
else:
947+
self.entrypoint_info_label.setText("Entrypoint: not set")
948+
if self._is_valid(self.file_path_edit):
949+
self.file_path_edit.clear()
950+
951+
def _browse_file(self) -> None:
952+
"""Select a Python file as temporary build entrypoint (no config write)."""
953+
start_dir = self.workspace_edit.text().strip() or self.workspace_dir or "."
898954
file_path, _ = QFileDialog.getOpenFileName(
899955
self,
900-
"Select Python file to compile",
901-
self.workspace_edit.text() or ".",
956+
"Select Python file (temporary entrypoint)",
957+
start_dir,
902958
"Python files (*.py);;All files (*)",
903959
)
960+
if not file_path:
961+
return
904962

905-
if file_path:
906-
self.file_path_edit.setText(file_path)
907-
self.selected_file = file_path
963+
abs_file = os.path.abspath(file_path)
964+
ws = self.workspace_edit.text().strip()
965+
if not ws:
966+
ws = os.path.dirname(abs_file)
967+
self.workspace_edit.setText(ws)
968+
ws = os.path.abspath(ws)
969+
self.workspace_dir = ws
970+
971+
# If selected file is outside current workspace, align workspace to file folder.
972+
try:
973+
common = os.path.commonpath([ws, abs_file])
974+
except Exception:
975+
common = ""
976+
if common != ws:
977+
ws = os.path.dirname(abs_file)
978+
self.workspace_dir = ws
979+
self.workspace_edit.setText(ws)
980+
981+
self.selected_file = abs_file
982+
983+
self._apply_entrypoint_marker()
984+
self._detect_venv()
985+
self._log("Temporary entrypoint selected for this build only")
986+
987+
def _resolve_compile_target(self) -> str | None:
988+
"""Resolve compile target from session selection first, then config."""
989+
if self.selected_file and os.path.isfile(self.selected_file):
990+
return self.selected_file
991+
if self.entrypoint_file and os.path.isfile(self.entrypoint_file):
992+
return self.entrypoint_file
993+
return None
908994

909995
def _browse_workspace(self):
910996
"""Ouvre une boîte de dialogue pour sélectionner un workspace."""
@@ -915,6 +1001,10 @@ def _browse_workspace(self):
9151001
if workspace_dir:
9161002
self.workspace_edit.setText(workspace_dir)
9171003
self.workspace_dir = workspace_dir
1004+
self.selected_file = None
1005+
self._load_entrypoint_from_workspace()
1006+
self._apply_entrypoint_marker()
1007+
self._detect_venv()
9181008

9191009
def _run_compilation(self):
9201010
"""Exécute la compilation avec le moteur de l'onglet courant."""
@@ -964,15 +1054,15 @@ def _run_compilation(self):
9641054
)
9651055
return
9661056

967-
file_path = self.file_path_edit.text()
1057+
file_path = self._resolve_compile_target()
9681058
if not file_path:
9691059
QMessageBox.warning(
9701060
self,
9711061
"Warning",
9721062
(
973-
"Please select a file to compile"
1063+
"Configure a workspace entrypoint before compiling"
9741064
if self.language == "en"
975-
else "Veuillez sélectionner un fichier à compiler"
1065+
else "Configurez un point d'entrée du workspace avant de compiler"
9761066
),
9771067
)
9781068
return
@@ -1143,9 +1233,13 @@ def _dry_run(self):
11431233
QMessageBox.warning(self, "Warning", "No engine available")
11441234
return
11451235

1146-
file_path = self.file_path_edit.text()
1236+
file_path = self._resolve_compile_target()
11471237
if not file_path:
1148-
QMessageBox.warning(self, "Warning", "Please select a file to compile")
1238+
QMessageBox.warning(
1239+
self,
1240+
"Warning",
1241+
"Configure a workspace entrypoint before dry-run",
1242+
)
11491243
return
11501244

11511245
try:

0 commit comments

Comments
 (0)