Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from PyQt5.QtCore import *
- from PyQt5.QtGui import *
- import MySQLdb
- from PyQt5.QtWidgets import *
- import sys
- from PyQt5.uic import loadUiType
- ui, _ = loadUiType('library.ui')
- class MainApp(QMainWindow, ui):
- def __init__(self):
- QMainWindow.__init__(self)
- self.setupUi(self)
- self.Handle_UI_Changes()
- self.Handle_Buttons()
- def Handle_UI_Changes(self):
- self.Hiding_Themes()
- self.tabWidget.tabBar().setVisible(False)
- self.tabWidget.setCurrentIndex(0)
- self.tabWidget_3.setCurrentIndex(0)
- self.Show_Category()
- self.Show_Author()
- self.Show_Publisher()
- self.Show_Publisher_Combobox()
- self.Show_Category_Combobox()
- self.Show_Author_Combobox()
- def Handle_Buttons(self):
- self.hideThemeButton.clicked.connect(self.Hiding_Themes)
- self.showThemeButton.clicked.connect(self.Show_Themes)
- self.showDayButton.clicked.connect(self.Open_Day_To_Day_Tab)
- self.showBooksButton.clicked.connect(self.Open_Books_Tab)
- self.showUsersButton.clicked.connect(self.Open_Users_Tab)
- self.showSettingsButton.clicked.connect(self.Open_Settings_Tab)
- self.addCategoryButton.clicked.connect(self.Add_Category)
- self.addAuthorButton.clicked.connect(self.Add_Author)
- self.addPublisherButton.clicked.connect(self.Add_Publisher)
- def Show_Themes(self):
- self.themeGroupBox.show()
- def Hiding_Themes(self):
- self.themeGroupBox.hide()
- ##########################################################
- #######################opening Tabs#######################
- def Open_Day_To_Day_Tab(self):
- self.tabWidget.setCurrentIndex(0)
- def Open_Books_Tab(self):
- self.tabWidget.setCurrentIndex(1)
- def Open_Users_Tab(self):
- self.tabWidget.setCurrentIndex(2)
- def Open_Settings_Tab(self):
- self.tabWidget.setCurrentIndex(3)
- ####################Books#################################
- def Add_New_Book(self):
- self.db = MySQLdb.connect(host='localhost',user='root',password='Fabella10',db='library')
- self.cur = self.db.cursor()
- book_title = self.addNewBookTitle_LE.text()
- book_code = self.addNewBookCode_LE.text()
- book_category = self.addNewBookCategory_COMBO.CurrentText()
- book_author = self.addNewBookAuthor_COMBO.CurrentText()
- book_publisher = self.addNewBookPublisher_COMBO.CurrentText()
- book_price = self.addNewBookCode_LE.text()
- book_description = self.addNewBookDescription.toPlainText()
- self.cur.execute('''
- INSERT INTO book
- VALUES (%s , %s, %s, %s, %s, %s, %s)
- '''),(book_title, book_description, book_code, book_category, book_author, book_publisher, book_price)
- self.db.commit()
- self.statusBar().showMessage('New Book Added')
- def Search_Books(self):
- pass
- def Edit_Books(self):
- pass
- def Delete_Books(self):
- pass
- ####################Settings -- ADD#######################
- def Add_Category(self):
- self.db = MySQLdb.connect(host='localhost',user='root',password='Fabella10',db='library')
- self.cur = self.db.cursor()
- category_name = self.addCategoryLine.text()
- self.cur.execute('''
- INSERT INTO category(category_name) VALUES(%s)
- ''', (category_name,))
- self.db.commit()
- self.addCategoryLine.setText('')
- self.categoryTable.setRowCount(0)
- self.Show_Category()
- self.statusBar().showMessage('New Category Added')
- def Add_Author(self):
- self.db = MySQLdb.connect(host='localhost',user='root',password='Fabella10',db='library')
- self.cur = self.db.cursor()
- author_name = self.addAuthorLine.text()
- self.cur.execute('''
- INSERT INTO authors(author_name) VALUES(%s)
- ''', (author_name,))
- self.db.commit()
- self.addAuthorLine.setText('')
- self.authorTable.setRowCount(0)
- self.Show_Author()
- self.statusBar().showMessage('New Author Added')
- def Add_Publisher(self):
- self.db = MySQLdb.connect(host='localhost',user='root',password='Fabella10',db='library')
- self.cur = self.db.cursor()
- publisher_name = self.addPublisherLine.text()
- self.cur.execute('''
- INSERT INTO publisher(publisher_name) VALUES(%s)
- ''',(publisher_name,))
- self.db.commit()
- self.addPublisherLine.setText('')
- self.publisherTable.setRowCount(0)
- self.Show_Publisher()
- self.statusBar().showMessage('New Publisher Added')
- ####################Settings -- SHOW######################
- def Show_Category(self):
- self.db = MySQLdb.connect(host='localhost', user='root', password='Fabella10', db='library')
- self.cur = self.db.cursor()
- self.cur.execute('''
- SELECT category_name FROM category
- ''')
- data = self.cur.fetchall()
- if data:
- self.categoryTable.insertRow(0)
- for row, form in enumerate(data):
- for column,item in enumerate(form):
- self.categoryTable.setItem(row,column,QTableWidgetItem(str(item)))
- column += 1
- row_position = self.categoryTable.rowCount()
- self.categoryTable.insertRow(row_position)
- def Show_Author(self):
- self.db = MySQLdb.connect(host='localhost', user='root', password='Fabella10', db='library')
- self.cur = self.db.cursor()
- self.cur.execute('''
- SELECT author_name FROM authors
- ''')
- data = self.cur.fetchall()
- if data:
- self.authorTable.insertRow(0)
- for row, form in enumerate(data):
- for column, item in enumerate(form):
- self.authorTable.setItem(row, column, QTableWidgetItem(str(item)))
- column += 1
- row_position = self.authorTable.rowCount()
- self.authorTable.insertRow(row_position)
- def Show_Publisher(self):
- self.db = MySQLdb.connect(host='localhost', user='root', password='Fabella10', db='library')
- self.cur = self.db.cursor()
- self.cur.execute('''
- SELECT publisher_name FROM publisher
- ''')
- data = self.cur.fetchall()
- if data:
- self.publisherTable.insertRow(0)
- for row, form in enumerate(data):
- for column, item in enumerate(form):
- self.publisherTable.setItem(row, column, QTableWidgetItem(str(item)))
- column += 1
- row_position = self.publisherTable.rowCount()
- self.publisherTable.insertRow(row_position)
- ######################################################
- ################show settings data in UI #############
- def Show_Category_Combobox(self):
- self.db = MySQLdb.connect(host='localhost', user='root', password='Fabella10', db='library')
- self.cur = self.db.cursor()
- self.cur.execute('''
- SELECT category_name FROM category
- ''')
- data = self.cur.fetchall()
- self.addNewBookCategory_COMBO.clear()
- for category in data:
- self.addNewBookCategory_COMBO.addItem(category[0])
- def Show_Author_Combobox(self):
- self.db = MySQLdb.connect(host='localhost', user='root', password='Fabella10', db='library')
- self.cur = self.db.cursor()
- self.cur.execute('''
- SELECT author_name FROM authors
- ''')
- data = self.cur.fetchall()
- self.addNewBookAuthor_COMBO.clear()
- for author in data:
- self.addNewBookAuthor_COMBO.addItem(author[0])
- def Show_Publisher_Combobox(self):
- self.db = MySQLdb.connect(host='localhost', user='root', password='Fabella10', db='library')
- self.cur = self.db.cursor()
- self.cur.execute('''
- SELECT publisher_name FROM publisher
- ''')
- data = self.cur.fetchall()
- self.addNewBookPublisher_COMBO.clear()
- for publisher in data:
- self.addNewBookPublisher_COMBO.addItem(publisher[0])
- def main():
- app = QApplication(sys.argv)
- window = MainApp()
- window.show()
- app.exec_()
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement