class QNGWItem(QTreeWidgetItem):
    def __init__(self):
        QTreeWidgetItem.__init__(self)
        
        self.locked_item = QTreeWidgetItem(["loading..."])
        self.locked_item.setFlags(Qt.NoItemFlags)
        self.locked_item.setDisabled(True)

        self.release()

    def lock(self):
        self.__isLock = True
        self.setFlags(Qt.NoItemFlags)

        self.addChild(
            self.locked_item
        )

    def is_locked(self):
        return self.__isLock

    def release(self):
        self.__isLock = False
        self.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable)

        self.removeChild(
            self.locked_item
        )

    def ngw_resource_children_count(self):
        raise NotImplementedError()
Beispiel #2
0
 def refresh(self):
     title = translate('Pylint', 'Results for ')+self.filename
     self.set_title(title)
     self.clear()
     self.data = {}
     # Populating tree
     results = ((translate('Pylint', 'Convention'),
                 get_icon('convention.png'), self.results['C:']),
                (translate('Pylint', 'Refactor'),
                 get_icon('refactor.png'), self.results['R:']),
                (translate('Pylint', 'Warning'),
                 get_icon('warning.png'), self.results['W:']),
                (translate('Pylint', 'Error'),
                 get_icon('error.png'), self.results['E:']))
     for title, icon, messages in results:
         title += ' (%d message%s)' % (len(messages),
                                       's' if len(messages)>1 else '')
         title_item = QTreeWidgetItem(self, [title])
         title_item.setIcon(0, icon)
         if not messages:
             title_item.setDisabled(True)
         modules = {}
         for module, lineno, message in messages:
             basename = osp.splitext(osp.basename(self.filename))[0]
             if not module.startswith(basename):
                 # Pylint bug
                 i_base = module.find(basename)
                 module = module[i_base:]
             dirname = osp.dirname(self.filename)
             if module.startswith('.'):
                 modname = osp.join(dirname, module)
             else:
                 modname = osp.join(dirname, *module.split('.'))
             if osp.isdir(modname):
                 modname = osp.join(modname, '__init__')
             for ext in ('.py', '.pyw'):
                 if osp.isfile(modname+ext):
                     modname = modname + ext
                     break
             if osp.isdir(self.filename):
                 parent = modules.get(modname)
                 if parent is None:
                     item = QTreeWidgetItem(title_item, [module])
                     item.setIcon(0, get_icon('py.png'))
                     modules[modname] = item
                     parent = item
             else:
                 parent = title_item
             msg_item = QTreeWidgetItem(parent,
                                        ["%d : %s" % (lineno, message)])
             msg_item.setIcon(0, get_icon('arrow.png'))
             self.data[msg_item] = (modname, lineno)
Beispiel #3
0
 def refresh(self):
     title = translate('Pylint', 'Results for ') + self.filename
     self.set_title(title)
     self.clear()
     self.data = {}
     # Populating tree
     results = ((translate('Pylint', 'Convention'),
                 get_icon('convention.png'), self.results['C:']),
                (translate('Pylint', 'Refactor'), get_icon('refactor.png'),
                 self.results['R:']),
                (translate('Pylint', 'Warning'), get_icon('warning.png'),
                 self.results['W:']), (translate('Pylint', 'Error'),
                                       get_icon('error.png'),
                                       self.results['E:']))
     for title, icon, messages in results:
         title += ' (%d message%s)' % (len(messages),
                                       's' if len(messages) > 1 else '')
         title_item = QTreeWidgetItem(self, [title])
         title_item.setIcon(0, icon)
         if not messages:
             title_item.setDisabled(True)
         modules = {}
         for module, lineno, message in messages:
             basename = osp.splitext(osp.basename(self.filename))[0]
             if not module.startswith(basename):
                 # Pylint bug
                 i_base = module.find(basename)
                 module = module[i_base:]
             dirname = osp.dirname(self.filename)
             modname = osp.join(dirname, *module.split('.'))
             if osp.isdir(modname):
                 modname = osp.join(modname, '__init__')
             for ext in ('.py', '.pyw'):
                 if osp.isfile(modname + ext):
                     modname = modname + ext
                     break
             if osp.isdir(self.filename):
                 parent = modules.get(modname)
                 if parent is None:
                     item = QTreeWidgetItem(title_item, [module])
                     item.setIcon(0, get_icon('py.png'))
                     modules[modname] = item
                     parent = item
             else:
                 parent = title_item
             msg_item = QTreeWidgetItem(parent,
                                        ["%d : %s" % (lineno, message)])
             msg_item.setIcon(0, get_icon('arrow.png'))
             self.data[msg_item] = (modname, lineno)
Beispiel #4
0
    def populate_tree(self,parentItem,childrenList):
        '''Recursive method to create each item (and associated data) in the tree.'''
        for childKey in childrenList:
            self.itemDepth +=1
            fileName,lineNumber,functionName,fileAndLine,nodeType = self.function_info(childKey)
            primCalls,totalCalls,locTime,cumTime,callers = self.stats[childKey]
            childItem = QTreeWidgetItem(parentItem)
            self.itemsList.append(childItem)
            childItem.setData(0,Qt.UserRole,self.itemDepth)

            # FIXME: indexes to data should be defined by a dictionary on init
            childItem.setToolTip(0,'Function or module name')
            childItem.setData(0,Qt.DisplayRole,functionName)
            childItem.setIcon(0,get_icon(self.iconDict[nodeType]))

            childItem.setToolTip(1,'Time in function (including sub-functions)')
            #childItem.setData(1,Qt.DisplayRole,cumTime)
            childItem.setData(1,Qt.DisplayRole,QString('%1').arg(cumTime,0,'f',3))
            childItem.setTextAlignment(1,Qt.AlignCenter)

            childItem.setToolTip(2,'Local time in function (not in sub-functions)')
            #childItem.setData(2,Qt.DisplayRole,locTime)
            childItem.setData(2,Qt.DisplayRole,QString('%1').arg(locTime,0,'f',3))
            childItem.setTextAlignment(2,Qt.AlignCenter)

            childItem.setToolTip(3,'Total number of calls (including recursion)')
            childItem.setData(3,Qt.DisplayRole,totalCalls)
            childItem.setTextAlignment(3,Qt.AlignCenter)

            childItem.setToolTip(4,'File:line where function is defined')
            childItem.setData(4,Qt.DisplayRole,fileAndLine)
            #childItem.setExpanded(True)
            if self.is_recursive(childItem):
                childItem.setData(4,Qt.DisplayRole,'(recursion)')
                childItem.setDisabled(True)
            else:
                self.populate_tree(childItem,self.find_callees(childKey))
            self.itemDepth -= 1
Beispiel #5
0
class RestoreDialog(widgets.dialog.Dialog):
    def __init__(self, parent=None):
        super(RestoreDialog, self).__init__(parent)
        self.messageLabel().setWordWrap(True)
        userguide.addButton(self.buttonBox(), "snippets")
        self.tree = QTreeWidget(headerHidden=True, rootIsDecorated=False)
        self.setMainWidget(self.tree)
        
        self.deletedItem = QTreeWidgetItem(self.tree)
        self.deletedItem.setFlags(Qt.ItemIsUserCheckable)
        self.changedItem = QTreeWidgetItem(self.tree)
        self.changedItem.setFlags(Qt.ItemIsUserCheckable)
        self.tree.itemChanged.connect(self.slotItemChanged)
        
        app.translateUI(self)
        app.languageChanged.connect(self.populate)
        self.accepted.connect(self.updateSnippets)
        qutil.saveDialogSize(self, "snippettool/restoredialog/size")
    
    def translateUI(self):
        self.setWindowTitle(
            app.caption(_("dialog title", "Restore Built-in Snippets")))
        self.setMessage(_(
            "This dialog allows you to recover built-in snippets that have "
            "been changed or deleted. Check the snippets you want to recover "
            "and click the button \"Restore Checked Snippets.\""))
        self.button("ok").setText(_("Restore Checked Snippets"))
        self.deletedItem.setText(0, _("Deleted Snippets"))
        self.changedItem.setText(0, _("Changed Snippets"))
        
    def populate(self):
        """Puts the deleted/changed snippets in the tree."""
        self.deletedItem.takeChildren()
        self.deletedItem.setExpanded(True)
        self.deletedItem.setCheckState(0, Qt.Unchecked)
        self.changedItem.takeChildren()
        self.changedItem.setExpanded(True)
        self.changedItem.setCheckState(0, Qt.Unchecked)
        
        builtins = list(builtin.builtin_snippets)
        builtins.sort(key = snippets.title)
        
        names = frozenset(snippets.names())
        
        for name in builtins:
            if name in names:
                if snippets.isoriginal(name):
                    continue
                parent = self.changedItem
            else:
                parent = self.deletedItem
            
            item = QTreeWidgetItem(parent)
            item.name = name
            item.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled)
            item.setCheckState(0, Qt.Unchecked)
            item.setText(0, snippets.title(name))
        
        self.deletedItem.setDisabled(self.deletedItem.childCount() == 0)
        self.changedItem.setDisabled(self.changedItem.childCount() == 0)
        self.checkOkButton()
    
    def slotItemChanged(self, item):
        if item in (self.deletedItem, self.changedItem):
            for i in range(item.childCount()):
                item.child(i).setCheckState(0, item.checkState(0))
        self.checkOkButton()
        
    def checkedSnippets(self):
        """Yields the names of the checked snippets."""
        for parent in (self.deletedItem, self.changedItem):
            for i in range(parent.childCount()):
                child = parent.child(i)
                if child.checkState(0) == Qt.Checked:
                    yield child.name
    
    def updateSnippets(self):
        """Restores the checked snippets."""
        collection = self.parent().parent().snippetActions
        for name in self.checkedSnippets():
            collection.restoreDefaultShortcuts(name)
            model.model().saveSnippet(name, None, None)

    def checkOkButton(self):
        """Enables the OK button if there are selected snippets."""
        self.button("ok").setEnabled(any(self.checkedSnippets()))
