Skip to content

x.interact() should print an error message when no canvas is open #862

@jypeter

Description

@jypeter

If I call x.interact() when the vcs canvas is not open, either because I have not plotted anything yet (e.g. the canvas has never been opened) or because, I have closed the canvas with x.close(), I get an ugly traceback. It would ne nicer to print a warning message

>>> import vcs
>>> x = vcs.init()
>>> x.interact()
/home/share/unix_files/cdat/versions/cdat_install_uv-2.0.0_x86_64_gcc4_12/lib/python2.7/site-packages/vcs/VTKPlots.py:60: UserWarning: Press 'Q' to exit interactive mode and continue script execution
  warnings.warn("Press 'Q' to exit interactive mode and continue script execution")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/share/unix_files/cdat/versions/cdat_install_uv-2.0.0_x86_64_gcc4_12/lib/python2.7/site-packages/vcs/Canvas.py", line 470, in interact
    self.backend.interact(*args,**kargs)
  File "/home/share/unix_files/cdat/versions/cdat_install_uv-2.0.0_x86_64_gcc4_12/lib/python2.7/site-packages/vcs/VTKPlots.py", line 61, in interact
    interactor = self.renWin.GetInteractor()
AttributeError: 'NoneType' object has no attribute 'GetInteractor'

The error is not exactly the same if I have plotted something with bg=1, but it's the same kind

>>> import vcs, numpy as np
>>> x = vcs.init()
>>> i = np.identity(100)
>>> x.plot(i, bg=1)
<vcs.displayplot.Dp object at 0x2b0b4d0be670>
>>> x.pdf('bgtest')
>>> x.interact()
/home/share/unix_files/cdat/versions/cdat_install_uv-2.0.0_x86_64_gcc4_12/lib/python2.7/site-packages/vcs/VTKPlots.py:60: UserWarning: Press 'Q' to exit interactive mode and continue script execution
  warnings.warn("Press 'Q' to exit interactive mode and continue script execution")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/share/unix_files/cdat/versions/cdat_install_uv-2.0.0_x86_64_gcc4_12/lib/python2.7/site-packages/vcs/Canvas.py", line 470, in interact
    self.backend.interact(*args,**kargs)
  File "/home/share/unix_files/cdat/versions/cdat_install_uv-2.0.0_x86_64_gcc4_12/lib/python2.7/site-packages/vcs/VTKPlots.py", line 62, in interact
    interactor.Start()
AttributeError: 'NoneType' object has no attribute 'Start'

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions