Skip to content

Commit

Permalink
When copying states, copy child {handle: state} dicts
Browse files Browse the repository at this point in the history
  • Loading branch information
cben committed Aug 15, 2022
1 parent bcea895 commit 278a9fb
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions newm/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,18 +163,18 @@ def without_view_state(self, view: View) -> WorkspaceState:

def copy(self, **kwargs: Any) -> WorkspaceState:
res = WorkspaceState(self._ws, **{**self.__dict__, **kwargs})
for h, s in self._view_states.items():
res._view_states[h] = s.copy()
res.intermediate_rows = list(self.intermediate_rows)
res.intermediate_cols = list(self.intermediate_cols)
res._view_states = {h: s.copy() for h, s in self._view_states.items()}
return res

def update(self, **kwargs: Any) -> None:
for k, v in kwargs.items():
self.__dict__[k] = v

def replacing_view_state(self, view: View, **kwargs: Any) -> WorkspaceState:
res = WorkspaceState(self._ws, **self.__dict__)
for h, s in self._view_states.items():
res._view_states[h] = s.copy(**(kwargs if h==view._handle else {}))
res = self.copy()
res.update_view_state(view, **kwargs)
return res

def update_view_state(self, view: View, **kwargs: Any) -> None:
Expand Down Expand Up @@ -651,8 +651,7 @@ def without_view_state(self, view: View) -> LayoutState:

def copy(self, **kwargs: Any) -> LayoutState:
res = LayoutState(self._wm, **{**self.__dict__, **kwargs})
for h, s in self._workspace_states.items():
res._workspace_states[h] = s.copy()
res._workspace_states = {h: s.copy() for h, s in self._workspace_states.items()}
return res

def update(self, **kwargs: Any) -> None:
Expand All @@ -661,14 +660,14 @@ def update(self, **kwargs: Any) -> None:

def replacing_workspace_state(self, workspace: Workspace, **kwargs: Any) -> LayoutState:
res = LayoutState(self._wm, **self.__dict__)
for h, s in self._workspace_states.items():
res._workspace_states[h] = s.copy(**(kwargs if h==workspace._handle else {}))
res._workspace_states = {h: s.copy(**(kwargs if h==workspace._handle else {}))
for h, s in self._workspace_states.items()}
return res

def setting_workspace_state(self, workspace: Workspace, state: WorkspaceState) -> LayoutState:
res = LayoutState(self._wm, **self.__dict__)
for h, s in self._workspace_states.items():
res._workspace_states[h] = s.copy() if h!=workspace._handle else state
res._workspace_states = {h: (s.copy() if h!=workspace._handle else state)
for h, s in self._workspace_states.items()}
return res

def update_view_state(self, view: View, **kwargs: Any) -> None:
Expand Down Expand Up @@ -759,12 +758,8 @@ def get_workspace_state(self, workspace: Workspace) -> WorkspaceState:
return self._workspace_states[workspace._handle]

def get_view_state(self, view: View) -> ViewState:
for h, s in self._workspace_states.items():
try:
return s.get_view_state(view)
except:
pass
raise Exception("Could not find view %d state" % view._handle)
view_state, ws_state, ws_handle = self.find_view(view)
return view_state

def find_view(self, view: View) -> tuple[ViewState, WorkspaceState, int]:
for h, s in self._workspace_states.items():
Expand Down

0 comments on commit 278a9fb

Please sign in to comment.