1+ from datetime import datetime
12from typing import TYPE_CHECKING
23from warnings import warn
3- from ..facet import Facet
4+ from pathlib import Path
5+
6+ from textual .widgets import (Checkbox , Footer , Header , Input , Label ,
7+ RadioButton , Static )
8+
9+ from humanize import naturalsize
10+
11+ from ..exceptions import DependencyRequired
12+ from ..facet import Facet , Image , LayoutElement
413if TYPE_CHECKING :
514 from .textual_adaptor import TextualAdaptor
615
@@ -22,6 +31,30 @@ def set_title(self, title: str):
2231 # NOTE: When you receive Facet in Command.init, the app does not exist yet
2332 warn ("Setting textual title not implemented well." )
2433
34+ def _layout (self , elements : list [LayoutElement ]):
35+ append = self .adaptor .layout_elements .append
36+ try :
37+ from PIL import Image as ImagePIL
38+ from textual_imageview .viewer import ImageViewer
39+ PIL = True
40+ except :
41+ PIL = False
42+
43+ for el in elements :
44+ match el :
45+ case Image ():
46+ if not PIL :
47+ raise DependencyRequired ("img" )
48+ append (ImageViewer (ImagePIL .open (el .src )))
49+ case Path ():
50+ size = naturalsize (el .stat ().st_size )
51+ mtime = datetime .fromtimestamp (el .stat ().st_mtime ).strftime ("%Y-%m-%d %H:%M:%S" )
52+ append (Label (f"{ el } / { size } / { mtime } " ))
53+ case str ():
54+ append (Label (el ))
55+ case _:
56+ append (Label ("Error in the layout: Unknown {el}" ))
57+
2558 def submit (self , * args , ** kwargs ):
2659 super ().submit (* args , ** kwargs )
2760 try :
0 commit comments