Skip to content
This repository was archived by the owner on Mar 31, 2020. It is now read-only.

Commit 84d46b6

Browse files
committed
Loading Screen
1 parent 30e7ef9 commit 84d46b6

3 files changed

Lines changed: 31 additions & 1 deletion

File tree

res/images/loading.gif

442 KB
Loading

src/front.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from .animate import Direction
66
from .view import Window, View
77
from .cache import ImageCache
8-
8+
from .loading import Loading
99

1010
def process_image(image: bytes, width: int, height: int):
1111
im = Image.open(io.BytesIO(image))

src/loading.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from PIL import Image, ImageTk
2+
from time import sleep
3+
from contextlib import suppress
4+
from itertools import cycle
5+
6+
from .widget import SecondaryCanvas
7+
from . import IMAGES
8+
9+
def generate_frames(im: Image):
10+
with suppress(EOFError):
11+
while True:
12+
im.seek(im.tell()+1)
13+
yield ImageTk.PhotoImage(im)
14+
15+
class Loading(SecondaryCanvas):
16+
frames = generate_frames(Image.open(IMAGES / "loading.gif"))
17+
active = True
18+
last = 0
19+
20+
def start(self):
21+
for im in cycle(self.frames):
22+
if not self.active:
23+
break
24+
if self.last:
25+
self.delete(self.last)
26+
self.last = self.create_image(0, 0, image=im, anchor='nw')
27+
self.update()
28+
29+
def stop(self):
30+
self.active = False

0 commit comments

Comments
 (0)