Explorar o código

introducing ui.html and nice presenting of docstrings in api_refrence

Rodja Trappe %!s(int64=4) %!d(string=hai) anos
pai
achega
a49d8b5a42
Modificáronse 8 ficheiros con 59 adicións e 35 borrados
  1. 3 1
      api_reference.py
  2. 24 0
      nicegui/elements/html.py
  3. 2 6
      nicegui/elements/input.py
  4. 7 22
      nicegui/elements/markdown.py
  5. 4 1
      nicegui/nicegui.py
  6. 1 0
      nicegui/ui.py
  7. 17 5
      poetry.lock
  8. 1 0
      pyproject.toml

+ 3 - 1
api_reference.py

@@ -6,6 +6,7 @@ from icecream import ic
 import inspect
 from executing import Source
 import sys
+import docutils.core
 
 @contextmanager
 def example():
@@ -25,7 +26,8 @@ def example():
 
 def describe(element, headline):
     doc = element.__init__.__doc__
-    ui.markdown(f'### {headline}\n{doc}')
+    html = docutils.core.publish_parts(doc, writer_name='html')['html_body']
+    ui.html(html)
 
 describe(ui.input, 'Text Input')
 with example():

+ 24 - 0
nicegui/elements/html.py

@@ -0,0 +1,24 @@
+import justpy as jp
+from .element import Element
+
+class Html(Element):
+
+    def __init__(self, content: str = ''):
+
+        view = jp.Div()
+        super().__init__(view, '')
+        self.content = content
+
+    @property
+    def content(self):
+
+        return self.content.inner_html
+
+    @content.setter
+    def content(self, content: any):
+
+        self.set_content(content)
+
+    def set_content(self, content: str):
+
+        self.view.inner_html = content

+ 2 - 6
nicegui/elements/input.py

@@ -13,12 +13,8 @@ class Input(StringElement):
                  on_change: Callable = None):
         """Text Input Element.
 
-        Parameters
-        ----------
-        label : str
-            displayed name of the text input
-
-
+        :param str label: display name for the text input
+        :param str placeholder: text to show if no value is entered
         """
         view = jp.QInput(
             label=label,

+ 7 - 22
nicegui/elements/markdown.py

@@ -1,28 +1,13 @@
 import markdown2
-import justpy as jp
-from typing import Union, List
-from .element import Element
-from icecream import ic
+from .html import Html
 
-class Markdown(Element):
+class Markdown(Html):
 
-    def __init__(self,
-                 content: str = ''):
+    def __init__(self, content: str = ''):
 
-        view = jp.Div()
-        view.inner_html = markdown2.markdown(content, extras=['fenced-code-blocks'])
-        super().__init__(view, '')
+        super().__init__(content)
 
-    @property
-    def text(self):
+    def set_content(self, content: str):
 
-        return self.view.text
-
-    @text.setter
-    def text(self, text: any):
-
-        self.view.text = text
-
-    def set_text(self, text: str):
-
-        self.text = text
+        html = markdown2.markdown(content, extras=['fenced-code-blocks'])
+        super().set_content(html)

+ 4 - 1
nicegui/nicegui.py

@@ -4,6 +4,7 @@ import uvicorn
 import sys
 import inspect
 import webbrowser
+import docutils.core
 from pygments import highlight
 from pygments.lexers import PythonLexer
 from pygments.formatters import HtmlFormatter
@@ -19,8 +20,10 @@ if not inspect.stack()[-2].filename.endswith('spawn.py'):
     sys.exit()
 
 wp = jp.QuasarPage(delete_flag=False, title='NiceGUI', favicon='favicon.png')
-wp.head_html = '<script>confirm = () => true;</script>'  # avoid confirmation dialog for reload
 wp.css = HtmlFormatter().get_style_defs('.codehilite')
+wp.head_html = '<script>confirm = () => true;</script>'  # avoid confirmation dialog for reload
+wp.head_html += docutils.core.publish_parts('', writer_name='html')['stylesheet']
+
 
 main = jp.Div(a=wp, classes='q-ma-md column items-start', style='row-gap: 1em')
 main.add_page(wp)

+ 1 - 0
nicegui/ui.py

@@ -5,6 +5,7 @@ class Ui:
     from .elements.icon import Icon as icon
     from .elements.input import Input as input
     from .elements.label import Label as label
+    from .elements.html import Html as html
     from .elements.markdown import Markdown as markdown
     from .elements.link import Link as link
     from .elements.number import Number as number

+ 17 - 5
poetry.lock

@@ -91,6 +91,14 @@ category = "main"
 optional = false
 python-versions = "*"
 
+[[package]]
+name = "docutils"
+version = "0.17.1"
+description = "Docutils -- Python Documentation Utilities"
+category = "main"
+optional = false
+python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
+
 [[package]]
 name = "executing"
 version = "0.6.0"
@@ -156,11 +164,11 @@ pygments = ">=2.2.0"
 
 [[package]]
 name = "idna"
-version = "3.1"
+version = "2.10"
 description = "Internationalized Domain Names in Applications (IDNA)"
 category = "main"
 optional = false
-python-versions = ">=3.4"
+python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
 
 [[package]]
 name = "itsdangerous"
@@ -378,7 +386,7 @@ python-versions = ">=3.6.1"
 [metadata]
 lock-version = "1.1"
 python-versions = "^3.7"
-content-hash = "52606d24d4be25e5ce4d00e95e26e92de12cca682ab0ee5c68aec8bdaf27ce0d"
+content-hash = "8e85098d955af42062b9f035490c66e0f724f245355248c1a4b62a5e9d3dfe53"
 
 [metadata.files]
 addict = [
@@ -474,6 +482,10 @@ debugpy = [
 demjson = [
     {file = "demjson-2.2.4.tar.gz", hash = "sha256:31de2038a0fdd9c4c11f8bf3b13fe77bc2a128307f965c8d5fb4dc6d6f6beb79"},
 ]
+docutils = [
+    {file = "docutils-0.17.1-py2.py3-none-any.whl", hash = "sha256:cf316c8370a737a022b72b56874f6602acf974a37a9fba42ec2876387549fc61"},
+    {file = "docutils-0.17.1.tar.gz", hash = "sha256:686577d2e4c32380bb50cbb22f575ed742d58168cee37e99117a854bcd88f125"},
+]
 executing = [
     {file = "executing-0.6.0-py2.py3-none-any.whl", hash = "sha256:a2f10f802b4312b92bd256279b43720271b0d9b540a0dbab7be4c28fbc536479"},
     {file = "executing-0.6.0.tar.gz", hash = "sha256:a07046e608c56948a899e1c7dc45327ed84ee67edf245041eb8c6722658c14e3"},
@@ -495,8 +507,8 @@ icecream = [
     {file = "icecream-2.1.0.tar.gz", hash = "sha256:c2e7b74c1c12caa2cfde050f2e636493ee77a9fb4a494b5593418ab359924a24"},
 ]
 idna = [
-    {file = "idna-3.1-py3-none-any.whl", hash = "sha256:5205d03e7bcbb919cc9c19885f9920d622ca52448306f2377daede5cf3faac16"},
-    {file = "idna-3.1.tar.gz", hash = "sha256:c5b02147e01ea9920e6b0a3f1f7bb833612d507592c837a6c49552768f4054e1"},
+    {file = "idna-2.10-py2.py3-none-any.whl", hash = "sha256:b97d804b1e9b523befed77c48dacec60e6dcb0b5391d57af6a65a312a90648c0"},
+    {file = "idna-2.10.tar.gz", hash = "sha256:b307872f855b18632ce0c21c5e45be78c0ea7ae4c15c828c20788b26921eb3f6"},
 ]
 itsdangerous = [
     {file = "itsdangerous-1.1.0-py2.py3-none-any.whl", hash = "sha256:b12271b2047cb23eeb98c8b5622e2e5c5e9abd9784a153e9d8ef9cb4dd09d749"},

+ 1 - 0
pyproject.toml

@@ -15,6 +15,7 @@ matplotlib = "^3.4.1"
 typing-extensions = "^3.10.0"
 markdown2 = "^2.4.0"
 Pygments = "^2.9.0"
+docutils = "^0.17.1"
 
 [tool.poetry.dev-dependencies]
 icecream = "^2.1.0"