'''
Accessible Access Control 1.0
2012-2104 Michigan Technological University
Supported in part by NSF grants: DUE-1140512, DUE-1245310 and IIS-1319363
Developer: Man Wang
Advisors:Dr. Steve Carr, Dr. Jean Mayo, Dr. Ching-Kuang Shene and Dr. Chaoli Wang
'''
'''
Created on 2013-02-07

@author: mandy
'''
from PyQt4.QtGui import QDialog
from PyQt4.QtCore import Qt
from Ui_AssignmentDialog import Ui_Dialog

class AssignmentDialog(QDialog):
    def __init__(self, scene):
        QDialog.__init__(self)
        self.scene = scene
        self.currentAssignment = ''
        self.ui = Ui_Dialog()
        self.ui.setupUi(self)
        self.setLayout(self.ui.verticalLayout)
        flags = Qt.Dialog | Qt.WindowStaysOnTopHint
        self.setWindowFlags(flags)
        self.ui.updatePushButton.clicked.connect(self.getAssignment)
        self.ui.closePushButton.clicked.connect(self.hide)
    
    def getAssignment(self):
        self.scene.assignment = self.scene.usrAssign + '\n' + self.scene.typeAssign
        self.ui.assignTextEdit.setPlainText(self.scene.assignment)
#        if self.currentAssignment == '':
#            self.ui.assignTextEdit.setPlainText(self.scene.assignment)
#            self.currentAssignment = self.scene.assignment
#        else:
#            if self.scene.assignment != self.ui.assignTextEdit.toPlainText():
#                self.currentAssignment = self.ui.assignTextEdit.toPlainText()
#                self.scene.assignment = self.currentAssignment
#                destFile = self.scene.parent.specDir.append('/updatedSpec.mls')
#                with open(destFile, 'w') as f:
#                    f.write('clearances: ')
#                    tempStr = ''
#                    for clr in self.scene.clearances:
#                        tempStr += clr+'<'
#                    f.write('%s\ncategories: ' % tempStr[:-2])
#                    tempStr = ''
#                    for cat in self.scene.categories:
#                        tempStr += cat+', '
#                    f.write('%s\n' % tempStr[:tempStr.rfind(',')])
#                    f.write('\n')
#                    f.write(self.scene.assignment)
#                    f.close()
#                self.scene.parent.readinFile(destFile)
#                if self.scene.parent.ui.actionType_Graph.isChecked():
#                    self.scene.parent.layoutTypeGraph()
                
#    def updateAssignment(self):
#        if self.scene.assignment != self.ui.assignTextEdit.toPlainText():
#            self.scene.assignment = self.ui.assignTextEdit.toPlainText()