Beispiel #6
0
class RestoreDialog(widgets.dialog.Dialog):
    def __init__(self, parent=None):
        super(RestoreDialog, self).__init__(parent)
        self.messageLabel().setWordWrap(True)
        userguide.addButton(self.buttonBox(), "snippets")
        self.tree = QTreeWidget(headerHidden=True, rootIsDecorated=False)
        self.setMainWidget(self.tree)

        self.deletedItem = QTreeWidgetItem(self.tree)
        self.deletedItem.setFlags(Qt.ItemIsUserCheckable)
        self.changedItem = QTreeWidgetItem(self.tree)
        self.changedItem.setFlags(Qt.ItemIsUserCheckable)
        self.tree.itemChanged.connect(self.slotItemChanged)

        app.translateUI(self)
        app.languageChanged.connect(self.populate)
        self.accepted.connect(self.updateSnippets)
        qutil.saveDialogSize(self, "snippettool/restoredialog/size")

    def translateUI(self):
        self.setWindowTitle(
            app.caption(_("dialog title", "Restore Built-in Snippets")))
        self.setMessage(
            _("This dialog allows you to recover built-in snippets that have "
              "been changed or deleted. Check the snippets you want to recover "
              "and click the button \"Restore Checked Snippets.\""))
        self.button("ok").setText(_("Restore Checked Snippets"))
        self.deletedItem.setText(0, _("Deleted Snippets"))
        self.changedItem.setText(0, _("Changed Snippets"))

    def populate(self):
        """Puts the deleted/changed snippets in the tree."""
        self.deletedItem.takeChildren()
        self.deletedItem.setExpanded(True)
        self.deletedItem.setCheckState(0, Qt.Unchecked)
        self.changedItem.takeChildren()
        self.changedItem.setExpanded(True)
        self.changedItem.setCheckState(0, Qt.Unchecked)

        builtins = list(builtin.builtin_snippets)
        builtins.sort(key=snippets.title)

        names = frozenset(snippets.names())

        for name in builtins:
            if name in names:
                if snippets.isoriginal(name):
                    continue
                parent = self.changedItem
            else:
                parent = self.deletedItem

            item = QTreeWidgetItem(parent)
            item.name = name
            item.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled)
            item.setCheckState(0, Qt.Unchecked)
            item.setText(0, snippets.title(name))

        self.deletedItem.setDisabled(self.deletedItem.childCount() == 0)
        self.changedItem.setDisabled(self.changedItem.childCount() == 0)
        self.checkOkButton()

    def slotItemChanged(self, item):
        if item in (self.deletedItem, self.changedItem):
            for i in range(item.childCount()):
                item.child(i).setCheckState(0, item.checkState(0))
        self.checkOkButton()

    def checkedSnippets(self):
        """Yields the names of the checked snippets."""
        for parent in (self.deletedItem, self.changedItem):
            for i in range(parent.childCount()):
                child = parent.child(i)
                if child.checkState(0) == Qt.Checked:
                    yield child.name

    def updateSnippets(self):
        """Restores the checked snippets."""
        collection = self.parent().parent().snippetActions
        for name in self.checkedSnippets():
            collection.restoreDefaultShortcuts(name)
            model.model().saveSnippet(name, None, None)

    def checkOkButton(self):
        """Enables the OK button if there are selected snippets."""
        self.button("ok").setEnabled(any(self.checkedSnippets()))