Skip to content

Commit 0142256

Browse files
committed
Updated CustomScroller.py
1 parent caa9b6a commit 0142256

File tree

1 file changed

+27
-39
lines changed

1 file changed

+27
-39
lines changed

CustomScroller.py

Lines changed: 27 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def __init__(self, master=None, **kw):
2525

2626
self.scroll_flag = True
2727
self.image_index = 0
28-
28+
self.top = self.canvas.yview()[1]
2929

3030
# Fill the frame with images
3131
if self.path != "":
@@ -68,25 +68,7 @@ def mouse_scroll(self, event):
6868
self.canvas.yview_scroll(self.scroll_speed, "units" )
6969

7070

71-
# If at the top of the scrollbar, load previous images
72-
if self.v_scroll.get()[1] < 0.1:
73-
if self.scroll_flag and self.image_index - self.image_load >= 0:
74-
self.image_index -= self.image_load
75-
self.fill(self.image_index)
76-
self.scroll_flag = False
77-
self.canvas.yview_moveto(1)
78-
79-
# If at the bottom of the scrollbar, load next images
80-
if self.v_scroll.get()[1] == 1:
81-
if self.scroll_flag and self.image_index + self.image_load < len(os.listdir(self.path)):
82-
self.image_index += self.image_load
83-
self.fill(self.image_index)
84-
self.scroll_flag = False
85-
self.canvas.yview_moveto(0)
86-
87-
# Enable flag to load next images
88-
if self.v_scroll.get()[1] > 0.1 and self.v_scroll.get()[1] != 1:
89-
self.scroll_flag = True
71+
self.checkLoadChapter()
9072

9173

9274

@@ -114,25 +96,7 @@ def update_scroll(self, event):
11496
self._starting_drag_position = (event.x, event.y)
11597

11698

117-
# If at the top of the scrollbar, load previous images
118-
if self.v_scroll.get()[1] < 0.1:
119-
if self.scroll_flag and self.image_index - self.image_load >= 0:
120-
self.image_index -= self.image_load
121-
self.fill(self.image_index)
122-
self.scroll_flag = False
123-
self.canvas.yview_moveto(1)
124-
125-
# If at the bottom of the scrollbar, load next images
126-
if self.v_scroll.get()[1] == 1:
127-
if self.scroll_flag and self.image_index + self.image_load < len(os.listdir(self.path)):
128-
self.image_index += self.image_load
129-
self.fill(self.image_index)
130-
self.scroll_flag = False
131-
self.canvas.yview_moveto(0)
132-
133-
# Enable flag to load next images
134-
if self.v_scroll.get()[1] > 0.1 and self.v_scroll.get()[1] != 1:
135-
self.scroll_flag = True
99+
self.checkLoadChapter()
136100

137101
def stop_scroll(self, event):
138102
self.canvas.config(xscrollincrement=0)
@@ -167,6 +131,30 @@ def fill(self, index):
167131
height = height + self.images[i].height()
168132

169133

134+
def checkLoadChapter(self):
135+
136+
# If at the top of the scrollbar, load previous images
137+
if self.v_scroll.get()[1] == self.top:
138+
if self.scroll_flag and self.image_index - self.image_load >= 0:
139+
self.image_index -= self.image_load
140+
self.fill(self.image_index)
141+
self.scroll_flag = False
142+
self.canvas.yview_moveto(1)
143+
144+
# If at the bottom of the scrollbar, load next images
145+
if self.v_scroll.get()[1] == 1:
146+
if self.scroll_flag and self.image_index + self.image_load < len(os.listdir(self.path)):
147+
self.image_index += self.image_load
148+
self.fill(self.image_index)
149+
self.scroll_flag = False
150+
self.canvas.yview_moveto(0)
151+
self.top = self.canvas.yview()[1]
152+
153+
# Enable flag to load next images
154+
if self.v_scroll.get()[1] > self.top and self.v_scroll.get()[1] != 1:
155+
self.scroll_flag = True
156+
157+
170158
# Natural sort files
171159
def natural_sort(self, l):
172160
convert = lambda text: int(text) if text.isdigit() else text.lower()

0 commit comments

Comments
 (0)