Send shutdown message when exiting ipython console
Shut down kernel correctly when closing tab in Qt console

Closes gh-6893
Merge pull request #6902 from takluyver/i6893

Send shutdown messages to kernel from Qt console and terminal console