Skip to content

Add automatic display in notebooks when MolSysView is the last expression #26

@dprada

Description

@dprada

We want MolSysView to display automatically in Jupyter when the object is the last expression in a cell, without requiring an explicit .show() call. This is to keep molsysmt.basic.view() returning the MolSysView object (no forced show) while still giving a good notebook UX.

Proposed options:

  1. Implement _repr_mimebundle_ (or _repr_html_) in MolSysView to delegate to self.show() or return the widget’s mimebundle. This would make MolSysView render automatically when evaluated in a notebook cell.
  2. Alternative: expose a .widget attribute and implement __repr__/_ipython_display_ to forward to the widget’s display.

Constraints:

  • Must not trigger display on object creation (only when evaluated as the last expression).
  • Keep .show() behavior unchanged (first call returns widget, subsequent calls return None).
  • Do not add extra dependencies.

Expected outcome:
MolSysView renders automatically in Jupyter when it’s the last expression, while still being a plain Python object in scripts.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions