Fixed the required.txt file. Removed old pyqt5 files and package requirements. Got forward/backward buttons working. Page is now displayed in the gui.
This commit is contained in:
130
main.py
130
main.py
@@ -1,45 +1,109 @@
|
||||
from tkinter import *
|
||||
from tkinter import filedialog
|
||||
from zipfile import ZipFile as zf
|
||||
from PIL import Image
|
||||
import time
|
||||
from PIL import Image, ImageTk
|
||||
import io
|
||||
|
||||
page = 0
|
||||
file = ''
|
||||
class MangaReader:
|
||||
def __init__(self, master):
|
||||
self.master = master
|
||||
self.page = 0
|
||||
self.total = 0
|
||||
self.file = 'None'
|
||||
self.img = ''
|
||||
|
||||
def open_menu():
|
||||
mangaFile = filedialog.askopenfilename()
|
||||
file = mangaFile
|
||||
displayManga(file,1)
|
||||
master.title("Manga Reader")
|
||||
|
||||
def displayManga(file,pg):
|
||||
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()
|
||||
fl.sort()
|
||||
data = zip.read(fl[pg-1])
|
||||
im = Image.open(io.BytesIO(data))
|
||||
im.show()
|
||||
page = pg
|
||||
# tk window size and allow resize
|
||||
master.geometry("700x900")
|
||||
master.resizable(width=True, height=True)
|
||||
|
||||
# Menu Bar
|
||||
self.menu = Menu(master)
|
||||
item = Menu(self.menu)
|
||||
item.add_command(label="Open", command=self.open_menu)
|
||||
item.add_separator()
|
||||
item.add_command(label="Exit", command=master.quit)
|
||||
self.menu.add_cascade(label="File", menu=item)
|
||||
root.config(menu=self.menu)
|
||||
|
||||
self.buttonFrame = 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.pack(side=BOTTOM)
|
||||
self.backPg = Button(self.buttonFrame, text='<')
|
||||
self.backPg.bind('<Button-1>', self.backPage)
|
||||
self.backPg.grid(row=0, column=0)
|
||||
|
||||
# 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.mangaTitle = Label(self.buttonFrame, text=self.file)
|
||||
self.mangaTitle.grid(row=0, column=1)
|
||||
|
||||
# display image
|
||||
self.panel = Label(self.master, image=self.img)
|
||||
self.panel.pack()
|
||||
|
||||
def open_menu(self):
|
||||
# file dialog. reset page counts, call display Maanga passing in starting values
|
||||
mangaFile = filedialog.askopenfilename()
|
||||
self.file = mangaFile
|
||||
self.page = 0
|
||||
self.total = 0
|
||||
self.mangaTitle.configure(text=self.file)
|
||||
self.displayManga(self.file, 0)
|
||||
|
||||
def displayManga(self, file, pg):
|
||||
basewidth = 500
|
||||
|
||||
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()
|
||||
fl.sort()
|
||||
self.total = len(fl)-1
|
||||
# grab the current page out of the array. treat it as byte data since it's still zipped.
|
||||
data = zip.read(fl[pg])
|
||||
im = Image.open(io.BytesIO(data))
|
||||
|
||||
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.
|
||||
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))
|
||||
|
||||
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
|
||||
self.page = self.page - 1
|
||||
# self.doNothing()
|
||||
|
||||
def backPage(self, event):
|
||||
self.page = self.page - 1
|
||||
if self.page >= 0:
|
||||
self.displayManga(self.file, self.page)
|
||||
else:
|
||||
#reset self.page and doNothing
|
||||
self.page = self.page + 1
|
||||
# self.doNothing()
|
||||
|
||||
def doNothing(self):
|
||||
print(self.page)
|
||||
print("FUCCK YOU")
|
||||
|
||||
|
||||
#initalize tk
|
||||
root=Tk()
|
||||
root.title("Manga Reader")
|
||||
|
||||
#tk window size and allow resize
|
||||
root.geometry("500x300")
|
||||
root.resizable(width=True, height=True)
|
||||
|
||||
#Menu Bar
|
||||
menu = Menu(root)
|
||||
item = Menu(menu)
|
||||
item.add_command(label="Open", command=open_menu)
|
||||
item.add_separator()
|
||||
item.add_command(label="Exit", command=root.quit)
|
||||
menu.add_cascade(label="File", menu=item)
|
||||
root.config(menu=menu)
|
||||
|
||||
|
||||
app = MangaReader(root)
|
||||
root.mainloop()
|
||||
|
||||
Reference in New Issue
Block a user