Skip to content

Commit 2021b79

Browse files
authored
Add read only option (#6)
* Add read-only option * Update test * Add release note * Add to cell demo
1 parent a215ac2 commit 2021b79

5 files changed

+42
-1
lines changed

_extensions/pyodide/qpyodide-cell-classes.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,8 @@ class InteractiveCell extends BaseCell {
247247
},
248248
fontSize: '17.5pt', // Bootstrap is 1 rem
249249
renderLineHighlight: "none", // Disable current line highlighting
250-
hideCursorInOverviewRuler: true // Remove cursor indictor in right hand side scroll bar
250+
hideCursorInOverviewRuler: true, // Remove cursor indictor in right hand side scroll bar
251+
readOnly: thiz.options['read-only'] ?? false
251252
}
252253
);
253254

_extensions/pyodide/qpyodide.lua

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ local qPyodideDefaultCellOptions = {
4545
["warning"] = "true",
4646
["message"] = "true",
4747
["results"] = "markup",
48+
["read-only"] = "false",
4849
["output"] = "true",
4950
["comment"] = "",
5051
["label"] = "",

docs/qpyodide-code-cell-demo.qmd

+23
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,28 @@ print("Hello quarto-pyodide World!")
8282

8383
By using these shortcuts, you can run code conveniently and efficiently. This practice can also help you become familiar with keyboard shortcuts when transitioning to integrated development environments (IDEs) like [RStudio](https://posit.co/products/open-source/rstudio/) or [Visual Studio Code with Python](https://code.visualstudio.com/docs/languages/python).
8484

85+
86+
## Preventing Modifications to Code
87+
88+
Code cells can be locked to their initial state by specifying `#| read-only: true`.
89+
90+
::: {.panel-tabset}
91+
## `{quarto-pyodide}` Output
92+
93+
```{pyodide-python}
94+
#| read-only: true
95+
1 + 1
96+
```
97+
98+
## Cell code
99+
100+
```{{pyodide-python}}
101+
#| read-only: true
102+
1 + 1
103+
```
104+
:::
105+
106+
85107
## Define and Call Functions
86108

87109
Functions can be defined in one cell and called.
@@ -100,6 +122,7 @@ num_list = [1, 2, 3]
100122
[square(num)for num in num_list]
101123
```
102124

125+
103126
## Load a package
104127

105128
We've enabled _dynamic_ package detection to handle importing packages into the environment. The _dynamic_ part comes from detecting whether a non-core Python package is used, installing, and, then, importing it.

docs/qpyodide-release-notes.qmd

+8
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ format:
1212
[python]: https://www.python.org/
1313
[quarto]: https://quarto.org/
1414

15+
16+
# 0.0.1.dev-1: What does the Python Say? (??-??-????)
17+
18+
## Features
19+
20+
- New code cell option that set the interactive cell to be read-only. ([#4](https://github.com/coatless-quarto/pyodide/issues/4))
21+
22+
1523
# 0.0.1: What does the Python Say? (02-19-2024)
1624

1725
## Features

tests/qpyodide-test-internal-cell.qmd

+8
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,19 @@ Test page for verifying cell context options set explicitly with `context`.
99

1010
## Interactive
1111

12+
### Editable
1213
```{pyodide-python}
1314
#| context: interactive
1415
1 + 1
1516
```
1617

18+
### Read-only
19+
```{pyodide-python}
20+
#| context: interactive
21+
#| read-only: true
22+
1 + 1
23+
```
24+
1725
## Setup
1826

1927
Hidden cell that sets `x` and `y` vector values.

0 commit comments

Comments
 (0)