2020-07-28 14:33:28 +00:00
|
|
|
# This software is licensed under the "GPLv3" License as described in the "LICENSE" file,
|
|
|
|
# which should be included with this package. The terms are also available at
|
|
|
|
# http://www.gnu.org/licenses/gpl-3.0.html
|
|
|
|
|
|
|
|
from PyQt5.QtCore import Qt, pyqtSlot
|
|
|
|
from PyQt5.QtWidgets import (
|
|
|
|
QPushButton, QLineEdit, QVBoxLayout, QGridLayout, QDialog,
|
|
|
|
QTableView, QAbstractItemView, QSpacerItem, QSizePolicy, QHeaderView
|
|
|
|
)
|
|
|
|
from .exclude_list_table import ExcludeListTable, ExcludeView
|
|
|
|
|
2020-08-17 02:13:20 +00:00
|
|
|
from core.exclude import AlreadyThereException
|
2020-07-28 14:33:28 +00:00
|
|
|
from hscommon.trans import trget
|
|
|
|
tr = trget("ui")
|
|
|
|
|
|
|
|
|
|
|
|
class ExcludeListDialog(QDialog):
|
|
|
|
def __init__(self, app, parent, model, **kwargs):
|
|
|
|
flags = Qt.CustomizeWindowHint | Qt.WindowTitleHint | Qt.WindowSystemMenuHint
|
|
|
|
super().__init__(parent, flags, **kwargs)
|
2020-08-17 02:13:20 +00:00
|
|
|
self.app = app
|
2020-07-28 14:33:28 +00:00
|
|
|
self.specific_actions = frozenset()
|
|
|
|
self._setupUI()
|
|
|
|
self.model = model # ExcludeListDialogCore
|
|
|
|
self.model.view = self
|
2020-08-17 02:13:20 +00:00
|
|
|
self.table = ExcludeListTable(app, view=self.tableView) # Qt ExcludeListTable
|
2020-07-28 14:33:28 +00:00
|
|
|
|
2020-08-17 02:13:20 +00:00
|
|
|
self.buttonAdd.clicked.connect(self.addStringFromLineEdit)
|
|
|
|
self.buttonRemove.clicked.connect(self.removeSelected)
|
2020-07-28 14:33:28 +00:00
|
|
|
self.buttonRestore.clicked.connect(self.restoreDefaults)
|
|
|
|
self.buttonClose.clicked.connect(self.accept)
|
2020-08-17 02:13:20 +00:00
|
|
|
self.buttonHelp.clicked.connect(self.display_help_message)
|
2020-07-28 14:33:28 +00:00
|
|
|
|
|
|
|
def _setupUI(self):
|
|
|
|
layout = QVBoxLayout(self)
|
|
|
|
gridlayout = QGridLayout()
|
|
|
|
self.buttonAdd = QPushButton(tr("Add"))
|
|
|
|
self.buttonRemove = QPushButton(tr("Remove Selected"))
|
|
|
|
self.buttonRestore = QPushButton(tr("Restore defaults"))
|
|
|
|
self.buttonClose = QPushButton(tr("Close"))
|
2020-08-17 02:13:20 +00:00
|
|
|
self.buttonHelp = QPushButton(tr("Help"))
|
2020-07-28 14:33:28 +00:00
|
|
|
self.linedit = QLineEdit()
|
|
|
|
self.tableView = ExcludeView()
|
|
|
|
triggers = (
|
|
|
|
QAbstractItemView.DoubleClicked
|
|
|
|
| QAbstractItemView.EditKeyPressed
|
|
|
|
| QAbstractItemView.SelectedClicked
|
|
|
|
)
|
|
|
|
self.tableView.setEditTriggers(triggers)
|
|
|
|
self.tableView.setSelectionMode(QTableView.ExtendedSelection)
|
|
|
|
self.tableView.setSelectionBehavior(QTableView.SelectRows)
|
2020-08-17 02:13:20 +00:00
|
|
|
self.tableView.setShowGrid(False)
|
|
|
|
vheader = self.tableView.verticalHeader()
|
|
|
|
vheader.setSectionsMovable(True)
|
|
|
|
vheader.setVisible(False)
|
2020-07-28 14:33:28 +00:00
|
|
|
hheader = self.tableView.horizontalHeader()
|
|
|
|
hheader.setSectionsMovable(False)
|
|
|
|
hheader.setSectionResizeMode(QHeaderView.Fixed)
|
|
|
|
hheader.setStretchLastSection(True)
|
|
|
|
hheader.setHighlightSections(False)
|
2020-08-17 02:13:20 +00:00
|
|
|
hheader.setVisible(True)
|
2020-07-28 14:33:28 +00:00
|
|
|
gridlayout.addWidget(self.linedit, 0, 0)
|
|
|
|
gridlayout.addWidget(self.buttonAdd, 0, 1, Qt.AlignLeft)
|
|
|
|
gridlayout.addWidget(self.buttonRemove, 1, 1, Qt.AlignLeft)
|
|
|
|
gridlayout.addWidget(self.buttonRestore, 2, 1, Qt.AlignLeft)
|
2020-08-17 02:13:20 +00:00
|
|
|
gridlayout.addWidget(self.buttonHelp, 3, 1, Qt.AlignLeft)
|
|
|
|
gridlayout.addWidget(self.tableView, 1, 0, 5, 1)
|
|
|
|
gridlayout.addItem(QSpacerItem(0, 0, QSizePolicy.Minimum, QSizePolicy.Expanding), 4, 1)
|
|
|
|
gridlayout.addWidget(self.buttonClose, 5, 1)
|
2020-07-28 14:33:28 +00:00
|
|
|
layout.addLayout(gridlayout)
|
|
|
|
|
|
|
|
# --- model --> view
|
|
|
|
def show(self):
|
|
|
|
super().show()
|
|
|
|
|
|
|
|
@pyqtSlot()
|
2020-08-17 02:13:20 +00:00
|
|
|
def addStringFromLineEdit(self):
|
2020-07-28 14:33:28 +00:00
|
|
|
text = self.linedit.text()
|
|
|
|
if not text:
|
|
|
|
return
|
2020-08-17 02:13:20 +00:00
|
|
|
try:
|
|
|
|
self.model.add(text)
|
|
|
|
except AlreadyThereException:
|
|
|
|
self.app.show_message("Expression already in the list.")
|
|
|
|
return
|
|
|
|
except Exception as e:
|
|
|
|
self.app.show_message(f"Expression is invalid: {e}")
|
|
|
|
return
|
2020-07-28 14:33:28 +00:00
|
|
|
self.linedit.clear()
|
|
|
|
|
2020-08-17 02:13:20 +00:00
|
|
|
def removeSelected(self):
|
2020-07-28 14:33:28 +00:00
|
|
|
self.model.remove_selected()
|
|
|
|
|
|
|
|
def restoreDefaults(self):
|
|
|
|
self.model.restore_defaults()
|
2020-08-17 02:13:20 +00:00
|
|
|
|
|
|
|
def display_help_message(self):
|
|
|
|
self.app.show_message("""\
|
|
|
|
These python regular expressions will filter out files and directory paths \
|
|
|
|
specified here.\nDuring directory selection, paths filtered here will be added as \
|
|
|
|
"Skipped" by default, but regular files will be ignored altogether during scans.""")
|