Skip to content

Commit

Permalink
Allow iotools.gui to fail to load without erroring (to handle environ…
Browse files Browse the repository at this point in the history
…ments that don't have the necessary dependencies for QT)
  • Loading branch information
matthewgdv committed Mar 13, 2020
1 parent 93867b1 commit 36f6075
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 18 deletions.
6 changes: 5 additions & 1 deletion iotools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions iotools/gui/__init__.py
Original file line number Diff line number Diff line change
@@ -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
11 changes: 6 additions & 5 deletions iotools/handler/argsgui.py → iotools/gui/argsgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion iotools/handler/clink.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
9 changes: 6 additions & 3 deletions iotools/handler/iohandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@

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_
from miscutils import cached_property, is_running_in_ipython

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
Expand Down Expand Up @@ -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
Expand Down
14 changes: 8 additions & 6 deletions iotools/handler/synchronizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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]:
Expand All @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions iotools/misc/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
__all__ = [
"Console", "SysTrayApp",
"Log", "PrintLog",
"Serializer", "Secrets",
"Serializer", "Secrets", "LostObject",
"Cache",
"Config", "IoToolsConfig",
"Validate", "Condition", "Validator",
Expand All @@ -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
Expand Down

0 comments on commit 36f6075

Please sign in to comment.