diff --git a/main.py b/main.py index eac41b1..1a47794 100644 --- a/main.py +++ b/main.py @@ -27,55 +27,31 @@ class MangaReader: self.menu.add_cascade(label="File", menu=item) root.config(menu=self.menu) - # Frames self.buttonFrame = Frame(master) - self.mangaFrame = Frame(master, bg="green") - self.titleFrame = Frame(master) # forward/back buttons self.nextPg = Button(self.buttonFrame, text='>') self.nextPg.bind('', self.nextPage) self.nextPg.grid(row=0, column=2) - self.buttonFrame.grid_rowconfigure(0, weight=1) - self.buttonFrame.grid_columnconfigure(2,weight=1) - self.buttonFrame.grid(row=2, column=0, columnspan=2) - self.master.grid_rowconfigure(2, weight=1) - self.master.grid_columnconfigure(0,weight=1) - # self.buttonFrame.pack(side=BOTTOM) + self.buttonFrame.pack(side=BOTTOM) self.backPg = Button(self.buttonFrame, text='<') self.backPg.bind('', self.backPage) self.backPg.grid(row=0, column=0) - self.buttonFrame.grid_rowconfigure(0, weight=1) - self.buttonFrame.grid_columnconfigure(0,weight=1) # page counter self.pgcount = Label(self.buttonFrame, text= str(self.page) + " of " + str(self.total)) self.pgcount.grid(row=1, columns=1, columnspan=2) - self.buttonFrame.grid_rowconfigure(1, weight=1) - self.buttonFrame.grid_columnconfigure(1,weight=1) - # title frame - - self.titleFrame.grid(row=0, column=0, sticky="EW") - self.master.grid_rowconfigure(0, weight=1) - self.master.grid_columnconfigure(0,weight=1) - self.mangaTitle = Label(self.titleFrame, text=self.file) - self.mangaTitle.grid(row=0, sticky="EW") - self.titleFrame.grid_rowconfigure(0,weight=1) - self.titleFrame.grid_columnconfigure(0,weight=1) + self.mangaTitle = Label(self.buttonFrame, text=self.file) + self.mangaTitle.grid(row=0, column=1) # display image - self.mangaFrame.grid(row=1, column=0, sticky="NESW") - self.master.grid_rowconfigure(1, weight=1) - self.master.grid_columnconfigure(0,weight=1) - self.panel = Label(self.mangaFrame, image=self.img) - self.panel.grid(row=0, column=0, sticky="NESW") - self.panel.grid_rowconfigure(0, weight=1) - self.panel.grid_columnconfigure(0, weight=1) + self.panel = Label(self.master, image=self.img) + self.panel.pack() def open_menu(self): - # file dialog. reset page counts, call display Manga passing in starting values - mangaFile = filedialog.askopenfilename() + # file dialog. reset page counts, call display Maanga passing in starting values + mangaFile = filedialog.askopenfilename(initialdir = "/home/dan/Desktop/") self.file = mangaFile self.page = 0 self.total = 0 @@ -83,9 +59,10 @@ class MangaReader: self.displayManga(self.file, 0) def displayManga(self, file, pg): - basewidth = 500 + #basewidth = 500 + hsize = self.master.winfo_height() - self.buttonFrame.winfo_height() - self.menu.winfo_height() + wsize = 500 - basewidth = self.mangaFrame.winfo_width() with zf(file, 'r') as zip: # grab all the manga pages from the cbz file and sort them to put them in the correct order fl = zip.namelist() @@ -95,23 +72,25 @@ class MangaReader: data = zip.read(fl[pg]) im = Image.open(io.BytesIO(data)) - # I found the below code to maintain image ratios at https://stackoverflow.com/questions/273946/how-do-i-resize-an-image-using-pil-and-maintain-its-aspect-ratio - wpercent = (basewidth / float(im.size[0])) - hsize = int((float(im.size[1]) * float(wpercent))) + # wpercent = (basewidth / float(im.size[0])) + # hsize = int((float(im.size[1]) * float(wpercent))) - im = im.resize((basewidth, hsize), Image.ANTIALIAS) - # convert to tkImage and update the on screen image. + + im = im.resize((wsize, hsize), Image.ANTIALIAS) + #convert to tkImage and update the on screen image. self.img = ImageTk.PhotoImage(im) self.panel.config(image=self.img) - # finally update the current page count + #finally update the current page count self.pgcount.configure(text=str(pg+1) + " of " + str(self.total)) + self.master.config(width=wsize) + def nextPage(self, event): self.page = self.page + 1 if self.page < self.total: self.displayManga(self.file, self.page) else: - # reset self.page and doNothing + #reset self.page and doNothing self.page = self.page - 1 # self.doNothing() @@ -120,7 +99,7 @@ class MangaReader: if self.page >= 0: self.displayManga(self.file, self.page) else: - # reset self.page and doNothing + #reset self.page and doNothing self.page = self.page + 1 # self.doNothing() @@ -128,7 +107,8 @@ class MangaReader: print(self.page) print("FUCCK YOU") -# initalize tk + +#initalize tk root=Tk() app = MangaReader(root) root.mainloop()