-
Notifications
You must be signed in to change notification settings - Fork 2
/
rofi.py
77 lines (67 loc) · 2.41 KB
/
rofi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import os
def generate_gallery(folder):
# Generate HTML for the gallery
html = f'''<!DOCTYPE html>
<html>
<head>
<title>Image Gallery</title>
<style>
body {{
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #111;
color: #fff;
}}
.gallery-container {{
display: grid;
grid-auto-flow: dense;
gap: 10px;
padding: 20px;
justify-content: center;
border: 2px solid #fff;
border-radius: 10px;
margin: 20px auto;
max-width: 800px;
}}
.gallery-item {{
max-width: 100%;
max-height: 100%;
object-fit: contain;
transition: transform 0.2s;
cursor: pointer; /* Add cursor pointer to indicate clickability */
}}
.gallery-item:hover {{
transform: scale(1.1);
}}
</style>
</head>
<body>
<div class="gallery-container">
'''
# Get list of image files sorted by modification date in reverse order
image_files = sorted((os.path.join(root, file) for root, _, files in os.walk(folder) for file in files if file.lower().endswith(('.png', '.jpg', '.jpeg', '.gif', '.bmp'))), key=os.path.getmtime, reverse=True)
# Add image thumbnails to the gallery
for image_path in image_files:
image_relative_path = image_path.split("/home/prtyksh/Wallpapers/")[1]
html += f'<img class="gallery-item" src="{image_relative_path}" alt="{os.path.basename(image_path)}" onclick="sendAjaxRequest(\'{image_relative_path}\')">\n'
html += '''</div>
<script>
function sendAjaxRequest(imageHref) {
var xhr = new XMLHttpRequest();
var url = 'http://localhost:8000/?query=' + encodeURIComponent(imageHref);
xhr.open('GET', url, true);
xhr.send();
}
</script>
</body>
</html>'''
return html
# Define the folder containing the images
folder_path = "/home/prtyksh/Wallpapers"
# Generate the gallery HTML
gallery_html = generate_gallery(folder_path)
# Write the HTML to a file
with open("gallery.html", "w") as f:
f.write(gallery_html)
print("Gallery generated successfully.")