Skip to content

Commit

Permalink
Merge pull request #8 from modularizer/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
modularizer authored Nov 6, 2022
2 parents 7f78b45 + 8970972 commit 8b92543
Show file tree
Hide file tree
Showing 19 changed files with 1,269 additions and 74 deletions.
27 changes: 25 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,16 @@ Run **client-side python** in your browser to **prez**ent your code.
- [About](#about)
- [Getting Started](#getting-started)
- [Use Cases](#use-cases)
- [Limitations](#limitations)
- [Limitations](#limitations)
- [Micropip](#micropip)
- [Tags](#pyprez-tags): [`<pyprez-editor>`](#pyprez-editor) , [`<pyprez-console>`](#pyprez-console), [`<pyprez-import>`](#pyprez-import), [`<pyprez-script>`](#pyprez-script)
- [Custom Themes](#codemirror-themes)
- [Feature Development](#feature-development)
- [namespaces](#namespaces)
- [input](#input)
- [matplotlib](#matplotlib)
- [linting](#linting)
- [Keyboard Shortcuts](#keyboard-shortcuts)
- [API](#pyprez-api)
- [Pyodide](#pyodide)
- [PyScript](#pyscript)
Expand All @@ -58,7 +61,7 @@ Run **client-side python** in your browser to **prez**ent your code.


## Method 1
Using any `<prprez-editor>` element (such as the one [here](https://modularizer.github.io/pyprez/samples/stackconverter.html)) to modify your code, then click `</>` button on the top bar to convert your python
Using any `<prprez-editor>` element (such as the one [here](https://modularizer.github.io/pyprez/samples/stackconverter.html)) to modify your code, then click `M↓` button on the top bar to convert your python
into markdown which can be pasted into your StackOverflow answer to create a **runnable and editable snippet**.

**The Question/Answer Editor will look something like this**
Expand Down Expand Up @@ -188,6 +191,9 @@ Some such limitations are:
* cannot access the local file system ( but can still read and write temporary files in webassembly)
* `__builtins__.input` is tricky. Currently it works with the fully blocking `window.prompt` function

# Micropip
The `micropip` object from pyodide is available at `window.pyodide`. Furthermore, `<pyprez-editor>` will autorecognize
comments like `# micropip install package_name` and call `micropip.install('package_name')`before running your code.

# Pyprez Tags
## Pyprez-Editor
Expand Down Expand Up @@ -376,6 +382,23 @@ Making it interactive would be tough (but not impossible). Bokeh and Plotly are
<img src="./sample_imgs/input-plot.png" />
</a>


## Linting
### autopep8
`Ctrl+k` can be used to auto-format code to pep8 standards. `Ctrl+Z` will undo.


# Keyboard Shortcuts
custom:
* `Ctrl + k`: autopep8.fix_file
* `Shift + Enter`: run code
* `Shift + Backspace`: reset code

builtin to codemirror:
* `Ctrl + z`
* `Ctrl + a`
* `Ctrl + c`

# Pyprez API
## elements
Any html elements created by the pyprez custom tags get added to `pyprez.elements` object for easy retrieval.
Expand Down
File renamed without changes.
26 changes: 26 additions & 0 deletions dev/md.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from markdown2 import Markdown

import os
os.chdir('..')

with open("README.md") as f:
mdt = f.read()

markdown = Markdown()
mdh = markdown.convert(mdt)
h = f"""
<!DOCTYPE html>
<html lang="en">
<head>
<title>PyPrez</title>
<link rel="icon" type="image/x-icon" href="../favicon.ico">
</head>
<body>
<div style="margin-left:8%;margin-right:8%;margin-top:3%;padding:5%;background-color:rgb(253, 253, 253);">
{mdh}
</div>
</body>
</html>
"""
with open("../README.html", 'w') as f:
f.write(h)
20 changes: 19 additions & 1 deletion server.py → dev/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,31 @@
"""
import asyncio
import sys
import os

import tornado.web
import tornado.ioloop

os.chdir(os.path.dirname(os.path.dirname(__file__)))
print(os.getcwd())


class RedirectHandler(tornado.web.RequestHandler):
"""main handler for requests to the base url"""
def initialize(self, homepage) -> None:
"""function which initializes the handler and sets the homepage"""
self.homepage = homepage

def get(self):
"""redirects the landing page to the home page"""
self.redirect(self.homepage)


if __name__ == "__main__":
app = tornado.web.Application([(r"/(.*)", tornado.web.StaticFileHandler, {"path": "."})])
app = tornado.web.Application([
(r"/", RedirectHandler, {"homepage": "/index.html"}),
(r"/(.*)", tornado.web.StaticFileHandler, {"path": "./site"})
])

if sys.platform == 'win32':
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
Expand Down
File renamed without changes.
Binary file added logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 8b92543

Please sign in to comment.