Guest User

Untitled

a guest
Mar 25th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.82 KB | None | 0 0
  1. from PyQt4.QtGui import *
  2. from PyQt4.QtSql import *
  3. from sqlite3 import *
  4.  
  5. from gym_database_class import *
  6.  
  7. class BrowseDataWidget(QWidget):
  8.     """A widget for displaying Database data"""
  9.      
  10.     def __init__(self):
  11.      
  12.         self.loadDataBase = None
  13.         super().__init__()
  14.         self.layout = QVBoxLayout()
  15.          
  16.         self.table_view = QTableView()
  17.          
  18.         self.layout.addWidget(self.table_view)
  19.          
  20.         self.setLayout(self.layout)
  21.  
  22.         self.database = None
  23.  
  24.          
  25.     def PopulateTable(self,item,labels):
  26.                 #method for adding all the information from the database to the table view based on the currently opened database
  27.                 self.database = Database(self.loadDataBase)
  28.                 self.database.loadDatabase()
  29.                 data = self.database.getAllData(item)
  30.                 model = QStandardItemModel()
  31.                 model.setHorizontalHeaderLabels(labels)
  32.                 row = 0
  33.                 for item in data:
  34.                     for column in range(len(item)):
  35.                         if item[column] == "None":
  36.                             print(item[column])
  37.                             item = (" ")
  38.                         else:
  39.                             StandardItem = QStandardItem("{}".format(item[column]))
  40.                             model.setItem(row, column, StandardItem)
  41.                     row += 1
  42.                 self.table_view.setModel(model)
  43.  
  44.                                                  
  45.                                                  
  46.                                  
  47.  
  48.                                  
  49.     def UpdateTable(self,newDataBase):
  50.                 #method for loading a new database when the user opens a new database or reopens a database
  51.         self.loadDataBase = newDataBase
Advertisement
Add Comment
Please, Sign In to add comment