Add a gallery page to boxesserver
This adds an image gallery to the server so you can visually search through all available generators and just click on the image you want.
This commit is contained in:
parent
618fe78314
commit
65a49ede39
|
@ -408,6 +408,7 @@ class BServer:
|
|||
<li><a href="https://hackaday.io/project/10649-boxespy" target="_blank" rel="noopener">""" + _("Home Page") + """</a></li>
|
||||
<li><a href="https://florianfesti.github.io/boxes/html/index.html" target="_blank" rel="noopener">""" + _("Documentation") + """</a></li>
|
||||
<li><a href="https://github.com/florianfesti/boxes" target="_blank" rel="noopener">""" + _("Sources") + """</a></li>
|
||||
<li><a href="Gallery">""" + _("Gallery") + """</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
"""
|
||||
|
@ -477,6 +478,57 @@ class BServer:
|
|||
|
||||
return url
|
||||
|
||||
def serveGallery(self, environ, start_response, lang):
|
||||
_ = lang.gettext
|
||||
lang_name = lang.info().get('language', None)
|
||||
langparam = ""
|
||||
if lang_name:
|
||||
langparam = "?language=" + lang_name
|
||||
|
||||
start_response("200 OK", [('Content-type', "text/html; charset=utf-8")])
|
||||
result = [f"""
|
||||
{self.genHTMLStart(lang)}
|
||||
<head>
|
||||
<title>{_("Gallery")} - {_("Boxes.py")}</title>
|
||||
{self.genHTMLMeta()}
|
||||
{self.genHTMLMetaLanguageLink()}
|
||||
{self.genHTMLCSS()}
|
||||
{self.genHTMLJS()}
|
||||
</head>
|
||||
<body onload="initPage()">
|
||||
<div class="container" style="background-color: #FFF8EA;">
|
||||
<div style="width: 75%; float: left;">
|
||||
<h1><a href="/">{_("Boxes.py")}</a></h1>
|
||||
<h2>{_("Gallery")}</h2>
|
||||
</div>
|
||||
|
||||
<div style="width: 25%; float: left;">
|
||||
<img alt="self-Logo" src="{self.static_url}/boxes-logo.svg" width="250">
|
||||
</div>
|
||||
<div class="clear"></div>
|
||||
|
||||
"""]
|
||||
for nr, group in enumerate(self.groups):
|
||||
for box in group.generators:
|
||||
name = box.__name__
|
||||
fn = f"samples/{name}-thumb.jpg"
|
||||
thumbnail = f"{self.static_url}/{fn}"
|
||||
static_filename = os.path.join(self.staticdir, fn)
|
||||
alt = f"{_(name)}"
|
||||
href = f"{name}{langparam}"
|
||||
if not os.path.exists(static_filename):
|
||||
result.append(f""" <span class="gallery_missing"><a href="{href}">{_(name)}<br><br>{_(box.__doc__)}</a></span>\n""")
|
||||
else:
|
||||
result.append(f""" <span class="gallery"><a title="{_(name)} - {_(box.__doc__)}" href="{href}"><img alt="{alt}" src="{thumbnail}"/></a></span>\n""")
|
||||
|
||||
result.append(f"""
|
||||
{self.genPagePartFooter(lang)}
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
)
|
||||
return (s.encode("utf-8") for s in result)
|
||||
|
||||
def serve(self, environ, start_response):
|
||||
# serve favicon from static for generated SVGs
|
||||
if environ["PATH_INFO"] == "favicon.ico":
|
||||
|
@ -497,6 +549,9 @@ class BServer:
|
|||
lang = self.getLanguage(args, environ.get("HTTP_ACCEPT_LANGUAGE", ""))
|
||||
_ = lang.gettext
|
||||
|
||||
if name == "Gallery":
|
||||
return self.serveGallery(environ, start_response, lang)
|
||||
|
||||
box_cls = self.boxes.get(name, None)
|
||||
if not box_cls:
|
||||
start_response(status, headers)
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 5.4 KiB |
|
@ -186,3 +186,18 @@ img[id|=sample] {
|
|||
textarea {
|
||||
font-family: monospace;
|
||||
}
|
||||
|
||||
.gallery_missing {
|
||||
display : inline-block;
|
||||
text-align : center;
|
||||
vertical-align: middle;
|
||||
width : 200px;
|
||||
margin : 5px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.gallery img {
|
||||
max-height : 200px;
|
||||
max-width : 200px;
|
||||
margin : 5px;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue