Browse Source

code review

Falko Schindler 2 years ago
parent
commit
347b201212

+ 5 - 5
README.md

@@ -78,11 +78,11 @@ The whole content of [https://nicegui.io](https://nicegui.io) is [implemented wi
 You may also have a look at the following examples for in-depth demonstrations of what you can do with NiceGUI:
 
 - [Slideshow](https://github.com/zauberzeug/nicegui/tree/main/examples/slideshow/main.py):
-  implements a keyboard controlled image slideshow
+  implements a keyboard-controlled image slideshow
 - [Authentication](https://github.com/zauberzeug/nicegui/blob/main/examples/authentication/main.py): shows how to use sessions to build a login screen
-- [Customization](https://github.com/zauberzeug/nicegui/blob/main/examples/customization/main.py): provides an example of how to modularize your application into multiple files and creating a specialized `@ui.page` decorator.
+- [Customization](https://github.com/zauberzeug/nicegui/blob/main/examples/customization/main.py): provides an example of how to modularize your application into multiple files and create a specialized `@ui.page` decorator.
 - [Map](https://github.com/zauberzeug/nicegui/blob/main/examples/map/main.py): using the JavaScript library [leaflet](https://leafletjs.com/) to display a map at specific locations
-- [AI User Interface](https://github.com/zauberzeug/nicegui/blob/main/examples/ai_interface/main.py): utilizing the great but non-async API from <https://replicate.com> to perform voice-to-text transcription and generate images from promts with Stable Diffusion.
+- [AI User Interface](https://github.com/zauberzeug/nicegui/blob/main/examples/ai_interface/main.py): utilizing the great but non-async API from <https://replicate.com> to perform voice-to-text transcription and generate images from prompts with Stable Diffusion.
 
 ## Why?
 
@@ -90,8 +90,8 @@ We like [Streamlit](https://streamlit.io/) but find it does [too much magic when
 In search for an alternative nice library to write simple graphical user interfaces in Python we discovered [JustPy](https://justpy.io/).
 While we liked the approach, it is too "low-level HTML" for our daily usage.
 
-Therefore we created NiceGUI ontop of [JustPy](https://justpy.io/).
-Which itself is based on the ASGI framework [Starlette](https://www.starlette.io/) (like [FastAPI](https://fastapi.tiangolo.com/)) and the ASGI webserver [Uvicorn](https://www.uvicorn.org/).
+Therefore we created NiceGUI on top of [JustPy](https://justpy.io/),
+which itself is based on the ASGI framework [Starlette](https://www.starlette.io/) (like [FastAPI](https://fastapi.tiangolo.com/)) and the ASGI webserver [Uvicorn](https://www.uvicorn.org/).
 
 ## Docker
 

+ 2 - 3
api_docs_and_examples.py

@@ -72,8 +72,7 @@ def example(content: Union[Callable, type, str]):
             ui.markdown(code).classes('mt-12 w-5/12 overflow-auto')
 
 
-async def create():
-
+def create():
     ui.markdown('## API Documentation and Examples')
 
     def h3(text: str) -> None:
@@ -696,6 +695,6 @@ To avoid the potentially costly import of Matplotlib, you set the environment va
 This will make `ui.plot` and `ui.line_plot` unavailable.
 '''
     with example(ui_run):
-        ui.label('dark page on port 7000 without relaoding')
+        ui.label('dark page on port 7000 without reloading')
 
         #ui.run(dark=True, port=7000, reload=False)

+ 1 - 1
examples/3d_scene/main.py

@@ -1,10 +1,10 @@
 #!/usr/bin/env python3
-
 import os
 
 from nicegui import ui
 
 ui.add_static_files('/static', f'{os.path.dirname(os.path.realpath(__file__))}/static')
+
 with ui.scene(width=1024, height=800) as scene:
     scene.spot_light(distance=100, intensity=0.1).move(-10, 0, 10)
     scene.stl('static/pikachu.stl').scale(0.1)

+ 1 - 2
examples/ai_interface/main.py

@@ -1,5 +1,4 @@
 #!/usr/bin/env python3
-
 import asyncio
 import functools
 import io
@@ -19,7 +18,7 @@ async def transcribe(args: UploadEventArguments):
     transcription.text = 'Transcribing...'
     model = replicate.models.get('openai/whisper')
     prediction = await io_bound(model.predict, audio=io.BytesIO(args.files[0]))
-    text = prediction.get("transcription", "no transcription")
+    text = prediction.get('transcription', 'no transcription')
     transcription.set_text(f'result: "{text}"')
 
 

+ 0 - 5
examples/map/leaflet.py

@@ -72,8 +72,3 @@ class map(ui.card):
             });
         </script>
         ''')
-
-# var target = L.latLng('53.44', '14.06'); // Fahrenwalde, Uckermark
-#                     map.setView(target, 13);
-#                     marker = L.marker(target);
-#                     marker.addTo(map);

+ 2 - 3
examples/map/main.py

@@ -1,8 +1,7 @@
 #!/usr/bin/env python3
-
 from nicegui import ui
 
-# this module wraps the javascript lib leafletjs.com into an easy to use NiceGUI element
+# this module wraps the JavaScript lib leafletjs.com into an easy-to-use NiceGUI element
 import leaflet
 
 locations = {
@@ -16,7 +15,7 @@ selection = None
 
 @ui.page('/', on_page_ready=lambda: selection.set_value(next(iter(locations))))
 def main_page():
-    # NOTE we need to use the on_page_ready event to make sure the page is loaded before we execute javascript
+    # NOTE we need to use the on_page_ready event to make sure the page is loaded before we execute JavaScript
     global selection
     map = leaflet.map()
     selection = ui.select(locations, on_change=map.set_location).style('width: 10em')

+ 8 - 7
main.py

@@ -9,20 +9,20 @@ import traffic_tracking
 from nicegui import ui
 from nicegui.elements.markdown import Markdown
 
-with open('README.md', 'r') as file:
-    content = file.read()
+with open('README.md') as f:
+    content = f.read()
     content = re.sub(r'(?m)^\<img.*\n?', '', content)
     # change absolute link on GitHub to relative link
     content = content.replace('(https://nicegui.io/reference)', '(reference)')
     README = Markdown.apply_tailwind(markdown2.markdown(content, extras=['fenced-code-blocks']))
 
 
-async def go_to_anchor():
-    # NOTE because the docs are added after inital page load, we need to manually trigger the jump tho the anchor
+async def go_to_anchor() -> None:
+    # NOTE because the docs are added after initial page load, we need to manually trigger the jump to the anchor
     await ui.run_javascript('''
         parts = document.URL.split("#");
         console.log(parts);
-        if (parts.length > 1){    
+        if (parts.length > 1) {
             console.log(window.location);
             window.location = parts[0] + "reference#" + parts[1];
             console.log(window.location);
@@ -74,7 +74,8 @@ async def index():
 
 
 @ui.page('/reference')
-async def reference():
-    await api_docs_and_examples.create()
+def reference():
+    api_docs_and_examples.create()
+
 
 ui.run()

+ 1 - 1
nicegui/elements/chart.py

@@ -11,7 +11,7 @@ class Chart(Element):
         """Chart
 
         An element to create a chart using `Highcharts <https://www.highcharts.com/>`_.
-        Updates can be pushed to the chart  by changing the `options` property.
+        Updates can be pushed to the chart by changing the `options` property.
         After data has changed, call the `update` method to refresh the chart.
 
         :param options: dictionary of Highcharts options

+ 7 - 6
nicegui/routes.py

@@ -17,10 +17,11 @@ def add_route(self, route: BaseRoute) -> None:
     """Route
 
     Adds a new `Starlette route <https://www.starlette.io/routing/>`_.
-    Routed paths must start with a `'/'`. Also see `@ui.get <https://nicegui.io/#get_decorator>`_ and 
-    `ui.add_static_files <https://nicegui.io/#get_decorator>`_ for more convinient ways to deliver non-ui content.
+    Routed paths must start with a slash "/".
+    Also see `@ui.get <https://nicegui.io/#get_decorator>`_ and `ui.add_static_files <https://nicegui.io/#get_decorator>`_
+    for more convenient ways to deliver non-UI content.
 
-    :param route: starlette route including a path and a function to be called
+    :param route: Starlette route including a path and a function to be called
     """
     globals.app.routes.insert(0, route)
 
@@ -31,7 +32,7 @@ def add_static_files(self, path: str, directory: str) -> None:
     Makes a local directory available at the specified endpoint, e.g. `'/static'`.
     Do only put non-security-critical files in there, as they are accessible to everyone.
 
-    :param path: string that starts with a '/'
+    :param path: string that starts with a slash "/"
     :param directory: folder with static files to serve under the given path
     """
     add_route(None, Mount(path, app=StaticFiles(directory=directory)))
@@ -40,13 +41,13 @@ def add_static_files(self, path: str, directory: str) -> None:
 def get(self, path: str):
     """GET Decorator
 
-    Decorating a function with the `@ui.get` makes it available at the specified endpoint, e.g. `'/another/route/<id>'`.
+    Decorating a function with `@ui.get` makes it available at the specified endpoint, e.g. `'/another/route/<id>'`.
 
     Path parameters can be passed to the request handler like with `FastAPI <https://fastapi.tiangolo.com/tutorial/path-params/>`_.
     If type-annotated, they are automatically converted to `bool`, `int`, `float` and `complex` values.
     An optional `request` argument gives access to the complete request object.
 
-    :param path: string that starts with a '/'
+    :param path: string that starts with a slash "/"
     """
     *_, converters = compile_path(path)