Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
24 changes: 17 additions & 7 deletions modules/dev/frame_quick_reload.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@
from ...submodules.base.ui.base_plugin import Plugin


class CustomFrameReloadException(Exception):
""" Exception raised for errors during frame reloading. """
pass


class FrameReloader:
"""Reloads modules and resolves reloadable frames for the picker."""
""" Reloads modules and resolves reloadable frames for the picker. """

@staticmethod
def is_alive(obj) -> bool:
Expand Down Expand Up @@ -81,7 +86,7 @@ def reload_module_source(self, cls: Type[UiModuleBase]) -> Type[UiModuleBase]:

:param cls: The class to reload.
:return: The reloaded class.
:raises AttributeError: If the class is not found in the reloaded module.
:raises CustomFrameReloadException: If the module cannot be imported or the class is not found after reloading.
"""
Comment thread
LeonardBuhl marked this conversation as resolved.
module_name = cls.__module__
purge_prefix = self._reload_prefix(module_name)
Expand All @@ -93,18 +98,18 @@ def reload_module_source(self, cls: Type[UiModuleBase]) -> Type[UiModuleBase]:

try:
fresh_module = importlib.import_module(module_name)
except Exception:
except Exception as e:
self._restore_modules(purge_prefix, purged_modules)
raise
raise CustomFrameReloadException(f"Modul '{module_name}' konnte nicht importiert werden.") from e
Comment thread
LeonardBuhl marked this conversation as resolved.

try:
return getattr(fresh_module, cls.__name__)
except AttributeError as exc:
except AttributeError as e:
self._restore_modules(purge_prefix, purged_modules)
raise AttributeError(
raise CustomFrameReloadException(
f"Klasse '{cls.__name__}' wurde nach dem Neuladen nicht in "
f"'{module_name}' gefunden."
) from exc
) from e

@staticmethod
def _add_layout_item(layout: QLayout, item,
Expand Down Expand Up @@ -132,6 +137,11 @@ def _add_layout_item(layout: QLayout, item,
layout.addItem(item)

def _move_layout_contents(self, source: QWidget, target: QWidget):
""" Move all layout items from the source widget's layout to the target widget's layout.

:param source: The source widget whose layout items will be moved.
:param target: The target widget to which the layout items will be moved.
"""
source_layout = source.layout()
target_layout = target.layout()
if source_layout is None or target_layout is None or source_layout is target_layout:
Expand Down
Loading