77from .cache import ImageCache
88from .loading import Loading
99
10+
1011def process_image (image : bytes , width : int , height : int ):
1112 im = Image .open (io .BytesIO (image ))
1213 im = im .resize ((width , height ), Image .NEAREST )
@@ -23,19 +24,27 @@ class Front(widget.PrimaryFrame):
2324 _last = None
2425
2526 def __next (self , direction : Direction = None ):
26- data : dict = self .cache .next ()
27- image = process_image (
28- data .pop ('image' ),
29- self .window .winfo_width (),
30- self .window .winfo_height ()
31- )
32- name = data .pop ('name' )
33- self .__load (name , image , data )
34- if direction is None :
35- self .window .set_view (self .image )
36- else :
27+ if self .cache .ready ():
28+ data : dict = self .cache .next ()
29+ image = process_image (
30+ data .pop ('image' ),
31+ self .window .winfo_width (),
32+ self .window .winfo_height ()
33+ )
34+ name = data .pop ('name' )
35+ self .__load (name , image , data )
3736 self .window .change_view (self .image , direction )
3837
38+ else :
39+ loadscreen = Loading (
40+ self .window ,
41+ width = self .window .winfo_width (),
42+ height = self .window .winfo_height ()
43+ )
44+ self .window .change_view (View (loadscreen , 'widget' ), direction )
45+ loadscreen .waitfor (self .cache .ready , self .__next , ('up' ,))
46+ self .update ()
47+
3948 def __load (self , name , image , data ):
4049 self .title .config (text = name )
4150 self .image = View (image , 'image' )
@@ -72,6 +81,8 @@ def init(self):
7281
7382 self .cache = ImageCache (self .cachesize )
7483 self .cache .start ()
84+
85+ def start (self ):
7586 self .after (0 , self .__next )
7687
7788 def cmd_dislike (self ):
0 commit comments