# coding: utf-8
# /*##########################################################################
#
# Copyright (c) 2004-2019 European Synchrotron Radiation Facility
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# ###########################################################################*/
"""This module provides an IPython console widget.
You can push variables - any python object - to the
console's interactive namespace. This provides users with an advanced way
of interacting with your program. For instance, if your program has a
:class:`PlotWidget` or a :class:`PlotWindow`, you can push a reference to
these widgets to allow your users to add curves, save data to files… by using
the widgets' methods from the console.
.. note::
This module has a dependency on
`qtconsole <https://pypi.org/project/qtconsole/>`_.
An ``ImportError`` will be raised if it is
imported while the dependencies are not satisfied.
Basic usage example::
from silx.gui import qt
from silx.gui.console import IPythonWidget
app = qt.QApplication([])
hello_button = qt.QPushButton("Hello World!", None)
hello_button.show()
console = IPythonWidget()
console.show()
console.pushVariables({"the_button": hello_button})
app.exec_()
This program will display a console widget and a push button in two separate
windows. You will be able to interact with the button from the console,
for example change its text::
>>> the_button.setText("Spam spam")
An IPython interactive console is a powerful tool that enables you to work
with data and plot it.
See `this tutorial <https://plot.ly/python/ipython-notebook-tutorial/>`_
for more information on some of the rich features of IPython.
"""
__authors__ = ["Tim Rae", "V.A. Sole", "P. Knobel"]
__license__ = "MIT"
__date__ = "24/05/2016"
import logging
from . import qt
_logger = logging.getLogger(__name__)
# This widget cannot be used inside an interactive IPython shell.
# It would raise MultipleInstanceError("Multiple incompatible subclass
# instances of InProcessInteractiveShell are being created").
try:
__IPYTHON__
except NameError:
pass # Not in IPython
else:
msg = "Module " + __name__ + " cannot be used within an IPython shell"
raise ImportError(msg)
try:
from qtconsole.rich_jupyter_widget import RichJupyterWidget as \
_RichJupyterWidget
except ImportError:
try:
from qtconsole.rich_ipython_widget import RichJupyterWidget as \
_RichJupyterWidget
except ImportError:
from qtconsole.rich_ipython_widget import RichIPythonWidget as \
_RichJupyterWidget
from qtconsole.inprocess import QtInProcessKernelManager
try:
from ipykernel import version_info as _ipykernel_version_info
except ImportError:
_ipykernel_version_info = None
def main():
"""Run a Qt app with an IPython console"""
app = qt.QApplication([])
widget = IPythonDockWidget()
widget.show()
app.exec_()
if __name__ == '__main__':
main()