Ejemplo n.º 1
0
def testGuiForObjectTree():
    keepReference = QApplication(sys.argv)

    global global_tree
    global_tree = KeyedTreeView()

    initHandlers()

    g = theGuiMsgHandler()

    g.registerAddCallback(SESSION_KEY, childInitCB)
    reqId = g.requestObject(
        typeNr = TYPE_PROJECT, callback = None, parentKey = SESSION_KEY)
    g.waitforAnswer(reqId)

    reqId = g.requestObject(
        typeNr = TYPE_CASE, callback = None, parentKey = project_key)
    g.waitforAnswer(reqId)

    caseP = coCaseMgrParams()
    nameAndCase = NameAndCoviseCase()
    nameAndCase.setFromFile('/work/common/Projekte/DC-CFDGui/datasets/'
                            'TINY/CoviseDaten/TINY.cocase')
    caseP.dsc = coviseCase2DimensionSeperatedCase(
        nameAndCase.case, nameAndCase.name)
    g.setParams(case_key, caseP)

    qApp.setMainWidget(global_tree)
    global_tree.show()
    qApp.exec_loop()
Ejemplo n.º 2
0
def testGuiForObjectTree():
    keepReference = QApplication(sys.argv)

    global global_tree
    global_tree = KeyedTreeView()

    initHandlers()

    g = theGuiMsgHandler()

    g.registerAddCallback(SESSION_KEY, childInitCB)
    reqId = g.requestObject(typeNr=TYPE_PROJECT,
                            callback=None,
                            parentKey=SESSION_KEY)
    g.waitforAnswer(reqId)

    reqId = g.requestObject(typeNr=TYPE_CASE,
                            callback=None,
                            parentKey=project_key)
    g.waitforAnswer(reqId)

    caseP = coCaseMgrParams()
    nameAndCase = NameAndCoviseCase()
    nameAndCase.setFromFile('/work/common/Projekte/DC-CFDGui/datasets/'
                            'TINY/CoviseDaten/TINY.cocase')
    caseP.dsc = coviseCase2DimensionSeperatedCase(nameAndCase.case,
                                                  nameAndCase.name)
    g.setParams(case_key, caseP)

    qApp.setMainWidget(global_tree)
    global_tree.show()
    qApp.exec_loop()
Ejemplo n.º 3
0
    def paramChanged( self, key):
        if key in Application.vrpApp.visuKey2GuiKey:
            key = Application.vrpApp.visuKey2GuiKey[key]

        typeNr = ObjectMgr.ObjectMgr().getTypeOfObject(key)
        params = ObjectMgr.ObjectMgr().getParamsOfObject(key)
        realparams = ObjectMgr.ObjectMgr().getRealParamsOfObject(key)
        if not hasattr(realparams, 'name'):
            return

        if not typeNr in typeNotInTree:
            if typeNr in typeWithoutVisibleCheckbox or ( not hasattr( params, 'isVisible') ):
                KeyedTreeView.setItemData(self, key, realparams.name)
            else :
                checkable = NamedCheckable(realparams.name, params.isVisible)
                KeyedTreeView.setItemData(self, key, checkable)
Ejemplo n.º 4
0
    def __init__(self, parent=None, choicePolicy=TreeSelectionHandler):
        _infoer.function = str(self.__init__)
        _infoer.write("")
        QtWidgets.QDialog.__init__(self, parent)
        Ui_CasesFilterBase.__init__(self)
        self.setupUi(self)

        self.checkBox5.hide() # not working

        # hide dialog specific buttons
        self.pushButtonOK.hide()
        self.pushButtonCancel.hide()
            
        self.completeTree = KeyedTreeView(
            self.completeWidgetStack, None, 'All Parts')
        #self.completeTree.setSelectionMode(QListView.ExtendedSelection)
        self.completeWidgetStack.addWidget(self.completeTree)
        self.completeWidgetStack.setCurrentWidget(self.completeTree)

        self.filteredTree = KeyedTreeView(
            self.filteredWidgetStack, None, 'Selected Parts')
        #self.filteredTree.setSelectionMode(QListView.Extended)
        self.filteredWidgetStack.addWidget(self.filteredTree)
        self.filteredWidgetStack.setCurrentWidget(self.filteredTree)

        self.treeSelectionHandler = choicePolicy(
            self.completeTree, self.filteredTree)

        self.__completeTreeKeyCounter = cLikeCounter()
        self.__key2CaseItem = {} # for class-internal lookup
        self.__usefulOnlyWithChild = []
        self.__cases = []

        self.selectAllButton.clicked.connect(self.__selectAllInCompleteTree)
        self.deselectAllButton.clicked.connect(self.__deselectAllInCompleteTree)
        
        self.completeTree.clicked.connect(self.setCompleteChildrenSelected)
        self.filteredTree.clicked.connect(self.setFilteredChildrenSelected)
        
        self.completeTree.doubleClicked.connect(self.completeTreeDoubleClicked)
        self.filteredTree.doubleClicked.connect(self.filteredTreeDoubleClicked)
Ejemplo n.º 5
0
    def addObject( self, key, parentKey, typeNr ):

        # dont add already existing objects
        if KeyedTreeView.has_key(self, key):
            return False

        if typeNr in typeNotInTree:
            return False

        if KeyedTreeView.has_key(self, parentKey) :
            parent = parentKey
        else :
            parent = None
        if typeNr in typeWithoutVisibleCheckbox: 
            KeyedTreeView.insert(self, parent, key, 'newentry')
        else :
            checkable = NamedCheckable('default', False)
            KeyedTreeView.insert(self, parent, key, checkable)
Ejemplo n.º 6
0
class CasesFilter(QtWidgets.QDialog, Ui_CasesFilterBase):

    @_log
    def __init__(self, parent=None, choicePolicy=TreeSelectionHandler):
        _infoer.function = str(self.__init__)
        _infoer.write("")
        QtWidgets.QDialog.__init__(self, parent)
        Ui_CasesFilterBase.__init__(self)
        self.setupUi(self)

        self.checkBox5.hide() # not working

        # hide dialog specific buttons
        self.pushButtonOK.hide()
        self.pushButtonCancel.hide()
            
        self.completeTree = KeyedTreeView(
            self.completeWidgetStack, None, 'All Parts')
        #self.completeTree.setSelectionMode(QListView.ExtendedSelection)
        self.completeWidgetStack.addWidget(self.completeTree)
        self.completeWidgetStack.setCurrentWidget(self.completeTree)

        self.filteredTree = KeyedTreeView(
            self.filteredWidgetStack, None, 'Selected Parts')
        #self.filteredTree.setSelectionMode(QListView.Extended)
        self.filteredWidgetStack.addWidget(self.filteredTree)
        self.filteredWidgetStack.setCurrentWidget(self.filteredTree)

        self.treeSelectionHandler = choicePolicy(
            self.completeTree, self.filteredTree)

        self.__completeTreeKeyCounter = cLikeCounter()
        self.__key2CaseItem = {} # for class-internal lookup
        self.__usefulOnlyWithChild = []
        self.__cases = []

        self.selectAllButton.clicked.connect(self.__selectAllInCompleteTree)
        self.deselectAllButton.clicked.connect(self.__deselectAllInCompleteTree)
        
        self.completeTree.clicked.connect(self.setCompleteChildrenSelected)
        self.filteredTree.clicked.connect(self.setFilteredChildrenSelected)
        
        self.completeTree.doubleClicked.connect(self.completeTreeDoubleClicked)
        self.filteredTree.doubleClicked.connect(self.filteredTreeDoubleClicked)


    @_log
    def getAllCases(self):
        _infoer.function = str(self.getAllCases)
        _infoer.write("")
        return self.__cases

    @_log
    def addDimensionSeperatedCase(self, aCase):
        _infoer.function = str(self.addDimensionSeperatedCase)
        _infoer.write("")

        """Add a representation of the case to the widget."""
        def internRegister(key, thing, usefulOnlyWithChild):
            self.__key2CaseItem[key] = thing
            if usefulOnlyWithChild: self.__usefulOnlyWithChild.append(key)
        caseKey = next(self.__completeTreeKeyCounter)
        self.completeTree.insert(
            parentKey = None, key = caseKey, itemData = str(aCase.name))
        internRegister(caseKey, aCase, True)
        parts2d = aCase.parts2d
        parts2dKey = next(self.__completeTreeKeyCounter)
        self.completeTree.insert(caseKey, parts2dKey, parts2d.name)
        internRegister(parts2dKey, parts2d, True)
        def addParts(parentKey):
            for part in self.__key2CaseItem[parentKey]:
                partKey = next(self.__completeTreeKeyCounter)
                self.completeTree.insert(parentKey, partKey, part.name)
                internRegister(partKey, part, False)
        addParts(parts2dKey)
        parts3d = aCase.parts3d
        parts3dKey = next(self.__completeTreeKeyCounter)
        self.completeTree.insert(caseKey, parts3dKey, parts3d.name)
        internRegister(parts3dKey, parts3d, True)
        addParts(parts3dKey)
        self.__cases.append(aCase)

    def erase(self):
        _infoer.function = str(self.erase)
        _infoer.write("")
        """ delete the complete content """
        self.completeTree.erase()
        self.filteredTree.erase()
        self.__completeTreeKeyCounter = cLikeCounter() # reset
        self.__key2CaseItem.clear()
        self.__usefulOnlyWithChild = []
        self.__cases = []

    @_log
    def getChoice(self):
        _infoer.function = str(self.getChoice)
        _infoer.write("")
        """Return list of the choice of dimension-separated-cases."""
        self.__decorateChoice()
        fineDscs = self.__createFineChosenList()
        roughDscs = self.__createRoughChosenList()
        self.__undecorateChoice()
        return  fineDscs, roughDscs

    def addToChoice(self):
        _infoer.function = str(self.addToChoice)
        _infoer.write("")
        self.treeSelectionHandler.addToChoice()
        self.__clearAllSelections()

    def removeFromChoice(self):
        _infoer.function = str(self.removeFromChoice)
        _infoer.write("")
        # remove selection from listview
        keys = self.treeSelectionHandler.getSelectedChoiceKeys()
        self.treeSelectionHandler.removeFromChoice()
        for key in keys: self.filteredTree.delete(key)
        # now delete the keys 
        childLessUOWCKeys = self.__keysOfUOWCWithoutChild()
        while childLessUOWCKeys:
            for key in childLessUOWCKeys:
                self.filteredTree.delete(key)
            childLessUOWCKeys = self.__keysOfUOWCWithoutChild()
        self.__clearAllSelections()


    #def collapseEquivalentInFilteredTree(self, lvi):
        #_infoer.function = str(self.collapseEquivalentInFilteredTree)
        #_infoer.write("")
        #key = self.completeTree.keyAndItem.preimage(lvi)
        #if self.filteredTree.has_key(key):
            #self.filteredTree.setItemOpen(key, False)
        ## ignore if no equivalent

    #def expandEquivalentInFilteredTree(self, lvi):
        #_infoer.function = str(self.expandEquivalentInFilteredTree)
        #_infoer.write("")
        #key = self.completeTree.keyAndItem.preimage(lvi)
        #if self.filteredTree.has_key(key):
            #self.filteredTree.setItemOpen(key, True)
        ## ignore if no equivalent

    #def collapseEquivalentInCompleteTree(self, lvi):
        #_infoer.function = str(self.collapseEquivalentInCompleteTree)
        #_infoer.write("")
        #key = self.filteredTree.keyAndItem.preimage(lvi)
        #if self.completeTree.has_key(key):
            #self.completeTree.setItemOpen(key, False)
        ## ignore if no equivalent

    #def expandEquivalentInCompleteTree(self, lvi):
        #_infoer.function = str(self.expandEquivalentInCompleteTree)
        #_infoer.write("")
        #key = self.filteredTree.keyAndItem.preimage(lvi)
        #if self.completeTree.has_key(key):
            #self.completeTree.setItemOpen(key, True)
        ## ignore if no equivalent

    def setCompleteChildrenSelected(self, lvi):
        _infoer.function = str(self.setCompleteChildrenSelected)
        _infoer.write("")
        setAllChildrenSelected(self.completeTree)

    def setFilteredChildrenSelected(self, lvi):
        _infoer.function = str(self.setFilteredChildrenSelected)
        _infoer.write("")
        setAllChildrenSelected(self.filteredTree)

    def completeTreeDoubleClicked(self, lvi):
        self.addButton.clicked.emit() # treat doubleclick as click on the add button (StartPreparation.py acts on the signal as well)

    def filteredTreeDoubleClicked(self, lvi):
        self.removeButton.clicked.emit() # treat doubleclick as click on the remove button (StartPreparation.py acts on the signal as well)

    def __keysOfUOWCWithoutChild(self): # UOWC = UsefulOnlyWithChild (a dict)
        _infoer.function = str(self.__keysOfUOWCWithoutChild)
        _infoer.write("")
        keys = []
        for key in self.__usefulOnlyWithChild:
            if self.filteredTree.has_key(key) and (self.filteredTree.childKeys(key) == []):
                keys.append(key)
        return keys

    def __clearAllSelections(self):
        _infoer.function = str(self.__clearAllSelections)
        _infoer.write("")
        self.completeTree.clearSelection()
        self.filteredTree.clearSelection()

    def __selectAllInCompleteTree(self):
        _infoer.function = str(self.__selectAllInCompleteTree)
        _infoer.write("")
        self.completeTree.selectAll()
        self.addToChoice()

    def __deselectAllInCompleteTree(self):
        _infoer.function = str(self.__deselectAllInCompleteTree)
        _infoer.write("")
        self.filteredTree.selectAll()
        self.removeFromChoice()

    def __decorateChoice(self):
        _infoer.function = str(self.__decorateChoice)
        _infoer.write("")
        selectedKeys = self.treeSelectionHandler.getChoiceKeys()
        for key in self.completeTree.getKeys():
            self.__key2CaseItem[key].chosen = (key in selectedKeys)

    def __createFineChosenList(self):
        _infoer.function = str(self.__createFineChosenList)
        def createSubDsc(aDsc):
            """Return sub-dsc with items with chosen == True."""
            def copyPartAndAppend(part, aList):
                copyOfPart = PartWithFileReference(
                    part.filename, part.name)
                copyOfPart.variables = part.variables
                aList.append(copyOfPart)

            subDsc = DimensionSeperatedCase(aDsc.name)
            partLists = [
                (aDsc.parts2d, subDsc.parts2d),
                (aDsc.parts3d, subDsc.parts3d)]
            for partList, partListSub in partLists:
                if partList.chosen:
                    for part in partList:
                        if part.chosen:
                            copyPartAndAppend(part, partListSub)
            _infoer.write("subDsc %s" %str(subDsc))
            return subDsc
        dscs = []
        for dsc in self.__cases:
            if dsc.chosen: dscs.append(createSubDsc(dsc))
        _infoer.write("dscs %s" %str(dscs))
        return dscs

    def __createRoughChosenList(self):
        _infoer.function = str(self.__createRoughChosenList)
        _infoer.write("")
        """Return list of added DSCS that have any chose part."""
        dscs = []
        for dsc in self.__cases:
            if dsc.chosen: dscs.append(dsc)
        return dscs

    def __undecorateChoice(self):
        _infoer.function = str(self.__undecorateChoice)
        _infoer.write("")
        for key in self.completeTree.getKeys():
            del self.__key2CaseItem[key].chosen
Ejemplo n.º 7
0
 def deleteObject( self, key, parentKey, typeNr):
     if not typeNr in typeNotInTree:
         KeyedTreeView.delete(self, key)
Ejemplo n.º 8
0
 def __init__(self, parent):
     KeyedTreeView.__init__(self, parent, KeyedTreeFilterProxy(parent), "TreeView")
     
     ObjectMgr.ObjectMgr().sigGuiObjectAdded.connect(self.addObject)
     ObjectMgr.ObjectMgr().sigGuiObjectDeleted.connect(self.deleteObject)
     ObjectMgr.ObjectMgr().sigGuiParamChanged.connect(self.paramChanged)