Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add interactive IPython console as a dock widget. #24

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ python:
before_install:
- "sudo apt-get update"
install:
- "sudo apt-get install -y python3-pyside xvfb"
- "sudo apt-get install -y python3-pyside ipython3 ipython3-qtconsole xvfb"
- pip install coveralls pylama
script:
- pylama src/
- xvfb-run --server-args="-screen 0 1280x1024x16" coverage run --source=src -m unittest discover -s src/tests/ -t src
after_success:
coveralls
coveralls
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
PySide>=1.2.2
pylama
cx_Freeze
ipython
# Seems like ipython doesn't declare all dependencies:
pygments
54 changes: 54 additions & 0 deletions src/docks/console_widget.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright 2011-2014 The LogikSim Authors. All rights reserved.
# Use of this source code is governed by the GNU GPL license that can
# be found in the LICENSE.txt file.
#
'''
Rich integrated IPython console as for use in dock widget.
'''

from IPython.qt.console.rich_ipython_widget import RichIPythonWidget
from IPython.qt.inprocess import QtInProcessKernelManager
from PySide import QtCore


class ConsoleWidget(RichIPythonWidget):
"""
Rich interactive ipython console widget.
"""
def __init__(self, parent=None):
"""
Creates a new interactive ipython console.

Starts an IPython in-process kernel and embeds a RichIPythonWidget
for interacting with it. Expose application variables using
the expose function.

:param parent: Optional Qt parent widget
"""
super().__init__(parent)

# Start interactive python shell
self.kernel_manager = QtInProcessKernelManager()
self.kernel_manager.start_kernel()
self.kernel = self.kernel_manager.kernel
self.kernel.gui = 'qt'

kernel_client = self.kernel_manager.client()
kernel_client.start_channels()

self.kernel_manager = self.kernel_manager
self.kernel_client = kernel_client

self.height = 10 # Reduce default number of rows.

@QtCore.Slot(dict)
def expose(self, what):
"""
Exposes the given variables to the interactive shell.

:param what: Dictionary of variable name to variable to expose.
"""
self.kernel.shell.push(what)
10 changes: 10 additions & 0 deletions src/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,18 @@ def __init__(self, parent=None):
# Add toggle view actions for dockwidgets
self.toggle_history_dock_widget_view_qaction = self.history_dock_widget.toggleViewAction()
self.menu_view.addAction(self.toggle_history_dock_widget_view_qaction)
self.toggle_console_dock_widget_view_qaction = self.console_dock_widget.toggleViewAction()
self.menu_view.addAction(self.toggle_console_dock_widget_view_qaction)

# Console
self.console_dock_widget.hide() # Hidden by default
self.console_widget.exit_requested.connect(self.close) # Request exit from console exits LogikSim
self.console_widget.expose({'app': QtGui.QApplication.instance(),
'main_window': self,
'settings': settings()})

s = settings()

# Restore layout
self.restoreGeometry(s.main_window_geometry)
self.restoreState(s.main_window_state)
Expand Down
21 changes: 21 additions & 0 deletions src/main_window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,21 @@
</layout>
</widget>
</widget>
<widget class="QDockWidget" name="console_dock_widget">
<property name="minimumSize">
<size>
<width>80</width>
<height>50</height>
</size>
</property>
<property name="windowTitle">
<string>Console</string>
</property>
<attribute name="dockWidgetArea">
<number>8</number>
</attribute>
<widget class="ConsoleWidget" name="console_widget"/>
</widget>
<action name="action_exit">
<property name="text">
<string>&amp;Exit</string>
Expand Down Expand Up @@ -169,6 +184,12 @@
<extends>QListView</extends>
<header>actions/action_stack_view/</header>
</customwidget>
<customwidget>
<class>ConsoleWidget</class>
<extends>QWidget</extends>
<header>docks/console_widget/</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources>
<include location="resources.qrc"/>
Expand Down
2 changes: 1 addition & 1 deletion src/resources_rc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Resource object code
#
# Created: Thu 16. Oct 22:16:21 2014
# Created: Sun 16. Nov 21:42:06 2014
# by: The Resource Compiler for PySide (Qt v4.8.5)
#
# WARNING! All changes made in this file will be lost!
Expand Down
11 changes: 10 additions & 1 deletion src/ui_main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Form implementation generated from reading ui file 'main_window.ui'
#
# Created: Thu Oct 16 22:16:21 2014
# Created: Sun Nov 16 21:42:06 2014
# by: pyside-uic 0.2.15 running on PySide 1.2.2
#
# WARNING! All changes made in this file will be lost!
Expand Down Expand Up @@ -66,6 +66,13 @@ def setupUi(self, MainWindow):
self.verticalLayout_2.addWidget(self.action_stack_view)
self.history_dock_widget.setWidget(self.history_widget)
MainWindow.addDockWidget(QtCore.Qt.DockWidgetArea(2), self.history_dock_widget)
self.console_dock_widget = QtGui.QDockWidget(MainWindow)
self.console_dock_widget.setMinimumSize(QtCore.QSize(80, 50))
self.console_dock_widget.setObjectName("console_dock_widget")
self.console_widget = ConsoleWidget()
self.console_widget.setObjectName("console_widget")
self.console_dock_widget.setWidget(self.console_widget)
MainWindow.addDockWidget(QtCore.Qt.DockWidgetArea(8), self.console_dock_widget)
self.action_exit = QtGui.QAction(MainWindow)
self.action_exit.setObjectName("action_exit")
self.action_redo = QtGui.QAction(MainWindow)
Expand Down Expand Up @@ -98,11 +105,13 @@ def retranslateUi(self, MainWindow):
self.menu_help.setTitle(QtGui.QApplication.translate("MainWindow", "&Help", None, QtGui.QApplication.UnicodeUTF8))
self.tool_bar.setWindowTitle(QtGui.QApplication.translate("MainWindow", "Toolbar", None, QtGui.QApplication.UnicodeUTF8))
self.history_dock_widget.setWindowTitle(QtGui.QApplication.translate("MainWindow", "History", None, QtGui.QApplication.UnicodeUTF8))
self.console_dock_widget.setWindowTitle(QtGui.QApplication.translate("MainWindow", "Console", None, QtGui.QApplication.UnicodeUTF8))
self.action_exit.setText(QtGui.QApplication.translate("MainWindow", "&Exit", None, QtGui.QApplication.UnicodeUTF8))
self.action_redo.setText(QtGui.QApplication.translate("MainWindow", "&Redo", None, QtGui.QApplication.UnicodeUTF8))
self.action_undo.setText(QtGui.QApplication.translate("MainWindow", "&Undo", None, QtGui.QApplication.UnicodeUTF8))
self.action_about.setText(QtGui.QApplication.translate("MainWindow", "&About", None, QtGui.QApplication.UnicodeUTF8))
self.action_about_qt.setText(QtGui.QApplication.translate("MainWindow", "About &Qt", None, QtGui.QApplication.UnicodeUTF8))

from docks.console_widget import ConsoleWidget
from actions.action_stack_view import ActionStackView
import resources_rc