def populateTree(self, selectedDetection=None): selected = None self.treeWidget.clear() self.treeWidget.setColumnCount(3) self.treeWidget.setHeaderLabels(["Rule/Process", "Pid", "Text"]) self.treeWidget.setItemsExpandable(True) parentRule = {} parentRuleProcess = {} for detection in self.detections: ancestor = parentRule.get(detection.rule_name) if ancestor is None: ancestor = QTreeWidgetItem(self.treeWidget, [detection.rule_name]) parentRule[detection.rule_name] = ancestor process = detection.process parent = parentRuleProcess.get(process) if parent is None: parent = QTreeWidgetItem(ancestor, [process, QString("%L1").arg(detection.pid)]) parentRuleProcess[process] = parent item = QTreeWidgetItem(parent, ['','', detection.text]) item.setTextAlignment(3, Qt.AlignRight|Qt.AlignVCenter) if selectedDetection is not None and selectedDetection == id(detection): selected = item #self.treeWidget.expandItem(parent) self.treeWidget.expandItem(ancestor) self.treeWidget.resizeColumnToContents(0) self.treeWidget.resizeColumnToContents(1) if selected is not None: selected.setSelected(True) self.treeWidget.setCurrentItem(selected)
def fill(self): self.clear() services = self._client.getServices() try: descrs = self._client.getServiceDescriptions(services) except Exception: descrs = {} self._client.startPoller(self.updateStatus) for service, instances in iteritems(services): serviceItem = QTreeWidgetItem([service]) serviceItem.setForeground(1, QBrush(QColor('white'))) serviceItem.setTextAlignment(1, Qt.AlignCenter) serviceItem.setFlags(Qt.ItemIsEnabled) serviceItem.setForeground(3, QBrush(QColor('red'))) self.addTopLevelItem(serviceItem) btns = [] has_empty_instance = None for instance in instances: if not instance: has_empty_instance = True continue instanceItem = QTreeWidgetItem([instance]) instanceItem.setForeground(1, QBrush(QColor('white'))) instanceItem.setTextAlignment(1, Qt.AlignCenter) instanceItem.setFlags(Qt.ItemIsEnabled) instanceItem.setForeground(3, QBrush(QColor('red'))) if descrs.get((service, instance)): instanceItem.setText(0, descrs[service, instance]) serviceItem.addChild(instanceItem) btn = JobButtons(self._client, service, instance, instanceItem) btns.append(btn) self.setItemWidget(instanceItem, 2, btn) self._items[service, instance] = instanceItem if has_empty_instance: btn = JobButtons(self._client, service, '', serviceItem) btn.setMinimumSize(QSize(30, 40)) self.setItemWidget(serviceItem, 2, btn) if descrs.get((service, '')): serviceItem.setText(0, descrs[service, '']) self._items[service, ''] = serviceItem else: # create "virtual" job with buttons that start/stop all # instances of the service self._virt_items[service] = serviceItem multibtn = MultiJobButtons(btns) self.setItemWidget(serviceItem, 2, multibtn) self.expandAll()
def fill(self): self.clear() services = self._client.getServices() try: descrs = self._client.getServiceDescriptions(services) except Exception: descrs = {} self._client.startPoller(self.updateStatus) for service, instances in iteritems(services): serviceItem = QTreeWidgetItem([service]) serviceItem.setForeground(1, QBrush(QColor('white'))) serviceItem.setTextAlignment(1, Qt.AlignCenter) serviceItem.setFlags(Qt.ItemIsEnabled) serviceItem.setForeground(3, QBrush(QColor('red'))) self.addTopLevelItem(serviceItem) if not instances: self._items[service] = serviceItem btn = JobButtons(self._client, service, None, serviceItem) self.setItemWidget(serviceItem, 2, btn) if descrs.get(service): serviceItem.setText(0, descrs[service]) else: self._items[service] = (serviceItem, {}) btns = [] for instance in instances: instanceItem = QTreeWidgetItem([instance]) instanceItem.setForeground(1, QBrush(QColor('white'))) instanceItem.setTextAlignment(1, Qt.AlignCenter) instanceItem.setFlags(Qt.ItemIsEnabled) instanceItem.setForeground(3, QBrush(QColor('red'))) if descrs.get((service, instance)): instanceItem.setText(0, descrs[service, instance]) serviceItem.addChild(instanceItem) btn = JobButtons(self._client, service, instance, instanceItem) btns.append(btn) self.setItemWidget(instanceItem, 2, btn) self._items[service][1][instance] = instanceItem multibtn = MultiJobButtons(btns) self.setItemWidget(serviceItem, 2, multibtn) self.expandAll()
def refresh(self): tree = self.uiFilterTREE tree.blockSignals(True) tree.setUpdatesEnabled(False) tree.clear() # create the code color codeClr = tree.palette().color(tree.palette().Base).darker(140) # sort the data hash filters = self._filterOptions.items() filters.sort(lambda x, y: cmp(x[1].get('order', 100000), y[1].get( 'order', 100000))) for key, option in filters: # create the data for this item data = {'code': key} data.update(option) # create the data item item = QTreeWidgetItem( [data.get('name', ''), data.get('code', '')]) item.setIcon(0, resources.icon(data.get('icon', '') % data)) item.setSizeHint(0, QSize(0, 18)) # check the item if its enabled if (self.isCheckable()): enabled = data.get('enabled', False) item.setCheckState(0, Qt.Checked if enabled else Qt.Unchecked) # set some ui data for the code name to hide it a bit item.setTextAlignment(1, Qt.AlignRight | Qt.AlignCenter) item.setForeground(1, codeClr) # add to the tree tree.addTopLevelItem(item) tree.setUpdatesEnabled(True) tree.blockSignals(False)
def refresh( self ): tree = self.uiFilterTREE tree.blockSignals(True) tree.setUpdatesEnabled(False) tree.clear() # create the code color codeClr = tree.palette().color(tree.palette().Base).darker(140) # sort the data hash filters = self._filterOptions.items() filters.sort( lambda x,y: cmp(x[1].get('order',100000),y[1].get('order',100000)) ) for key, option in filters: # create the data for this item data = { 'code': key } data.update(option) # create the data item item = QTreeWidgetItem( [data.get('name',''),data.get('code','')] ) item.setIcon( 0, resources.icon( data.get('icon','') % data ) ) item.setSizeHint( 0, QSize( 0, 18 ) ) # check the item if its enabled if ( self.isCheckable() ): enabled = data.get('enabled',False) item.setCheckState( 0, Qt.Checked if enabled else Qt.Unchecked ) # set some ui data for the code name to hide it a bit item.setTextAlignment( 1, Qt.AlignRight | Qt.AlignCenter ) item.setForeground( 1, codeClr ) # add to the tree tree.addTopLevelItem(item) tree.setUpdatesEnabled(True) tree.blockSignals(False)
def refresh(self): self.uiStatusTREE.blockSignals(True) self.uiStatusTREE.setUpdatesEnabled(False) self.uiStatusTREE.clear() # collect the data from the prefs ordered = self._statusPrefs.values('order').items() # sort the items by their order ordered.sort(lambda x, y: cmp(x[1], y[1])) # add the statuses to the tree from PyQt4.QtCore import Qt from PyQt4.QtGui import QTreeWidgetItem, QPalette, QIcon for status, order in ordered: # grab info from the hash icon, display_name = self._statusHash.get(status, ('', 'Missing')) item = QTreeWidgetItem([display_name, status]) item.setIcon(0, QIcon(icon)) # check the item if it is enabled enabled = self._statusPrefs.value(status, 'enabled') item.setCheckState(0, Qt.Checked if enabled else Qt.Unchecked) # set some ui options for the status name to hide it a bit item.setTextAlignment(1, Qt.AlignRight | Qt.AlignVCenter) item.setForeground( 1, self.uiStatusTREE.palette().color(QPalette.Base).darker(140)) # add to the tree self.uiStatusTREE.addTopLevelItem(item) self.uiStatusTREE.blockSignals(False) self.uiStatusTREE.setUpdatesEnabled(True)
def __createEntry(self, info): """ Private method to create a list entry based on the provided info. @param info tuple giving the info for the entry """ infoList = QStringList() \ << info[0] \ << info[1] \ << info[2] \ << (info[3] and self.trUtf8("Yes") or self.trUtf8("No")) \ << (info[4] and self.trUtf8("Yes") or self.trUtf8("No")) \ << info[5] itm = QTreeWidgetItem(self.pluginList, infoList) if info[6]: # plugin error for col in range(self.pluginList.columnCount()): itm.setForeground(col, QBrush(Qt.red)) itm.setTextAlignment(self.__autoActivateColumn, Qt.AlignHCenter) itm.setTextAlignment(self.__activeColumn, Qt.AlignHCenter) self.pluginList.header().resizeSections(QHeaderView.ResizeToContents) self.pluginList.header().setStretchLastSection(True)
def refresh( self ): self.uiStatusTREE.blockSignals(True) self.uiStatusTREE.setUpdatesEnabled(False) self.uiStatusTREE.clear() # collect the data from the prefs ordered = self._statusPrefs.values('order').items() # sort the items by their order ordered.sort( lambda x,y: cmp( x[1], y[1] ) ) # add the statuses to the tree from PyQt4.QtCore import Qt from PyQt4.QtGui import QTreeWidgetItem, QPalette, QIcon for status, order in ordered: # grab info from the hash icon, display_name = self._statusHash.get(status,('','Missing')) item = QTreeWidgetItem([display_name,status]) item.setIcon( 0, QIcon(icon) ) # check the item if it is enabled enabled = self._statusPrefs.value(status,'enabled') item.setCheckState( 0, Qt.Checked if enabled else Qt.Unchecked ) # set some ui options for the status name to hide it a bit item.setTextAlignment( 1, Qt.AlignRight | Qt.AlignVCenter ) item.setForeground( 1, self.uiStatusTREE.palette().color(QPalette.Base).darker(140) ) # add to the tree self.uiStatusTREE.addTopLevelItem(item) self.uiStatusTREE.blockSignals(False) self.uiStatusTREE.setUpdatesEnabled(True)
def generate_children(self, parent): # Clean parent of previous items self.clear_tree_item(parent) for item in parent.get_items(): # Read item params columns = QStringList() columns.append(item.get_name()) columns.append(item.get_size()) # Create tree item child = QTreeWidgetItem(columns) child.setTextAlignment(1, Qt.AlignRight|Qt.AlignVCenter) child.setFirstColumnSpanned(True) # Set icon with mime type, and folder indicator self.set_icon(item.mime_type, child) if item.is_folder(): child.setChildIndicatorPolicy(QTreeWidgetItem.ShowIndicator) # Set tree item to item data item.tree_item = child # sort alphapetically and add items to tree self.sort_and_show_children(parent) # add loading widgets self.add_loading_widgets(parent.get_items())
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