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

[toc2 extension feature request] highlight TOC section with executing cell #791

Closed
dinya opened this issue Nov 10, 2016 · 13 comments
Closed

Comments

@dinya
Copy link

dinya commented Nov 10, 2016

Is it possible to highlight TOC section which contains executing cell?

I think it will be very easy to navigate notebooks with a large number of cells.

@jcb91
Copy link
Member

jcb91 commented Nov 10, 2016

This could certainly be possible, but the current toc2 machinery doesn't have a mechanism to add it in simply, so it'd need a bit of a rewrite. My best guess for how to go about it would be to loop through cells backwards instead of the current forwards while rebuilding the toc, allowing you to decide whether the current 'section' is being executed, so that once you get to the section heading, you can alter its rendering...

@dinya
Copy link
Author

dinya commented Nov 11, 2016

@jcb91 The simplest and therefore the best solution!

allowing you to decide whether the current 'section' is being executed, so that once you get to the section heading, you can alter its rendering...

Do you mean this way allows me to add rules to customize toc entries (for example highlighting)? Or you talk about plugin realization in general?

@jcb91
Copy link
Member

jcb91 commented Nov 11, 2016

Do you mean this way allows me to add rules to customize toc entries (for example highlighting)? Or you talk about plugin realization in general?

well, I meant that's how I'd make the plugin implement it, but the other also makes sense. To clarify, I'd do the customization by just applying a css class (plus adding some css rules), which would then allow you to add additional rules, or override the provided ones by adding to your own custom.css. Does that make sense?

@jfbercher
Copy link
Member

jfbercher commented Nov 11, 2016

@dinya I don't completely understand what you mean by "executing cell". Do you mean the section of the currently selected cell, which if it is a code cell can be executed? (I mean sometimes execution is very short and it would not be as easy to catch the event).

Actually we do not really loop over the cells (only for finding the index of the "toc_cell" if needed) but over the headers. So this would require finding the current "executing" (may be 'selected'?) cell, and then the corresponding nearest (above) header and adding a style attribute to it.

A point is that the toc is currently refreshed only when a markdown cell is created/updated. I do not if we have an event to detect the execution of a cell; otherwise detecting execution would require to patch CodeCell prototype. Ok, while writing this I think that it is probably what you meant. Feasible, but not that easy.

@jcb91
Copy link
Member

jcb91 commented Nov 11, 2016

Ah, I'd thought more in terms of cells queued for execution/executing now, but yeah, maybe selected is what was meant?

Actually we do not really loop over the cells [...] but over the headers.

Ah, true, I'd forgotten that! Yeah, in this case it makes it more additional work than it would have been!

@dinya
Copy link
Author

dinya commented Nov 12, 2016

@jcb91 @jfbercher Thanks for clarifying the question

@jcb91

I meant that's how I'd make the plugin implement it, but the other also makes sense. To clarify, I'd do the customization by just applying a css class (plus adding some css rules), which would then allow you to add additional rules, or override the provided ones by adding to your own custom.css. Does that make sense?

Customization is a very cool feature for any tool, but I don't know what it is really necessary in the context of a feature request (just highlight "selected", "executing" and "editing" cell, see bellow). If it is possible to implement, and it's not hard work, why not? Maybe it will helpful for other users.

@jfbercher

I don't completely understand what you mean by "executing cell". Do you mean the section of the currently selected cell, which if it is a code cell can be executed?

I meant by "selected", "editing" and "executing (running)" cells the following.

selected cell is the cell under cursor (blue highlighed cell in the notebook).

toc2_selected_cell

executing (running) cell is the cell which is first queued for execution (in terms of execute_time plugin). It will leave FIFO stack after execution and the first cell in the stack's head will be "executing cell". And so on.

editing cell is the currently editing cell (green highlighed cell in the notebook).

toc2_executing_editing_cells

(I mean sometimes execution is very short and it would not be as easy to catch the event).

I think it's not a problem: we are talk about "long term tasks" :-)

@jfbercher
Copy link
Member

I have done something that highlights toc-sections with selected/edited cells. For executing cells I don't see yet how to do it (in a reasonable time). You will be welcome to test this and report comments/issues. You can update by

jupyter nbextension install https://rawgit.com/jfbercher/small_nbextensions/master/toc2.zip  --user
jupyter nbextension enable toc2/main 

@dinya
Copy link
Author

dinya commented Nov 15, 2016

@jfbercher,

Thank you very much! It works fine for me. Now I'm in anticipation of executing cell highlighting feature :). Could you highlight it independently of the selected/edited cell (the cell is deep-yellow highlighted currently)?

@jfbercher
Copy link
Member

@dinya
Done!
I found the way to highlight toc items for sections with executing cells, in addition to those with selected/edited cells.
You can test it by

jupyter nbextension install https://rawgit.com/jfbercher/small_nbextensions/master/toc2.zip  --user
jupyter nbextension enable toc2/main 

I also make a PR for this new feature.

@dinya
Copy link
Author

dinya commented Nov 21, 2016

@jfbercher Thanks!

But I have a question about the logic of highlighting.

Current selected/edited section is yellow. It's ok.

toc2_highlight0

But when I go to queued section, the section is still red.

toc2_highlight1

Why not highlight the section with yellow while it is focused and color the section with red again when it is out of focus and it is not still finished?

@dinya
Copy link
Author

dinya commented Nov 21, 2016

@jfbercher,

When I click "Kernel -> Restart & Run All" every section is highlighted in red for a moment. But then none of the "running" sections are not highlighted (see screenshot)

toc2

@jfbercher
Copy link
Member

@dinya
Try the new version

jupyter nbextension install https://rawgit.com/jfbercher/small_nbextensions/master/toc2.zip  --user

where I tried to address the two comments above.
Also the highlight colors are now configurable in the nbextensions-configurator.

@dinya
Copy link
Author

dinya commented Nov 24, 2016

@jfbercher, Many thanks! Great work! I'm so happy :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants