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:
2020-08-23 00:37:41 -04:00
parent d44b67dbe3
commit 909442ae32
6 changed files with 100 additions and 207 deletions

2
.gitignore vendored
View File

@@ -1 +1,3 @@
__pycache__/*
.idea
venv/*

120
main.py
View File

@@ -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():
master.title("Manga Reader")
# 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()
file = mangaFile
displayManga(file,1)
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
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
# 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])
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))
im.show()
page = pg
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()

View File

@@ -1,20 +0,0 @@
import sys
import readergui as rg
from PyQt5.QtWidgets import QMainWindow, QApplication
from PyQt5.QtCore import Qt
class Window(QMainWindow):
def __init__(self):
super(Window, self).__init__()
self.ui = rg.Ui_MainWindow()
self.ui.setupUi(self)
self.ui.nextButton.clicked.connect(self.but_test)
def but_test(self):
print("button clicked")
if __name__ == '__main__':
app = QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec())

View File

@@ -1,81 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>480</width>
<height>640</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QGraphicsView" name="mainImage">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>461</width>
<height>511</height>
</rect>
</property>
</widget>
<widget class="QDialogButtonBox" name="testBox">
<property name="geometry">
<rect>
<x>70</x>
<y>140</y>
<width>174</width>
<height>34</height>
</rect>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
<widget class="QWidget" name="">
<property name="geometry">
<rect>
<x>10</x>
<y>550</y>
<width>461</width>
<height>36</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="backButton">
<property name="text">
<string>Back</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="nextButton">
<property name="text">
<string>Next</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>480</width>
<height>30</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -1,65 +0,0 @@
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'reader.ui'
#
# Created by: PyQt5 UI code generator 5.15.0
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(480, 640)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.mainImage = QtWidgets.QGraphicsView(self.centralwidget)
self.mainImage.setGeometry(QtCore.QRect(10, 10, 461, 511))
self.mainImage.setObjectName("mainImage")
self.testBox = QtWidgets.QDialogButtonBox(self.centralwidget)
self.testBox.setGeometry(QtCore.QRect(70, 140, 174, 34))
self.testBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok)
self.testBox.setObjectName("testBox")
self.widget = QtWidgets.QWidget(self.centralwidget)
self.widget.setGeometry(QtCore.QRect(10, 550, 461, 36))
self.widget.setObjectName("widget")
self.horizontalLayout = QtWidgets.QHBoxLayout(self.widget)
self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout.setObjectName("horizontalLayout")
self.backButton = QtWidgets.QPushButton(self.widget)
self.backButton.setObjectName("backButton")
self.horizontalLayout.addWidget(self.backButton)
self.nextButton = QtWidgets.QPushButton(self.widget)
self.nextButton.setObjectName("nextButton")
self.horizontalLayout.addWidget(self.nextButton)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 480, 30))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.backButton.setText(_translate("MainWindow", "Back"))
self.nextButton.setText(_translate("MainWindow", "Next"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())

View File

@@ -1,8 +1 @@
Package Version
---------- -------
Pillow 7.2.0
pip 20.2.2
PyQt5 5.15.0
PyQt5-sip 12.8.0
setuptools 47.1.0
tk 0.1.0
Pillow==7.2.0