ignoring the frame work I started on the main branch. This one seems to be a better starting point. I have it scaling the verticle size to the fit the window now. Working on resizing the window to fit the image. Also need to work on resizing width to maintain aspect ratio

This commit is contained in:
Dan
2021-05-07 00:50:09 -04:00
parent 39341595c6
commit 7e33775b4f

54
main.py
View File

@@ -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('<Button-1>', 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('<Button-1>', 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,17 +72,19 @@ 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)
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
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:
@@ -128,6 +107,7 @@ class MangaReader:
print(self.page)
print("FUCCK YOU")
#initalize tk
root=Tk()
app = MangaReader(root)