def addManga(ignore=''): global mangas name=mangaAdd_entry.get().lower() temp = Manga(name) temp.update_chapterList() if len(temp.chapterList_updates)==0: #does this acctually exist? rmtree("files/"+temp.name) #if not exits, then delete what was made else: #update our manga list that we have for x in walk('files'): #same as up top that was to start it all out mangas=x[1] break for x in xrange(len(mangas)): #again, same as up top mangas[x]=Manga(mangas[x]) mangaList.delete(0,END) #clear out the old list for manga in mangas: #bring in the new list mangaList.insert(END,manga.name) mangaList.selection_set(0)#set the default to view at 0 viewManga() #show the info of the first one
class MangaFrame(Frame): #self.name ==> name of the manga #self.manga ==> manga object that does the housekeeping like things for us #self.__PICTURE ==> Tkinter.Label that hols the image from self.manga.image and displays it #self.__NAME ==> Tkinter label that says the title of the manga #self.__CHAPTERS ==> Displays how many chapters we have def __init__(self,parent,name,*args,**kwargs): self.name=name self.manga=Manga(self.name) self.archive=archive(self.name) if not "relief" in kwargs: kwargs["relief"]=RAISED if not "borderwidth" in kwargs: kwargs["borderwidth"]=3 Frame.__init__(self,parent,*args,**kwargs) self.__PICTURE=Label(self,image=self.getImage()) self.__PICTURE.grid(row=0,column=0,sticky=N+S+E+W) self.grid_rowconfigure(0,weight=1) self.grid_columnconfigure(0,weight=1) self.__NAME=Label(self,text=self.name) self.__NAME.grid(row=1,column=0,sticky=S) self.__CHAPTERS=Label(self,text="{} Chapters".format(len(self.manga.chapterList_have))) self.__CHAPTERS.grid(row=2,column=0,sticky=S) self.inProgress=False #to tell if the button should say update or cancel in the lower menu self.downloadInProgress=False self.archivingInProgress=False def redraw(self): self.__PICTURE.config(image=self.manga.getImage()) self.manga.update_chapterList_have() self.__CHAPTERS.config(text="%d Chapters"%len(self.manga.chapterList_have)) if(self.numberOfUpdates()==0):self.__setBackgroundColor("light grey") else:self.__setBackgroundColor("green") def bind(self,EVENT_NAME,FUNCTION,ADD=None): # ===== PLEASE ADD TO ME ===== #all new elements this frame ever gets needs to be added to this list #or esle there will be dead spots where clicking does nothing #This must modify the event passed to the widgets so that it calls the frame parent and not the children Labels Frame.bind(self,EVENT_NAME,FUNCTION,ADD) #give the event to the function as if this Frame (aka self) called it #this way if the event is passed to the child, it is instead passed to the frame self.__PICTURE.bind(EVENT_NAME,lambda event: FUNCTION(self.__FIX_EVENT_FOR_BINDING(event)),ADD) self.__NAME.bind(EVENT_NAME,lambda event: FUNCTION(self.__FIX_EVENT_FOR_BINDING(event)),ADD) self.__CHAPTERS.bind(EVENT_NAME,lambda event: FUNCTION(self.__FIX_EVENT_FOR_BINDING(event)),ADD) def __FIX_EVENT_FOR_BINDING(self,event): #assigns ourselves as the calling widget and not any of our children for any event that happens event.widget=self #yes, equals self return event def __setBackgroundColor(self,color): self.config(bg=color) for x in self.winfo_children(): x.config(bg=color) def updateManga(self,LowerFrame): if self.inProgress:return #DONT LET US TRY TO UPDATE THE SAME WAY MULTIPLE TIMES if(self.manga.numberOfUpdates()==0):self.updateManga_check() #check online for updates self.inProgress=True self.LowerFrame=LowerFrame self.downloadInProgress=True self.thread=Thread(target=self.manga.download_updates) self.thread.daemon=True #if the main prog dies, it takes all the threads with it self.thread.start() self.after(10,self.checkUpdate) def updateManga_check(self): if self.inProgress:return #DONT LET US TRY TO UPDATE THE SAME WAY MULTIPLE TIMES self.inProgress=True self.manga.update_chapterList() #check online for updates self.inProgress=False self.redraw() #since our image got screwed with, lets redraw it def checkUpdate(self,*args): self.LowerFrame.redraw() #if something here changed, then make sure to make the user notice if(self.thread.is_alive()): self.after(50,self.checkUpdate) else: print "Finished Updating "+self.getName() self.inProgress=False self.downloadInProgress=False self.redraw() self.LowerFrame.redraw() #fix the updates button self.archiveManga() #we need to update the zip files return def archiveManga(self): if(self.inProgress):return self.inProgress=True self.archivingInProgress=True self.archive.update_chaptersHave() #set it up for things self.thread=Thread(target=self.archive.update_zipFiles) self.thread.daemon=True self.thread.start() self.after(10,self.checkArchive) def checkArchive(self): self.LowerFrame.redraw() if(self.thread.is_alive()): self.after(50,self.checkArchive) else: print "Finished Updating "+self.getName() self.archivingInProgress=False self.inProgress=False self.redraw() self.LowerFrame.redraw() return def cancelUpdate(self): if not self.inProgress:return #we arn't updating so there is no cancel self.manga.cancelCurrentDownload() #this puts up a stop flag and it will finish the chapter and then exit cleanly self.LowerFrame.redraw() def numberOfUpdates(self):return self.manga.numberOfUpdates() def numberOfChapters(self):return self.manga.numberOfChapters() def getStatus(self): if(self.downloadInProgress):return self.manga.getStatus() if(self.archivingInProgress):return self.archive.getStatus() return "" def getSummary(self):return self.manga.getSummary() def getName(self):return self.manga.getName() def getImage(self): self.image=self.manga.getImage() return self.image def getProgress(self): if(self.downloadInProgress): #returns a percentage of X of 100 of how far we are done try:chapterPercentage=(100/self.numberOfUpdates())*(self.manga.curtMangaDownloading()-1) except ZeroDivisionError: chapterPercentage=0 averageNumberOfImagesInAMangaChapter=30 try: imagePercentage=(100/(self.numberOfUpdates()*averageNumberOfImagesInAMangaChapter))*(self.manga.curtImageDownloading()-1) except ZeroDivisionError: imagePercentage=0 return chapterPercentage+imagePercentage if(self.archivingInProgress): return (100/self.numberOfChapters())*self.archive.curtChapter() return 0 #we are doing nothing so no progress