85 lines
3.0 KiB
Org Mode
85 lines
3.0 KiB
Org Mode
:PROPERTIES:
|
|
:ID: 6cc56ee4-6d42-4d50-beb3-bb22a98298dd
|
|
:mtime: 20220814131534
|
|
:ctime: 20220130153624
|
|
:END:
|
|
#+title: textual
|
|
#+filetags: :Python:UI:
|
|
|
|
* Introduction
|
|
Framework de création d'IHM inspiré par le developpement web moderne (CSS) basé sur Rich.
|
|
Rich est une librairie Python permettant de :
|
|
* Appliquer des styles à la sortie sur le terminal,
|
|
* Afficher des tables et du contenu markdown,
|
|
* Appliquer une coloration synthaxique.
|
|
|
|
* Howto
|
|
** Pour inspecter un objet (/rich.inspect method)
|
|
#+BEGIN_SRC python :results output
|
|
from rich import inspect
|
|
|
|
class Dummy:
|
|
|
|
def __init__(self):
|
|
self.a = 'A'
|
|
self.b = 123
|
|
|
|
inspect(vars)
|
|
|
|
inspect(Dummy())
|
|
#+END_SRC
|
|
#+RESULTS:
|
|
: ╭────────────────── <built-in function vars> ──────────────────╮
|
|
: │ def vars(...) │
|
|
: │ │
|
|
: │ vars([object]) -> dictionary │
|
|
: │ │
|
|
: │ 29 attribute(s) not shown. Run inspect(inspect) for options. │
|
|
: ╰──────────────────────────────────────────────────────────────╯
|
|
: ╭────────── <class '__main__.Dummy'> ───────────╮
|
|
: │ ╭───────────────────────────────────────────╮ │
|
|
: │ │ <__main__.Dummy object at 0x7f55d6d2d7c0> │ │
|
|
: │ ╰───────────────────────────────────────────╯ │
|
|
: │ │
|
|
: │ a = 'A' │
|
|
: │ b = 123 │
|
|
: ╰───────────────────────────────────────────────╯
|
|
|
|
** Formatter les logs
|
|
#+BEGIN_SRC python :results output
|
|
import logging
|
|
from rich.logging import RichHandler
|
|
|
|
FORMAT = "%(message)s"
|
|
logging.basicConfig(
|
|
level="NOTSET",
|
|
format=FORMAT,
|
|
datefmt="[%X]",
|
|
handlers=[RichHandler(rich_tracebacks=True)])
|
|
|
|
log = logging.getLogger("rich")
|
|
|
|
log.info("Logging set up.")
|
|
|
|
def division(a, b):
|
|
log.debug(f"Dividing {a} by {b}.")
|
|
try:
|
|
return a / b
|
|
except ZeroDivisionError:
|
|
log.exception("Oh noes!")
|
|
|
|
division(3, 2)
|
|
division(5, 0)
|
|
#+END_SRC
|
|
#+RESULTS:
|
|
|
|
|
|
* Projets
|
|
** [[https://github.com/Traumatism/ToastCord][ToastCord - Github]]
|
|
** [[https://github.com/kraanzu/dooit][Dooit - Github]]
|
|
|
|
* Références
|
|
* [[https://github.com/Textualize/textual][Textual - Github]]
|
|
* [[https://github.com/Textualize/rich][Rich - Github]]
|
|
* [[https://rich.readthedocs.io/en/latest/introduction.html][Rich - ReadTheDocs]]
|