diff --git a/iotools/__init__.py b/iotools/__init__.py index 5b40a42..59613fe 100644 --- a/iotools/__init__.py +++ b/iotools/__init__.py @@ -13,4 +13,8 @@ from .misc import Console, SysTrayApp, Config, Serializer, Secrets, Cache, Log, PrintLog, Validate, Script from .handler import IOHandler, Argument, RunMode, ArgType -from .gui import Gui, HtmlGui, ThreePartGui, SystemTrayGui, widget + +try: + from .gui import Gui, HtmlGui, ThreePartGui, SystemTrayGui, widget +except ImportError: + pass diff --git a/iotools/gui/__init__.py b/iotools/gui/__init__.py index ba92f8c..6fd0264 100644 --- a/iotools/gui/__init__.py +++ b/iotools/gui/__init__.py @@ -1,5 +1,9 @@ __all__ = [ "Gui", "HtmlGui", "ThreePartGui", "SystemTrayGui", + "ArgsGui", "ArgFrame", + "widget", ] from .gui import Gui, HtmlGui, ThreePartGui, SystemTrayGui +from .argsgui import ArgsGui, ArgFrame +from . import widget diff --git a/iotools/handler/argsgui.py b/iotools/gui/argsgui.py similarity index 95% rename from iotools/handler/argsgui.py rename to iotools/gui/argsgui.py index 4d18914..f29869e 100644 --- a/iotools/handler/argsgui.py +++ b/iotools/gui/argsgui.py @@ -10,13 +10,14 @@ from pathmagic import File, Dir from miscutils import issubclass_safe -from ..gui.gui import ThreePartGui -from ..gui.widget import WidgetHandler, Button, Label, DropDown, CheckBar, IntEntry, FloatEntry, Text, DateTimeEdit, Table, Calendar, ListTable, DictTable, FileSelect, DirSelect, HorizontalGroupBox -from ..misc.console import Console +from .gui import ThreePartGui +from .widget import WidgetHandler, Button, Label, DropDown, CheckBar, IntEntry, FloatEntry, Text, DateTimeEdit, Table, Calendar, ListTable, DictTable, FileSelect, DirSelect, HorizontalGroupBox + +from iotools.misc import Console if TYPE_CHECKING: - from .iohandler import IOHandler, Argument - from .synchronizer import Synchronizer + from iotools.handler import IOHandler, Argument + from iotools.handler.synchronizer import Synchronizer class ArgsGui(ThreePartGui): diff --git a/iotools/handler/clink.py b/iotools/handler/clink.py index 73e4d61..fda2724 100644 --- a/iotools/handler/clink.py +++ b/iotools/handler/clink.py @@ -3,7 +3,7 @@ import sys from pathmagic import PathLike, Dir, File -from ..misc.config import IoToolsConfig, Config +from iotools.misc import IoToolsConfig, Config class ClinkConfig(Config): diff --git a/iotools/handler/iohandler.py b/iotools/handler/iohandler.py index 148293b..d81aa94 100644 --- a/iotools/handler/iohandler.py +++ b/iotools/handler/iohandler.py @@ -2,7 +2,7 @@ import string import sys -from typing import Any, Callable, Dict, List, Union, Optional, Type, Tuple +from typing import Any, Callable, Dict, List, Union, Optional, Type, Tuple, TYPE_CHECKING from maybe import Maybe from subtypes import Enum, ValueEnum, Dict_ @@ -10,9 +10,12 @@ from .synchronizer import Synchronizer -from iotools.gui import widget from iotools.misc import Validate, Condition, Validator, IoToolsConfig as Config +if TYPE_CHECKING: + from iotools.gui.widget import WidgetHandler + + # TODO: implement argument profiles # TODO: improve dependent arguments # TODO: improve smart runmode logic @@ -151,7 +154,7 @@ def __init__(self, name: str, argtype: Union[type, Callable] = None, default: An choices: Union[Type[Enum], List[Any]] = None, conditions: Union[Callable, List[Callable], Dict[str, Callable]] = None, magnitude: int = None, info: str = None, aliases: List[str] = None, widget_kwargs: dict = None) -> None: self.name, self.default, self.magnitude, self.info, self._value, self.widget_kwargs = name, default, magnitude, info, default, widget_kwargs or {} - self.widget: Optional[widget.WidgetHandler] = None + self.widget: Optional[WidgetHandler] = None self._aliases: Optional[List[str]] = None self.aliases = aliases diff --git a/iotools/handler/synchronizer.py b/iotools/handler/synchronizer.py index 04a79a5..ab83584 100644 --- a/iotools/handler/synchronizer.py +++ b/iotools/handler/synchronizer.py @@ -4,13 +4,13 @@ from subtypes import Dict_ -from .argsgui import ArgsGui, ArgFrame from .argparser import ArgParser -from ..gui.widget import TabPage -from ..misc.serializer import LostObject + +from iotools.misc import LostObject if TYPE_CHECKING: from .iohandler import IOHandler + from iotools.gui.widget import TabPage class Synchronizer: @@ -40,6 +40,7 @@ def run_programatically(self, values: Dict_, handler: IOHandler = None) -> Tuple return node.get_namespace_ascending(), node.handler def run_as_gui(self, values: Dict[str, Any], handler: IOHandler = None) -> Tuple[Dict_, IOHandler]: + from iotools.gui import ArgsGui return ArgsGui(sync=self, values=values, handler=self.determine_chosen_handler(handler)).start().output def run_from_commandline(self, args: List[str] = None, values: Dict_ = None, handler: IOHandler = None) -> Tuple[Dict_, IOHandler]: @@ -62,8 +63,7 @@ def set_active_tabs_from_handler_ascending(self, handler: IOHandler) -> None: def set_widgets_from_last_config_at_current_node(self) -> None: """Load the latest valid arguments profile at the current node and set the widgets accordingly.""" - current = self.current_node - last_config = current.handler._load_latest_input_config() + last_config = (current := self.current_node).handler._load_latest_input_config() if last_config is not None: current.set_widgets_from_namespace_ascending(last_config) @@ -117,11 +117,13 @@ def add_subparsers_recursively(self) -> None: child.add_subparsers_recursively() def create_widgets_recursively(self) -> None: + from iotools.gui import ArgFrame, widget + for arg in self.handler.arguments.values(): ArgFrame.from_arg(arg).stack() if self.children: - with TabPage(page_names=list(self.children)).stack() as self.page: + with widget.TabPage(page_names=list(self.children)).stack() as self.page: for name, child in self.children.items(): with self.page[name]: child.create_widgets_recursively() diff --git a/iotools/misc/__init__.py b/iotools/misc/__init__.py index 69bee6e..a160c92 100644 --- a/iotools/misc/__init__.py +++ b/iotools/misc/__init__.py @@ -1,7 +1,7 @@ __all__ = [ "Console", "SysTrayApp", "Log", "PrintLog", - "Serializer", "Secrets", + "Serializer", "Secrets", "LostObject", "Cache", "Config", "IoToolsConfig", "Validate", "Condition", "Validator", @@ -10,7 +10,7 @@ from .console import Console, SysTrayApp from .config import Config, IoToolsConfig -from .serializer import Serializer, Secrets +from .serializer import Serializer, Secrets, LostObject from .cache import Cache from .log import Log, PrintLog from .validator import Validate, Condition, Validator