Skip to content

Commit 436ed4d

Browse files
authored
fix live refresh (#310)
1 parent 39c014d commit 436ed4d

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

src/daf_gui/widgets/convert.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -327,16 +327,13 @@ def convert_object_info():
327327
new_obj = d.class_(**data_conv)
328328
if keep_original_object and d.real_object is not None:
329329
real = d.real_object
330-
try:
331-
args = vars(real)
332-
except TypeError:
333-
args = real.__slots__ if hasattr(real, "__slots__") else dir(real)
334-
335-
for a in args:
336-
with suppress(Exception):
330+
with suppress(TypeError, AttributeError):
331+
# Only update old objects that are surely not built-in and have information about attributes
332+
args = real.__slots__ if hasattr(real, "__slots__") else vars(real)
333+
for a in args:
337334
setattr(real, a, getattr(new_obj, a))
338335

339-
new_obj = real
336+
new_obj = real
340337

341338
return new_obj
342339

src/daf_gui/widgets/extra.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,15 @@ def setup_additional_live_refresh(w: ttk.Button, frame):
126126
return
127127

128128
def _callback(*args):
129-
real = frame.old_object_info.real_object
130-
frame._update_old_object(convert_to_object_info(real, True))
131-
frame.load()
132-
frame.save_gui_values()
129+
opened_frames = frame.origin_window.opened_frames
130+
# Need to do this on all previous frames, otherwise we would have wrong data
131+
for frame_ in reversed(opened_frames):
132+
if not isinstance(frame_.old_object_info, list):
133+
real = frame_.old_object_info.real_object
134+
frame_._update_old_object(convert_to_object_info(real, True))
135+
frame_.load()
136+
137+
frame_.save_gui_values()
133138

134139
w.configure(command=_callback)
135140
ToolTip(w, "Load updated values from the object into the window", topmost=True)

0 commit comments

Comments
 (0)