Skip to content

Commit

Permalink
Add read only option (#6)
Browse files Browse the repository at this point in the history
* Add read-only option

* Update test

* Add release note

* Add to cell demo
  • Loading branch information
coatless authored Feb 22, 2024
1 parent a215ac2 commit 2021b79
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 1 deletion.
3 changes: 2 additions & 1 deletion _extensions/pyodide/qpyodide-cell-classes.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ class InteractiveCell extends BaseCell {
},
fontSize: '17.5pt', // Bootstrap is 1 rem
renderLineHighlight: "none", // Disable current line highlighting
hideCursorInOverviewRuler: true // Remove cursor indictor in right hand side scroll bar
hideCursorInOverviewRuler: true, // Remove cursor indictor in right hand side scroll bar
readOnly: thiz.options['read-only'] ?? false
}
);

Expand Down
1 change: 1 addition & 0 deletions _extensions/pyodide/qpyodide.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ local qPyodideDefaultCellOptions = {
["warning"] = "true",
["message"] = "true",
["results"] = "markup",
["read-only"] = "false",
["output"] = "true",
["comment"] = "",
["label"] = "",
Expand Down
23 changes: 23 additions & 0 deletions docs/qpyodide-code-cell-demo.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,28 @@ print("Hello quarto-pyodide World!")

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).


## Preventing Modifications to Code

Code cells can be locked to their initial state by specifying `#| read-only: true`.

::: {.panel-tabset}
## `{quarto-pyodide}` Output

```{pyodide-python}
#| read-only: true
1 + 1
```

## Cell code

```{{pyodide-python}}
#| read-only: true
1 + 1
```
:::


## Define and Call Functions

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


## Load a package

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.
Expand Down
8 changes: 8 additions & 0 deletions docs/qpyodide-release-notes.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ format:
[python]: https://www.python.org/
[quarto]: https://quarto.org/


# 0.0.1.dev-1: What does the Python Say? (??-??-????)

## Features

- New code cell option that set the interactive cell to be read-only. ([#4](https://github.com/coatless-quarto/pyodide/issues/4))


# 0.0.1: What does the Python Say? (02-19-2024)

## Features
Expand Down
8 changes: 8 additions & 0 deletions tests/qpyodide-test-internal-cell.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,19 @@ Test page for verifying cell context options set explicitly with `context`.

## Interactive

### Editable
```{pyodide-python}
#| context: interactive
1 + 1
```

### Read-only
```{pyodide-python}
#| context: interactive
#| read-only: true
1 + 1
```

## Setup

Hidden cell that sets `x` and `y` vector values.
Expand Down

0 comments on commit 2021b79

Please sign in to comment.