Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
J
JupyLabBook
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SIRIUS Beamline
Notebooks
JupyLabBook
Commits
f739acd9
Commit
f739acd9
authored
4 months ago
by
HEMMERLE Arnaud
Browse files
Options
Downloads
Patches
Plain Diff
Start migration
parent
81370f64
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/frontend/notebook.py
+17
-37
17 additions, 37 deletions
lib/frontend/notebook.py
lib/jupylabbook.py
+7
-3
7 additions, 3 deletions
lib/jupylabbook.py
with
24 additions
and
40 deletions
lib/frontend/notebook.py
+
17
−
37
View file @
f739acd9
...
@@ -3,28 +3,23 @@ Module dealing with actions on the notebook itself (create cell, save nb, ...).
...
@@ -3,28 +3,23 @@ Module dealing with actions on the notebook itself (create cell, save nb, ...).
The code requires use of Javascript to modify the structure of the notebook
The code requires use of Javascript to modify the structure of the notebook
and is therefore not usable in Jupyter Lab, which forbids Javascript.
and is therefore not usable in Jupyter Lab, which forbids Javascript.
"""
"""
import
time
import
base64
from
IPython.display
import
Javascript
,
display
from
ipywidgets
import
Widget
from
ipywidgets
import
Widget
from
ipylab
import
JupyterFrontEnd
app
=
JupyterFrontEnd
()
def
save_nb
():
def
save_nb
():
"""
"""
Save the current state of the notebook (including the widgets).
Save the current state of the notebook (including the widgets).
"""
"""
#display(HTML('<script>Jupyter.menubar.actions._actions["widgets:save-with-widgets"].handler()</script>') )
app
.
commands
.
execute
(
'
docmanager:save
'
)
display
(
Javascript
(
'
IPython.notebook.save_checkpoint();
'
))
def
delete_cell
():
def
delete_cell
():
"""
"""
Delete the cell in which this function was called in the Jupyter Notebook.
Delete the cell in which this function was called in the Jupyter Notebook.
"""
"""
display
(
Javascript
(
app
.
commands
.
execute
(
'
notebook:move-cursor-up
'
)
"""
app
.
commands
.
execute
(
'
notebook:delete-cell
'
)
var index = IPython.notebook.get_selected_cells_indices();
IPython.notebook.delete_cell(index);
"""
))
def
create_cell
(
code
,
position
=
'
below
'
,
celltype
=
'
markdown
'
,
def
create_cell
(
code
,
position
=
'
below
'
,
celltype
=
'
markdown
'
,
is_print
=
True
,
is_execute
=
True
):
is_print
=
True
,
is_execute
=
True
):
...
@@ -45,40 +40,28 @@ def create_cell(code, position='below', celltype='markdown',
...
@@ -45,40 +40,28 @@ def create_cell(code, position='below', celltype='markdown',
Execute the cell after its creation
Execute the cell after its creation
"""
"""
encoded_code
=
(
base64
.
b64encode
(
code
.
encode
(
'
latin1
'
))).
decode
(
'
utf8
'
)
if
position
==
'
below
'
:
app
.
commands
.
execute
(
'
notebook:insert-cell-below
'
)
# Create a unique id for the cell based on epoch time
if
position
==
'
at_bottom
'
:
time
.
sleep
(
0.1
)
# Delay to ensure unique id
app
.
commands
.
execute
(
'
notebook:extend-marked-cells-bottom
'
)
display_id
=
int
(
time
.
time
()
*
1e9
)
app
.
commands
.
execute
(
'
notebook:insert-cell-below
'
)
js_code
=
"""
var cell = IPython.notebook.insert_cell_{0}(
"
{1}
"
);
app
.
commands
.
execute
(
'
notebook:move-cursor-up
'
)
cell.set_text(atob(
"
{2}
"
));
app
.
commands
.
execute
(
'
notebook:replace-selection
'
,
{
'
text
'
:
code
})
"""
if
not
is_print
:
if
celltype
==
'
markdown
'
:
js_code
+=
"""
cell.metadata.tags = [
'
notPrint
'
]
app
.
commands
.
execute
(
'
notebook:change-cell-to-markdown
'
)
"""
if
is_execute
:
if
is_execute
:
js_code
+=
"""
cell.execute();
app
.
commands
.
execute
(
'
notebook:run-cell
'
)
"""
display
(
Javascript
(
js_code
.
format
(
position
,
celltype
,
encoded_code
)),
display_id
=
display_id
)
# Necessary hack to avoid self-execution of cells at notebook re-opening
display
(
Javascript
(
"""
"""
),
display_id
=
display_id
,
update
=
True
)
def
refresh_cell
():
def
refresh_cell
():
"""
"""
Refresh the current cell.
Refresh the current cell.
"""
"""
# Create a unique id for the cell based on epoch time
app
.
commands
.
execute
(
'
notebook:run-cell
'
)
display_id
=
int
(
time
.
time
()
*
1e9
)
display
(
Javascript
(
"""
IPython.notebook.execute_selected_cells();
"""
),
display_id
=
display_id
)
# Necessary hack to avoid self-execution of cells at notebook re-opening
display
(
Javascript
(
"""
"""
),
display_id
=
display_id
,
update
=
True
)
def
create_cell_action_widgets
(
is_delete_current_cell
):
def
create_cell_action_widgets
(
is_delete_current_cell
):
"""
"""
...
@@ -95,8 +78,5 @@ def create_cell_action_widgets(is_delete_current_cell):
...
@@ -95,8 +78,5 @@ def create_cell_action_widgets(is_delete_current_cell):
celltype
=
'
code
'
,
is_print
=
False
,
is_execute
=
True
celltype
=
'
code
'
,
is_print
=
False
,
is_execute
=
True
)
)
# Close all the active widgets to save memory
Widget
.
close_all
()
if
is_delete_current_cell
:
if
is_delete_current_cell
:
delete_cell
()
delete_cell
()
This diff is collapsed.
Click to expand it.
lib/jupylabbook.py
+
7
−
3
View file @
f739acd9
...
@@ -3,11 +3,15 @@ Custom module called by `JupyLabBook.ipynb`.
...
@@ -3,11 +3,15 @@ Custom module called by `JupyLabBook.ipynb`.
Coordinates the different sub-modules.
Coordinates the different sub-modules.
The object `experiment` containing all the attributes relevant to the current experiment is defined here.
The object `experiment` containing all the attributes relevant to the current experiment is defined here.
"""
"""
from
IPython.display
import
Javascript
,
display
from
IPython.display
import
display
from
lib.frontend
import
action
,
process
,
experiment
,
notebook
from
lib.frontend
import
action
,
process
,
experiment
,
notebook
from
ipylab
import
JupyterFrontEnd
app
=
JupyterFrontEnd
()
# To have all the cells expanded (not collapsed)
# To have all the cells expanded (not collapsed)
display
(
Javascript
(
'
IPython.OutputArea.prototype._should_scroll = function(lines) {return false;}
'
))
app
.
commands
.
execute
(
'
notebook:disable-output-scrolling
'
)
# Save pdf images for the final pdf report
# Save pdf images for the final pdf report
try
:
try
:
...
@@ -22,7 +26,7 @@ except ModuleNotFoundError:
...
@@ -22,7 +26,7 @@ except ModuleNotFoundError:
# Rules for numbering versions
# Rules for numbering versions
# vX.Y.Z with X major, Y minor, Z patch. Each new version increments Z (not used if Z=0).
# vX.Y.Z with X major, Y minor, Z patch. Each new version increments Z (not used if Z=0).
# If the file Example.ipynb cannot run with the new libraries, increment Y and restart at Z=0.
# If the file Example.ipynb cannot run with the new libraries, increment Y and restart at Z=0.
__version__
=
'
v3.2.3
'
__version__
=
'
jupyterlab
'
# Define the object experiment
# Define the object experiment
# It contains all the attributes relevant to the current experiment
# It contains all the attributes relevant to the current experiment
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment