69 lines
2.0 KiB
Python
69 lines
2.0 KiB
Python
#!/usr/bin/env python3
|
|
# -*- encoding: utf-8 -*-
|
|
|
|
import traceback
|
|
from io import BytesIO
|
|
from pathlib import Path
|
|
from typing import Optional
|
|
|
|
from PIL import Image
|
|
|
|
from .system.downloader.downloadedData import MainApp
|
|
|
|
millisamount = 10
|
|
|
|
AnyInt = Optional[int]
|
|
|
|
|
|
def updateImage(tk: MainApp, old_url_modified: AnyInt, old_file_modified: AnyInt, old_file_sz: AnyInt):
|
|
try:
|
|
path_file = Path('latest_put_image.file')
|
|
path_url = Path('latest_put_image.url')
|
|
new_url_modified = None
|
|
new_file_modified = None
|
|
new_file_sz = None
|
|
try:
|
|
st = path_url.stat()
|
|
new_url_modified = st.st_mtime_ns
|
|
except BaseException:
|
|
pass
|
|
try:
|
|
st = path_file.stat()
|
|
new_file_modified = st.st_mtime_ns
|
|
new_file_sz = st.st_size
|
|
except BaseException:
|
|
pass
|
|
tk.after(millisamount, updateImage, tk,
|
|
new_url_modified, new_file_modified, new_file_sz)
|
|
if old_url_modified != new_url_modified or old_file_modified != new_file_modified or old_file_sz != new_file_sz:
|
|
url = None
|
|
bts = None
|
|
try:
|
|
url = path_url.read_text()
|
|
bts = path_file.read_bytes()
|
|
except BaseException:
|
|
pass
|
|
if url is not None and bts is not None:
|
|
try:
|
|
tk.update_image(Image.open(BytesIO(bts)), url)
|
|
except BaseException:
|
|
print()
|
|
print("Exception on link %r" % url)
|
|
traceback.print_exc()
|
|
if ((old_url_modified is not None or old_file_modified is not None) and (new_url_modified is None and new_file_modified is None)):
|
|
tk.destroy()
|
|
except BaseException:
|
|
print()
|
|
traceback.print_exc()
|
|
tk.destroy()
|
|
|
|
|
|
def main():
|
|
tk = MainApp()
|
|
tk.after(1, updateImage, tk, None, None, None)
|
|
tk.mainloop()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|