A place to see the demo and gallary code in working order?

88 views
Skip to first unread message

Brian

unread,
Apr 17, 2018, 9:39:17 PM4/17/18
to brython
Is there a place where newbs can see the code from brython.info in working order?  

Sure, I know that you can "view source" for the pages, but there's so much cruft (Other html for the page) around it that it's nearly incomprehensible, and the demo code is shown sans html, so it's not very useful...  Has anyone thought to compile this stuff in a useful-to-newbs way, or maybe a zip file?

Jonathan Verner

unread,
Apr 19, 2018, 5:40:24 AM4/19/18
to brython
So far I don't think anything like this is available :-(

Pierre Quentel

unread,
Apr 19, 2018, 7:40:01 AM4/19/18
to brython


Le mercredi 18 avril 2018 03:39:17 UTC+2, Brian a écrit :
Is there a place where newbs can see the code from brython.info in working order?  

Sure, I know that you can "view source" for the pages, but there's so much cruft (Other html for the page) around it that it's nearly incomprehensible, and the demo code is shown sans html, so it's not very useful...  Has anyone thought to compile this stuff in a useful-to-newbs way, or maybe a zip file?

I'm not sure to understand what you would like : if it's complete pages with html and Python code, the source code of the gallery examples should be ok - what exactly do you mean by "cruft" there ?

 

Brian

unread,
Apr 19, 2018, 4:23:30 PM4/19/18
to brython
 As said:  " (Other html for the page)".  

Brian

unread,
Apr 19, 2018, 4:26:01 PM4/19/18
to brython
UPDATE:  For some reason (Why?), the brython.info page doesn't actually present runnable-demo code for the newbs.  BUT, that code is available, it's just hidden: https://github.com/brython-dev/brython/tree/master/www/gallery

Why these files aren't available on brython.info is a mystery, it makes getting started much harder.

Brian

unread,
Apr 19, 2018, 4:26:31 PM4/19/18
to brython
Turns out, it is but it's hidden at https://github.com/brython-dev/brython/tree/master/www/gallery
Sad, but true.

André

unread,
Apr 19, 2018, 8:00:06 PM4/19/18
to brython


On Thursday, 19 April 2018 17:26:31 UTC-3, Brian wrote:
Turns out, it is but it's hidden at https://github.com/brython-dev/brython/tree/master/www/gallery
Sad, but true.



They are definitely NOT hidden.

Brian

unread,
Apr 19, 2018, 8:35:56 PM4/19/18
to brython
If by "definitely NOT hidden" you mean "oh, it's not actually visible unless the newb (Who is unlikely to think of it) thinks to do a "view source" for the page", then sure.
Because the page certainly does NOT display the html + code that a newb would require to make it work, nor does it describe how (s)he should go about getting it.

Btw, the lang=en flag with the gallery_fr.html does nothing. If you want to cite the english version, you need to cite gallery_en.html. 

Pierre Quentel

unread,
Apr 20, 2018, 3:24:38 AM4/20/18
to brython

This other html is not "cruft" (not being an English native speaker I had to watch the definition:  "software or hardware that doesn't work properly because it's badly written or badly put together"), it's necessary to make the code work.

Do you think that adding a paragraph on gallery_en.html explaining how to view the source code would be useful ?

Brian

unread,
Apr 20, 2018, 4:32:03 PM4/20/18
to brython
First, "cruft" also means that which is not useful, or distracting.  In the case of many of the examples they also contain the html for additional web page features, such as menus and other links.  Expecting a newb (Or heck, even an experienced developer!) to sort through hundreds of extra lines of html to figure out how to replicate the example is unrealistic.

For example, check out http://www.brython.info/gallery/turtle.html . The first example consists of 28 lines of code, spaces included.  And, what will the newb get with those 28 lines?  Disappointment, followed quickly by annoyance, because those 28 lines won't actually work for him/her.  Then, some research on the web might (Eventually!) yield the sage advice of viewing the page source.  Following that, our hapless newb gets to see over 1200 lines of brython & html!!!  

In truth, this example takes about 40 lines of brython and html to run.  Why not list that instead of the 28 lines of useless code?  (This is a poor example for several reasons, but a lot of the example code rely upon buttons or ether page elements to run.)   I suggest that EVERY example page should include a full html and brython listing. 

What do you think?

jlaurens

unread,
Jun 29, 2018, 4:07:13 AM6/29/18
to brython
Below is the demo code for the turtle. Put `brython.js`  and `brython_stdlib.js` next to this file and serve the folder.

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<script type="text/javascript" src="brython.js"></script>
<script type="text/javascript" src="brython_stdlib.js"></script>
<script id="python_script" type="text/python">
from browser
import document

def run_code
(ev):
 _code
= document["source"].text
 
try:
 exec
(_code)
 except
:
 print
('Failed')

document
["run"].bind("click", run_code)
</script>
</head>
<body onload="brython(1)">
<h1>Turtle demo</h1>
<p>Be patient, loading turtle module takes some time (15 s).</p>
<button id="run" class="btn-enabled">Run</button>
<pre id="source">import turtle
turtle.set_defaults(
 turtle_canvas_wrapper = document['turtle-div'],
 canvwidth = 200,
 canvheight = 200
)
t = turtle.Turtle()
t.width(5)
for c in ['red', '#00ff00', '#fa0', 'rgb(0,0,200)']:
 t.color(c)
 t.forward(50)
 t.left(90)
turtle.done()
</pre>
<div id="turtle-div" style="width:200px;height:200px;border:1px solid;"> </div>
</body>
</html>


jlaurens

unread,
Jun 29, 2018, 4:13:07 AM6/29/18
to brython
Of course you can run the file locally
Reply all
Reply to author
Forward
0 new messages