Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Basthon
Basthon Notebook
Commits
f42f5b42
Commit
f42f5b42
authored
Oct 30, 2020
by
Romain Casati
Browse files
Better way of opening file.
parent
a520c74a
Changes
3
Hide whitespace changes
Inline
Side-by-side
notebook/basthon/gui.js
View file @
f42f5b42
...
...
@@ -196,6 +196,54 @@ Un lien vers la page de Basthon avec le contenu actuel du script a été créé.
* Load a notebook.
*/
that
.
openNotebook
=
function
(
file
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
const
reader
=
new
FileReader
();
reader
.
readAsText
(
file
);
reader
.
onload
=
async
function
(
event
)
{
/* TODO: connect filename to notebook name */
await
that
.
notebook
.
load
(
JSON
.
parse
(
event
.
target
.
result
));
// notification seems useless here.
resolve
();
};
reader
.
onerror
=
reject
;
});
};
/**
* Loading file in the (emulated) local filesystem (async).
*/
that
.
putFSRessource
=
function
(
file
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
const
reader
=
new
FileReader
();
reader
.
readAsArrayBuffer
(
file
);
reader
.
onload
=
async
function
(
event
)
{
await
Basthon
.
putRessource
(
file
.
name
,
event
.
target
.
result
);
const
msg
=
$
(
"
<div>
"
).
html
(
file
.
name
+
"
est maintenant utilisable depuis Python
"
);
that
.
dialog
.
modal
({
notebook
:
that
.
notebook
,
keyboard_manager
:
that
.
notebook
.
keyboard_manager
,
title
:
"
Fichier utilisable depuis Python
"
,
body
:
msg
,
buttons
:
{
OK
:
{
"
class
"
:
"
btn-primary
"
,
},
}
});
resolve
();
};
reader
.
onerror
=
reject
;
});
};
/**
* Opening file: If it has .ipynb extension, load the notebok,
* if it has .py extension, loading it in the first cell
* or put on (emulated) local filesystem (user is asked to),
* otherwise, loading it in the local filesystem.
*/
that
.
openFile
=
function
()
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
var
input
=
document
.
createElement
(
'
input
'
);
input
.
type
=
'
file
'
;
...
...
@@ -203,22 +251,13 @@ Un lien vers la page de Basthon avec le contenu actuel du script a été créé.
input
.
onchange
=
async
function
(
event
)
{
for
(
var
file
of
event
.
target
.
files
)
{
const
ext
=
file
.
name
.
split
(
'
.
'
).
pop
();
var
reader
=
new
FileReader
();
if
(
ext
===
'
ipynb
'
)
{
reader
.
readAsText
(
file
);
reader
.
onload
=
function
(
event
)
{
/* TODO: connect filename to notebook name */
await
that
.
notebook
.
load
(
JSON
.
parse
(
event
.
target
.
result
));
resolve
();
};
await
that
.
openNotebook
(
file
);
}
else
{
reader
.
readAsArrayBuffer
(
file
);
reader
.
onload
=
function
(
event
)
{
await
Basthon
.
putFile
(
file
.
name
,
event
.
target
.
result
);
resolve
();
};
await
that
.
putFSRessource
(
file
);
}
}
resolve
();
}
document
.
body
.
appendChild
(
input
);
input
.
click
();
...
...
notebook/static/notebook/js/actions.js
View file @
f42f5b42
...
...
@@ -891,7 +891,7 @@ define([
help_index
:
'
fd
'
,
icon
:
'
fa-folder-open-o
'
,
handler
:
function
(
env
,
event
)
{
basthonGUI
.
open
Notebook
();
basthonGUI
.
open
File
();
if
(
event
){
event
.
preventDefault
();
}
...
...
notebook/static/notebook/js/menubar.js
View file @
f42f5b42
...
...
@@ -159,7 +159,7 @@ define([
var
that
=
this
;
this
.
element
.
find
(
'
#open_notebook
'
).
click
(
function
()
{
basthonGUI
.
open
Notebook
();
basthonGUI
.
open
File
();
});
this
.
element
.
find
(
'
#copy_notebook
'
).
click
(
function
()
{
that
.
notebook
.
copy_notebook
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment