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

PR: Add option to open an IPython console connected to the current notebook #79

Merged
merged 9 commits into from
Jul 12, 2017

Conversation

dalthviz
Copy link
Member

Fixes #75


Dependent of this PR

@dalthviz dalthviz added this to the v0.1 milestone Jun 29, 2017
@dalthviz dalthviz self-assigned this Jun 29, 2017
@dalthviz dalthviz requested a review from ccordoba12 June 29, 2017 13:11
for session in sessions:
if session['notebook']['path'] == path:
kernel_id = session['kernel']['id']
return (kernel_id, sessions_url)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to return sessions_url here? If this function is called get_kernel_id, we should only return the kernel id, no?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a method that I create initialy for a test (it was on test_plugin.py as a utility function). For the test where is used it, kernel_id and session_id are needed, should I rename it with something like get_kernel_info?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, please create a new function to get session_id and make this one to only return kernel_id

if self.ipyconsole is not None:
kernel_name = 'kernel-' + client.get_kernel_id()[0] + '.json'
kernel_path = osp.join(jupyter_runtime_dir(), kernel_name)
self.ipyconsole._create_client_for_kernel(kernel_path, None, None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be enough to pass kernel_id here instead of kernel_path or kernel_name. Is that not working?

Copy link
Member Author

@dalthviz dalthviz Jun 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not working, I think it is because osp.dirname is returning an empty string instead of None. Should I fix this?

@ccordoba12 ccordoba12 changed the title PR: Add option to open an IPython console PR: Add option to open an IPython console connected to the current notebook Jun 29, 2017
@goanpeca
Copy link
Member

?@dalthviz images

@dalthviz
Copy link
Member Author

dalthviz commented Jun 29, 2017

@goanpeca
Preview:

console

@@ -20,6 +20,7 @@
from qtpy.QtWidgets import QApplication, QMessageBox, QVBoxLayout, QMenu

# Third-party imports
from jupyter_core.paths import jupyter_runtime_dir
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This import is no longer necessary.

menu_btn = create_toolbutton(self, icon=ima.icon('tooloptions'),
tip=_('Options'))

self.menu = QMenu(self)
menu_btn.setMenu(self.menu)
menu_btn.setPopupMode(menu_btn.InstantPopup)
add_actions(self.menu, self.menu_actions)
corner_widgets = {Qt.TopRightCorner: [new_notebook_btn, menu_btn]}
corner_widgets = {Qt.TopRightCorner: [new_notebook_btn,
open_console_btn, menu_btn]}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove open_console_btn from here. It takes too much space on the tabbar.

if session['notebook']['path'] == path:
kernel_id = session['kernel']['id']
return kernel_id

def shutdown_kernel(self):
"""Shutdown the kernel of the client."""
sessions_url = self.add_token(url_path_join(self.server_url,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use self.get_session_url here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, we can simplify this whole function by simply calling self.get_kernel_id().

Please do it so we can remove this chunk of repeated code here.

@ccordoba12
Copy link
Member

A couple of things are missing before merging this PR, but they depend on spyder-ide/spyder#4691, which I hope to merge later today:

  1. Rename the console attached to the notebook to have the same name as the notebook. You can use ipyconsole.rename_client_tab for that, and you need to take 20 chars of the notebook name and after that use an ellipsis.
  2. Change client.allow_rename = False to prevent people to rename clients associated with notebooks.

Note: You can select the client create with create_client_for_kernel with ipyconsole.get_current_client().

@ccordoba12
Copy link
Member

@dalthviz, please post a screenshot with your latest changes.

@dalthviz
Copy link
Member Author

dalthviz commented Jul 6, 2017

Preview:
imagen

@ccordoba12 ccordoba12 merged commit d94d1ac into spyder-ide:master Jul 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants