Exemplo n.º 1
0
 def SetItems(parentItem, fictiveObjects, level):
     level += 1
     for object in fictiveObjects:
         type = object.type
         if not type in showTypes:
             continue
         # Construct text
         if type=='cell':
             type = '##'
         elif type=='attribute':
             type = 'attr'
         #
         if type == 'import':                   
             text = "%s (%s)" % (object.name, object.text)
         elif type=='todo':
             text = object.name
         else:
             text = "%s %s" % (type, object.name)
         # Create item
         thisItem = QtGui.QTreeWidgetItem(parentItem, [text])
         color = QtGui.QColor(colours[object.type])
         thisItem.setForeground(0, QtGui.QBrush(color))
         font = thisItem.font(0)
         font.setBold(True)
         thisItem.setFont(0, font)
         thisItem.linenr = object.linenr
         # Is this the current item?
         if ln and object.linenr <= ln and object.linenr2 > ln:
             selectedItem[0] = thisItem 
         # Any children that we should display?
         if object.children:
             SetItems(thisItem, object.children, level)
         # Set visibility 
         thisItem.setExpanded( bool(level < showLevel) )
Exemplo n.º 2
0
 def updateStructure(self):
     """ Updates the tree. 
     """
     
     # Get editor
     editor = iep.editors.getCurrentEditor()
     if not editor:
         return
     
     # Something to show
     result = iep.parser._getResult()
     if result is None:
         return
     
     # Do the ids match?
     id0, id1, id2 = self._currentEditorId, id(editor), result.editorId 
     if id0 != id1 or id0 != id2:
         return
     
     # Get current line number and the structure
     ln = editor.textCursor().blockNumber()
     ln += 1  # is ln as in line number area
     
     # Define colours
     colours = {'cell':'#007F00', 'class':'#0000FF', 'def':'#007F7F', 
                 'attribute':'#444444', 'import':'#8800BB', 'todo':'#FF3333'}
     
     # Define what to show
     showTypes = self._config.showTypes
     
     # Define to what level to show (now is also a good time to save)
     showLevel = int( self._slider.value() )
     self._config.level = showLevel
     
     # Define function to set items
     selectedItem = [None]
     def SetItems(parentItem, fictiveObjects, level):
         level += 1
         for object in fictiveObjects:
             type = object.type
             if not type in showTypes:
                 continue
             # Construct text
             if type=='cell':
                 type = '##'
             elif type=='attribute':
                 type = 'attr'
             #
             if type == 'import':                   
                 text = "%s (%s)" % (object.name, object.text)
             elif type=='todo':
                 text = object.name
             else:
                 text = "%s %s" % (type, object.name)
             # Create item
             thisItem = QtGui.QTreeWidgetItem(parentItem, [text])
             color = QtGui.QColor(colours[object.type])
             thisItem.setForeground(0, QtGui.QBrush(color))
             font = thisItem.font(0)
             font.setBold(True)
             thisItem.setFont(0, font)
             thisItem.linenr = object.linenr
             # Is this the current item?
             if ln and object.linenr <= ln and object.linenr2 > ln:
                 selectedItem[0] = thisItem 
             # Any children that we should display?
             if object.children:
                 SetItems(thisItem, object.children, level)
             # Set visibility 
             thisItem.setExpanded( bool(level < showLevel) )
     
     # Go
     self._tree.setUpdatesEnabled(False)
     self._tree.clear()
     SetItems(self._tree, result.rootItem.children, 0)
     self._tree.setUpdatesEnabled(True)
     
     # Handle selected item
     selectedItem = selectedItem[0]
     if selectedItem:
         selectedItem.setBackground(0, QtGui.QBrush(QtGui.QColor('#CCC')))
         self._tree.scrollToItem(selectedItem) # ensure visible