This repository was archived by the owner on Jun 22, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 608
Expand file tree
/
Copy patheel_CRA.py
More file actions
80 lines (61 loc) · 2.33 KB
/
eel_CRA.py
File metadata and controls
80 lines (61 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"""Main Python application file for the EEL-CRA demo."""
import os
import platform
import random
import sys
import eel
# Use latest version of Eel from parent directory
sys.path.insert(1, '../../')
@eel.expose # Expose function to JavaScript
def say_hello_py(x):
"""Print message from JavaScript on app initialization, then call a JS function."""
print('Hello from %s' % x) # noqa T001
eel.say_hello_js('Python {from within say_hello_py()}!')
@eel.expose
def expand_user(folder):
"""Return the full path to display in the UI."""
return '{}/*'.format(os.path.expanduser(folder))
@eel.expose
def pick_file(folder):
"""Return a random file from the specified folder."""
folder = os.path.expanduser(folder)
if os.path.isdir(folder):
listFiles = [_f for _f in os.listdir(folder) if not os.path.isdir(os.path.join(folder, _f))]
if len(listFiles) == 0:
return 'No Files found in {}'.format(folder)
return random.choice(listFiles)
else:
return '{} is not a valid folder'.format(folder)
def start_eel(develop):
"""Start Eel with either production or development configuration."""
if develop:
directory = 'src'
app = None
page = {'port': 3000}
else:
directory = 'build'
app = 'chrome-app'
page = 'index.html'
eel.init(directory, ['.tsx', '.ts', '.jsx', '.js', '.html'])
# These will be queued until the first connection is made, but won't be repeated on a page reload
say_hello_py('Python World!')
eel.say_hello_js('Python World!') # Call a JavaScript function (must be after `eel.init()`)
eel.show_log('https://github.com/samuelhwilliams/Eel/issues/363 (show_log)')
eel_kwargs = dict(
host='localhost',
port=8080,
size=(1280, 800),
shutdown_delay=60 # Prevent disconnect when webpack hot refresh
)
try:
eel.start(page, mode=app, **eel_kwargs)
except EnvironmentError:
# If Chrome isn't found, fallback to Microsoft Edge on Win10 or greater
if sys.platform in ['win32', 'win64'] and int(platform.release()) >= 10:
eel.start(page, mode='edge', **eel_kwargs)
else:
raise
if __name__ == '__main__':
import sys
# Pass any second argument to enable debugging
start_eel(develop=len(sys.argv) == 2)