Basthon Console issueshttps://framagit.org/basthon/basthon-console/-/issues2022-01-22T17:38:45Zhttps://framagit.org/basthon/basthon-console/-/issues/6Proposal for download of python created files2022-01-22T17:38:45ZLaurent COOPERProposal for download of python created filesI can make a proposal for downloading from browser python created file
My setup is a bit different as my basthon editor is in a bootstrap modal, but it certainly can be converted to the original baston console (and maybe notebook)
### C...I can make a proposal for downloading from browser python created file
My setup is a bit different as my basthon editor is in a bootstrap modal, but it certainly can be converted to the original baston console (and maybe notebook)
### Context
User create a file in python
```python
fichier = open("test.txt",'w')
fichier.write('test...\n$€...\nmultiligne et utf-8')
fichier.close()
```
now test.txt lives in emscripten virtual filesystem. It is, by now not reachable for download.
### New functions for gui
I made two new functions for gui. As I still use an old version, it is javascript and not Typescript, but I'm sure you can convert them
The first function takes a name as argument and send back the file, utf-8 encoded
```javascript
/**
* @memberof gui
* @function
* @name download_file
* @param {string} file_name - name of file to download from pyodide FS
* @description permet de télécharger un fichier qui est dans le FS de pyodide
*/
that.download_file = async function (file_name) {
let txt = pyodide._module.FS.readFile(file_name,{encoding:'utf8'});
const blob = new Blob([txt], {type : 'application/text'});
let url = window.URL.createObjectURL(blob);
let a = document.createElement("a");
a.style = "display: none";
a.href=url;
a.target="_blank";
a.download = file_name;
let python = document.getElementById('pythonModal');
python.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
a.remove();
};
```
The second function will explore the FS and look for all files at root (not directories).
It will populate the dropdwon menu
```javascript
/**
* @memberof gui
* @function
* @name propose_downloads
* @param None
* @description modify dropdown to propose downloads
*/
that.propose_downloads = function() {
let fichiers = pyodide._module.FS.readdir('.');
let downloadables = Array();
fichiers.forEach(element => {
let mode = pyodide._module.FS.stat(element).mode;
if (pyodide._module.FS.isFile(mode)) {
downloadables.push(element);
}
});
if (downloadables.length == 0) {
let item = document.createElement("li");
item.className="dropdown-item";
item.innerHTML="Aucun fichier";
let ul = document.getElementById("fileList");
ul.innerHTML="";
ul.appendChild(item);
} else {
let ul = document.getElementById("fileList");
ul.innerHTML="";
downloadables.forEach(fichier => {
let item = document.createElement("li");
item.className = "dropdown-item";
item.innerHTML = fichier;
item.onclick = function() {
window.gui.download_file(fichier);
};
ul.appendChild(item);
});
}
};
```
And lastly, I put an event listener that will capture the moment my bootstrap dropdown will show (bootstrap specific, but should be adapted to popper as bootstrap uses popper.js for dropdown). (NB : localdropdown is my dropdown bootstrap menu for downloading locally created files)
```javascript
document.getElementById('localDownload').addEventListener('show.bs.dropdown', function (event) {
window.gui.propose_downloads();
});
```
Well. It works, and now my pupils can download files they have created (very usefull for studying CSV creation for example)
Hope it helps and it can be converted to basthon console via typescript easely.
Giving back what I've did is the least I can do to thank you for your awesome work
(Sorry it's not a merge request, but I first have to learn typescript :( )https://framagit.org/basthon/basthon-console/-/issues/5Circular dependencies ?2022-01-21T17:05:31ZLaurent COOPERCircular dependencies ?Actually, editor depends on gui to access kernel and kernelsafe getters
gui depends on editor
There is a circular dependencies
Shouldn't it be avoided ?
As far as I can see, kernel is used for completion only (I never did typescript bef...Actually, editor depends on gui to access kernel and kernelsafe getters
gui depends on editor
There is a circular dependencies
Shouldn't it be avoided ?
As far as I can see, kernel is used for completion only (I never did typescript before so I'm not an expert). Why do we need to depend on the whole GUI class for this ?
I'm looking at this because I want to code my own gui class for my needs. This circular dependencie appeared on this occasionhttps://framagit.org/basthon/basthon-console/-/issues/3No output if line has no line feed2023-08-20T23:47:54ZLaurent COOPERNo output if line has no line feed# what is done
type into console this very simple code
```python
print("toto", end=" ")
```
and launch the execution
# what is expected
toto should be output
# what happens
nothing
The output seems to not be sent (maybe by kernel) onl...# what is done
type into console this very simple code
```python
print("toto", end=" ")
```
and launch the execution
# what is expected
toto should be output
# what happens
nothing
The output seems to not be sent (maybe by kernel) only if there is a line feed
[Exemple in basthon](https://console.basthon.fr/?script=eJwrKMrMK9FQKskvyVfSSc1LsVVSUNIEAFH-Bo0)https://framagit.org/basthon/basthon-console/-/issues/2Allowing console to work offline, and locally!2021-02-25T01:21:33ZLilian BessonAllowing console to work offline, and locally!I'm not talking about installing it (mobile or desktop) here, just that it should work locally offline using the browser cache.
I think it will work easily.
The first issue I encountered is that the console page loads loooots of things ...I'm not talking about installing it (mobile or desktop) here, just that it should work locally offline using the browser cache.
I think it will work easily.
The first issue I encountered is that the console page loads loooots of things from CDN like ttps://cdnjs.cloudflare.com/ajax/libs/pako/2.0.2/pako.min.js
Downloading this and including it in the page should solve the issue.
I'll try this on a local version of console, and let you know if you want.