Implement UI for excluding types from an analysis/query.

Connect it up to InfoFlowAnalysisTab.
This commit is contained in:
Chris PeBenito 2015-09-02 15:35:32 -04:00
parent 56b2811aa9
commit a899206ab6
6 changed files with 295 additions and 3 deletions

196
data/exclude_types.ui Normal file
View File

@ -0,0 +1,196 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>485</width>
<height>340</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>20</height>
</size>
</property>
<property name="font">
<font>
<pointsize>11</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Included Types</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="label_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>20</height>
</size>
</property>
<property name="font">
<font>
<pointsize>11</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Excluded Types</string>
</property>
</widget>
</item>
<item row="1" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="1">
<widget class="QPushButton" name="exclude_a_type">
<property name="toolTip">
<string>Exclude selected types.</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset>
<normaloff>icons/Button_Next.png</normaloff>icons/Button_Next.png</iconset>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QPushButton" name="include_a_type">
<property name="toolTip">
<string>Include selected types.</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset>
<normaloff>icons/Button_Back.png</normaloff>icons/Button_Back.png</iconset>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
</item>
<item row="4" column="1">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="5" column="2">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="1" column="0" rowspan="4">
<widget class="QListWidget" name="included_types">
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
<property name="sortingEnabled">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="2" rowspan="4">
<widget class="QListWidget" name="excluded_types">
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
<property name="sortingEnabled">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>Dialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>Dialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

BIN
data/icons/Button_Back.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

BIN
data/icons/Button_Next.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

@ -483,6 +483,13 @@
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Limit results:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="limit_paths">
<property name="minimum">
@ -496,10 +503,17 @@
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_7">
<item row="2" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Limit results:</string>
<string>Excluded Types:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QPushButton" name="exclude_types">
<property name="text">
<string>Edit...</string>
</property>
</widget>
</item>

View File

@ -0,0 +1,76 @@
# Copyright 2015, Tresys Technology, LLC
#
# This file is part of SETools.
#
# SETools is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation, either version 2.1 of
# the License, or (at your option) any later version.
#
# SETools is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with SETools. If not, see
# <http://www.gnu.org/licenses/>.
#
import logging
from PyQt5.QtWidgets import QDialog
from ..widget import SEToolsWidget
class ExcludeTypes(SEToolsWidget, QDialog):
"""Dialog for choosing excluded types."""
def __init__(self, parent, policy):
super(ExcludeTypes, self).__init__(parent)
self.log = logging.getLogger(self.__class__.__name__)
self.parent = parent
self.policy = policy
self.excluded_list = [str(e) for e in self.parent.query.exclude]
self.setupUi()
def setupUi(self):
self.load_ui("exclude_types.ui")
self.exclude_a_type.clicked.connect(self.exclude_clicked)
self.include_a_type.clicked.connect(self.include_clicked)
self.buttonBox.accepted.connect(self.ok_clicked)
# populate the lists:
self.included_types.clear()
for item in self.policy.types():
if item not in self.excluded_list:
self.included_types.addItem(str(item))
self.excluded_types.clear()
for item in self.excluded_list:
self.excluded_types.addItem(item)
def include_clicked(self):
for item in self.excluded_types.selectedItems():
self.included_types.addItem(item.text())
self.excluded_types.takeItem(self.excluded_types.row(item))
def exclude_clicked(self):
for item in self.included_types.selectedItems():
self.excluded_types.addItem(item.text())
self.included_types.takeItem(self.included_types.row(item))
def ok_clicked(self):
exclude = []
item = self.excluded_types.takeItem(0)
while item:
exclude.append(item.text())
item = self.excluded_types.takeItem(0)
self.log.debug("Chosen for exclusion: {0!r}".format(exclude))
self.parent.query.exclude = exclude
self.accept()

View File

@ -24,6 +24,7 @@ from PyQt5.QtGui import QPalette, QTextCursor
from PyQt5.QtWidgets import QCompleter, QHeaderView, QMessageBox, QProgressDialog, QScrollArea
from setools import InfoFlowAnalysis
from .excludetypes import ExcludeTypes
from ..widget import SEToolsWidget
@ -97,6 +98,7 @@ class InfoFlowAnalysisTab(SEToolsWidget, QScrollArea):
self.flows_in.toggled.connect(self.flows_in_toggled)
self.flows_out.toggled.connect(self.flows_out_toggled)
self.min_perm_weight.valueChanged.connect(self.set_min_weight)
self.exclude_types.clicked.connect(self.choose_excluded_types)
#
# Analysis mode
@ -156,6 +158,10 @@ class InfoFlowAnalysisTab(SEToolsWidget, QScrollArea):
def set_min_weight(self, value):
self.query.min_weight = value
def choose_excluded_types(self):
chooser = ExcludeTypes(self, self.policy)
chooser.show()
#
# Results runner
#