Add events to Jupyter Notebook - python

I would like to add some simple actions that should be done automatically each time I execute the cell or save the notebook. Let's imagine I want to make a log of some of my activities in notebook (ipynb, the json) metadata.
For example, let's image I want to do following:
each time I run cell I want to store such information in metadata so I will know exactly when and which cell I executed,
after each notebook save (Ctrl+S) I want to perform some postprocessing and generate some report,
after each copy/paste (Ctrl+C/Ctrl+V) I want to check the clipboard and process it.
Is it possible to somehow implement it in Jupyter Notebook? I need it to be embedded to notebook file (not as external extension that user need to install and turn on).

Related

How to display entire output of a code cell when the code is imported from a Python script?

I am plotting some figures using matplotlib inside a notebook in JupyterLab. The code which is plotting these figures is imported from a .py file present in the same directory as of the notebook.
Assuming that figures are of appropriate size, how can I display them entirely i.e. where scrolling is not needed or disabled to display the output and I can get one-shot overview of the output given it is not populating the display beyond the screen size?
The issue is resolved if I copy the code from .py file and run it in the notebook directly:
I have tried Toddneal's answer from Making a Jupyter notebook output cell fullscreen, but scroll bar still exists in the output cell. I also referred to How to avoid output into scrollable frames in jupyter notebook? and tried:
%%javascript
IPython.OutputArea.prototype._should_scroll = function(lines) {
return false;
}
as the first code cell in the notebook, but gives out the error: Javascript Error: Can't find variable: IPython.
The output cell is already expanded, so the issue is with the height of the output cell. There are bunch of cells beyond the output cells (could that be possibly affecting the height of output cell?). The extension autoscroll might not work because it is a Jupyter Notebook extension:
Due to major differences between the Jupyter Notebook and JupyterLab, the extensions in this repository will not work in JupyterLab.
As krassowki suggested in a comment, the scrolling is disabled by right-clicking on the output cell and choosing "Disable Scrolling for Outputs."

How to add button to hide cell inputs in python jupyter notebook without nbextensions

I'm new to python and dont understand tag and cell metadata. I want to add button to hide cell input code in jupyter notebook itself, as shown in: https://jupyterbook.org/interactive/hiding.html > Hide cell inputs. Can someone direct me please.
If you want to add a button on the notebook you must have an extension fir that.
You can use an existing one like https://github.com/osscar-org/jupyterlab-hide-code or do it yourself.
Otherwise you can use the 'Collapse' commands in the 'view' menu.

VS Code Jupyter Notebooks - How to stop result text wrapping?

When using Jupyter Notebooks within VS Code is it possible to stop the code cell result text from wrapping?
When querying wide dataframes (Eg 100 columns wide) the resulting text is unreadable due to the text wrapping and requires copying out to other text editors to be able to read the results.
Attached is a screenshot of a simple dataframe header that is wrapping over a couple of lines, once you're returning actual rows it's unusable.
Screenshot
This could be a limitation of Jupyter's UI. I recommend you to see your data in variable explorer and data viewer. By clicking theĀ VariablesĀ icon in the top side after running, you'll see a list of the current variables. For additional information of the variables, you can double-click on a row or use the Show variable in data viewer button to see a more detailed view.

Messaging and Jupyter Notebooks

I'm trying to wrap my head around messaging in Jupyter notebooks. But I'm a bit lost and confused.
My goal is fairly straight forward to state: I want my python kernel to update the output of a cell in a Jupyter notebook while a long calculation is running. Whenever new data arrives in the browser, I want to trigger a redraw by calling some javascript function.
Specifically, the cell output contains HTML with a WebGL canvas. That part works well. I can easily visualize the initial data in the canvas with WebGL/javascript. But I want to update the data dynamically, as the kernel performs a long calculation on it. What I'd like to know is how one of my javascript functions in a notebook can receive binary data from my kernel.
I tried to read the documentation on messaging and jupyter notebooks, but it's really short and doesn't provide any links for further reading. What would really help is an example in the form of two code snippets, one for the notebook and the other for the kernel side.

Extract data from application using python

I want to know if it is possible to extract data out of any windows application.
The problem i am facing is that i want to be able to monitor the text that is being generated on a certain label field on an window application i have running on my desktop.
I want to know if there is a python library or way to read the values generated by the application.
Just to make it clear an example would be:
If i use the default calc.exe on windows and i want to run a script to get me the answer being displayed on the calc application.

Categories