read-only cells in ipython/jupyter notebook - jupyter-notebook

Is there a way to mark a cell in the ipython/jupyter notebook readonly using the json format in the ipynb file? (E.g., a cell attribute "readonly":false or some such.) If not, is there a jquery hack to find suppress the double click event in the cell?

#Richard Ackon's answer requires adjustments for JupyterLab:
Open the Property Inspector.
Focus the cell you want to lock.
Add the following lines to the Cell Metadata:
{
"trusted": true,
"editable": false,
"deletable": false
}
Click on the tick to save the metadata... Tadah!, your cell can't be modified or deleted.
The Property Inspector comes built-in since JupyterLab 2.0 (note it was moved to the right sidebar by default in JupyterLab 3.0). For older JupyterLab versions you would need to modify the notebook file manually.
Unfortunately, the outputs can still be cleared by intentionally selecting that option in the menu bar (Edit > Clear Ouputs). Of course that can only happen if you DO WANT to clear the outputs and not just update them by running the cell.
Source

Yes, Use the steps below:
Select view on the menubar
Point to Cell Toolbar and select Edit Metadata
An "Edit Metadata" button will appear at the top-right corner of the cell.
Click on that button and edit the json that pops up. Set the editable key to true or false to get the desired effect.
The JSON will look something like this:
{
"deletable": false,
"editable": false,
"scrolled": true,
"trusted": true
}

There is an extension for IPython that is supposed to that:
Read Only Cell extension.
Getting it to work is something else, but it is there.

Related

Removing redundant color box in VS Code

New to coding.
How do I remove the redundant color box next to the highlighted(colored) item in VSCode?
I like to keep 'Colorize' and remove the unknown and redundant extension.
Here are the extensions I have installed.
Enabled Extensions Screenshot
Here is the issue screenshot.
code screenshot
Add this lines in your settings.json by pressing ctrl+shift+p and pressing Open Settings (JSON)
"css.colorDecorators.enable": false,
"scss.colorDecorators.enable": false,
"less.colorDecorators.enable": false,
As of VS Code v1.49 (August 2020), this is the setting:
"editor.colorDecorators": false

Add proper selector for keybinding event in Atom editor

I develop a package, which allows user to use Home button to toggle cursor position in soft-wrapped lines, as it is in Komodo Edit editor.
In my toggle() function I try to get active text editor from Atom Workspace using getActiveTextEditor function and then I do my logic.
atom.workspace.getActiveTextEditor()
I bind a Home key with a selector atom-text-editor.editor, and it mainly works fine until triggered inside Search&Replace pane or Command Palette.
"atom-text-editor.editor": {
"home": "toggle-home:toggle"
}
In this case, getActiveTextEditor returns always a currently edited file's text editor. It leads to a situation, when a cursor is moved inside an edited file's pane, but not inside focused field. When I use a Home inside a text field in Settings pane, Atom throws an exception, as it can't find any active text editor.
I did a research through Atom Docs, Atom API, even community packages, but all I found, was adding 'mini' to my event selector, to narrow event scope a bit.
"atom-text-editor.editor:not([mini])": {
"home": "toggle-home:toggle"
}
Nevertheless it still causes exception or misbehaviour in text fields without 'mini' (ie. textarea of Git/GitHub package).
What I want to achieve is:
1) to find a proper keybinding selector, that would fire only inside currently edited file pane;
OR
2) to find a method to get focused instance (Search&Replace, Command Palette or any other field) for further processing.
Solution
As DamnedScholar mentioned here:
the selector atom-workspace-axis.vertical atom-pane-container atom-text-editor:not([mini]) will do it.
Already tested, works fine.

Bootstrap switch with own text

I’d like to be able to add a LOCK / UNLOCK behaviour on the checkbox using twitter bootstrap. I found a similar sample at boostrap-switch.org at the section of Label Text. In this example they have used ON-TV-OFF, Similarly I want to give my own text in the place of ON, OFF. Like UNLOCK-Username-LOCK.
LOCK should be disappeared by clicking on UNLOCK then output should be like XXX-LOCK
UNLOCK should be disappeared by click on ON text then output should be like UNLOCK-XXX
How can I do this with bootstrap?
It's a Github repository. Go to /build/js and in the bootstrap-switch.js change the string in the following:
html = "ON";
It's the line 35 of the js file.
Similarly change the string in:
html = "OFF";
i.e. line 47.
This might not be exact same thing as boostrap-switch.org, but I have done it using fadeTo() property of jquery.
Here is the jsfiddle output link.

