<gh_stars>0
import sys
from PyQt5 import QtWidgets, QtGui, QtCore

##### App Configuration
app = QtWidgets.QApplication(sys.argv)
window = QtWidgets.QWidget()
window.setWindowTitle("Bookshelf")
#window.setWindowIcon("")
window.setFixedSize(400, 800)
color = window.palette()
color.setColor(window.backgroundRole(), QtCore.Qt.lightGray)
window.setPalette(color)


### Book Class & Functions
bookshelf = list()


class Book:
    """ A Book class with Name, Author and Page properties. """

    def __init__(self, bookname, bookauthor, bookpage):
        self.bookname = bookname
        self.bookauthor = bookauthor
        self.bookpage = bookpage

    def changeName(self, bookname):
        self.bookname = bookname

    def changeAuthor(self, bookauthor):
        self.bookauthor = bookauthor

    def changePage(self, bookpage):
        self.bookpage = bookpage


bookshelf.append(Book("Dune", "<NAME>", 500))
bookshelf.append(Book("LOTR", "JRRR Tolkien", 700))
bookshelf.append(Book("Işık Tanrısı", "<NAME>", 700))
bookshelf.append(Book("Babalar ve Oğullar", "<NAME>", 700))
########## AddBook Popup Setting ##########

addBookWindow = QtWidgets.QWidget()
addBookWindow.setWindowTitle("Bookshelf")
#addBookWindow.setWindowIcon("")
addBookWindow.setFixedSize(400, 240)
color = window.palette()
color.setColor(window.backgroundRole(), QtCore.Qt.lightGray)
addBookWindow.setPalette(color)

### Input for book name, author and page
addBookTitle = QtWidgets.QLabel(addBookWindow)
addBookTitle.setText("Enter book name:")
addBookTitle.move(25, 15)

addBookName = QtWidgets.QPlainTextEdit(addBookWindow)
addBookName.move(25, 30)
addBookName.resize(350, 25)

addBookAuthorTitle = QtWidgets.QLabel(addBookWindow)
addBookAuthorTitle.setText("Enter book author:")
addBookAuthorTitle.move(25, 70)

addBookAuthor = QtWidgets.QPlainTextEdit(addBookWindow)
addBookAuthor.move(25, 85)
addBookAuthor.resize(350, 25)

addBookPageTitle = QtWidgets.QLabel(addBookWindow)
addBookPageTitle.setText("Enter book page:")
addBookPageTitle.move(25, 125)

addBookPage = QtWidgets.QSpinBox(addBookWindow)
addBookPage.move(25, 140)
addBookPage.resize(350, 25)

addBookButton = QtWidgets.QPushButton(addBookWindow)
addBookButton.setText("Add Book")
addBookButton.move(150, 185)
addBookButton.resize(100, 40)


def addBook():
    global window
    global bookshelf
    bookName = addBookName.toPlainText()
    bookAuthor = addBookAuthor.toPlainText()
    bookPage = addBookPage.text()
    bookshelf.append(Book(bookName, bookAuthor, bookPage))

    addBookName.setPlainText("")
    addBookAuthor.setPlainText("")
    addBookPage.setValue(0)

    addBookWindow.close()
    #window.QApplication.processEvents()
    listBooks()
    print(bookshelf)


addBookButton.clicked.connect(addBook)


### Add Book Button
def addBookPopup():
    addBookWindow.show()


openAddWindow = QtWidgets.QPushButton(window)
openAddWindow.move(100, 25)
openAddWindow.resize(200, 30)
openAddWindow.setText("Open Add Book Window")
openAddWindow.clicked.connect(addBookPopup)

### Divider
divider = QtWidgets.QLabel(window)
divider.setText("-------------------------")
divider.move(150, 65)


def listBooks():
    for i in range(len(bookshelf)):
        bk = QtWidgets.QLabel(window)
        bk.setText(f"{i+1}- {bookshelf[i].bookname} ({bookshelf[i].bookauthor})")
        bk.move(25, 100+i*50)


##### Run
listBooks()
window.show()
sys.exit(app.exec_())
