def __init__(self):
        QtGui.QDialog.__init__(self)

        # setup
        self.dialog = Ui_studentsDialog()
        self.dialog.setupUi(self)

        self.sid = None
        self.adding = False

        header = ['Sid', 'Apelido', 'First Name', 'Last Name']
        self.dialog.studentTableWidget.setHorizontalHeaderLabels(header)

        self.connect(self.dialog.studentTableWidget, \
                     QtCore.SIGNAL("cellClicked(int, int)"), \
                     self._on_cell_click)
        self.connect(self.dialog.updateButton, QtCore.SIGNAL("clicked()"), \
                    self._on_update_click)
        self.connect(self.dialog.newButton, QtCore.SIGNAL("clicked()"), \
                    self._on_new_click)

        self.db = AttendDB()

        self._update_list()
示例#2
0
    def __init__(self):
        QtGui.QDialog.__init__(self)

        # setup
        self.dialog = Ui_studentsDialog()
        self.dialog.setupUi(self)

        self.sid = None
        self.adding = False

        header = ['Sid','Apelido', 'First Name', 'Last Name']
        self.dialog.studentTableWidget.setHorizontalHeaderLabels(header)

        self.connect(self.dialog.studentTableWidget, \
                     QtCore.SIGNAL("cellClicked(int, int)"), \
                     self._on_cell_click)
        self.connect(self.dialog.updateButton, QtCore.SIGNAL("clicked()"), \
                    self._on_update_click)
        self.connect(self.dialog.newButton, QtCore.SIGNAL("clicked()"), \
                    self._on_new_click)

        self.db = AttendDB()

        self._update_list()        
class Students(QtGui.QDialog):
    def __init__(self):
        QtGui.QDialog.__init__(self)

        # setup
        self.dialog = Ui_studentsDialog()
        self.dialog.setupUi(self)

        self.sid = None
        self.adding = False

        header = ['Sid', 'Apelido', 'First Name', 'Last Name']
        self.dialog.studentTableWidget.setHorizontalHeaderLabels(header)

        self.connect(self.dialog.studentTableWidget, \
                     QtCore.SIGNAL("cellClicked(int, int)"), \
                     self._on_cell_click)
        self.connect(self.dialog.updateButton, QtCore.SIGNAL("clicked()"), \
                    self._on_update_click)
        self.connect(self.dialog.newButton, QtCore.SIGNAL("clicked()"), \
                    self._on_new_click)

        self.db = AttendDB()

        self._update_list()

    def _update_list(self):
        """Refresh the student list."""
        #for i in range(self.dialog.studentTableWidget.rowCount()):
        #    self.dialog.studentTableWidget.removeRow(i)
        self.dialog.studentTableWidget.clear()

        rows = self.dialog.studentTableWidget.rowCount()
        students = self.db.get_students()

        while (rows < len(students)):
            self.dialog.studentTableWidget.insertRow(rows)
            rows += 1

        for i, student in enumerate(students):
            #self.dialog.studentTableWidget.insertRow(i)
            for j, item in enumerate(student):
                if item == None:
                    item = ''
                newitem = QtGui.QTableWidgetItem(str(item))
                self.dialog.studentTableWidget.setItem(i, j, newitem)
            if self.sid != None and str(student[0]) == str(self.sid):
                self.dialog.studentTableWidget.setCurrentItem(newitem)

        self.dialog.studentTableWidget.sortItems(1)

    def _on_cell_click(self, row, column):
        """Fill out the entries when a cell is clicked."""
        # Get selected row
        items = self.dialog.studentTableWidget.selectedItems()

        # Set the input fields
        self.dialog.nickNameInput.setText(items[1].text())
        self.dialog.firstNameInput.setText(items[2].text())
        self.dialog.lastNameInput.setText(items[3].text())

    def _on_update_click(self):
        """Update current student or add new student."""
        # Get filled in information
        apelido = str(self.dialog.nickNameInput.text())
        fn = str(self.dialog.firstNameInput.text())
        ln = str(self.dialog.lastNameInput.text())

        if self.adding:
            self.sid = self.db.add_student(apelido, fn, ln)
            self.dialog.studentTableWidget.setEnabled(True)
        else:
            items = self.dialog.studentTableWidget.selectedItems()
            self.sid = str(items[0].text())

            self.db.update_student(self.sid, apelido, fn, ln)

        self.adding = False
        self._update_list()

    def _on_new_click(self):
        self.adding = True
        self.dialog.studentTableWidget.setEnabled(False)
示例#4
0
class Students(QtGui.QDialog):

    def __init__(self):
        QtGui.QDialog.__init__(self)

        # setup
        self.dialog = Ui_studentsDialog()
        self.dialog.setupUi(self)

        self.sid = None
        self.adding = False

        header = ['Sid','Apelido', 'First Name', 'Last Name']
        self.dialog.studentTableWidget.setHorizontalHeaderLabels(header)

        self.connect(self.dialog.studentTableWidget, \
                     QtCore.SIGNAL("cellClicked(int, int)"), \
                     self._on_cell_click)
        self.connect(self.dialog.updateButton, QtCore.SIGNAL("clicked()"), \
                    self._on_update_click)
        self.connect(self.dialog.newButton, QtCore.SIGNAL("clicked()"), \
                    self._on_new_click)

        self.db = AttendDB()

        self._update_list()        

    def _update_list(self):
        """Refresh the student list."""
        #for i in range(self.dialog.studentTableWidget.rowCount()):
        #    self.dialog.studentTableWidget.removeRow(i)
        self.dialog.studentTableWidget.clear()

        rows = self.dialog.studentTableWidget.rowCount()
        students = self.db.get_students()

        while(rows < len(students)):
            self.dialog.studentTableWidget.insertRow(rows)
            rows += 1
    
        for i, student in enumerate(students):
            #self.dialog.studentTableWidget.insertRow(i)
            for j, item in enumerate(student):
                if item == None:
                    item = ''
                newitem = QtGui.QTableWidgetItem(str(item))
                self.dialog.studentTableWidget.setItem(i, j, newitem)
            if self.sid != None and str(student[0]) == str(self.sid):
                self.dialog.studentTableWidget.setCurrentItem(newitem)


        self.dialog.studentTableWidget.sortItems(1)

    def _on_cell_click(self, row, column):
        """Fill out the entries when a cell is clicked."""
        # Get selected row
        items = self.dialog.studentTableWidget.selectedItems()

        # Set the input fields
        self.dialog.nickNameInput.setText(items[1].text())
        self.dialog.firstNameInput.setText(items[2].text())
        self.dialog.lastNameInput.setText(items[3].text())

    def _on_update_click(self):
        """Update current student or add new student."""
        # Get filled in information
        apelido = str(self.dialog.nickNameInput.text())
        fn = str(self.dialog.firstNameInput.text())
        ln = str(self.dialog.lastNameInput.text())

        if self.adding:
            self.sid = self.db.add_student(apelido, fn, ln)
            self.dialog.studentTableWidget.setEnabled(True)
        else:
            items = self.dialog.studentTableWidget.selectedItems()
            self.sid = str(items[0].text())
        
            self.db.update_student(self.sid, apelido, fn, ln)
        
        self.adding = False
        self._update_list()

    def _on_new_click(self):
        self.adding = True
        self.dialog.studentTableWidget.setEnabled(False)