Skip to content

Commit

Permalink
add class to separate novel from callback management
Browse files Browse the repository at this point in the history
  • Loading branch information
safirex committed Aug 4, 2022
1 parent fe54154 commit a78ea5c
Showing 1 changed file with 32 additions and 12 deletions.
44 changes: 32 additions & 12 deletions src/Downloaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,18 @@
from enum import Enum, auto

class Callbacks(Enum):
chapterListFetched = auto(),
ChapterListFetched = auto(),
ChapterBeginUpdate = auto(),
ChapterBeginFetch = auto(),
ChapterEndFetch = auto(),
NovelBeginUpdate = auto(),
NovelBeginTOCFetch = auto(),
NovelEndTOCFetch = auto(),
NovelNotFound = auto(),


class NovelCallbacks():
"""gives to subclass a"""
class SystemCallbacks():
"""gives to subclass a callback interface"""
def __init__(self, enum: Enum = Callbacks):
self.enum = enum
self.callbacks_dict = dict()
Expand All @@ -27,7 +33,11 @@ def init_callback_list(self):
self.callbacks_dict[enum] = []

def registerCallback(self, hook: Enum, callback):
"""add a the callback to the method called on hook call"""
self.callbacks_dict.get(hook).append(callback)

def removeCallback(self, hook: Enum, callback):
self.callbacks_dict.get(hook).remove(callback)

def exec_callbacks(self,hook: Enum ,args=None):
for method in self.callbacks_dict[hook]:
Expand All @@ -39,25 +49,35 @@ def exec_callbacks(self,hook: Enum ,args=None):
method(args)


class NovelCallbacks(SystemCallbacks):
"""middle-man between callback implementation and novel class for more visibility"""
def __init__(self):
super().__init__()
self.init_callbacks()


def init_callbacks(self):
"""create a Novel basic callback"""
self.registerCallback(Callbacks.ChapterBeginUpdate,self.tempFunc)
self.registerCallback(Callbacks.ChapterListFetched,self.onChapterListFetched)

def tempFunc(self):
print("callback works")

def onChapterListFetched(self):
print("chapter list obtained")


class Novel(NovelCallbacks):
def __init__(self, codeNovel, titreNovel, keep_text_format=False):
super(Novel, self).__init__()
self.code = codeNovel
self.titre = titreNovel
self.keep_text_format = keep_text_format
self.init_callbacks()
# should be used to return a
if(type(self)==Novel):
self.updateObject()


def init_callbacks(self):
"""create a Novel basic callback"""
self.registerCallback(Callbacks.ChapterBeginUpdate,self.tempFunc)

def tempFunc(self):
print("callback works")

def downloadNovel(self, chapter) -> str:
"""download chapter from site."""
pass
Expand Down

0 comments on commit a78ea5c

Please sign in to comment.