16
16
17
17
SETTINGS_FILE = os .path .join (Path .home (), "webtoonreader_settings.json" )
18
18
19
- # To do
20
- # Add bookmarks of where you left off on a manga
21
19
22
20
class WebtoonReader :
23
21
def __init__ (self ):
24
22
# Create settings file in the home directory if it does not exist
25
23
if not os .path .isfile (SETTINGS_FILE ):
26
24
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 )
28
26
f .close ()
29
27
30
28
@@ -35,6 +33,8 @@ def __init__(self):
35
33
self .width = get_json ('width' )
36
34
self .height = get_json ('height' )
37
35
self .scroll_speed = get_json ('scroll_speed' )
36
+ self .load = get_json ('load' )
37
+ self .invert_scroll = get_json ('invert_scroll' )
38
38
39
39
40
40
# Center Window
@@ -44,7 +44,14 @@ def __init__(self):
44
44
45
45
# ImageScroller
46
46
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 )
48
55
self .frame .pack ()
49
56
manga = os .path .basename (os .path .dirname (chapter_path ))
50
57
self .window .title ("[WebtoonReader] - " + manga + ": " + os .path .basename (chapter_path ))
@@ -115,7 +122,14 @@ def create_chapter(self, path):
115
122
116
123
# Updates the image scroller
117
124
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 )
119
133
self .frame .pack ()
120
134
121
135
# Updates settings json
@@ -145,7 +159,14 @@ def next_chapter(self):
145
159
146
160
# Updates the image scroller
147
161
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 )
149
170
self .frame .pack ()
150
171
151
172
# Updates the settings json
@@ -175,7 +196,14 @@ def prev_chapter(self):
175
196
176
197
# Updates the image scroller
177
198
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 )
179
207
self .frame .pack ()
180
208
181
209
# Updates the settings json
@@ -220,24 +248,59 @@ def set_settings(self):
220
248
self .scroll_speed_slider .set (self .scroll_speed )
221
249
self .scroll_speed_slider .pack (pady = 10 )
222
250
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 )
223
261
224
262
settings .mainloop ()
225
263
226
264
# Updates width in settings json
227
265
def update_width (self , e ):
228
266
self .width = self .width_slider .get ()
229
267
update_json ('width' , self .width_slider .get ())
268
+ self .restart_canvas ()
230
269
231
270
# Updates height in settings json
232
271
def update_height (self , e ):
233
272
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 ()
235
275
236
276
# Updates scroll speed in settings json
237
277
def update_speed (self , e ):
238
278
self .scroll_speed = self .scroll_speed_slider .get ()
239
279
update_json ('scroll_speed' , self .scroll_speed_slider .get ())
280
+ self .restart_canvas ()
240
281
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 ()
241
304
242
305
# Update the json value if key exists, otherwise adds to json
243
306
def update_json (key , value ):
@@ -260,7 +323,14 @@ def get_json(key):
260
323
json_file .close ()
261
324
return value
262
325
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 )
264
334
265
335
266
336
# Returns a natural sorted list of absolute paths directories
@@ -269,12 +339,12 @@ def abslistdir(path):
269
339
for root , dirs , files in os .walk (path ):
270
340
for dir in dirs :
271
341
list .append (os .path .join (root , dir ).replace ("\\ " , "/" ))
272
- list .sort (key = natural_sort_key )
342
+ list .sort (key = natural_sort )
273
343
return list
274
344
275
345
276
346
# Natural sort a list
277
- def natural_sort_key (list ):
347
+ def natural_sort (list ):
278
348
return [int (text ) if text .isdigit () else text .lower ()
279
349
for text in re .split (re .compile ('([0-9]+)' ), list )]
280
350
0 commit comments