widgets.python_repl_widget

Class for a custom RichJupyterWidget to use as Python REPL.

author:
  1. Savolainen (VTT)
date:

14.3.2019

Module Contents

class widgets.python_repl_widget.PythonReplWidget(toolbox)[source]

Bases: qtconsole.rich_jupyter_widget.RichJupyterWidget

Python Repl Widget class.

toolbox

App main window (QMainWindow) instance

Type:ToolboxUI
execution_finished_signal[source]
connect_signals(self)[source]

Connect signals.

disconnect_signals(self)[source]

Disconnect signals. Needed before switching to another Python kernel.

python_kernel_name(self)[source]

Returns the name of the Python kernel specification and its display name according to the selected Python environment in Settings. Returns None if Python version cannot be determined.

setup_python_kernel(self)[source]

Context menu Start action handler.

launch_kernel(self, k_name, k_display_name)[source]

Check if selected kernel exists or if it needs to be set up before launching.

check_and_install_requirements(self)[source]

Prompts user to install IPython and ipykernel if they are missing. After installing the required packages, installs kernelspecs for the selected Python if they are missing.

Returns:Boolean value depending on whether or not the user chooses to proceed.
is_package_installed(self, package_name)[source]

Checks if given package is installed to selected Python environment.

Parameters:package_name (str) – Package name
Returns:True if installed, False if not
Return type:(bool)
start_package_install_process(self, package_name)[source]

Starts installing the given package using pip.

Parameters:package_name (str) – Package name to install using pip
package_install_process_finished(self, retval)[source]

Installing package finished.

Parameters:retval (int) – Process return value. 0: success, !0: failure
start_kernelspec_install_process(self)[source]

Install kernel specifications for the selected Python environment.

kernelspec_install_process_finished(self, retval)[source]

Installing package finished.

Parameters:retval (int) – Process return value. 0: success, !0: failure
start_python_kernel(self)[source]

Starts kernel manager and client and attaches the client to the Python Console.

execute_instance(self, commands)[source]

Start executing the first command in the command queue in Python Console.

execution_in_progress(self, code)[source]

Slot for handling the ‘executing’ signal. Signal is emitted when a user visible ‘execute_request’ has been submitted to the kernel from the FrontendWidget.

Parameters:code (str) – Code to be executed (actually not ‘str’ but ‘object’)
execution_done(self, msg)[source]

Slot for handling the ‘executed’ signal. Signal is emitted when a user-visible ‘execute_reply’ has been received from the kernel and processed by the FrontendWidget.

Parameters:msg (dict) – Response message (actually not ‘dict’ but ‘object’)
iopub_msg_received(self, msg)[source]

Message received from the IOPUB channel. Note: We are only monitoring when the kernel has started successfully and ready for action here. Alternatively, this could be done in the Slot for the ‘executed’ signal. However, this Slot could come in handy at some point. See ‘Messaging in Jupyter’ for details: https://jupyter-client.readthedocs.io/en/latest/messaging.html

Parameters:msg (dict) – Received message from IOPUB channel
terminate_process(self)[source]

Send interrupt signal to kernel.

shutdown_kernel(self, hush=False)[source]

Shut down Python kernel.

push_vars(self, var_name, var_value)[source]

Push a variable to Python Console session. Simply executes command ‘var_name=var_value’.

Parameters:
  • var_name (str) – Variable name
  • var_value (object) – Variable value
Returns:

True if succeeded, False otherwise

Return type:

(bool)

test_push_vars(self)[source]

QAction slot to test pushing variables to Python Console.

_context_menu_make(self, pos)[source]

Reimplemented to add custom actions.

dragEnterEvent(self, e)[source]

Don’t accept project item drops.