Skip to content

Rename from CueObject the display_object to object #96

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/scwidgets/cue/_widget_cue_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class CueObject(CueOutput):
A cued displayable ipywidget.Output for any Python object. Provides utilities to
clear and redraw the object, for example after an update.

:param display_object:
:param object:
The object to display
:param widgets_to_observe:
The widget to observe if the :param traits_to_observe: has changed.
Expand All @@ -35,7 +35,7 @@ class CueObject(CueOutput):

def __init__(
self,
display_object: Any = None,
object: Any = None,
widgets_to_observe: Union[None, List[Widget], Widget] = None,
traits_to_observe: Union[
None, str, List[str], List[List[str]], Sentinel
Expand All @@ -54,23 +54,23 @@ def __init__(
**kwargs,
)

self._display_object = display_object
self._object = object
self.draw_display()

@property
def display_object(self):
return self._display_object
def object(self):
return self._object

@display_object.setter
def display_object(self, display_object: Any):
self._display_object = display_object
@object.setter
def object(self, object: Any):
self._object = object

def clear_display(self, wait=False):
self.clear_output(wait=wait)

def draw_display(self):
with self:
if isinstance(self._display_object, str):
print(self._display_object)
elif self._display_object is not None:
display(self._display_object)
if isinstance(self._object, str):
print(self._object)
elif self._object is not None:
display(self._object)
6 changes: 3 additions & 3 deletions tests/test_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def update_print():
output = code_ex.params
else:
output = code_ex.run_code(**code_ex.params)
code_ex.output.display_object = f"Output:\n{output}"
code_ex.output.object = f"Output:\n{output}"

else:

Expand All @@ -198,7 +198,7 @@ def update_print(code_ex: CodeExercise):
output = code_ex.params
else:
output = code_ex.run_code(**code_ex.params)
code_ex.output.display_object = f"Output:\n{output}"
code_ex.output.object = f"Output:\n{output}"

code_ex = CodeExercise(
code=code_input,
Expand Down Expand Up @@ -329,7 +329,7 @@ def test_save_registry(self, function):
"""

def print_success(code_ex: CodeExercise | None):
code_ex.output.display_object = "Success"
code_ex.output.object = "Success"

cue_output = CueObject("Not initialized")
exercise_registry = ExerciseRegistry()
Expand Down
Loading