def _load_dir(self, path: str): """Load all operations in a set directory.""" os.makedirs(path, exist_ok=True) for obj_name in os.listdir(path): if obj_name in {"__init__.py", "__pycache__"}: continue obj_path = os.path.join(path, obj_name) if os.path.isfile(obj_path) and not obj_path.endswith(".py"): continue try: mod = load_module(obj_path) except ImportError: log.warning(f"Failed to import {obj_path}.\n{traceback.format_exc()}") else: if hasattr(mod, "export"): export = mod.export if isinstance(export, dict): self._load_operation(obj_path, export) elif isinstance(export, (list, tuple)): for i, export_dict in export: self._load_operation(f"{obj_path}[{i}]", export_dict) else: log.error(f"The format of export in {obj_path} is invalid.") else: log.error(f"export is not present in {obj_path}")
def GetAny(self) -> Optional[Any]: """Return the value currently selected in the form before it was converted to a string""" log.warning( "SimpleChoiceAny.GetAny is being depreciated and will be removed in the future. Please use SimpleChoiceAny.GetCurrentObject instead", exc_info=True, ) return self.GetCurrentObject()
def load_extension(module_name: str): # load module and confirm that all required attributes are defined try: module = importlib.import_module(module_name) except ImportError: log.warning( f"Failed to import {module_name}.\n{traceback.format_exc()}") else: if hasattr(module, "export"): export = getattr(module, "export") if ("ui" in export and issubclass(export["ui"], BaseProgram) and issubclass(export["ui"], wx.Window)): _extensions.append((export.get("name", "missingno"), export["ui"]))
def _load_pyinstaller(self, package: str): # pyinstaller support toc = set() for importer in pkgutil.iter_importers(amulet_map_editor.__name__): if hasattr(importer, "toc"): toc |= importer.toc prefix = f"{package}." match = re.compile(f"^{re.escape(prefix)}[a-zA-Z0-9_]*$") for module_name in toc: if match.fullmatch(module_name): try: mod = importlib.import_module(module_name) except ImportError: log.warning( f"Failed to import {module_name}.\n{traceback.format_exc()}" ) else: self._load_module(module_name, mod)
def load_extension( module_name: str, ) -> Optional[Tuple[str, Union[Type[BaseProgram], Type[wx.Window]]]]: # load module and confirm that all required attributes are defined try: module = importlib.import_module(module_name) except ImportError: log.warning( f"Failed to import {module_name}.\n{traceback.format_exc()}") else: if hasattr(module, "export"): export = getattr(module, "export") if isinstance(export, dict): ui = export.get("ui", None) name = export.get("name", None) if (isinstance(name, str) and issubclass(ui, BaseProgram) and issubclass(ui, wx.Window)): return name, ui
def _load_dir(self, path: str, make: bool = False): """Load all operations in a set directory.""" if make: os.makedirs(path, exist_ok=True) if os.path.isdir(path): for obj_name in os.listdir(path): if obj_name in {"__init__.py", "__pycache__"}: continue obj_path = os.path.join(path, obj_name) if os.path.isfile(obj_path) and not obj_path.endswith(".py"): continue try: mod = load_module(obj_path) except ImportError: log.warning( f"Failed to import {obj_path}.\n{traceback.format_exc()}" ) else: self._load_module(obj_path, mod)
def _load_submodules(self, path: str, package: str = ""): """ Load all operations in a path. You should not use this directly. Use _load_internal_submodules or _load_external_submodules :param path: The path to load modules from. :param package: The package name prefix """ # clean the path path = os.path.abspath(path) for _, module_name, _ in pkgutil.iter_modules([path]): module_name = f"{package}{module_name}" try: mod = importlib.import_module(module_name) mod = importlib.reload(mod) except ImportError: log.warning( f"Failed to import {module_name}.\n{traceback.format_exc()}" ) except SyntaxError: log.warning( f"There was a syntax error in {module_name}.\n{traceback.format_exc()}" ) else: if (os.path.dirname(mod.__path__[0] if hasattr( mod, "__path__") else mod.__file__) == path): # If the loaded module is actually in the path it was loaded from. # There may be cases where the name is shadowed by another module. self._load_module(module_name, mod) else: log.warning( f"Module {module_name} shadows another module. Try using a different module name." )
from amulet.api.errors import LoaderNoneMatched from amulet_map_editor.api.wx.ui.select_world import WorldSelectDialog from amulet_map_editor import __version__, lang, log from amulet_map_editor.api.framework.pages import WorldPageUI from .pages import AmuletMainMenu, BasePageUI from amulet_map_editor.api import image from amulet_map_editor.api.wx.util.ui_preferences import preserve_ui_preferences # Uses a conditional so if this breaks a build, we can just delete the file and it will skip the check try: from amulet_map_editor.api.framework import update_check except ImportError: update_check = None log.warning("Could not import update checker") NOTEBOOK_MENU_STYLE = (flatnotebook.FNB_NO_X_BUTTON | flatnotebook.FNB_HIDE_ON_SINGLE_TAB | flatnotebook.FNB_NAV_BUTTONS_WHEN_NEEDED) NOTEBOOK_STYLE = NOTEBOOK_MENU_STYLE | flatnotebook.FNB_X_ON_TAB CLOSEABLE_PAGE_TYPE = Union[WorldPageUI] wx.Image.SetDefaultLoadFlags(0) @preserve_ui_preferences class AmuletUI(wx.Frame): def __init__(self, parent): wx.Frame.__init__(