Example #1
0
class TypeView(basisView.BasisView):
    updateContViewSignal = QtCore.Signal()

    def __init__(self, parent=None):
        super(TypeView, self).__init__(parent)
        self.labelWidInfo = {}

    def buildElements(self):
        super(TypeView, self).buildElements()
        self.typeLW = QtGui.QListWidget()
        self.chkOnBtn = QtGui.QPushButton('Check On All')
        self.chkOffBtn = QtGui.QPushButton('Check Off All')

    def buildWidget(self):
        super(TypeView, self).buildWidget()

        self.mainLO.addWidget(self.mainFrame)

        self.frameLO.addWidget(self.titleLabel, 0, 0, 1, 2, self.centerAlign)
        self.frameLO.addWidget(self.typeLW, 1, 0, 1, 2)
        self.frameLO.addWidget(self.chkOnBtn, 2, 0)
        self.frameLO.addWidget(self.chkOffBtn, 2, 1)

    def connectFunc(self):
        self.chkOnBtn.clicked.connect(partial(self.checkStateChange, 1))
        self.chkOffBtn.clicked.connect(partial(self.checkStateChange, 0))

    def initContent(self):
        self.titleLabel.setText('File Type Filter')
        fileTypes = self.dataCtrl.getDataVal('fileTypes')
        activeFileTypes = self.dataCtrl.getDataVal('activeFileTypes')
        for fileType in fileTypes:
            item = QtGui.QListWidgetItem()
            ftCb = QtGui.QCheckBox(fileType, parent=self)
            if fileType in activeFileTypes:
                ftCb.setChecked(2)

            self.typeLW.addItem(item)
            self.typeLW.setItemWidget(item, ftCb)
            item.setToolTip('FileType: %s' % fileType)

            ftCb.stateChanged.connect(self.typeChangeFunc)

    def typeChangeFunc(self):
        itemCount = self.typeLW.count()
        curActiveFileTypes = []
        for i in range(itemCount):
            item = self.typeLW.item(i)
            cbWid = self.typeLW.itemWidget(item)
            if cbWid.isChecked():
                fileType = str(cbWid.text())
                curActiveFileTypes.append(fileType)

        oriActiveFileTypes = self.dataCtrl.getDataVal('activeFileTypes', [])
        if not set(oriActiveFileTypes) == set(curActiveFileTypes):
            updateInfo = {'activeFileTypes': curActiveFileTypes}
            self.dataCtrl.setData(updateInfo)

            self.dataCtrl.genFileContentInfo()
            self.emitUpdateSignal()

    def emitUpdateSignal(self):
        self.updateContViewSignal.emit()

    def checkStateChange(self, chkState):
        itemCount = self.typeLW.count()
        cbWids = []
        for i in range(itemCount):
            item = self.typeLW.item(i)
            cbWid = self.typeLW.itemWidget(item)
            cbWid.stateChanged.disconnect(self.typeChangeFunc)
            cbWid.setChecked(chkState)
            cbWids.append(cbWid)

        for cbWid in cbWids:
            cbWid.stateChanged.connect(self.typeChangeFunc)

        self.typeChangeFunc()
Example #2
0
class ButtonView(basisView.BasisView):
    checkOutFileSignal = QtCore.Signal(str, str, int)
    compareDiffVersionsSignal = QtCore.Signal()
    compareMainFileSignal = QtCore.Signal()
    compareCurrentFileSignal = QtCore.Signal(dict)
    
    def __init__(self, parent=None):
        super(ButtonView, self).__init__(parent)
        self.labelWidInfo = {}

    def buildElements(self):
        super(ButtonView, self).buildElements()
        
        outInfoKeys = self.dataCtrl.getDataVal('outInfoKeys')
        self.picLabel = QtGui.QLabel()
        self.funcBtn = QtGui.QToolButton()
        self.picmap = QtGui.QPixmap()
        self.menu = QtGui.QMenu()

        for outInfoKey in outInfoKeys:
            label = QtGui.QLabel()
            self.labelWidInfo[outInfoKey] = label

    def buildWidget(self):
        super(ButtonView, self).buildWidget()
        
        self.mainLO.addWidget(self.mainFrame)

        self.frameLO.addWidget(self.picLabel, 0, 0, 3, 3)
        i = 3
        outInfoKeys = self.dataCtrl.getDataVal('outInfoKeys')
        for outInfoKey in outInfoKeys:
            label = self.labelWidInfo[outInfoKey]
            self.frameLO.addWidget(label, i, 0, 1, 3)
            i += 1

        i -= 1
        self.frameLO.addWidget(self.funcBtn, i, 2)

        scaleFractor = self.dataCtrl.getDataVal('scaleFractor')
        defWidSize = self.dataCtrl.getDataVal(
            'defWidSize')
        defPicSize = self.dataCtrl.getDataVal(
            'defPicSize')
        widSize = [defWidSize[0] * scaleFractor,
                   defWidSize[1] * scaleFractor]
        picSize = [defPicSize[0] * scaleFractor,
                   defPicSize[1] * scaleFractor]
        self.setFixedSize(widSize[0], widSize[1])
        self.picLabel.setFixedSize(picSize[0], picSize[1])

    def connectFunc(self):
        # self.funcCB.activated.connect(self.itemInnerFunc)
        return

    def initContent(self):
        currentDir = self.dataCtrl.getDataVal('currentDir')
        metaData = self.dataCtrl.getDataVal('metaData')
        pic = metaData.get('picFile', '')
        picFile = os.path.join(currentDir, pic).replace('\\', '/')

        self.picmap.load(picFile)
        self.picLabel.setPixmap(self.picmap)
        self.picLabel.setScaledContents(1)

        for outInfoKey, label in self.labelWidInfo.items():
            val = metaData.get(outInfoKey, '')
            mess = '%s: %s' % (outInfoKey, val)
            label.setText(mess)

        self.funcBtn.setText('Menu')
        self.funcBtn.setMenu(self.menu)

        self.setupFuncMenu()
        self.initTooltips()

    def setupFuncMenu(self):
        funcInfo = self.dataCtrl.getDataVal('funcInfo')
        allDesc = ''
        funcKeys = funcInfo.keys()
        funcKeys.sort()
        for funcKey in funcKeys:
            info = funcInfo[funcKey]
            conditions = info.get('conditions', [])
            appTest = 1
            for condition in conditions:
                if not self.dataCtrl.getDataVal(condition):
                    appTest = 0
                    break

            if appTest:
                validTypes = info['validFileTypes']
                fileType = self.dataCtrl.getDataVal('fileType')
                if validTypes and fileType not in validTypes:
                    appTest = 0

            if appTest:
                funcName = info['func']
                func = self.dataCtrl.getFunc(funcName)
                if func:
                    desc = info['desc']
                    allDesc += '%s: %s\n' % (funcKey, desc)
                    self.menu.addAction(funcKey, func)

        self.menu.setToolTip(allDesc)

    def initTooltips(self):
        metaData = self.dataCtrl.getDataVal('metaData')
        for outInfoKey, label in self.labelWidInfo.items():
            val = metaData.get(outInfoKey)
            mess = '%s: %s' % (outInfoKey, val)
            label.setToolTip(mess)

        tipsKeys = self.dataCtrl.getDataVal('tipsKeys')
        allMess = ''
        for tipsKey in tipsKeys:
            val = metaData.get(tipsKey)
            mess = '%s: %s\n' % (tipsKey, val)
            allMess += mess
            
        self.picLabel.setToolTip(allMess)

    def emitCheckOutSignal(self, mess, subject, checkOutTest):
        self.checkOutFileSignal.emit(mess, subject, checkOutTest)

    def emitCompareDiffVersionSignal(self):
        self.compareDiffVersionsSignal.emit()

    def emitCompareDiffMainFileSignal(self):
        self.compareMainFileSignal.emit()

    def emitCompareDiffCurrentFileSignal(self, diffInfo):
        self.compareCurrentFileSignal.emit(diffInfo)
