I want to create a GUI that allows a user to create new employee objects and access their respective attributes. So far my program only allows for one object's information to be printed at a time:
import sys
from PyQt4 import QtGui
class Employee:
def __init__(self, id, salary):
self.id = id
self.salary = salary
def info(self):
return "Employee ID: {}\nFull name:{}\nSalary:{}".format(self.id, self.full_name, self.salary)
class Window(QtGui.QMainWindow, Employee):
def __init__(self):
super(Window, self).__init__() #Returns the parent object or the QMainWindow object
self.setGeometry(50, 50, 500, 300)
self.setWindowTitle("Employee builder")
extractAction = QtGui.QAction("&Add Employee", self)
extractAction.triggered.connect(self.create_employee)
mainMenu = self.menuBar()
fileMenu = mainMenu.addMenu('&File')
fileMenu.addAction(extractAction)
self.home()
def home(self):
self.show()
def create_employee(self):
ID, ok = QtGui.QInputDialog.getInt(self, "integer input dualog", "Enter employees id number:")
pay, ok = QtGui.QInputDialog.getInt(self, "integer input dualog", "Enter employees salary:")
emp1 = Employee(ID, pay)
QtGui.QMessageBox.information(None, "Employee information:", emp1.info)
def run():
app = QtGui.QApplication(sys.argv)
GUI = Window()
sys.exit(app.exec_())
run()
The next logic step as I see it would be to call a method which stores each newly created employee object so that a user can access the objects information based on the objects ID. In Python, would it pay to create a more advanced data structure like a hash table to store the objects? Or should I just be using a dictionary or a list (is a dictionary a hash table)? I am only doing this to learn Python and PyQt4 GUI's so I do not expect to be saving mega bytes of employee information or anything like that.