Brython web app embedded in electron desktop app?

379 views
Skip to first unread message

André

unread,
Dec 3, 2017, 11:32:01 AM12/3/17
to brython
Hello everyone,

Has anybody ever used Electron (https://electronjs.org/) to create a desktop version of a web app that uses Brython?  If so, can you describe how you did it, and if there was any particular issue to pay attention to?

The reason I am asking is that someone has asked if my app (http://reeborg.ca/reeborg.html) could be made to work on individual students' computers as they apparently cannot rely not only on Internet access (for accessing my public site), but also not on the internal network, for which I had created a special version (https://github.com/aroberge/reeborg-dist). The best potential solution I could think of was to create a desktop app using Electron - but I have no experience with it (yet).

Feel free to comment on this list (obviously) or on an issue I created on this topic on my project's repository (https://github.com/aroberge/reeborg/issues/391).  [If you are just interested in following any development of this for my project, feel free to comment on that issue so that Github can alert you of any update.]

Cheers,

André

Joao S. O. Bueno

unread,
Dec 3, 2017, 12:36:41 PM12/3/17
to bry...@googlegroups.com
I never tried it, but I alaways assumed things liek this should "just
work". Can you give it a try and tell us the results?
> --
> You received this message because you are subscribed to the Google Groups
> "brython" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to brython+u...@googlegroups.com.
> To post to this group, send email to bry...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/brython/57ef96a1-bfc3-4eda-8e1b-a1be1f16da1b%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Olemis Lang

unread,
Dec 3, 2017, 12:57:58 PM12/3/17
to bry...@googlegroups.com
Hello André

On 12/3/17, André <andre....@gmail.com> wrote:
> Hello everyone,
>
> Has anybody ever used Electron (https://electronjs.org/) to create a
> desktop version of a web app that uses Brython? If so, can you describe
> how you did it, and if there was any particular issue to pay attention to?
>
> The reason I am asking is that someone has asked if my app
> (http://reeborg.ca/reeborg.html) could be made to work on individual
> students' computers
>
[...]

Ideally it should be possible to run the same (Python) code in both
Brython and CPython , and Jython , and ... this was one of the reasons
why I liked PyBee approach . Code should be mostly the same , Batavia
(and other project I do not recall the name of now) adjusts the
details to run that code on browsers (js) , others do the same for
Java, Android , iOS, and other environments . But still code is
written once and ported across environments .

That's the way I see it useful . Brython is quite focused on the
browser , so maybe part of (or everything) I said is off topic . Feel
free to fork the conversation in that case .

--
Regards,

Olemis - @olemislc

Apache™ Bloodhound contributor
http://issues.apache.org/bloodhound
http://blood-hound.net

Brython committer
http://brython.info
http://github.com/brython-dev/brython

SciPy Latin America - Cuban Ambassador

Blog ES: http://simelo-es.blogspot.com/
Blog EN: http://simelo-en.blogspot.com/

Featured article:

Olemis Lang

unread,
Dec 3, 2017, 1:26:40 PM12/3/17
to bry...@googlegroups.com
On 12/3/17, Olemis Lang <ole...@gmail.com> wrote:
>
[...]
>
> On 12/3/17, André <andre....@gmail.com> wrote:
>>
[...]
>>
>> The reason I am asking is that someone has asked if my app
>> (http://reeborg.ca/reeborg.html) could be made to work on individual
>> students' computers
>>
> [...]
>
> Ideally it should be possible to run the same (Python) code in both
> Brython and CPython , and Jython , and ... this was one of the reasons
> why I liked PyBee approach . Code should be mostly the same , Batavia
> (and other project I do not recall the name of now) adjusts the
> details to run that code on browsers (js) , others do the same for
> Java, Android , iOS, and other environments . But still code is
> written once and ported across environments .
>

If I recall correctly project name is Toga [1]_

.. [1] https://pybee.org/toga/

[...]

Andre Roberge

unread,
Dec 3, 2017, 3:01:48 PM12/3/17
to bry...@googlegroups.com
On Sun, Dec 3, 2017 at 1:36 PM, Joao S. O. Bueno <gwi...@gmail.com> wrote:
I never tried it, but I alaways assumed things liek this should "just
work". Can you give it a try and tell us the results?


I intend to ... but I have a few other things to work on first. I will make sure to post a follow-up when I try.

André

 
On 3 December 2017 at 14:32, André <andre....@gmail.com> wrote:
> Hello everyone,
>
> Has anybody ever used Electron (https://electronjs.org/) to create a desktop
> version of a web app that uses Brython?  If so, can you describe how you did
> it, and if there was any particular issue to pay attention to?
>
> The reason I am asking is that someone has asked if my app
> (http://reeborg.ca/reeborg.html) could be made to work on individual
> students' computers as they apparently cannot rely not only on Internet
> access (for accessing my public site), but also not on the internal network,
> for which I had created a special version
> (https://github.com/aroberge/reeborg-dist). The best potential solution I
> could think of was to create a desktop app using Electron - but I have no
> experience with it (yet).
>
> Feel free to comment on this list (obviously) or on an issue I created on
> this topic on my project's repository
> (https://github.com/aroberge/reeborg/issues/391).  [If you are just
> interested in following any development of this for my project, feel free to
> comment on that issue so that Github can alert you of any update.]
>
> Cheers,
>
> André
>
> --
> You received this message because you are subscribed to the Google Groups
> "brython" group.
> To unsubscribe from this group and stop receiving emails from it, send an

> To post to this group, send email to bry...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/brython/57ef96a1-bfc3-4eda-8e1b-a1be1f16da1b%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "brython" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/brython/0HE7DkqS4pg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to brython+unsubscribe@googlegroups.com.

To post to this group, send email to bry...@googlegroups.com.

Andre Roberge

unread,
Dec 3, 2017, 3:07:45 PM12/3/17
to bry...@googlegroups.com


On Sun, Dec 3, 2017 at 1:57 PM, Olemis Lang <ole...@gmail.com> wrote:
Hello André

Hello Olemis,
 

[...]

Ideally it should be possible to run the same (Python) code in both
Brython and CPython , and Jython , and ... this was one of the reasons
why I liked PyBee approach . Code should be mostly the same , Batavia
(and other project I do not recall the name of now) adjusts the
details to run that code on browsers (js) , others do the same for
Java, Android , iOS, and other environments . But still code is
written once and ported across environments .

That's the way I see it useful . Brython is quite focused on the
browser , so maybe part of (or everything) I said is off topic . Feel
free to fork the conversation in that case .


My app is about 95 % Javascript (over 17,000 lines of code, not including tests, mostly written by myself), and makes use of external libraries such as jQuery and jQueryUI.  Brython plays a crucial part, but I use it mostly to execute Python code entered by the users. 

So, most unfortunately, I need to look outside of the Python world to turn it into a desktop app.

Thanks for the thought,

André
 

--
Regards,

Olemis - @olemislc

Apache™ Bloodhound contributor
http://issues.apache.org/bloodhound
http://blood-hound.net

Brython committer
http://brython.info
http://github.com/brython-dev/brython

SciPy Latin America - Cuban Ambassador

Blog ES: http://simelo-es.blogspot.com/
Blog EN: http://simelo-en.blogspot.com/

Featured article:
--
You received this message because you are subscribed to a topic in the Google Groups "brython" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/brython/0HE7DkqS4pg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to brython+unsubscribe@googlegroups.com.
To post to this group, send email to bry...@googlegroups.com.

Olemis Lang

unread,
Dec 3, 2017, 4:15:49 PM12/3/17
to brython
On Sun, Dec 3, 2017 at 3:07 PM, Andre Roberge <andre....@gmail.com> wrote:


On Sun, Dec 3, 2017 at 1:57 PM, Olemis Lang <ole...@gmail.com> wrote:
[...] 
 
Ideally it should be possible to run the same (Python) code in both
Brython and CPython , and Jython , and ...
[...] 

My app is about 95 % Javascript (over 17,000 lines of code, not including tests, mostly written by myself), and makes use of external libraries such as jQuery and jQueryUI.  Brython plays a crucial part, but I use it mostly to execute Python code entered by the users. 

So, most unfortunately, I need to look outside of the Python world to turn it into a desktop app.


[...] 

Understood . It is not clear to me how is it that electron.js works. If it depends on node.js , the challenge then would be to run Brython on top of it . I've never tried to do so but e.g. if .py files are stored in the file system the the js APIs should be different and I am not sure of whether the import machinery will work.

André , if try to do so please let us know of the results of your research .

Kiko

unread,
Dec 4, 2017, 12:58:19 PM12/4/17
to bry...@googlegroups.com
Other option:

PyQt5/PySide2.

I've tested the following simple code and it works:

Files brython.js, index.html and main.py should be on the same folder.

File brython.js is already known.

File index.html is a dummy example:
<!DOCTYPE html>
<html><head>
<meta name="description" content="Brython">
<meta name="keywords" content="Python,Brython">
<meta name="author" content="Pierre Quentel">
<meta http-equiv="content-type" content="text/html; charset=windows-1252">

<noscript>Please enable Javascript to view this page correctly.</noscript>
<script type="text/javascript" src="brython.js"></script>

<script type="text/python3">
from browser import alert, document

def fn(ev):
    alert("Hola mundo")
   
document["btn"].bind("click", fn)
</script>

<body onload="brython({debug:1, cache:'none'})">
  <div id="content">
    <button id="btn">click!!</button>
  </div>
</body>
</html>

 
File main.py is a Qt Application that uses a QWebView and contains:
import sys
import os

from PyQt5.QtWidgets import (
    QMainWindow,
    QApplication,
    QVBoxLayout,
    QWidget
)
from PyQt5.QtCore import QUrl
from PyQt5.QtWebKitWidgets import QWebView

class Window(QWebView):
    def __init__(self):
        super().__init__()
        self._setup()
       
    def _setup(self):
        # setup main window
        self.setGeometry(100, 100, 600, 400)
        self.setWindowTitle('Hola mundo')
        # show main window
        self.show()
       
        # Layout
        main_layout = QVBoxLayout()
        webv = QWebView()
        localpath = os.path.dirname(os.path.abspath(__file__))
        url = os.path.join(localpath, "index.html")
        webv.load(QUrl.fromLocalFile(url))
        main_layout.addWidget(webv)
        self.setLayout(main_layout)

if __name__ == "__main__":
    app = QApplication(sys.argv)
    w = Window()
    sys.exit(app.exec_())


I hope it helps.

--
You received this message because you are subscribed to the Google Groups "brython" group.
To unsubscribe from this group and stop receiving emails from it, send an email to brython+unsubscribe@googlegroups.com.

To post to this group, send email to bry...@googlegroups.com.

André

unread,
Dec 4, 2017, 4:03:50 PM12/4/17
to brython
Hi Kiko,

Thanks for the suggestion. As I have indicated elsewhere, in addition to Python code, my app contains more than 17,000 lines of Javascript code (and uses third-party libraries including jquery and jqueryUI) - so a pure Python solution is unlikely to be the answer.

André
 

--
You received this message because you are subscribed to the Google Groups "brython" group.
To unsubscribe from this group and stop receiving emails from it, send an email to brython+u...@googlegroups.com.

Kiko

unread,
Dec 4, 2017, 4:10:56 PM12/4/17
to bry...@googlegroups.com
If all the code is frontend I think the solution will be something similar using PyQt to open chrome to run the JS or open electron to open chrome to run JS. 

But I'm very far from my confort zone so maybe I'm just saying something really stupid o_O
 

André
 

--
You received this message because you are subscribed to the Google Groups "brython" group.
To unsubscribe from this group and stop receiving emails from it, send an email to brython+u...@googlegroups.com.
To post to this group, send email to bry...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/brython/57ef96a1-bfc3-4eda-8e1b-a1be1f16da1b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "brython" group.
To unsubscribe from this group and stop receiving emails from it, send an email to brython+unsubscribe@googlegroups.com.

To post to this group, send email to bry...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/brython/dec65b90-cd85-472e-9987-13d5efd3277c%40googlegroups.com.

Christophe BAL (via GMAIL)

unread,
Dec 4, 2017, 4:31:55 PM12/4/17
to bry...@googlegroups.com

Indeed if a server can work loccally using Python why don't you use a browser.

Jupyter does that so why Reeeborg can't do that also.

The main problem to solve is to produce a version of Reeborg that don't need internet to work, but this seems to have been done.

The minor problem is to give a click-to-launch script but this should be very easy to do.


Le 04/12/2017 à 22:10, Kiko a écrit :


El lunes, 4 de diciembre de 2017, André <andre....@gmail.com> escribió:


On Monday, 4 December 2017 13:58:19 UTC-4, kiko (on pybonacci) wrote:
2017-12-03 17:32 GMT+01:00 André <andre....@gmail.com>:
Hello everyone,

Has anybody ever used Electron (https://electronjs.org/) to create a desktop version of a web app that uses Brython?  If so, can you describe how you did it, and if there was any particular issue to pay attention to?

The reason I am asking is that someone has asked if my app (http://reeborg.ca/reeborg.html) could be made to work on individual students' computers as they apparently cannot rely not only on Internet access (for accessing my public site), but also not on the internal network, for which I had created a special version (https://github.com/aroberge/reeborg-dist). The best potential solution I could think of was to create a desktop app using Electron - but I have no experience with it (yet).

Feel free to comment on this list (obviously) or on an issue I created on this topic on my project's repository (https://github.com/aroberge/reeborg/issues/391).  [If you are just interested in following any development of this for my project, feel free to comment on that issue so that Github can alert you of any update.]

Cheers,

André

Other option:

PyQt5/PySide2.

I've tested the following simple code and it works:

Files brython.js, index.html and main.py should be on the same folder.

File brython.js is already known.

File index.html is a dummy example:
<!DOCTYPE html>
<html><head>
<meta name="description" content="Brython">
<meta name="keywords" content="Python,Brython">
<meta name="author" content="Pierre Quentel">
<meta http-equiv="content-type" content="text/html; enable Javascript to view this page correctly.</noscript>

For more options, visit https://groups.google.com/d/optout.

-- 
Christophe BAL
Enseignant Agrégé de Mathématiques
Programmeur Python Amateur

Andre Roberge

unread,
Dec 4, 2017, 5:45:15 PM12/4/17
to bry...@googlegroups.com
On Mon, Dec 4, 2017 at 5:31 PM, Christophe BAL (via GMAIL) <proj...@gmail.com> wrote:

Indeed if a server can work loccally using Python why don't you use a browser.

Jupyter does that so why Reeeborg can't do that also.

The main problem to solve is to produce a version of Reeborg that don't need internet to work, but this seems to have been done.

Yes, of course. 

The minor problem is to give a click-to-launch script but this should be very easy to do.

I know since you already shared your version with me! :-)
 

The person that asked me is aware of the version using a local webserver ... but the school (lycée) network administrator apparently does not want to have any kind of local web server installed on the students' computers.  And the school network is apparently not reliable enough to trust a version implemented on a local server. Hence the request for creating a desktop version of Reeborg's World...

André

Christophe BAL (via GMAIL)

unread,
Dec 4, 2017, 5:59:43 PM12/4/17
to bry...@googlegroups.com

In that case, Electron should be your "only" friend.

--
You received this message because you are subscribed to the Google Groups "brython" group.
To unsubscribe from this group and stop receiving emails from it, send an email to brython+u...@googlegroups.com.
To post to this group, send email to bry...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages