Compare commits

...

3 commits

Author SHA1 Message Date
86692904a3 Pull template out to global. 2023-09-17 12:53:19 -07:00
6e3fea4160 Remove unnecessary return. 2023-09-17 12:52:55 -07:00
8483a9f136 Close PGUI on ctrl+w. 2023-09-16 12:03:00 -07:00
2 changed files with 431 additions and 417 deletions

View file

@ -84,6 +84,7 @@ class PGUILauncher(tkinter.Frame):
)
self.filter_entry.bind('<Return>', self.launch_filtered)
self.filter_entry.bind('<Escape>', self.quit)
self.filter_entry.bind('<Control-w>', self.quit)
self.open_folder_button = tkinter.Button(
self.upper_frame,
@ -97,7 +98,6 @@ class PGUILauncher(tkinter.Frame):
self.upper_frame.grid(row=0, column=0, columnspan=999, sticky='ew', padx=8, pady=8)
self.filter_entry.grid(row=0, column=0, sticky='news', padx=2, pady=2)
self.open_folder_button.grid(row=0, column=1, sticky='news', padx=2, pady=2)
return self.filter_entry
def filter(self, *args):
text = self.filter_entry.get().lower()

View file

@ -10,12 +10,7 @@ from voussoirkit import vlogging
log = vlogging.getLogger(__name__, 'imagegallery')
def imagegallery_argparse(args):
patterns = pipeable.input_many(args.patterns)
files = list(pathclass.glob_many_files(patterns))
files.sort()
html = jinja2.Template(textwrap.dedent('''
TEMPLATE = jinja2.Template('''
<html>
<head>
{% if title %}
@ -293,7 +288,9 @@ def imagegallery_argparse(args):
{% for file in files %}
<article class="photograph">
<a target="_blank" href="{{urlroot}}{{file.relative_to('.', simple=True)}}"><img loading="lazy" src="{{urlroot}}thumbs/small_{{file.relative_to('.', simple=True)}}"/></a>
{% if with_download_links %}
<a class="download_link" download="{{file.basename}}" href="{{urlroot}}{{file.relative_to('.', simple=True)}}">#{{loop.index}}/{{files|length}}</a>
{% endif %}
</article>
{% endfor %}
</body>
@ -430,10 +427,27 @@ def imagegallery_argparse(args):
document.addEventListener("DOMContentLoaded", on_pageload);
</script>
</html>
''')).render(
''')
def imagegallery(files, title, urlroot, with_download_links):
html = TEMPLATE.render(
files=files,
title=title,
urlroot=urlroot,
with_download_links=with_download_links,
)
return html
def imagegallery_argparse(args):
patterns = pipeable.input_many(args.patterns)
files = list(pathclass.glob_many_files(patterns))
files.sort()
html = imagegallery(
files=files,
title=args.title,
urlroot=args.urlroot or '',
with_download_links=True,
)
pathclass.Path('gallery.html').open('w', encoding='utf-8').write(html)
return 0