1616
1717SETTINGS_FILE = os .path .join (Path .home (), "webtoonreader_settings.json" )
1818
19- # To do
20- # Add bookmarks of where you left off on a manga
2119
2220class WebtoonReader :
2321 def __init__ (self ):
2422 # Create settings file in the home directory if it does not exist
2523 if not os .path .isfile (SETTINGS_FILE ):
2624 with open (SETTINGS_FILE , "a" ) as f :
27- json .dump ({"library" : os .getcwd (), "width" : 720 , "height" : 800 , "scroll_speed" : 3 , "recent_chapter" : "" , "recent_chapter_index" : "" }, f )
25+ json .dump ({"library" : os .getcwd (), "width" : 720 , "height" : 800 , "scroll_speed" : 3 , "recent_chapter" : "" , "recent_chapter_index" : "" , "load" : 5 , "invert_scroll" : False }, f )
2826 f .close ()
2927
3028
@@ -35,6 +33,8 @@ def __init__(self):
3533 self .width = get_json ('width' )
3634 self .height = get_json ('height' )
3735 self .scroll_speed = get_json ('scroll_speed' )
36+ self .load = get_json ('load' )
37+ self .invert_scroll = get_json ('invert_scroll' )
3838
3939
4040 # Center Window
@@ -44,7 +44,14 @@ def __init__(self):
4444
4545 # ImageScroller
4646 chapter_path = get_json ('recent_chapter' )
47- self .frame = ImageScroller (self .window , path = chapter_path , scrollbarwidth = 15 , width = self .width , height = self .height , speed = self .scroll_speed )
47+ self .frame = ImageScroller (self .window ,
48+ path = chapter_path ,
49+ scrollbarwidth = 15 ,
50+ width = self .width ,
51+ height = self .height ,
52+ speed = self .scroll_speed ,
53+ load = self .load ,
54+ invert = self .invert_scroll )
4855 self .frame .pack ()
4956 manga = os .path .basename (os .path .dirname (chapter_path ))
5057 self .window .title ("[WebtoonReader] - " + manga + ": " + os .path .basename (chapter_path ))
@@ -115,7 +122,14 @@ def create_chapter(self, path):
115122
116123 # Updates the image scroller
117124 self .frame .destroy ()
118- self .frame = ImageScroller (self .window , path = chapter_path , scrollbarwidth = 15 , width = self .width , height = self .height , speed = self .scroll_speed )
125+ self .frame = ImageScroller (self .window ,
126+ path = chapter_path ,
127+ scrollbarwidth = 15 ,
128+ width = self .width ,
129+ height = self .height ,
130+ speed = self .scroll_speed ,
131+ load = self .load ,
132+ invert = self .invert_scroll )
119133 self .frame .pack ()
120134
121135 # Updates settings json
@@ -145,7 +159,14 @@ def next_chapter(self):
145159
146160 # Updates the image scroller
147161 self .frame .destroy ()
148- self .frame = ImageScroller (self .window , path = chapter_path , scrollbarwidth = 15 , width = self .width , height = self .height , speed = self .scroll_speed )
162+ self .frame = ImageScroller (self .window ,
163+ path = chapter_path ,
164+ scrollbarwidth = 15 ,
165+ width = self .width ,
166+ height = self .height ,
167+ speed = self .scroll_speed ,
168+ load = self .load ,
169+ invert = self .invert_scroll )
149170 self .frame .pack ()
150171
151172 # Updates the settings json
@@ -175,7 +196,14 @@ def prev_chapter(self):
175196
176197 # Updates the image scroller
177198 self .frame .destroy ()
178- self .frame = ImageScroller (self .window , path = chapter_path , scrollbarwidth = 15 , width = self .width , height = self .height , speed = self .scroll_speed )
199+ self .frame = ImageScroller (self .window ,
200+ path = chapter_path ,
201+ scrollbarwidth = 15 ,
202+ width = self .width ,
203+ height = self .height ,
204+ speed = self .scroll_speed ,
205+ load = self .load ,
206+ invert = self .invert_scroll )
179207 self .frame .pack ()
180208
181209 # Updates the settings json
@@ -220,24 +248,59 @@ def set_settings(self):
220248 self .scroll_speed_slider .set (self .scroll_speed )
221249 self .scroll_speed_slider .pack (pady = 10 )
222250 self .scroll_speed_slider .bind ("<ButtonRelease-1>" , self .update_speed )
251+
252+ invert_label = tk .Label (settings , text = "Invert Scroll" ).pack (pady = 10 )
253+ self .invert_checkbox = tk .IntVar ()
254+ self .checkbutton = tk .Checkbutton (settings , variable = self .invert_checkbox )
255+ if self .invert_scroll :
256+ self .checkbutton .select ()
257+ else :
258+ self .checkbutton .deselect ()
259+ self .checkbutton .pack (pady = 10 )
260+ self .checkbutton .bind ("<ButtonRelease-1>" , self .update_invert )
223261
224262 settings .mainloop ()
225263
226264 # Updates width in settings json
227265 def update_width (self , e ):
228266 self .width = self .width_slider .get ()
229267 update_json ('width' , self .width_slider .get ())
268+ self .restart_canvas ()
230269
231270 # Updates height in settings json
232271 def update_height (self , e ):
233272 self .height = self .height_slider .get ()
234- update_json ('height' , self .height_slider .get ())
273+ update_json ('height' , self .height_slider .get ())
274+ self .restart_canvas ()
235275
236276 # Updates scroll speed in settings json
237277 def update_speed (self , e ):
238278 self .scroll_speed = self .scroll_speed_slider .get ()
239279 update_json ('scroll_speed' , self .scroll_speed_slider .get ())
280+ self .restart_canvas ()
240281
282+ def update_invert (self , e ):
283+ if self .invert_checkbox .get () == 0 :
284+ update_json ('invert_scroll' , True )
285+ self .invert_scroll = True
286+ else :
287+ update_json ('invert_scroll' , False )
288+ self .invert_scroll = False
289+ self .restart_canvas ()
290+
291+
292+ def restart_canvas (self ):
293+ chapter_path = get_json ('recent_chapter' )
294+ self .frame .destroy ()
295+ self .frame = ImageScroller (self .window ,
296+ path = chapter_path ,
297+ scrollbarwidth = 15 ,
298+ width = self .width ,
299+ height = self .height ,
300+ speed = self .scroll_speed ,
301+ load = self .load ,
302+ invert = self .invert_scroll )
303+ self .frame .pack ()
241304
242305# Update the json value if key exists, otherwise adds to json
243306def update_json (key , value ):
@@ -260,7 +323,14 @@ def get_json(key):
260323 json_file .close ()
261324 return value
262325 json_file .close ()
263- return None
326+
327+ # Recreate the settings file if its broken
328+ if os .path .isfile (SETTINGS_FILE ):
329+ os .remove (SETTINGS_FILE )
330+ with open (SETTINGS_FILE , "a" ) as f :
331+ json .dump ({"library" : os .getcwd (), "width" : 720 , "height" : 800 , "scroll_speed" : 3 , "recent_chapter" : "" , "recent_chapter_index" : "" , "load" : 5 , "invert_scroll" : False }, f )
332+ f .close ()
333+ return get_json (key )
264334
265335
266336# Returns a natural sorted list of absolute paths directories
@@ -269,12 +339,12 @@ def abslistdir(path):
269339 for root , dirs , files in os .walk (path ):
270340 for dir in dirs :
271341 list .append (os .path .join (root , dir ).replace ("\\ " , "/" ))
272- list .sort (key = natural_sort_key )
342+ list .sort (key = natural_sort )
273343 return list
274344
275345
276346# Natural sort a list
277- def natural_sort_key (list ):
347+ def natural_sort (list ):
278348 return [int (text ) if text .isdigit () else text .lower ()
279349 for text in re .split (re .compile ('([0-9]+)' ), list )]
280350
0 commit comments