Advertisement
jfabella

index.py

Sep 11th, 2019
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.56 KB | None | 0 0
  1. from PyQt5.QtCore import *
  2. from PyQt5.QtGui import *
  3. import MySQLdb
  4. from PyQt5.QtWidgets import *
  5. import sys
  6.  
  7. from PyQt5.uic import loadUiType
  8.  
  9. ui, _ = loadUiType('library.ui')
  10.  
  11.  
  12. class MainApp(QMainWindow, ui):
  13. def __init__(self):
  14. QMainWindow.__init__(self)
  15. self.setupUi(self)
  16. self.Handle_UI_Changes()
  17. self.Handle_Buttons()
  18.  
  19. def Handle_UI_Changes(self):
  20. self.Hiding_Themes()
  21. self.tabWidget.tabBar().setVisible(False)
  22. self.tabWidget.setCurrentIndex(0)
  23. self.tabWidget_3.setCurrentIndex(0)
  24. self.Show_Category()
  25. self.Show_Author()
  26. self.Show_Publisher()
  27. self.Show_Publisher_Combobox()
  28. self.Show_Category_Combobox()
  29. self.Show_Author_Combobox()
  30.  
  31. def Handle_Buttons(self):
  32. self.hideThemeButton.clicked.connect(self.Hiding_Themes)
  33. self.showThemeButton.clicked.connect(self.Show_Themes)
  34. self.showDayButton.clicked.connect(self.Open_Day_To_Day_Tab)
  35. self.showBooksButton.clicked.connect(self.Open_Books_Tab)
  36. self.showUsersButton.clicked.connect(self.Open_Users_Tab)
  37. self.showSettingsButton.clicked.connect(self.Open_Settings_Tab)
  38. self.addCategoryButton.clicked.connect(self.Add_Category)
  39. self.addAuthorButton.clicked.connect(self.Add_Author)
  40. self.addPublisherButton.clicked.connect(self.Add_Publisher)
  41.  
  42. def Show_Themes(self):
  43. self.themeGroupBox.show()
  44.  
  45. def Hiding_Themes(self):
  46. self.themeGroupBox.hide()
  47.  
  48. ##########################################################
  49. #######################opening Tabs#######################
  50.  
  51. def Open_Day_To_Day_Tab(self):
  52. self.tabWidget.setCurrentIndex(0)
  53.  
  54. def Open_Books_Tab(self):
  55. self.tabWidget.setCurrentIndex(1)
  56.  
  57. def Open_Users_Tab(self):
  58. self.tabWidget.setCurrentIndex(2)
  59.  
  60. def Open_Settings_Tab(self):
  61. self.tabWidget.setCurrentIndex(3)
  62.  
  63.  
  64. ####################Books#################################
  65. def Add_New_Book(self):
  66. self.db = MySQLdb.connect(host='localhost',user='root',password='Fabella10',db='library')
  67. self.cur = self.db.cursor()
  68.  
  69. book_title = self.addNewBookTitle_LE.text()
  70. book_code = self.addNewBookCode_LE.text()
  71. book_category = self.addNewBookCategory_COMBO.CurrentText()
  72. book_author = self.addNewBookAuthor_COMBO.CurrentText()
  73. book_publisher = self.addNewBookPublisher_COMBO.CurrentText()
  74. book_price = self.addNewBookCode_LE.text()
  75. book_description = self.addNewBookDescription.toPlainText()
  76.  
  77. self.cur.execute('''
  78. INSERT INTO book
  79. VALUES (%s , %s, %s, %s, %s, %s, %s)
  80. '''),(book_title, book_description, book_code, book_category, book_author, book_publisher, book_price)
  81. self.db.commit()
  82. self.statusBar().showMessage('New Book Added')
  83.  
  84. def Search_Books(self):
  85. pass
  86.  
  87. def Edit_Books(self):
  88. pass
  89.  
  90. def Delete_Books(self):
  91. pass
  92.  
  93. ####################Settings -- ADD#######################
  94.  
  95. def Add_Category(self):
  96. self.db = MySQLdb.connect(host='localhost',user='root',password='Fabella10',db='library')
  97. self.cur = self.db.cursor()
  98.  
  99. category_name = self.addCategoryLine.text()
  100.  
  101. self.cur.execute('''
  102. INSERT INTO category(category_name) VALUES(%s)
  103. ''', (category_name,))
  104.  
  105. self.db.commit()
  106. self.addCategoryLine.setText('')
  107. self.categoryTable.setRowCount(0)
  108. self.Show_Category()
  109. self.statusBar().showMessage('New Category Added')
  110.  
  111.  
  112.  
  113. def Add_Author(self):
  114. self.db = MySQLdb.connect(host='localhost',user='root',password='Fabella10',db='library')
  115. self.cur = self.db.cursor()
  116. author_name = self.addAuthorLine.text()
  117.  
  118. self.cur.execute('''
  119. INSERT INTO authors(author_name) VALUES(%s)
  120. ''', (author_name,))
  121.  
  122. self.db.commit()
  123. self.addAuthorLine.setText('')
  124. self.authorTable.setRowCount(0)
  125. self.Show_Author()
  126. self.statusBar().showMessage('New Author Added')
  127.  
  128.  
  129. def Add_Publisher(self):
  130. self.db = MySQLdb.connect(host='localhost',user='root',password='Fabella10',db='library')
  131. self.cur = self.db.cursor()
  132. publisher_name = self.addPublisherLine.text()
  133.  
  134. self.cur.execute('''
  135. INSERT INTO publisher(publisher_name) VALUES(%s)
  136. ''',(publisher_name,))
  137.  
  138. self.db.commit()
  139. self.addPublisherLine.setText('')
  140. self.publisherTable.setRowCount(0)
  141. self.Show_Publisher()
  142. self.statusBar().showMessage('New Publisher Added')
  143.  
  144.  
  145. ####################Settings -- SHOW######################
  146.  
  147. def Show_Category(self):
  148. self.db = MySQLdb.connect(host='localhost', user='root', password='Fabella10', db='library')
  149. self.cur = self.db.cursor()
  150.  
  151. self.cur.execute('''
  152. SELECT category_name FROM category
  153. ''')
  154. data = self.cur.fetchall()
  155.  
  156. if data:
  157. self.categoryTable.insertRow(0)
  158. for row, form in enumerate(data):
  159. for column,item in enumerate(form):
  160. self.categoryTable.setItem(row,column,QTableWidgetItem(str(item)))
  161. column += 1
  162.  
  163. row_position = self.categoryTable.rowCount()
  164. self.categoryTable.insertRow(row_position)
  165.  
  166. def Show_Author(self):
  167. self.db = MySQLdb.connect(host='localhost', user='root', password='Fabella10', db='library')
  168. self.cur = self.db.cursor()
  169.  
  170. self.cur.execute('''
  171. SELECT author_name FROM authors
  172. ''')
  173. data = self.cur.fetchall()
  174.  
  175. if data:
  176.  
  177. self.authorTable.insertRow(0)
  178. for row, form in enumerate(data):
  179. for column, item in enumerate(form):
  180. self.authorTable.setItem(row, column, QTableWidgetItem(str(item)))
  181. column += 1
  182.  
  183. row_position = self.authorTable.rowCount()
  184. self.authorTable.insertRow(row_position)
  185.  
  186. def Show_Publisher(self):
  187. self.db = MySQLdb.connect(host='localhost', user='root', password='Fabella10', db='library')
  188. self.cur = self.db.cursor()
  189.  
  190. self.cur.execute('''
  191. SELECT publisher_name FROM publisher
  192. ''')
  193.  
  194. data = self.cur.fetchall()
  195.  
  196. if data:
  197. self.publisherTable.insertRow(0)
  198. for row, form in enumerate(data):
  199. for column, item in enumerate(form):
  200. self.publisherTable.setItem(row, column, QTableWidgetItem(str(item)))
  201. column += 1
  202.  
  203. row_position = self.publisherTable.rowCount()
  204. self.publisherTable.insertRow(row_position)
  205.  
  206.  
  207.  
  208.  
  209. ######################################################
  210. ################show settings data in UI #############
  211. def Show_Category_Combobox(self):
  212. self.db = MySQLdb.connect(host='localhost', user='root', password='Fabella10', db='library')
  213. self.cur = self.db.cursor()
  214.  
  215. self.cur.execute('''
  216. SELECT category_name FROM category
  217. ''')
  218. data = self.cur.fetchall()
  219.  
  220. self.addNewBookCategory_COMBO.clear()
  221.  
  222. for category in data:
  223. self.addNewBookCategory_COMBO.addItem(category[0])
  224.  
  225.  
  226. def Show_Author_Combobox(self):
  227. self.db = MySQLdb.connect(host='localhost', user='root', password='Fabella10', db='library')
  228. self.cur = self.db.cursor()
  229.  
  230. self.cur.execute('''
  231. SELECT author_name FROM authors
  232. ''')
  233. data = self.cur.fetchall()
  234.  
  235. self.addNewBookAuthor_COMBO.clear()
  236.  
  237. for author in data:
  238. self.addNewBookAuthor_COMBO.addItem(author[0])
  239.  
  240. def Show_Publisher_Combobox(self):
  241. self.db = MySQLdb.connect(host='localhost', user='root', password='Fabella10', db='library')
  242. self.cur = self.db.cursor()
  243.  
  244. self.cur.execute('''
  245. SELECT publisher_name FROM publisher
  246. ''')
  247. data = self.cur.fetchall()
  248.  
  249. self.addNewBookPublisher_COMBO.clear()
  250.  
  251. for publisher in data:
  252. self.addNewBookPublisher_COMBO.addItem(publisher[0])
  253.  
  254.  
  255.  
  256. def main():
  257. app = QApplication(sys.argv)
  258. window = MainApp()
  259. window.show()
  260. app.exec_()
  261.  
  262.  
  263. if __name__ == '__main__':
  264. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement