Skip to content

Commit c021eeb

Browse files
committed
refactor: déplacement de l'UI Qt et de l'i18n vers Ui/
Transfert de _BCASLWorker, _BCASLUiBridge et _build_plugin_item depuis bcasl/Loader.py vers Ui/Gui/Dialogs/BcaslDialog.py ; déplacement de Core/i18n.py vers Ui/i18n.py et de Core/IdeLikeGui/ vers Ui/Gui/IdeLikeGui/ avec mise à jour de tous les imports dans les fichiers concernés et suppression des anciens modules.
1 parent 023d158 commit c021eeb

14 files changed

Lines changed: 189 additions & 211 deletions

File tree

Core/Auto_Command_Builder/auto_build.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import re
2222
from typing import Optional
2323

24-
from Core.i18n import log_with_level, log_i18n_level
24+
from Ui.i18n import log_with_level, log_i18n_level
2525

2626
# Optional access to registered engines for discovery
2727
try:

Core/Compiler/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080

8181
# Importations de EngineLoader
8282
from EngineLoader.registry import get_engine, create
83-
from Core.i18n import log_with_level, log_i18n_level
83+
from Ui.i18n import log_with_level, log_i18n_level
8484

8585
__all__ = [
8686
# compiler.py

Core/IdeLikeGui/__init__.py

Lines changed: 0 additions & 12 deletions
This file was deleted.

Core/IdeLikeGui/connections.py

Lines changed: 0 additions & 15 deletions
This file was deleted.

Core/PreferencesManager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def save_preferences(self):
149149
pass
150150
except Exception as e:
151151
try:
152-
from .i18n import log_i18n_level
152+
from Ui.i18n import log_i18n_level
153153

154154
log_i18n_level(
155155
self,
@@ -159,7 +159,7 @@ def save_preferences(self):
159159
)
160160
except Exception:
161161
try:
162-
from .i18n import log_with_level
162+
from Ui.i18n import log_with_level
163163

164164
log_with_level(
165165
self, "warning", f"Impossible de sauvegarder les préférences : {e}"

Core/deps_analyser/analyser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from PySide6.QtWidgets import QApplication, QMessageBox
2929

3030
from Core.WidgetsCreator import ProgressDialog
31-
from Core.i18n import log_with_level
31+
from Ui.i18n import log_with_level
3232

3333

3434
def _log_append(gui, msg: str) -> None:

Core/sys_deps.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,21 +208,21 @@ def _dbg(self, message: str) -> None:
208208
pw.logger.debug(line)
209209
else:
210210
try:
211-
from Core.i18n import log_with_level
211+
from Ui.i18n import log_with_level
212212

213213
log_with_level(pw, "state", line)
214214
except Exception:
215215
pass
216216
except Exception:
217217
try:
218-
from Core.i18n import log_with_level
218+
from Ui.i18n import log_with_level
219219

220220
log_with_level(pw, "state", line)
221221
except Exception:
222222
pass
223223
else:
224224
try:
225-
from Core.i18n import log_with_level
225+
from Ui.i18n import log_with_level
226226

227227
log_with_level(None, "state", line)
228228
except Exception:

Ui/Gui/Dialogs/BcaslDialog.py

Lines changed: 155 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
import yaml
3535

36-
from PySide6.QtCore import Qt, Signal, QMimeData, QByteArray
36+
from PySide6.QtCore import Qt, Signal, QMimeData, QByteArray, QObject, QThread, Slot
3737
from PySide6.QtGui import QColor, QShortcut, QKeySequence, QPalette
3838
from PySide6.QtWidgets import (
3939
QAbstractItemView,
@@ -772,6 +772,160 @@ def _do_save(self) -> None:
772772
)
773773

774774

775+
# ---------------------------------------------------------------------------
776+
# Worker et bridge Qt (déplacés depuis bcasl/Loader.py)
777+
# ---------------------------------------------------------------------------
778+
779+
780+
class _BCASLWorker(QObject):
781+
finished = Signal(object) # report or None
782+
log = Signal(str)
783+
784+
def __init__(
785+
self,
786+
workspace_root: "Path",
787+
Plugins_dir: "Path",
788+
cfg: "dict[str, Any]",
789+
plugin_timeout: float,
790+
) -> None:
791+
super().__init__()
792+
self.workspace_root = workspace_root
793+
self.Plugins_dir = Plugins_dir
794+
self.cfg = cfg
795+
self.plugin_timeout = plugin_timeout
796+
self._cancel_requested = False
797+
798+
def request_cancel(self) -> None:
799+
try:
800+
self._cancel_requested = True
801+
except Exception:
802+
pass
803+
804+
@Slot()
805+
def run(self) -> None:
806+
try:
807+
from bcasl.Loader import _run_bcasl_sync
808+
809+
report = _run_bcasl_sync(
810+
self.workspace_root,
811+
self.Plugins_dir,
812+
self.cfg,
813+
self.plugin_timeout,
814+
log_cb=self.log.emit,
815+
stop_requested=lambda: bool(self._cancel_requested),
816+
)
817+
self.finished.emit(report)
818+
except Exception as e:
819+
try:
820+
self.log.emit(f"Erreur BCASL: {e}\n")
821+
except Exception:
822+
pass
823+
self.finished.emit(None)
824+
825+
826+
class _BCASLUiBridge(QObject):
827+
def __init__(self, gui, on_done, thread) -> None:
828+
super().__init__()
829+
self._gui = gui
830+
self._on_done = on_done
831+
self._thread = thread
832+
833+
@Slot(str)
834+
def on_log(self, s: str) -> None:
835+
try:
836+
if hasattr(self._gui, "log") and self._gui.log:
837+
self._gui.log.append(s)
838+
except Exception:
839+
pass
840+
841+
@Slot(object)
842+
def on_finished(self, rep) -> None:
843+
try:
844+
if rep and hasattr(self._gui, "log") and self._gui.log is not None:
845+
self._gui.log.append("BCASL - Rapport:\n")
846+
for item in rep:
847+
try:
848+
state = (
849+
"OK"
850+
if getattr(item, "success", False)
851+
else f"FAIL: {getattr(item, 'error', '')}"
852+
)
853+
dur = getattr(item, "duration_ms", 0.0)
854+
pid = getattr(item, "plugin_id", "?")
855+
self._gui.log.append(f" - {pid}: {state} ({dur:.1f} ms)\n")
856+
except Exception:
857+
pass
858+
try:
859+
self._gui.log.append(rep.summary() + "\n")
860+
except Exception:
861+
pass
862+
try:
863+
if callable(self._on_done):
864+
self._on_done(rep)
865+
except Exception:
866+
pass
867+
finally:
868+
try:
869+
self._thread.quit()
870+
except Exception:
871+
pass
872+
873+
874+
def _build_plugin_item(
875+
pid: str,
876+
meta: "dict[str, Any]",
877+
plugins_cfg: "dict[str, Any]",
878+
Qt,
879+
QListWidgetItem,
880+
) -> Any:
881+
"""Construit un QListWidgetItem pour un plugin BCASL."""
882+
from bcasl.tagging import get_tag_phase_name
883+
884+
label = meta.get("name") or pid
885+
ver = meta.get("version") or ""
886+
tags = meta.get("tags") or []
887+
888+
phase_name = get_tag_phase_name(tags[0]) if tags else ""
889+
text = f"{label} ({pid})" + (f" v{ver}" if ver else "")
890+
if phase_name:
891+
text += f" [Phase: {phase_name}]"
892+
893+
item = QListWidgetItem(text)
894+
895+
try:
896+
desc = meta.get("description") or ""
897+
tooltip = desc
898+
if tags:
899+
tooltip += f"\n\nTags: {', '.join(tags)}"
900+
reqs = meta.get("requirements", [])
901+
if reqs:
902+
tooltip += "\n\nRequirements:\n" + "\n".join(f" • {req}" for req in reqs)
903+
if tooltip:
904+
item.setToolTip(tooltip)
905+
except Exception:
906+
pass
907+
908+
from bcasl.Loader import _plugin_enabled
909+
910+
enabled = _plugin_enabled(plugins_cfg, pid)
911+
try:
912+
item.setData(0x0100, pid)
913+
except Exception:
914+
pass
915+
if Qt is not None:
916+
item.setFlags(
917+
item.flags()
918+
| Qt.ItemIsUserCheckable
919+
| Qt.ItemIsEnabled
920+
| Qt.ItemIsSelectable
921+
| Qt.ItemIsDragEnabled
922+
)
923+
item.setCheckState(
924+
Qt.CheckState.Checked if enabled else Qt.CheckState.Unchecked
925+
)
926+
return item
927+
928+
775929
# ---------------------------------------------------------------------------
776930
# Point d'entrée (appelé depuis bcasl/Loader.py)
777931
# ---------------------------------------------------------------------------

Ui/Gui/Gui.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from Core.Globals import _latest_gui_instance, _workspace_dir_cache, _workspace_dir_lock
3030
from Core.Globals import _run_coro_async
3131
from Core.Venv_Manager import VenvManager
32-
from Core.i18n import (
32+
from Ui.i18n import (
3333
resolve_system_language,
3434
get_translations,
3535
tr_fr_en,

Ui/Gui/UiConnection.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
except Exception:
3434
QSvgRenderer = None # type: ignore[assignment]
3535

36-
from Core.i18n import show_language_dialog
36+
from Ui.i18n import show_language_dialog
3737

3838

3939
def _detect_system_color_scheme() -> str:
@@ -876,7 +876,7 @@ def apply_theme(self, pref: str) -> None:
876876
except Exception:
877877
pass
878878
try:
879-
from Core.i18n import log_i18n_level
879+
from Ui.i18n import log_i18n_level
880880

881881
if chosen_path:
882882
log_i18n_level(
@@ -898,7 +898,7 @@ def apply_theme(self, pref: str) -> None:
898898
try:
899899
if hasattr(self, "log") and self.log:
900900
try:
901-
from Core.i18n import log_i18n_level
901+
from Ui.i18n import log_i18n_level
902902

903903
log_i18n_level(
904904
self,
@@ -907,7 +907,7 @@ def apply_theme(self, pref: str) -> None:
907907
f"Failed to apply theme: {e}",
908908
)
909909
except Exception:
910-
from Core.i18n import log_with_level
910+
from Ui.i18n import log_with_level
911911

912912
log_with_level(
913913
self, "warning", f"Échec d'application du thème: {e}"
@@ -940,7 +940,7 @@ def show_theme_dialog(self) -> None:
940940
pass
941941
else:
942942
try:
943-
from Core.i18n import log_i18n_level
943+
from Ui.i18n import log_i18n_level
944944

945945
log_i18n_level(
946946
self,

0 commit comments

Comments
 (0)