Skip to content
This repository was archived by the owner on Jul 26, 2024. It is now read-only.

Commit c904a1c

Browse files
committed
Update browser documentation
1 parent b0e6735 commit c904a1c

1 file changed

Lines changed: 27 additions & 31 deletions

File tree

README.md

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
# Eel, but then Paling
22

3-
[![PyPI version](https://img.shields.io/pypi/v/Eel?style=for-the-badge)](https://pypi.org/project/Paling/)
4-
[![PyPi Downloads](https://img.shields.io/pypi/dm/Eel?style=for-the-badge)](https://pypistats.org/packages/paling)
3+
[![PyPI version](https://img.shields.io/pypi/v/Paling?style=for-the-badge)](https://pypi.org/project/Paling/)
4+
[![PyPi Downloads](https://img.shields.io/pypi/dm/Paling?style=for-the-badge)](https://pypistats.org/packages/paling)
55
![Python](https://img.shields.io/pypi/pyversions/Paling?style=for-the-badge)
6-
[![License](https://img.shields.io/pypi/l/Eel.svg?style=for-the-badge)](https://pypi.org/project/Paling/)
6+
[![License](https://img.shields.io/pypi/l/Paling.svg?style=for-the-badge)](https://pypi.org/project/Paling/)
77

88
Paling is a updated version of Eel, the Python library for making simple Electron-like offline HTML/JS GUI apps, with full access to Python capabilities and libraries.
99

1010
> **Eel hosts a local webserver, then lets you annotate functions in Python so that they can be called from Javascript, and vice versa.**
1111
12-
Eel is designed to take the hassle out of writing short and simple GUI applications. If you are familiar with Python and web development, probably just jump to [this example](https://github.com/ChrisKnott/Eel/tree/master/examples/04%20-%20file_access) which picks random file names out of the given folder (something that is impossible from a browser).
12+
~~Eel~~ Paling is designed to take the hassle out of writing short and simple GUI applications. If you are familiar with Python and web development, probably just jump to [this example](https://github.com/python-paling/Paling/tree/master/examples/04%20-%20file_access) which picks random file names out of the given folder (something that is impossible from a browser).
1313

14-
<p align="center"><img src="https://raw.githubusercontent.com/samuelhwilliams/Eel/master/examples/04%20-%20file_access/Screenshot.png" ></p>
14+
<p align="center"><img src="https://raw.githubusercontent.com/python-paling/Paling/master/examples/04%20-%20file_access/Screenshot.png" ></p>
1515

1616
<!-- TOC -->
1717

@@ -40,13 +40,9 @@ Eel has always been our favorite library for writing UI's in python, because it
4040

4141
There are several options for making GUI apps in Python, but if you want to use HTML/JS (in order to use jQueryUI or Bootstrap, for example) then you generally have to write a lot of boilerplate code to communicate from the Client (Javascript) side to the Server (Python) side.
4242

43-
The closest Python equivalent to Electron (to my knowledge) is [cefpython](https://github.com/cztomczak/cefpython). It is a bit heavy weight for what I wanted.
43+
~~Eel~~ Paling is not as fully-fledged as Electron or cefpython - it is probably not suitable for making full blown applications like Atom - but it is very suitable for making the GUI equivalent of little utility scripts that you use internally in your team.
4444

45-
Eel is not as fully-fledged as Electron or cefpython - it is probably not suitable for making full blown applications like Atom - but it is very suitable for making the GUI equivalent of little utility scripts that you use internally in your team.
46-
47-
For some reason many of the best-in-class number crunching and maths libraries are in Python (Tensorflow, Numpy, Scipy etc) but many of the best visualization libraries are in Javascript (D3, THREE.js etc). Hopefully Eel makes it easy to combine these into simple utility apps for assisting your development.
48-
49-
Join Eel's users and maintainers on [Discord](https://discord.com/invite/3nqXPFX), if you like.
45+
For some reason many of the best-in-class number crunching and maths libraries are in Python (Tensorflow, Numpy, Scipy etc) but many of the best visualization libraries are in Javascript (D3, THREE.js etc). Hopefully ~~Eel~~ Paling makes it easy to combine these into simple utility apps for assisting your development.
5046

5147
## Install
5248

@@ -59,14 +55,14 @@ pip install paling
5955
To include support for HTML templating, currently using [Jinja2](https://pypi.org/project/Jinja2/#description):
6056

6157
```shell
62-
pip install eel[jinja2]
58+
pip install paling[jinja2]
6359
```
6460

6561
## Usage
6662

6763
### Directory Structure
6864

69-
An Eel application will be split into a frontend consisting of various web-technology files (.html, .js, .css) and a backend consisting of various Python scripts.
65+
An ~~Eel~~ Paling application will be split into a frontend consisting of various web-technology files (.html, .js, .css) and a backend consisting of various Python scripts.
7066

7167
All the frontend files should be put in a single directory (they can be further divided into folders inside this if necessary).
7268

@@ -86,7 +82,7 @@ static_web_folder/ <-- Web folder
8682
Suppose you put all the frontend files in a directory called `web`, including your start page `main.html`, then the app is started like this;
8783

8884
```python
89-
import eel
85+
import paling
9086
paling.init('web')
9187
paling.start('main.html')
9288
```
@@ -101,7 +97,7 @@ Additional options can be passed to `paling.start()` as keyword arguments.
10197

10298
Some of the options include the mode the app is in (e.g. 'chrome'), the port the app runs on, the host name of the app, and adding additional command line flags.
10399

104-
As of Eel v0.12.0, the following options are available to `start()`:
100+
As of ~~Eel~~ Paling v0.12.0, the following options are available to `start()`:
105101
- **mode**, a string specifying what browser to use (e.g. `'chrome'`, `'electron'`, `'edge'`, `'custom'`). Can also be `None` or `False` to not open a window. *Default: `'chrome'`*
106102
- **host**, a string specifying what hostname to use for the Bottle server. *Default: `'localhost'`)*
107103
- **port**, an int specifying what port to use for the Bottle server. Use `0` for port to be picked automatically. *Default: `8000`*.
@@ -112,8 +108,8 @@ As of Eel v0.12.0, the following options are available to `start()`:
112108
- **position**, a tuple of ints specifying the (left, top) of the main window in pixels *Default: `None`*
113109
- **geometry**, a dictionary specifying the size and position for all windows. The keys should be the relative path of the page, and the values should be a dictionary of the form `{'size': (200, 100), 'position': (300, 50)}`. *Default: {}*
114110
- **close_callback**, a lambda or function that is called when a websocket to a window closes (i.e. when the user closes the window). It should take two arguments; a string which is the relative path of the page that just closed, and a list of other websockets that are still open. *Default: `None`*
115-
- **app**, an instance of Bottle which will be used rather than creating a fresh one. This can be used to install middleware on the instance before starting eel, e.g. for session management, authentication, etc. If your `app` is not a Bottle instance, you will need to call `paling.register_eel_routes(app)` on your custom app instance.
116-
- **shutdown_delay**, timer configurable for Eel's shutdown detection mechanism, whereby when any websocket closes, it waits `shutdown_delay` seconds, and then checks if there are now any websocket connections. If not, then Eel closes. In case the user has closed the browser and wants to exit the program. By default, the value of **shutdown_delay** is `1.0` second
111+
- **app**, an instance of Bottle which will be used rather than creating a fresh one. This can be used to install middleware on the instance before starting ~~eel~~ paling, e.g. for session management, authentication, etc. If your `app` is not a Bottle instance, you will need to call `paling.register_paling_routes(app)` on your custom app instance.
112+
- **shutdown_delay**, timer configurable for ~~Eel~~ Paling's shutdown detection mechanism, whereby when any websocket closes, it waits `shutdown_delay` seconds, and then checks if there are now any websocket connections. If not, then ~~Eel~~ Paling closes. In case the user has closed the browser and wants to exit the program. By default, the value of **shutdown_delay** is `1.0` second
117113

118114

119115

@@ -125,7 +121,7 @@ In addition to the files in the frontend folder, a Javascript library will be se
125121
<script type="text/javascript" src="/paling.js"></script>
126122
```
127123

128-
Including this library creates an `eel` object which can be used to communicate with the Python side.
124+
Including this library creates an `paling` object which can be used to communicate with the Python side.
129125

130126
Any functions in the Python code which are decorated with `@paling.expose` like this...
131127

@@ -135,7 +131,7 @@ def my_python_function(a, b):
135131
print(a, b, a + b)
136132
```
137133

138-
...will appear as methods on the `eel` object on the Javascript side, like this...
134+
...will appear as methods on the `paling` object on the Javascript side, like this...
139135

140136
```javascript
141137
console.log("Calling Python...");
@@ -168,9 +164,9 @@ paling.expose(someFunction, "my_javascript_function");
168164

169165
When passing complex objects as arguments, bear in mind that internally they are converted to JSON and sent down a websocket (a process that potentially loses information).
170166

171-
### Eello, World!
167+
### Hello, World!
172168

173-
> See full example in: [examples/01 - hello_world](https://github.com/ChrisKnott/Eel/tree/master/examples/01%20-%20hello_world)
169+
> See full example in: [examples/01 - hello_world](https://github.com/python-paling/Paling/tree/master/examples/01%20-%20hello_world)
174170
175171
Putting this together into a **Hello, World!** example, we have a short HTML page, `web/hello.html`:
176172

@@ -202,7 +198,7 @@ Putting this together into a **Hello, World!** example, we have a short HTML pag
202198
and a short Python script `hello.py`:
203199

204200
```python
205-
import eel
201+
import paling
206202

207203
# Set web files folder and optionally specify which file types to check for paling.expose()
208204
# *Default allowed_extensions are: ['.js', '.html', '.txt', '.htm', '.xhtml']
@@ -240,7 +236,7 @@ You will notice that in the Python code, the Javascript function is called befor
240236

241237
While we want to think of our code as comprising a single application, the Python interpreter and the browser window run in separate processes. This can make communicating back and forth between them a bit of a mess, especially if we always had to explicitly _send_ values from one side to the other.
242238

243-
Eel supports two ways of retrieving _return values_ from the other side of the app, which helps keep the code concise.
239+
~~Eel~~ Paling supports two ways of retrieving _return values_ from the other side of the app, which helps keep the code concise.
244240

245241
To prevent hanging forever on the Python side, a timeout has been put in place for trying to retrieve values from
246242
the JavaScript side, which defaults to 10000 milliseconds (10 seconds). This can be changed with the `_js_result_timeout` parameter to `paling.init`. There is no corresponding timeout on the JavaScript side.
@@ -301,14 +297,14 @@ run();
301297

302298
## Asynchronous Python
303299

304-
Eel is built on Bottle and Gevent, which provide an asynchronous event loop similar to Javascript. A lot of Python's standard library implicitly assumes there is a single execution thread - to deal with this, Gevent can "[monkey patch](https://en.wikipedia.org/wiki/Monkey_patch)" many of the standard modules such as `time`. ~~This monkey patching is done automatically when you call `import eel`~~. If you need monkey patching you should `import gevent.monkey` and call `gevent.monkey.patch_all()` _before_ you `import eel`. Monkey patching can interfere with things like debuggers so should be avoided unless necessary.
300+
~~Eel~~ Paling is built on Bottle and Gevent, which provide an asynchronous event loop similar to Javascript. A lot of Python's standard library implicitly assumes there is a single execution thread - to deal with this, Gevent can "[monkey patch](https://en.wikipedia.org/wiki/Monkey_patch)" many of the standard modules such as `time`. ~~This monkey patching is done automatically when you call `import eel`~~. If you need monkey patching you should `import gevent.monkey` and call `gevent.monkey.patch_all()` _before_ you `import paling`. Monkey patching can interfere with things like debuggers so should be avoided unless necessary.
305301

306-
For most cases you should be fine by avoiding using `time.sleep()` and instead using the versions provided by `gevent`. For convenience, the two most commonly needed gevent methods, `sleep()` and `spawn()` are provided directly from Eel (to save importing `time` and/or `gevent` as well).
302+
For most cases you should be fine by avoiding using `time.sleep()` and instead using the versions provided by `gevent`. For convenience, the two most commonly needed gevent methods, `sleep()` and `spawn()` are provided directly from ~~Eel~~ Paling (to save importing `time` and/or `gevent` as well).
307303

308304
In this example...
309305

310306
```python
311-
import eel
307+
import paling
312308
paling.init('web')
313309

314310
def my_other_thread():
@@ -327,7 +323,7 @@ while True:
327323

328324
...we would then have three "threads" (greenlets) running;
329325

330-
1. Eel's internal thread for serving the web folder
326+
1. ~~Eel~~ Paling's internal thread for serving the web folder
331327
2. The `my_other_thread` method, repeatedly printing **"I'm a thread"**
332328
3. The main Python thread, which would be stuck in the final `while` loop, repeatedly printing **"I'm a main loop"**
333329

@@ -337,9 +333,9 @@ If you want to package your app into a program that can be run on a computer wit
337333

338334
1. Configure a virtualenv with desired Python version and minimum necessary Python packages
339335
2. Install PyInstaller `pip install PyInstaller`
340-
3. In your app's folder, run `python -m eel [your_main_script] [your_web_folder]` (for example, you might run `python -m eel hello.py web`)
336+
3. In your app's folder, run `python -m paling [your_main_script] [your_web_folder]` (for example, you might run `python -m paling hello.py web`)
341337
4. This will create a new folder `dist/`
342-
5. Valid PyInstaller flags can be passed through, such as excluding modules with the flag: `--exclude module_name`. For example, you might run `python -m eel file_access.py web --exclude win32com --exclude numpy --exclude cryptography`
338+
5. Valid PyInstaller flags can be passed through, such as excluding modules with the flag: `--exclude module_name`. For example, you might run `python -m paling file_access.py web --exclude win32com --exclude numpy --exclude cryptography`
343339
6. When happy that your app is working correctly, add `--onefile --noconsole` flags to build a single executable file
344340

345341
Consult the [documentation for PyInstaller](http://PyInstaller.readthedocs.io/en/stable/) for more options.
@@ -348,5 +344,5 @@ Consult the [documentation for PyInstaller](http://PyInstaller.readthedocs.io/en
348344

349345
For Windows 10 users, Microsoft Edge (`paling.start(.., mode='edge')`) is installed by default and a useful fallback if a preferred browser is not installed. See the examples:
350346

351-
- A Hello World example using Microsoft Edge: [examples/01 - hello_world-Edge/](https://github.com/ChrisKnott/Eel/tree/master/examples/01%20-%20hello_world-Edge)
352-
- Example implementing browser-fallbacks: [examples/07 - CreateReactApp/eel_CRA.py](https://github.com/ChrisKnott/Eel/tree/master/examples/07%20-%20CreateReactApp/eel_CRA.py)
347+
- A Hello World example using Microsoft Edge: [examples/01 - hello_world-Edge/](https://github.com/python-paling/Paling/tree/master/examples/01%20-%20hello_world-Edge)
348+
- Example implementing browser-fallbacks: [examples/07 - CreateReactApp/paling_CRA.py](https://github.com/python-paling/Paling/tree/master/examples/07%20-%20CreateReactApp/paling_CRA.py)

0 commit comments

Comments
 (0)