Skip to content

Commit e8160a9

Browse files
authored
Merge pull request #1 from rmorshea/initial-work
Initial Work
2 parents 2b543d4 + cdb1fbc commit e8160a9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+13503
-1
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2019 Ryan S. Morshead
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 111 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,113 @@
11
# iDOM
22

3-
Coming soon...
3+
Libraries for defining and controlling interactive webpages with Python 3.6 and above.
4+
5+
* [Python Documentation](https://github.com/rmorshea/idom/blob/master/idom/py/README.md)
6+
* [Javascript Documentation](https://github.com/rmorshea/idom/blob/master/idom/js/README.md)
7+
8+
9+
## Early Days
10+
11+
iDOM is still young. If you have ideas or find a bug, be sure to post an
12+
[issue](https://github.com/rmorshea/idom/issues)
13+
or create a
14+
[pull request](https://github.com/rmorshea/idom/pulls). Thanks in advance!
15+
16+
17+
## At a Glance
18+
19+
iDOM can be used to create a simple slideshow which changes whenever a user clicks an image.
20+
21+
```python
22+
import idom
23+
24+
@idom.element
25+
async def slideshow(self, index=0):
26+
events = idom.Events()
27+
28+
@events.on("click")
29+
def change():
30+
self.update(index + 1)
31+
32+
url = f"https://picsum.photos/800/300?image={index}"
33+
return idom.node("img", src=url, eventHandlers=events)
34+
35+
idom.SimpleWebServer(slideshow).daemon("localhost", 8765).join()
36+
```
37+
38+
Running this will serve our slideshow to `"https://localhost:8765/idom/client/index.html"`
39+
40+
<img src='https://picsum.photos/800/300?random'/>
41+
42+
You could even display the same thing in a Jupyter notebook!
43+
44+
```python
45+
idom.display("jupyter", "https://localhost:8765/idom/stream")
46+
```
47+
48+
Every click will then cause the image to change (it won't here of course).
49+
50+
51+
## Breaking it Down
52+
53+
That might have been a bit much to throw out at once. Let's break down each piece of the
54+
example above:
55+
56+
```python
57+
@idom.element
58+
async def slideshow(self, index=0):
59+
```
60+
61+
The decorator indicates that the function or coroutine to follow defines an update-able
62+
element. The `slideshow` coroutine is responsible for building a DOM model, and every
63+
time an update is triggered, it will be called with new parameters to recreate the model.
64+
65+
```python
66+
events = idom.Events()
67+
```
68+
69+
Creates an object to which event handlers will be assigned. Adding `events` to a DOM
70+
model will given you the ability to respond to events that may be triggered when users
71+
interact with the image. Under the hood though, `events` is just a mapping which
72+
conforms to the
73+
[VDOM event specification](https://github.com/nteract/vdom/blob/master/docs/event-spec.md).
74+
75+
```python
76+
@events.on("click")
77+
def change():
78+
self.update(index + 1)
79+
```
80+
81+
By using the `idom.Events()` object we created above, we can register a function as an
82+
event handler. This handler will be called once a user clicks on the image. All supported
83+
events are listed [here](https://reactjs.org/docs/events.html).
84+
85+
You can add parameters to this handler which will allow you to access attributes of the
86+
JavaScript event which occurred in the browser. For example when a key is pressed in
87+
an `<input/>` element you can access the key's name by adding a `key` parameter to
88+
the event handler.
89+
90+
Inside the handler itself we update `self` which is out `slideshow` element. Calling
91+
`self.update(*args, **kwargs)` will schedule a new render of the `slideshow` element to
92+
be performed with new `*args` and `**kwargs`.
93+
94+
```python
95+
url = f"https://picsum.photos/800/300?image={index}"
96+
return idom.node("img", src=url, eventHandlers=events)
97+
```
98+
99+
We return a model for an `<img/>` element which draws its image from https://picsum.photos
100+
and will respond to the `events` we defined earlier. Similarly to the `events` object
101+
`idom.node` returns a mapping which conforms to the
102+
[VDOM mimetype specification](https://github.com/nteract/vdom/blob/master/docs/mimetype-spec.md)
103+
104+
105+
```python
106+
idom.SimpleWebServer(slideshow).daemon("localhost", 8765).join()
107+
```
108+
109+
This sets up a simple web server which will display the layout of elements and update
110+
them when events occur over a websocket. To display the layout we can navigate to
111+
http://localhost:8765/idom/client/index.html or use `idom.display()` to show it
112+
in a Jupyter Notebook via a widget. The exact protocol for communicating DOM models
113+
over a network is not documented yet.

docs/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build

docs/Makefile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line.
5+
SPHINXOPTS =
6+
SPHINXBUILD = sphinx-build
7+
SOURCEDIR = source
8+
BUILDDIR = build
9+
10+
# Put it first so that "make" without argument is like "make help".
11+
help:
12+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
13+
14+
.PHONY: help Makefile
15+
16+
# Catch-all target: route all unknown targets to Sphinx using the new
17+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
18+
%: Makefile
19+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

docs/make.bat

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
@ECHO OFF
2+
3+
pushd %~dp0
4+
5+
REM Command file for Sphinx documentation
6+
7+
if "%SPHINXBUILD%" == "" (
8+
set SPHINXBUILD=sphinx-build
9+
)
10+
set SOURCEDIR=source
11+
set BUILDDIR=build
12+
13+
if "%1" == "" goto help
14+
15+
%SPHINXBUILD% >NUL 2>NUL
16+
if errorlevel 9009 (
17+
echo.
18+
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
19+
echo.installed, then set the SPHINXBUILD environment variable to point
20+
echo.to the full path of the 'sphinx-build' executable. Alternatively you
21+
echo.may add the Sphinx directory to PATH.
22+
echo.
23+
echo.If you don't have Sphinx installed, grab it from
24+
echo.http://sphinx-doc.org/
25+
exit /b 1
26+
)
27+
28+
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%
29+
goto end
30+
31+
:help
32+
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%
33+
34+
:end
35+
popd

docs/source/conf.py

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# Configuration file for the Sphinx documentation builder.
4+
#
5+
# This file does only contain a selection of the most common options. For a
6+
# full list see the documentation:
7+
# http://www.sphinx-doc.org/en/master/config
8+
9+
# -- Path setup --------------------------------------------------------------
10+
11+
# If extensions (or modules to document with autodoc) are in another directory,
12+
# add these directories to sys.path here. If the directory is relative to the
13+
# documentation root, use os.path.abspath to make it absolute, like shown here.
14+
# autodo
15+
# import os
16+
# import sys
17+
# sys.path.insert(0, os.path.abspath('.'))
18+
19+
20+
# -- Project information -----------------------------------------------------
21+
22+
project = "iDOM"
23+
copyright = "2019, Ryan Morshead"
24+
author = "Ryan Morshead"
25+
26+
# The short X.Y version
27+
version = ""
28+
# The full version, including alpha/beta/rc tags
29+
release = "0.1.0"
30+
31+
32+
# -- General configuration ---------------------------------------------------
33+
34+
# If your documentation needs a minimal Sphinx version, state it here.
35+
#
36+
# needs_sphinx = '1.0'
37+
38+
# Add any Sphinx extension module names here, as strings. They can be
39+
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
40+
# ones.
41+
extensions = [
42+
"sphinx.ext.autodoc",
43+
"sphinx.ext.intersphinx",
44+
"sphinx.ext.coverage",
45+
"sphinx.ext.viewcode",
46+
"sphinx.ext.githubpages",
47+
"sphinx.ext.napoleon",
48+
"sphinx_autodoc_typehints",
49+
"sphinx_js",
50+
]
51+
52+
# Add any paths that contain templates here, relative to this directory.
53+
templates_path = ["_templates"]
54+
55+
# The suffix(es) of source filenames.
56+
# You can specify multiple suffix as a list of string:
57+
#
58+
# source_suffix = ['.rst', '.md']
59+
source_suffix = ".rst"
60+
61+
# The master toctree document.
62+
master_doc = "index"
63+
64+
# The language for content autogenerated by Sphinx. Refer to documentation
65+
# for a list of supported languages.
66+
#
67+
# This is also used if you do content translation via gettext catalogs.
68+
# Usually you set "language" from the command line for these cases.
69+
language = None
70+
71+
autodoc_member_order = "bysource"
72+
73+
# List of patterns, relative to source directory, that match files and
74+
# directories to ignore when looking for source files.
75+
# This pattern also affects html_static_path and html_extra_path.
76+
exclude_patterns = []
77+
78+
# The name of the Pygments (syntax highlighting) style to use.
79+
pygments_style = None
80+
81+
# Path to javascript source
82+
js_source_path = "../idom/js/packages/idom-layout/src"
83+
84+
# favicon location
85+
html_favicon = "favicon.ico"
86+
87+
# -- Options for HTML output -------------------------------------------------
88+
89+
# The theme to use for HTML and HTML Help pages. See the documentation for
90+
# a list of builtin themes.
91+
#
92+
html_theme = "sphinx_rtd_theme"
93+
94+
# Theme options are theme-specific and customize the look and feel of a theme
95+
# further. For a list of options available for each theme, see the
96+
# documentation.
97+
#
98+
# html_theme_options = {}
99+
100+
# Add any paths that contain custom static files (such as style sheets) here,
101+
# relative to this directory. They are copied after the builtin static files,
102+
# so a file named "default.css" will overwrite the builtin "default.css".
103+
html_static_path = ["_static"]
104+
105+
# Custom sidebar templates, must be a dictionary that maps document names
106+
# to template names.
107+
#
108+
# The default sidebars (for documents that don't match any pattern) are
109+
# defined by theme itself. Builtin themes are using these templates by
110+
# default: ``['localtoc.html', 'relations.html', 'sourcelink.html',
111+
# 'searchbox.html']``.
112+
#
113+
# html_sidebars = {}
114+
115+
116+
# -- Options for HTMLHelp output ---------------------------------------------
117+
118+
# Output file base name for HTML help builder.
119+
htmlhelp_basename = "iDOMdoc"
120+
121+
122+
# -- Options for LaTeX output ------------------------------------------------
123+
124+
latex_elements = {
125+
# The paper size ('letterpaper' or 'a4paper').
126+
#
127+
# 'papersize': 'letterpaper',
128+
# The font size ('10pt', '11pt' or '12pt').
129+
#
130+
# 'pointsize': '10pt',
131+
# Additional stuff for the LaTeX preamble.
132+
#
133+
# 'preamble': '',
134+
# Latex figure (float) alignment
135+
#
136+
# 'figure_align': 'htbp',
137+
}
138+
139+
# Grouping the document tree into LaTeX files. List of tuples
140+
# (source start file, target name, title,
141+
# author, documentclass [howto, manual, or own class]).
142+
latex_documents = [
143+
(master_doc, "iDOM.tex", "iDOM Documentation", "Ryan Morshead", "manual")
144+
]
145+
146+
147+
# -- Options for manual page output ------------------------------------------
148+
149+
# One entry per manual page. List of tuples
150+
# (source start file, name, description, authors, manual section).
151+
man_pages = [(master_doc, "idom", "iDOM Documentation", [author], 1)]
152+
153+
154+
# -- Options for Texinfo output ----------------------------------------------
155+
156+
# Grouping the document tree into Texinfo files. List of tuples
157+
# (source start file, target name, title, author,
158+
# dir menu entry, description, category)
159+
texinfo_documents = [
160+
(
161+
master_doc,
162+
"iDOM",
163+
"iDOM Documentation",
164+
author,
165+
"iDOM",
166+
"One line description of project.",
167+
"Miscellaneous",
168+
)
169+
]
170+
171+
172+
# -- Options for Epub output -------------------------------------------------
173+
174+
# Bibliographic Dublin Core info.
175+
epub_title = project
176+
177+
# The unique identifier of the text. This can be a ISBN number
178+
# or the project homepage.
179+
#
180+
# epub_identifier = ''
181+
182+
# A unique identification for the text.
183+
#
184+
# epub_uid = ''
185+
186+
# A list of files that should not be packed into the epub file.
187+
epub_exclude_files = ["search.html"]
188+
189+
190+
# -- Extension configuration -------------------------------------------------
191+
192+
# -- Options for intersphinx extension ---------------------------------------
193+
194+
# Example configuration for intersphinx: refer to the Python standard library.
195+
intersphinx_mapping = {"https://docs.python.org/": None}
196+
197+
# -- Options for todo extension ----------------------------------------------
198+
199+
# If true, `todo` and `todoList` produce output, else they produce nothing.
200+
todo_include_todos = True

docs/source/favicon.ico

166 KB
Binary file not shown.

0 commit comments

Comments
 (0)