Example #3
0
class RootView(basisView.BasisView):
    updateDirViewSignal = QtCore.Signal()

    def __init__(self, parent=None):
        super(RootView, self).__init__(parent)

    def buildElements(self):
        super(RootView, self).buildElements()

        self.label = QtGui.QLabel('Project Root:')
        self.projPathLE = QtGui.QLineEdit()
        self.specBtn = QtGui.QPushButton('Browse')

    def buildWidget(self):
        super(RootView, self).buildWidget()

        self.mainLO.setRowStretch(0, 0)
        self.mainLO.addWidget(self.mainFrame)

        self.frameLO.addWidget(self.label, 0, 0)
        self.frameLO.addWidget(self.projPathLE, 0, 1)
        self.frameLO.addWidget(self.specBtn, 0, 2)
        self.frameLO.setColumnStretch(0, 0)
        self.frameLO.setColumnStretch(1, 1)
        self.frameLO.setColumnStretch(2, 0)

    def connectFunc(self):
        self.specBtn.clicked.connect(self.browseProjPath)
        self.projPathLE.returnPressed.connect(self.specProjPath)

    def browseProjPath(self):
        oriDir = self.dataCtrl.getDataVal('projectRoot')
        newDir = QtGui.QFileDialog.getExistingDirectory(
            self, "Choose Project Root", oriDir)
        if newDir:
            newDir = newDir.replace('\\', '/')
            updateInfo = {'newProjectRoot': newDir}
            self.dataCtrl.setData(updateInfo)
            self.renewProjPath()

    def specProjPath(self):
        newDir = str(self.projPathLE.text())
        if os.path.isdir(newDir):
            newDir = newDir.replace('\\', '/')
            updateInfo = {'newProjectRoot': newDir}
            self.dataCtrl.setData(updateInfo)
            self.renewProjPath()

    def renewProjPath(self):
        oriProjDir = self.dataCtrl.getDataVal('projectRoot')
        newProjDir = self.dataCtrl.getDataVal('newProjectRoot')
        if newProjDir and not newProjDir == oriProjDir:
            updateInfo = {
                'projectRoot': newProjDir,
                'currentDir': newProjDir,
                'currentDirs': [newProjDir],
                'currentDirId': 0
            }
            self.dataCtrl.setData(updateInfo)
            self.initContent()

            self.emitUpdateSignal()

    def initContent(self):
        rootDir = self.dataCtrl.getDataVal('projectRoot')
        self.projPathLE.setText(rootDir)

    def emitUpdateSignal(self):
        self.updateDirViewSignal.emit()
Example #4
0
class CheckInView(QtGui.QDialog, basisView.BasisView):
    updateContViewSignal = QtCore.Signal()

    def __init__(self, parent=None):
        super(CheckInView, self).__init__(parent)

    def buildElements(self):
        super(CheckInView, self).buildElements()

        self.diffLabel = QtGui.QLabel('Compare Different:')
        self.cmpView = cmpView.CmpView()
        self.cmpView.do(self.dataCtrl)

        self.nextBtn = QtGui.QPushButton('Next')

        self.descLabel = QtGui.QLabel('Description:')
        self.picLabel = QtGui.QLabel()
        self.picmap = QtGui.QPixmap()
        self.descTE = QtGui.QTextEdit()
        self.screenBtn = QtGui.QPushButton('Screen Shot')
        self.publishBtn = QtGui.QPushButton('Publish')

    def buildWidget(self):
        super(CheckInView, self).buildWidget()

        self.mainLO.addWidget(self.diffLabel, 0, 0, 1, 2, self.centerAlign)
        self.mainLO.addWidget(self.cmpView, 1, 0, 1, 2)
        self.mainLO.addWidget(self.nextBtn, 2, 1)

        self.picLabel.setFixedSize(300, 225)

        self.setWindowTitle('Check in Window')

    def connectFunc(self):
        self.nextBtn.clicked.connect(self.renewWidget)
        self.screenBtn.clicked.connect(self.takeScreenShot)
        self.publishBtn.clicked.connect(self.publishFile)

    def renewWidget(self):
        self.diffLabel.hide()
        self.diffLabel.close()
        self.cmpView.hide()
        self.cmpView.close()
        self.nextBtn.hide()
        self.nextBtn.close()

        self.mainLO.addWidget(self.descLabel, 0, 0, 1, 2, self.centerAlign)
        self.mainLO.addWidget(self.picLabel, 1, 0)
        self.mainLO.addWidget(self.descTE, 1, 1)
        self.mainLO.addWidget(self.screenBtn, 2, 0)
        self.mainLO.addWidget(self.publishBtn, 2, 1)

    def initCmpContent(self, diffInfo):
        self.cmpView.initCmpContent(diffInfo)

    def takeScreenShot(self):
        temPic = self.dataCtrl.takeCurrentAppScreenShot()
        updateInfo = {'outputTemPic': temPic}
        self.dataCtrl.setData(updateInfo)

        self.picmap.load(temPic)
        self.picLabel.setPixmap(self.picmap)
        self.picLabel.setScaledContents(1)

    def publishFile(self):
        desc = str(self.descTE.toPlainText())
        temPic = self.dataCtrl.getDataVal('outputTemPic', '')
        updateInfo = {'outputDescStr': desc, 'outputTemPic': temPic}
        self.dataCtrl.setData(updateInfo)
        self.dataCtrl.checkInFile()
        self.buildUpNotificationView()
        self.emitUpdateContentViewSignal()
        self.close()

    def emitUpdateContentViewSignal(self):
        self.updateContViewSignal.emit()

    def buildUpNotificationView(self):
        checkInOutputInfo = self.dataCtrl.getDataVal('checkInOutputInfo')
        subject = checkInOutputInfo['subject']
        mess = checkInOutputInfo['mess']
        QtGui.QMessageBox.warning(self, subject, mess)

    def closeEvent(self, qevent):
        self.clearCheckInData()

    def clearCheckInData(self):
        updateInfo = {
            'outputTemFile': '',
            'outputTemPic': '',
            'outputDetailInfo': {},
            'outputFileName': '',
            'checkInOutputInfo': {}
        }
        self.dataCtrl.setData(updateInfo)

    def reject(self):
        self.clearCheckInData()
        super(CheckInView, self).reject()
Example #5
0
class FuncView(basisView.BasisView):
    updateContViewSignal = QtCore.Signal()

    def __init__(self, parent=None):
        super(FuncView, self).__init__(parent)

    def buildElements(self):
        super(FuncView, self).buildElements()
        self.ftLabel = QtGui.QLabel('File Type:')
        self.ftCB = QtGui.QComboBox()

        self.fnLabel = QtGui.QLabel('File Name:')
        self.fnLE = QtGui.QLineEdit()
        self.autoCfgBtn = QtGui.QPushButton('Auto Config')

        self.mailLabel = QtGui.QLabel('Mail List:')
        self.mailTE = QtGui.QTextEdit()
        self.chkInBtn = QtGui.QPushButton('Check In')

        self.setMlBtn = QtGui.QPushButton('Set Mail List')

    def buildWidget(self):
        super(FuncView, self).buildWidget()
        self.mainLO.addWidget(self.mainFrame)

        self.frameLO.addWidget(self.titleLabel, 0, 0, 1, 2, self.centerAlign)

        self.frameLO.addWidget(self.ftLabel, 1, 0)
        self.frameLO.addWidget(self.ftCB, 1, 1, 1)

        self.frameLO.addWidget(self.fnLabel, 2, 0)
        self.frameLO.addWidget(self.fnLE, 2, 1)

        self.frameLO.addWidget(self.chkInBtn, 3, 0)
        self.frameLO.addWidget(self.autoCfgBtn, 3, 1)

        self.frameLO.addWidget(self.mailLabel, 4, 0, self.centerAlign)
        self.frameLO.addWidget(self.setMlBtn, 4, 1)
        self.frameLO.addWidget(self.mailTE, 5, 0, 3, 2)

        self.frameLO.setRowStretch(4, 1)
        self.titleLabel.setText('Function')

    def connectFunc(self):
        self.setMlBtn.clicked.connect(self.renewMailList)
        self.autoCfgBtn.clicked.connect(self.autoConfig)
        self.ftCB.currentIndexChanged.connect(self.renewFileType)
        self.chkInBtn.clicked.connect(self.checkInFile)

    def initContent(self):
        fileTypes = self.dataCtrl.getDataVal('fileTypes')
        fileType = self.dataCtrl.getDataVal('fileType')
        self.ftCB.addItems(fileTypes)
        ftId = 0
        if fileType in fileTypes:
            ftId = fileTypes.index(fileType)

        self.ftCB.setCurrentIndex(ftId)

        mailList = self.dataCtrl.getDataVal('mailList', [])
        mailStr = '\n'.join(mailList)
        self.mailTE.setText(mailStr)

        mayaInit = self.dataCtrl.getDataVal('mayaInit')
        if not mayaInit:
            self.chkInBtn.setEnabled(0)

    def renewMailList(self):
        mailStr = self.mailTE.toPlainText()
        mailList = []
        if '\r\n' in mailStr:
            mailList = mailStr.split('\r\n')
        else:
            mailList = mailStr.split('\n')

        updateInfo = {'mailList': mailList}
        self.dataCtrl.setData(updateInfo)

    def autoConfig(self):
        detailFileName = self.dataCtrl.getDataVal('detailFileName')
        detailFileType = self.dataCtrl.getDataVal('detailFileType')
        if not detailFileName or not detailFileType:
            return

        fileTypes = self.dataCtrl.getDataVal('fileTypes')
        fileTypeId = fileTypes.index(detailFileType)
        self.fnLE.setText(detailFileName)
        self.ftCB.setCurrentIndex(fileTypeId)

    def renewFileType(self, ftId):
        fileType = str(self.ftCB.itemText(ftId))
        updateInfo = {'fileType': fileType}
        self.dataCtrl.setData(updateInfo)

    def checkInFile(self):
        outputFileName = str(self.fnLE.text())
        outputFileType = str(self.ftCB.currentText())
        updateInfo = {
            'outputFileName': outputFileName,
            'outputFileType': outputFileType
        }
        self.dataCtrl.setData(updateInfo)

        rec = self.dataCtrl.validOutputCheck()
        status = rec[0]
        if status:
            mess = rec[1]
            self.buildUpCheckInFailView(mess)
        else:
            outputTemFile = self.dataCtrl.outputCurrentAppFile()
            outputDetailInfo = self.dataCtrl.outputCurrentFileDetailInfo()
            updateInfo = {
                'outputTemFile': outputTemFile,
                'outputDetailInfo': outputDetailInfo
            }
            self.dataCtrl.setData(updateInfo)
            diffInfo = self.dataCtrl.doCheckInCompare()
            self.buildUpCheckInView(diffInfo)

    def buildUpCheckInFailView(self, mess):
        title = 'Check In Error'
        QtGui.QMessageBox.warning(self, title, mess)

    def buildUpCheckInView(self, diffInfo):
        ciV = checkInView.CheckInView(self)
        ciV.do(self.dataCtrl)
        ciV.setWindowModality(QtCore.Qt.ApplicationModal)

        ciV.updateContViewSignal.connect(self.emitUpdateContentViewSignal)
        ciV.show()
        ciV.initCmpContent(diffInfo)

    def emitUpdateContentViewSignal(self):
        self.updateContViewSignal.emit()
Example #6
0
class DirView(basisView.BasisView):
    updateContViewSignal = QtCore.Signal()
    
    def __init__(self, parent=None):
        super(DirView, self).__init__(parent)

    def buildElements(self):
        super(DirView, self).buildElements()
        
        self.backwardBtn = QtGui.QPushButton('<-')
        self.forwardBtn = QtGui.QPushButton('->')
        self.dirTreeWid = QtGui.QTreeWidget(parent=self)
        self.selModel = self.dirTreeWid.selectionModel()

    def buildWidget(self):
        super(DirView, self).buildWidget()

        self.mainLO.addWidget(self.mainFrame)
        
        self.frameLO.addWidget(self.backwardBtn, 0, 0)
        self.frameLO.addWidget(self.forwardBtn, 0, 1)
        self.frameLO.addWidget(self.dirTreeWid, 1, 0, 10, 2)

        self.dirTreeWid.setHeaderHidden(1)
        self.dirTreeWid.setMinimumHeight(200)

        self.frameLO.setRowStretch(0, 0)
        self.frameLO.setRowStretch(1, 0)

    def connectFunc(self):
        self.backwardBtn.clicked.connect(partial(self.moveCurrentDir, 1))
        self.forwardBtn.clicked.connect(partial(self.moveCurrentDir, 0))
        self.dirTreeWid.itemClicked.connect(self.renewCurrentDir)

    def initContent(self):
        self.clearDirView()
        self.refreshCurrentDirView()

    def clearDirView(self):
        self.dirTreeWid.clear()

    def refreshCurrentDirView(self):
        projRoot = self.dataCtrl.getDataVal('projectRoot')
        curPath = self.dataCtrl.getDataVal('currentDir')

        if not projRoot.endswith('/'):
            projRoot += '/'
        if not curPath.endswith('/'):
            curPath += '/'
            
        if not curPath.startswith(projRoot):
            curPath = projRoot

        self.selModel.clearSelection()
        srcPath = projRoot
        pathInfo = {'Root': srcPath}
        rootItem = self.dirTreeWid
        oldRootItem = None
        outCurPath = srcPath
        while srcPath:
            keys = pathInfo.keys()
            keys.sort()
            itemList = []
            if isinstance(rootItem, QtGui.QTreeWidget):
                topNum = rootItem.topLevelItemCount()
                for i in range(topNum):
                    item = rootItem.topLevelItem(i)
                    itemList.append(item)
            else:
                chdNum = rootItem.childCount()
                for i in range(chdNum):
                    item = rootItem.child(i)
                    itemList.append(item)

            srcPath = ''
            for key in keys:
                full = pathInfo[key]
                if os.path.isdir(full) and \
                   not key == 'innerVersion' and \
                   not key == 'innerFile' and \
                   not key.startswith('.'):
                    if not full.endswith('/'):
                        full += '/'

                    twItem = None
                    for item in itemList:
                        if item.curPath == full:
                            twItem = item
                            break

                    if not twItem:
                        twItem = QtGui.QTreeWidgetItem(rootItem)
                        twItem.setText(0, key)
                        twItem.curPath = full

                    if curPath.startswith(full):
                        srcPath = full
                        if oldRootItem:
                            oldRootItem.setExpanded(1)

                        oldRootItem = twItem

            if srcPath:
                rootItem = oldRootItem
                outCurPath = srcPath
                pathInfo = {}
                tem = os.listdir(srcPath)
                for t in tem:
                    rFull = os.path.join(srcPath, t).replace('\\', '/')
                    pathInfo[t] = rFull

        if oldRootItem:
            oldRootItem.setSelected(1)

        updateInfo = {'currentDir': outCurPath}
        self.dataCtrl.setData(updateInfo)
        self.dataCtrl.genDirValidContentInfo()
        self.emitUpdateSignal()

    def renewCurrentDir(self, curTwItem, actId):
        if not curTwItem:
            return
        
        currentDir = curTwItem.curPath
        oriCurrentDir = self.dataCtrl.getDataVal('currentDir')
        currentDirs = self.dataCtrl.getDataVal('currentDirs', [oriCurrentDir])
        
        if currentDir in currentDirs:
            curId = currentDirs.index(currentDir)
            currentDirs.pop(curId)
            currentDirs.append(currentDir)
        else:
            if len(currentDirs) >= 10:
                currentDirs.pop(0)
                
            currentDirs.append(currentDir)

        currentDirId = len(currentDirs) - 1

        updateInfo = {'currentDir': currentDir,
                      'currentDirId': currentDirId,
                      'currentDirs': currentDirs}
        self.dataCtrl.setData(updateInfo)
        self.refreshCurrentDirView()

    def emitUpdateSignal(self):
        self.updateContViewSignal.emit()

    def moveCurrentDir(self, movType):
        currentDirId = self.dataCtrl.getDataVal('currentDirId')
        newDirId = currentDirId + pow(-1, movType)
        
        currentDirs = self.dataCtrl.getDataVal('currentDirs')
        newDirId = min(max(0, newDirId), len(currentDirs) - 1)

        currentDir = currentDirs[newDirId]
        updateInfo = {'currentDir': currentDir,
                      'currentDirId': newDirId}

        self.dataCtrl.setData(updateInfo)
        self.refreshCurrentDirView()
Example #7
0
class ContentView(basisView.BasisView):
    updateCmpViewSignal = QtCore.Signal(dict)

    def __init__(self, parent=None):
        super(ContentView, self).__init__(parent)

    def buildElements(self):
        super(ContentView, self).buildElements()
        self.contLW = QtGui.QListWidget()
        self.detailW = QtGui.QWidget()
        self.versionLW = QtGui.QListWidget()

        self.detailLabel = QtGui.QLabel('Detail:')
        self.historyLabel = QtGui.QLabel('History:')

    def buildWidget(self):
        super(ContentView, self).buildWidget()

        self.mainLO.addWidget(self.mainFrame)

        self.frameLO.addWidget(self.titleLabel, 0, 0, 1, 2, self.centerAlign)
        self.frameLO.addWidget(self.contLW, 1, 0, 4, 1)
        self.frameLO.addWidget(self.detailLabel, 1, 1, self.centerAlign)
        self.frameLO.addWidget(self.detailW, 2, 1)
        self.frameLO.addWidget(self.historyLabel, 3, 1, self.centerAlign)
        self.frameLO.addWidget(self.versionLW, 4, 1)

        self.contLW.setResizeMode(QtGui.QListView.Adjust)
        self.contLW.setMinimumWidth(180)
        self.contLW.setSpacing(1)
        self.contLW.setViewMode(QtGui.QListView.IconMode)
        self.contLW.setUniformItemSizes(True)

        self.detailW.setFixedWidth(200)
        self.detailW.setFixedHeight(200)

        self.versionLW.setResizeMode(QtGui.QListView.Adjust)
        self.versionLW.setSpacing(1)
        self.versionLW.setUniformItemSizes(True)
        self.versionLW.setFixedWidth(200)
        self.versionLW.setSelectionMode(
            QtGui.QListWidget.SelectionMode.MultiSelection)

        self.titleLabel.setText('Content')

    def connectFunc(self):
        self.contLW.itemClicked.connect(self.showItemDetails)
        self.versionLW.itemClicked.connect(self.renewVersionSelection)

    def initContent(self):
        self.clearContentWidget()
        self.renewContentWidget(self.contLW,
                                'contentFileInfo',
                                self.buildUpContItemView,
                                reverse=0)
        self.clearDetailWidget()
        self.clearHistoryWidget()
        self.initEmptyDetailWidget()

    def initEmptyDetailWidget(self):
        self.detailW = QtGui.QWidget()
        self.detailW.setFixedWidth(200)
        self.detailW.setFixedHeight(200)
        self.frameLO.addWidget(self.detailW, 2, 1)

    def clearContentWidget(self):
        self.contLW.clear()

    def renewContentWidget(self,
                           listWid,
                           contKey,
                           buildItemFunc,
                           outWidth=None,
                           reverse=0):
        defWidSize = self.dataCtrl.getDataVal('buttonWidgetSize')
        scaleFractor = self.dataCtrl.getDataVal('buttonWidgetScaleFractor')
        itemSize = [
            defWidSize[0] * scaleFractor + 2, defWidSize[1] * scaleFractor + 2
        ]
        if outWidth is not None:
            outScale = 1.0 * outWidth / itemSize[0]
            itemSize = [itemSize[0] * outScale, itemSize[1] * outScale]

        fileInfo = self.dataCtrl.getDataVal(contKey)
        files = fileInfo.keys()
        files.sort(reverse=reverse)
        for f in files:
            info = fileInfo[f]
            info['inputJson'] = f
            item = QtGui.QListWidgetItem()

            item.setSizeHint(QtCore.QSize(itemSize[0], itemSize[1]))
            listWid.addItem(item)
            buildItemFunc(info, item, listWid)

    def buildUpButtonView(self, info):
        outInfo = {}
        outInfo.update(info)
        btnV = buttonView.ButtonView()
        btnM = buttonModel.ButtonModel('', info)
        btnC = buttonControl.ButtonControl()

        btnC.do(btnV, btnM)
        btnV.do(btnC)
        btnV.checkOutFileSignal.connect(self.checkOutAction)
        btnV.compareDiffVersionsSignal.connect(self.compareDiffVersionsAction)
        btnV.compareMainFileSignal.connect(self.compareDiffMainFileAction)
        btnV.compareCurrentFileSignal.connect(
            self.compareDiffCurrentFileAction)
        return btnV

    def buildUpContItemView(self, info, item, listWid):
        info['currentDir'] = self.dataCtrl.getDataVal('currentDir')
        info['versionDetail'] = 0

        generalInfo = self.dataCtrl.getGeneralInfo()
        info.update(generalInfo)

        btnV = self.buildUpButtonView(info)
        listWid.setItemWidget(item, btnV)

    def showItemDetails(self, item):
        self.renewDetailVersionInfo(item)
        self.clearDetailWidget()
        self.renewDetailWidget(item)
        self.clearHistoryWidget()
        self.renewHistoryWidget()

    def renewDetailVersionInfo(self, item):
        oriBtnV = self.contLW.itemWidget(item)
        oriBtnC = oriBtnV.dataCtrl

        metaData = oriBtnC.getDataVal('metaData')
        fileName = metaData.get('fileName')
        fileType = metaData.get('fileType')
        inputJson = oriBtnC.getDataVal('inputJson')
        updateInfo = {
            'detailFileName': fileName,
            'detailFileType': fileType,
            'detailInputJson': inputJson,
            'versionSelIds': []
        }
        self.dataCtrl.setData(updateInfo)
        self.dataCtrl.getDetailVersionInfo()

    def clearDetailWidget(self):
        if self.detailW:
            self.detailW.hide()
            self.detailW.close()
            self.detailW = None

    def renewDetailWidget(self, item):
        oriBtnV = self.contLW.itemWidget(item)
        oriBtnM = oriBtnV.dataCtrl.dataObj

        info = {}
        info.update(oriBtnM.data)
        info['scaleFractor'] = 1.15
        info['outInfoKeys'] = info['tipsKeys']
        info['versionDetail'] = 0

        generalInfo = self.dataCtrl.getGeneralInfo()
        info.update(generalInfo)

        btnV = self.buildUpButtonView(info)

        self.detailW = btnV
        self.detailW.setFixedWidth(200)
        self.detailW.setFixedHeight(200)
        self.frameLO.addWidget(self.detailW, 2, 1)

    def clearHistoryWidget(self):
        self.versionLW.clear()

    def renewHistoryWidget(self):
        self.renewContentWidget(self.versionLW,
                                'detailVersionInfo',
                                self.buildUpVersionItemView,
                                reverse=1,
                                outWidth=196)

    def buildUpVersionItemView(self, info, item, listWid):
        info['currentDir'] = self.dataCtrl.getDataVal('detailInnerDir')
        info['outInfoKeys'] = ['fileName', 'version']
        info['versionDetail'] = 1

        generalInfo = self.dataCtrl.getGeneralInfo()
        info.update(generalInfo)

        btnV = self.buildUpButtonView(info)
        listWid.setItemWidget(item, btnV)

    def renewVersionSelection(self):
        self.versionLW.itemClicked.disconnect(self.renewVersionSelection)
        versionSelIds = []
        items = self.versionLW.selectedItems()
        popItems = items[:-2]
        selItems = items[-2:]
        for item in selItems:
            rowId = self.versionLW.row(item)
            versionSelIds.append(rowId)

        for popItem in popItems:
            popItem.setSelected(0)

        updateInfo = {'versionSelIds': versionSelIds}
        self.dataCtrl.setData(updateInfo)
        self.versionLW.itemClicked.connect(self.renewVersionSelection)

    def checkOutAction(self, mess, subject, checkOutTest):
        if checkOutTest:
            # mailInfo = {'mess': mess,
            #             'subject': subject}
            # self.dataCtrl.triggerMail(mailInfo)
            self.refreshContentWidget()

        self.buildUpNotificationView(mess, subject)

    def buildUpNotificationView(self, mess, subject):
        QtGui.QMessageBox.warning(self, subject, mess)

    def refreshContentWidget(self):
        detailFileName = self.dataCtrl.getDataVal('detailFileName')
        self.dataCtrl.genDirValidContentInfo()
        self.initContent()
        self.reselectCurrentItem(detailFileName)

    def reselectCurrentItem(self, oriFileName):
        itemNum = self.contLW.count()
        for i in range(itemNum):
            item = self.contLW.item(i)
            wid = self.contLW.itemWidget(item)
            metaData = wid.dataCtrl.getDataVal('metaData')
            fileName = metaData['fileName']
            if fileName == oriFileName:
                self.showItemDetails(item)
                break

    def compareDiffVersionsAction(self):
        versionSelIds = self.dataCtrl.getDataVal('versionSelIds')
        if not len(versionSelIds) == 2:
            title = 'Compare Different With Two Version'
            mess = 'Must Select Two Version Files And Then Compare'
            QtGui.QMessageBox.warning(self, title, mess)
        else:
            detailVersionInfo = self.dataCtrl.getDataVal('detailVersionInfo')
            files = detailVersionInfo.keys()
            files.sort(reverse=1)
            aId = versionSelIds[0]
            bId = versionSelIds[1]
            aFile = files[aId]
            bFile = files[bId]
            diffInfo = self.dataCtrl.compareDiffFiles(aFile, bFile)
            self.emitCmpViewUpdateInfo(diffInfo)

    def compareDiffMainFileAction(self):
        versionSelIds = self.dataCtrl.getDataVal('versionSelIds')
        if not versionSelIds:
            title = 'Compare Different With Main File'
            mess = 'Must Select One Version Files And Then Compare'
            QtGui.QMessageBox.warning(self, title, mess)
        else:
            detailVersionInfo = self.dataCtrl.getDataVal('detailVersionInfo')
            files = detailVersionInfo.keys()
            files.sort(reverse=1)

            inputJson = self.dataCtrl.getDataVal('detailInputJson')
            bId = versionSelIds[0]
            if len(versionSelIds) == 2:
                bId = versionSelIds[1]

            aFile = inputJson
            bFile = files[bId]
            diffInfo = self.dataCtrl.compareDiffFiles(aFile, bFile)
            self.emitCmpViewUpdateInfo(diffInfo)

    def compareDiffCurrentFileAction(self, diffInfo):
        self.emitCmpViewUpdateInfo(diffInfo)

    def emitCmpViewUpdateInfo(self, diffInfo):
        self.updateCmpViewSignal.emit(diffInfo)