def load_from_file(file_name: str, callback: Optional[Callable]):
    """Loads model from file.

    :param file_name: File path.
    :param callback: Callback function, to be executed after loading model from file.
    """
    try:
        with open(file_name, mode='r') as file:
            state = State()
            json = file.read()
            model = Model.from_json(json)

            state.file = file
            state.model = model
            Settings.get_settings().add_recently_opened_project(
                model.root_name, file_name)

            if callback is not None:
                callback()

            pub.sendMessage(actions.MODEL_SAVED, file_name=file_name)
            pub.sendMessage(actions.MODEL_LOADED)

    except JSONDecodeError as e:
        messagebox.showerror('Error',
                             f'Error while opening the project file.\n{e}')
    except BGError as e:
        messagebox.showerror('Error', e)
    except FileNotFoundError as e:
        messagebox.showerror('File not found.', str(e))
예제 #2
0
    def __init__(self, parent_notebook):
        self.__state: State = State()
        self.__selected_component: Optional[Component] = None

        Tab.__init__(self, parent_notebook, TAB_NAME)
        HasCommonSetup.__init__(self)
        SubscribesToEvents.__init__(self)
    def __init__(self, parent_notebook):

        self.__state = State()
        self.__selected_constraint: Optional[
            Any] = None  # can be either simple or complex constraint

        Tab.__init__(self, parent_notebook, TAB_NAME)
        HasCommonSetup.__init__(self)
        SubscribesToEvents.__init__(self)
예제 #4
0
    def __init__(self, parent_frame):
        self.__state = State()
        self.__settings = Settings.get_settings()

        Window.__init__(self, parent_frame, WINDOW_TITLE)
        HasCommonSetup.__init__(self)

        # Protect from closing this window while solving.
        self.protocol('WM_DELETE_WINDOW', lambda: self.__solve_frame.on_close(self))
예제 #5
0
    def __init__(self,
                 parent_frame: ttk.Frame):
        self.__state = State()
        self.__settings = Settings.get_settings()

        Window.__init__(self, parent_frame, WINDOW_TITLE)
        HasCommonSetup.__init__(self)

        # Prevent from closing parent window when solving is in progress
        self.protocol('WM_DELETE_WINDOW', lambda: self.__solve_frame.on_close(self))
    def __init__(self, parent_frame, callback: Callable):
        self.__state = State()
        self.__settings = Settings.get_settings()

        self.__callback = callback
        self.__has_recent_projects = len(
            self.__settings.recently_opened_projects) > 0

        Window.__init__(self, parent_frame, WINDOW_TITLE)
        HasCommonSetup.__init__(self)
    def __init__(self, parent_frame, selected_port: Port,
                 ports_right: List[Port], ports_left: List[Port],
                 callback: Callable[[List[Port]], Any]):
        self.__state: State = State()
        self.__callback: Callable[[List[Port]], Any] = callback

        self.__ports_right: List[Port] = ports_right
        self.__ports_left: List[Port] = ports_left

        self.__selected_port_left: Optional[Port] = None
        self.__selected_port_right: Optional[Port] = None

        Window.__init__(self, parent_frame,
                        WINDOW_TITLE.format(selected_port.name))
        HasCommonSetup.__init__(self)
예제 #8
0
    def __init__(self,
                 parent_frame,
                 callback: Optional[Callable],
                 constraint: Optional[SimpleConstraint] = None):
        self.__state = State()
        self.__callback = callback
        self.__constraint: SimpleConstraint = copy.deepcopy(constraint) if constraint is not None \
            else SimpleConstraint()
        self.__components_ids = [] if constraint is None else [
            *constraint.components_ids
        ]  # Deep copy of component ids
        self.__selected_taxonomy_tree_item: Optional[Component] = None
        self.__selected_listbox_item: Optional[Component] = None

        Window.__init__(self, parent_frame, WINDOW_TITLE)
        HasCommonSetup.__init__(self)
예제 #9
0
    def __init__(self, parent_frame):
        self.__state = State()
        self.__settings = Settings.get_settings()

        Window.__init__(self, parent_frame, WINDOW_TITLE)
        HasCommonSetup.__init__(self)
    def __init__(self, parent_frame, callback):
        self.__callback = callback
        self.__state = State()

        Window.__init__(self, parent_frame, WINDOW_TITLE)
        HasCommonSetup.__init__(self)