QFileDialog : how to set option to show content of folder in getExistingDirectory()

I am using QFileDialog as
filename = QFileDialog::getExistingDirectory(this,"Select Image File: ",dataDir,0);
I want that I can check files inside folder before selecting it. function getExistingDirectory() is setting QFileDialog::ShowDirsOnly as a default option. I checked in docs there is no any option that do opposite of this. So I set last parameter 0. But now it is not using native dialog. I want to use native dialog with this. I have no clue how to do this cause no flag found in options for UseNativeDialog. Please help.
Try creating the file dialog on your own, something like:
QFileDialog dialog(this);
dialog.setFileMode(QFileDialog::Directory);
dialog.setViewMode(QFileDialog::Detail);
dialog.setDirectory(datadir);
dialog.exec();
The code by Sebastian should create a native dialog, unless you make a line such as:
dialog.setOption(QFileDialog::DontUseNativeDialog, true);
However, I have not been able to get this working under Windows, even though the documentation says that the QFileDialog::Directory option should display files by default. Not only that, but doing:
qDebug() << dir_selector.testOption(QFileDialog::ShowDirsOnly);
displays false on my system, indicating that there is probably a bug somewhere.

QRadioButton check/uncheck issue in Qt

I am finding issues related to check/uncheck of QRadioButton. The images I have used for checking(a white dot) and unchecking(without a white dot) is not updated.
My issue is like: I have implemented few QRadioButton(s). For the first time all the QRadioButtons checked false. So the images for this case is without a white dot. When user selects any QRadioButton then it's image changes to another i.e. image with a white dot. On a button click I am resetting the state of the radio buttons from checked to uncheck state . However the images state are not changing. They remain in checked state. The code snippet is as follows:
Code:
if(ui->radioButtonReadOnlineData->isChecked())
ui->radioButtonReadOnlineData->setChecked(false);
if(ui->radioButtonSavetoDBReadOfflineData->isChecked())
ui->radioButtonSavetoDBReadOfflineData->setChecked(false);
if(ui->radioButtonViewLocalData->isChecked())
ui->radioButtonViewLocalData->setChecked(false);
if(ui->radioButtonDateRange->isChecked())
ui->radioButtonDateRange->setChecked(false);
if(ui->radioButtonAll->isChecked())
ui->radioButtonAll->setChecked(false);
The images for each of the QRadioButtons is set as like:
Code:
ui->radioButtonAll->setStyleSheet(
"QRadioButton::indicator::checked { image: url(:/Resources/radio-btn-selected.png);}"
"QRadioButton::indicator::unchecked {image: url(:/Resources/radio-btn-unselected.png);}"
);
Any clues why the QRradioButton images are not updated. Thanks.
Your problem is most probably related to
setAutoExclusive(bool)
By default all buttons belonging to the same parent behave as if they were part of the same exclusive button group. After having selected one you are not able to return to having all buttons unchecked.
A work around is to find out what button is checked, and for that button do the following
theSelectedButton->setAutoExclusive(false);
thsSelectedButton->setChecked(false);
theSelectedButton->setAutoExclusive(true);
Take a look at these links for more information:
http://developer.qt.nokia.com/forums/viewthread/5482
http://www.qtforum.org/article/19619/qradiobutton-setchecked-bug.html
Make sure your resource file look like :
<qresource>
<file>Resources/radio-btn-selected.png</file>
<file>Resources/radio-btn-unselected.png</file>
</qresource>
And that it is included correctly in your application.
Either include the .qrc in your .pro file with
RESOURCES = myresource.qrc
either create an external binary resource file, then register it at runtime with
QResource::registerResource("/path/to/myresource.rcc");
Or if you are using the designer, you can do like this.

Resources