Ejemplo n.º 1
0
 def __init__(self, window):
     Library.__init__(self, window, "resource")
     self.dialog = CreateResourceDialog(self)
     self.setupWindow(window)
     self.filter = NetworkFilter()
Ejemplo n.º 2
0
class Resources(Library):
    REFRESH_DOMAIN = u"resources"
    URL_FORMAT = u"resource:%s"
    RULESET_ATTRIBUTE = "resources"
    CHILD_CLASS = Resource
    GROUP_CLASS = NetworkGroup
    ACTIONS = NetworkActions
    MODEL_CLASS = NetworksModel

    def __init__(self, window):
        Library.__init__(self, window, "resource")
        self.dialog = CreateResourceDialog(self)
        self.setupWindow(window)
        self.filter = NetworkFilter()

    def setupWindow(self, window):
        self.setButtons()
        self.setContainer(window.resource_tree)
        menu = NetworkMenu(self, window.config,
            tr("New"),
            tr("Edit"),
            tr("Delete"))
        self.setMenu(menu)

    def __iter__(self):
        return self.model.resourcesIterator()

    def create(self):
        parent = self.currentObject()
        self.dialog.create(parent)

    def modify(self, resource):
        self.dialog.modify(resource)

    def createInterfaceEvent(self):
        self.dialog.create(None)

    def _createTree(self, resources):
        resources.sort(key=getIdentifier)
        root = []
        for resource in resources:
            ignore = not self.filter.match(resource)
            tree = self.createTreeItem(resource)
            if 'children' in resource:
                children = resource['children'].values()
                nodes = self._createTree(children)
                for node in nodes:
                    tree.addChild(node)
                    ignore = False
            if resource['editable']:
                font = tree.font(0)
                font.setBold(True)
                tree.setFont(0, font)
            if ignore:
                continue
            root.append(tree)
        return root

    def createTree(self):
        nodes = self._createTree(list(self.model))
        root = QTreeWidgetItem([tr("Network interfaces")])
        root.setIcon(0, QIcon(":/icons-32/home.png"))
        unsetFlag(root, Qt.ItemIsSelectable)
        for node in nodes:
            root.addChild(node)
        return [root]