Add mouseover images for most groups

Resolves: #253
This commit is contained in:
Florian Festi 2021-06-05 18:22:05 +02:00
parent 261c194851
commit ef94daa006
2 changed files with 25 additions and 17 deletions

View File

@ -7,10 +7,11 @@ ui_groups_by_name = {}
class UIGroup: class UIGroup:
def __init__(self, name, title=None, description=""): def __init__(self, name, title=None, description="", image=""):
self.name = name self.name = name
self.title = title or name self.title = title or name
self.description = description self.description = description
self._image = image
self.generators = [] self.generators = []
# register # register
ui_groups_by_name[name] = self ui_groups_by_name[name] = self
@ -19,15 +20,23 @@ class UIGroup:
self.generators.append(box) self.generators.append(box)
self.generators.sort(key=lambda b:getattr(b, '__name__', None) or b.__class__.__name__) self.generators.sort(key=lambda b:getattr(b, '__name__', None) or b.__class__.__name__)
@property
def thumbnail(self):
return self._image and f"{self._image}-thumb.jpg"
@property
def image(self):
return self._image and f"{self._image}.jpg"
ui_groups = [ ui_groups = [
UIGroup("Box", "Boxes"), UIGroup("Box", "Boxes", image="UniversalBox"),
UIGroup("FlexBox", "Boxes with flex"), UIGroup("FlexBox", "Boxes with flex", image="RoundedBox"),
UIGroup("Tray", "Trays and Drawer Inserts"), UIGroup("Tray", "Trays and Drawer Inserts", image="TypeTray"),
UIGroup("Shelf", "Shelves"), UIGroup("Shelf", "Shelves", image="DisplayShelf"),
UIGroup("SlatWall"), UIGroup("SlatWall", image="SlatwallTypeTray"),
UIGroup("Holes", "Hole patterns"), UIGroup("Holes", "Hole patterns", image=""),
UIGroup("Part", "Parts and Samples"), UIGroup("Part", "Parts and Samples", image="BurnTest"),
UIGroup("Misc"), UIGroup("Misc", image="TrafficLight"),
UIGroup("Unstable", description="Generators are still untested or need manual adjustment to be useful."), UIGroup("Unstable", description="Generators are still untested or need manual adjustment to be useful."),
] ]

View File

@ -335,11 +335,11 @@ class BServer:
""" ] """ ]
for nr, group in enumerate(self.groups): for nr, group in enumerate(self.groups):
result.append(f''' result.append(f'''
<h3 id="h-{nr}" class="open" onclick="showHide('{nr}')">{_(group.title)}</h3>\n <div id="{nr}"> <h3 id="h-{nr}" class="open" onclick="showHide('{nr}')"
''') onmouseenter="change('{group.name}', 'static/samples/{group.thumbnail}')"
result.append(f""" onmouseleave="changeback('{group.name}')">{_(group.title)}</h3>
<img style="width: 200px;" id="sample-{group.name}" src="static/nothing.png" alt="" /> <img style="width: 200px;" id="sample-{group.name}" src="static/nothing.png" alt="" />
<ul>\n""") <div id="{nr}"><ul>''')
for box in group.generators: for box in group.generators:
name = box.__name__ name = box.__name__
if name in ("TrayLayout2", ): if name in ("TrayLayout2", ):
@ -348,10 +348,9 @@ class BServer:
if box.__doc__: if box.__doc__:
docs = " - " + _(box.__doc__) docs = " - " + _(box.__doc__)
result.append(f""" result.append(f"""
<li onmouseenter="change('{group.name}', 'static/samples/{name}-thumb.jpg')" onmouseleave="changeback('{group.name}')"><a href="{name}{langparam}">{_(name)}</a>{docs}</li>\n""") <li onmouseenter="change('{group.name}', 'static/samples/{name}-thumb.jpg')" onmouseleave="changeback('{group.name}')"><a href="{name}{langparam}">{_(name)}</a>{docs}</li>""")
result.append(""" result.append("""
</ul> </ul></div>
</div>
""") """)
result.append(""" result.append("""
</div> </div>