Forráskód Böngészése

proof of conecept for using NiceGUI as API reference

Rodja Trappe 4 éve
szülő
commit
b794a06963
4 módosított fájl, 47 hozzáadás és 7 törlés
  1. 39 0
      api_reference.py
  2. 1 1
      nicegui/__init__.py
  3. 6 6
      poetry.lock
  4. 1 0
      pyproject.toml

+ 39 - 0
api_reference.py

@@ -0,0 +1,39 @@
+
+#!/usr/bin/env python3
+from nicegui import ui, wp
+from contextlib import contextmanager
+from icecream import ic
+import inspect
+from executing import Source
+import sys
+
+from pygments import highlight
+from pygments.lexers import PythonLexer
+from pygments.formatters import HtmlFormatter
+
+wp.css = HtmlFormatter().get_style_defs('.highlight')
+
+@contextmanager
+def example():
+    callFrame = inspect.currentframe().f_back.f_back
+    begin = callFrame.f_lineno
+    with ui.card():
+        with ui.row():
+            with ui.column():
+                yield
+            callFrame = inspect.currentframe().f_back.f_back
+            end = callFrame.f_lineno
+            code = inspect.getsource(sys.modules[__name__])
+            code = code.splitlines()[begin:end]
+            code = '\n'.join(code)
+            html = highlight(code, PythonLexer(), HtmlFormatter())
+            label = ui.label()
+            label.view.inner_html = html
+            ic(html)
+
+with example():
+
+    ui.input(label='Text', on_change=lambda e: result.set_text(e.value))
+    ui.number(label='Number', format='%.2f', on_change=lambda e: result.set_text(e.value))
+
+    result = ui.label('result', typography='bold')

+ 1 - 1
nicegui/__init__.py

@@ -1 +1 @@
-from nicegui.nicegui import app, ui
+from nicegui.nicegui import app, ui, wp

+ 6 - 6
poetry.lock

@@ -18,7 +18,7 @@ python-versions = "*"
 name = "asttokens"
 version = "2.0.5"
 description = "Annotate AST trees with source code positions"
-category = "main"
+category = "dev"
 optional = false
 python-versions = "*"
 
@@ -60,7 +60,7 @@ python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
 name = "colorama"
 version = "0.4.4"
 description = "Cross-platform colored terminal text."
-category = "main"
+category = "dev"
 optional = false
 python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
 
@@ -95,7 +95,7 @@ python-versions = "*"
 name = "executing"
 version = "0.6.0"
 description = "Get the currently executing AST node of a frame, and other information"
-category = "main"
+category = "dev"
 optional = false
 python-versions = "*"
 
@@ -144,7 +144,7 @@ http2 = ["h2 (>=3.0.0,<4.0.0)"]
 name = "icecream"
 version = "2.1.0"
 description = "Never use print() to debug again; inspect variables, expressions, and program execution with a single, simple function call."
-category = "main"
+category = "dev"
 optional = false
 python-versions = "*"
 
@@ -263,7 +263,7 @@ python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
 name = "pygments"
 version = "2.9.0"
 description = "Pygments is a syntax highlighting package written in Python."
-category = "main"
+category = "dev"
 optional = false
 python-versions = ">=3.5"
 
@@ -370,7 +370,7 @@ python-versions = ">=3.6.1"
 [metadata]
 lock-version = "1.1"
 python-versions = "^3.7"
-content-hash = "92d54b567e9f97f0e1f80c7a8ab8fb64e17fe879a9f42ab695d8200c9e80e096"
+content-hash = "d56fa651727b425db52d6d47848f4cb08b032d62c191807b1faff8911fdaa8a2"
 
 [metadata.files]
 addict = [

+ 1 - 0
pyproject.toml

@@ -18,6 +18,7 @@ typing-extensions = "^3.10.0"
 icecream = "^2.1.0"
 autopep8 = "^1.5.7"
 debugpy = "^1.3.0"
+Pygments = "^2.9.0"
 
 [build-system]
 requires = ["poetry-core>=1.0.0"]