python-eel/Eel

redirecting pages while keep python running

Open

Aperta il 19 feb 2023

Vedi su GitHub
 (2 commenti) (0 reazioni) (0 assegnatari)Python (5980 star) (570 fork)batch import
help wanted

Descrizione

Similar to #426 , I am trying to redirect pages while keeping python running So i have just ran a loading screen on python and i am trying to switch from index.html to home.html once python is done loading. I have tried the solution on #426 too

import eel
import time
eel.init('web')

@eel.expose
def load_modules():
    import pandas as pd
    from sklearn.linear_model import LinearRegression
    from sklearn.model_selection import train_test_split
    import yfinance as yf
    from datetime import datetime, timedelta
    print('load done')
    done = "1"
    eel.go_to('home.html')
    return done

eel.start('index.html')

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>OMEGA</title>
    <script type="text/javascript" src="/eel.js"></script>
    <script type="text/javascript" src="main.js"></script>
    <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body onload="load_modules()">
    <div class="omega">OMEGA</div>
    <div class="loading">
        <div class="spinner"></div>
        <div class="loading-text">Loading...</div>
    </div>
</body>
</html>

eel.expose(go_to)
function go_to(url) {window.location.replace(url);};
function callback(done){
    if (done === done) {
        //window.location.href = "home.html";
        //go_to('home.html')
    }      
}

function load_modules(){
    eel.load_modules()(callback)
};

so once its done loading, it should be redirected to another page called

home.html

Problem is: Once everything is done and index.html is redirected to home.html, my python code stops. I think I know why..? (probably because index.html is closed to the program stops) is there a way to keep the python code running despite changing to another page?

Many thanks

Guida contributor