Skip to content

Commit

Permalink
Merge pull request #575 from Technion-Kishony-lab/hotfix/runtime_erro…
Browse files Browse the repository at this point in the history
…r_upon_slider_drag

HOTFIX: runtime error upon slider drag
  • Loading branch information
rkishony authored Mar 28, 2023
2 parents 36dbb81 + e5d1640 commit d34ff11
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 27 deletions.
11 changes: 5 additions & 6 deletions pyquibbler/pyquibbler/assignment/override_choice/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from pyquibbler.assignment import AssignmentToQuib
from pyquibbler.project.undo_group import undo_group_mode
from pyquibbler.quib.graphics import aggregate_redraw_mode
from pyquibbler.utilities.basic_types import Flag


@dataclass
Expand All @@ -28,11 +27,11 @@ class OverrideGroup:
"""
quib_changes: List[AssignmentToQuib] = field(default_factory=list)

def apply(self, temporarily: bool = False) -> Flag:
with undo_group_mode(temporarily) as ugm, aggregate_redraw_mode(temporarily):
for quib_change in self.quib_changes:
quib_change.apply()
return ugm
def apply(self, temporarily: bool = False):
with undo_group_mode(temporarily):
with aggregate_redraw_mode(temporarily):
for quib_change in self.quib_changes:
quib_change.apply()

def __bool__(self):
return len(self.quib_changes) > 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ def set_quib_to_update_widget_upon_change(self):

def _inverse_assign(self, value: Any, on_drag: bool = False):
assignment = create_assignment(value, path=[], tolerance=self.get_tolerance(value))
get_override_group_for_quib_changes([AssignmentToQuib(self.quib, assignment)]) \
.apply()
get_override_group_for_quib_changes([AssignmentToQuib(self.quib, assignment)]).apply()

def get_tolerance(self, value):
return None
Expand Down
36 changes: 17 additions & 19 deletions pyquibbler/pyquibbler/project/undo_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from .project import Project
from pyquibbler.quib.graphics.graphics_assignment_mode import is_within_graphics_assignment_mode
from pyquibbler.quib.graphics.redraw import is_dragging
from ..utilities.basic_types import Flag

IN_UNDO_GROUP_MODE = False

Expand All @@ -21,23 +20,22 @@ def undo_group_mode(temporarily: bool = False):
global IN_UNDO_GROUP_MODE
if IN_UNDO_GROUP_MODE:
yield
IN_UNDO_GROUP_MODE = True
project = Project.get_or_create()
all_ok = Flag(True)
try:
project.start_pending_undo_group()
yield all_ok
except Exception:
if is_within_graphics_assignment_mode():
all_ok.set(False)
project.undo_pending_group(False)
else:
raise
else:
if not temporarily:
if is_dragging():
project.squash_pending_group_into_last_undo()
IN_UNDO_GROUP_MODE = True
project = Project.get_or_create()
try:
project.start_pending_undo_group()
yield
except Exception:
if is_within_graphics_assignment_mode():
project.undo_pending_group(False)
else:
project.push_pending_undo_group_to_undo_stack()
finally:
IN_UNDO_GROUP_MODE = False
raise
else:
if not temporarily:
if is_dragging():
project.squash_pending_group_into_last_undo()
else:
project.push_pending_undo_group_to_undo_stack()
finally:
IN_UNDO_GROUP_MODE = False

0 comments on commit d34ff11

Please sign in to comment.